pk11.c revision e20788e1216ed720aefa84f3295f7899d9f28c22
a86310b25a2fc01f76df88293287b3908ab3d7f0Mark Andrews * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
0762ca086ec6768356d75c0684f883fcb9fa70c0Mark Andrews * Permission to use, copy, modify, and/or distribute this software for any
6b9f38958cf2859836f7eda7f6fd23f79282ec49Mark Andrews * purpose with or without fee is hereby granted, provided that the above
f2720d2436969ffac9e9fff547f23dd9f963af8cEvan Hunt * copyright notice and this permission notice appear in all copies.
52f38b35e770252ee0488ef25e58f964359be0c0Evan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
ad309e8dfa0601d6053aaa12770a98a6940f89deEvan Hunt * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
52f38b35e770252ee0488ef25e58f964359be0c0Evan Hunt * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
d77cb075aae5595e460e3299bfc1e8ea5d42b560Evan Hunt * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
c80e152862cc3e3207dc837fde7116bd4c0e4b9dTinderbox User * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
d77cb075aae5595e460e3299bfc1e8ea5d42b560Evan Hunt * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* use in the OpenSSL Toolkit (http://www.openssl.org/).
* This project also referenced hw_pkcs11-0.9.7b.patch written by
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
#include <config.h>
#ifdef USE_PKCS11
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef PK11_NO_LOGERR
struct iscpk11_session {
unsigned int magic;
struct iscpk11_token {
unsigned int magic;
unsigned int operations;
static void choose_slots(void);
#ifndef PK11_LIB_LOCATION
#ifndef WIN32
pk11_get_lib_name(void) {
return (lib_name);
initialize(void) {
char *pk11_provider;
void *ptr;
return (ptr);
if (initialized) {
lib_name);
choose_slots();
#ifdef PKCS11CRYPTO
dst__pkcs11_destroy(void) {
return (ret);
pk11_shutdown(void) {
(void) dst__pkcs11_destroy();
return (ret);
return (ISC_R_SUCCESS);
return (DST_R_CRYPTOFAILURE);
goto cleanup;
goto cleanup;
goto cleanup;
switch(optype) {
#ifdef PKCS11CRYPTO
case OP_RAND:
case OP_DIGEST:
case OP_ANY:
#ifdef PKCS11CRYPTO
return (ISC_R_NOTFOUND);
return (ISC_R_NOTFOUND);
if (logon)
return (ret);
return (ISC_R_NOMEMORY);
return (ret);
static isc_result_t
free_all_sessions(void) {
return (ret);
static isc_result_t
return (ret);
static isc_result_t
if (rw)
return (DST_R_CRYPTOFAILURE);
return (ISC_R_SUCCESS);
static isc_result_t
#if PK11_NO_LOGERR
return (ret);
choose_slots(void) {
slotCount = 0;
if (slotCount == 0)
for (i = 0; i < slotCount; i++) {
goto try_rsa;
&mechInfo);
goto try_dsa;
&mechInfo);
goto try_dsa;
&mechInfo);
goto try_dsa;
&mechInfo);
goto try_dsa;
&mechInfo);
goto try_dsa;
&mechInfo);
goto try_dh;
&mechInfo);
goto try_dh;
goto try_dh;
#ifdef notdef
&mechInfo);
goto try_digest;
&mechInfo);
goto try_digest;
&mechInfo);
goto try_digest;
#ifdef PKCS11CRYPTOWITHHMAC
&mechInfo);
goto try_gost;
goto try_gost;
&mechInfo);
&mechInfo);
switch (optype) {
case OP_RAND:
case OP_RSA:
case OP_DSA:
case OP_DH:
case OP_DIGEST:
case OP_EC:
case OP_GOST:
unsigned int bitcnt, i;
if (bytecnt == 0)
for (i = 0; i < bytecnt; i++) {
if (top == 0) {
return (bitcnt);
INSIST(0);
return (NULL);
return (next);
return (attr);
return (NULL);
return (NULL);
return (NULL);
(*len)++;
(*len)++;
static isc_boolean_t
static CK_ATTRIBUTE *
return (NULL);
return (NULL);
return (attr);
return (ISC_R_NOMEMORY);
if (p == NULL)
a = na;
if (p == NULL) {
na = p;
if (p != NULL) {
v = percent_decode(v, &l);
if (v == NULL)
goto err;
goto err;
goto err;
if (gotpin) {
err:
return (ret);
pk11_dump_tokens(void)
if (!first)
if (!first)
if (!first)
if (!first)
if (!first)
if (!first)