Configurable for PKCS#11 v2.20 related changes.

- Correctly report Cryptoki version if v2.20 is used.
 - Consistently report no version for hardware/software we know no version information about.



git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3627 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
martin 2009-01-19 12:06:38 +00:00
parent 4d5c61d90c
commit c58bcfab84
6 changed files with 20 additions and 10 deletions

View File

@ -300,6 +300,12 @@ app default {
# Parameters for the OpenSC PKCS11 module
app opensc-pkcs11 {
pkcs11 {
# Should the module work in PKCS#11 v2.20 (instead of v2.11) mode?
# This affects slot changes and PC/SC PnP, as v2.11 applications
# are not allowed to change the length of the slot list.
# Default: false
# v2_20_mode = true;
# Maximum Number of virtual slots.
# If there are more slots than defined here,
# the remaining slots will be hidden from PKCS#11.

View File

@ -212,9 +212,9 @@ static void pkcs15_init_token_info(struct sc_pkcs15_card *card, CK_TOKEN_INFO_PT
pToken->ulFreePublicMemory = CK_UNAVAILABLE_INFORMATION;
pToken->ulTotalPrivateMemory = CK_UNAVAILABLE_INFORMATION;
pToken->ulFreePrivateMemory = CK_UNAVAILABLE_INFORMATION;
pToken->hardwareVersion.major = 1;
pToken->hardwareVersion.major = 0;
pToken->hardwareVersion.minor = 0;
pToken->firmwareVersion.major = 1;
pToken->firmwareVersion.major = 0;
pToken->firmwareVersion.minor = 0;
}

View File

@ -82,9 +82,9 @@ static CK_RV pkcs15init_create_tokens(struct sc_pkcs11_card *p11card)
pToken->ulFreePublicMemory = CK_UNAVAILABLE_INFORMATION;
pToken->ulTotalPrivateMemory = CK_UNAVAILABLE_INFORMATION;
pToken->ulFreePrivateMemory = CK_UNAVAILABLE_INFORMATION;
pToken->hardwareVersion.major = 1;
pToken->hardwareVersion.major = 0;
pToken->hardwareVersion.minor = 0;
pToken->firmwareVersion.major = 1;
pToken->firmwareVersion.major = 0;
pToken->firmwareVersion.minor = 0;
}

View File

@ -317,6 +317,7 @@ void load_pkcs11_parameters(struct sc_pkcs11_config *conf, sc_context_t *ctx)
int i;
/* Set defaults */
conf->v2_20_mode = 0;
conf->max_virtual_slots = 16;
conf->slots_per_card = 4;
conf->hide_empty_tokens = 0;
@ -330,6 +331,7 @@ void load_pkcs11_parameters(struct sc_pkcs11_config *conf, sc_context_t *ctx)
return;
/* contains the defaults, if there is a "pkcs11" config block */
conf->v2_20_mode = scconf_get_bool(conf_block, "v2_20_mode", conf->v2_20_mode);
conf->max_virtual_slots = scconf_get_int(conf_block, "max_virtual_slots", conf->max_virtual_slots);
/*XXX: rename the option in 0.12+ */
conf->slots_per_card = scconf_get_int(conf_block, "num_slots", conf->slots_per_card);

View File

@ -295,15 +295,15 @@ CK_RV C_GetInfo(CK_INFO_PTR pInfo)
memset(pInfo, 0, sizeof(CK_INFO));
pInfo->cryptokiVersion.major = 2;
pInfo->cryptokiVersion.minor = 11;
pInfo->cryptokiVersion.minor = sc_pkcs11_conf.v2_20_mode ? 20 : 11;
strcpy_bp(pInfo->manufacturerID,
"OpenSC (www.opensc-project.org)",
sizeof(pInfo->manufacturerID));
strcpy_bp(pInfo->libraryDescription,
"smart card PKCS#11 API",
sizeof(pInfo->libraryDescription));
pInfo->libraryVersion.major = 1;
pInfo->libraryVersion.minor = 0;
pInfo->libraryVersion.major = 0;
pInfo->libraryVersion.minor = 0; /* FIXME: use 0.116 for 0.11.6 from autoconf */
out: sc_pkcs11_unlock();
return rv;
@ -347,7 +347,8 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
}
sc_debug(context, "Getting slot listing\n");
if (pSlotList == NULL_PTR) {
/* Slot list can only change in v2.20 */
if (pSlotList == NULL_PTR && sc_pkcs11_conf.v2_20_mode) {
sc_ctx_detect_readers(context);
}
card_detect_all();
@ -684,7 +685,7 @@ sc_pkcs11_init_lock(CK_C_INITIALIZE_ARGS_PTR args)
/* Shall be used in threaded envirnoment, must use app provided locking */
global_locking = args;
} else if (!applock && !oslock) {
/* Shall not be used in threaded environemtn, use operating system locking */
/* Shall not be used in threaded environment, use operating system locking */
global_locking = default_mutex_funcs;
}
@ -753,7 +754,7 @@ void sc_pkcs11_free_lock(void)
}
CK_FUNCTION_LIST pkcs11_function_list = {
{ 2, 11 },
{ 2, 11 }, /* Note: NSS/Firefox ignores this version number and uses C_GetInfo() */
C_Initialize,
C_Finalize,
C_GetInfo,

View File

@ -87,6 +87,7 @@ struct sc_pkcs11_pool {
};
struct sc_pkcs11_config {
unsigned int v2_20_mode;
unsigned int max_virtual_slots;
unsigned int slots_per_card;
unsigned char hide_empty_tokens;