2018-05-04 16:08:28 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2015-10-21 05:03:22 +02:00
|
|
|
/*
|
|
|
|
* The following code handles the storage of PKCS 11 modules used by the
|
|
|
|
* NSS. This file is written to abstract away how the modules are
|
|
|
|
* stored so we can deside that later.
|
|
|
|
*/
|
|
|
|
#include "pkcs11i.h"
|
|
|
|
#include "sdb.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "prenv.h"
|
2018-05-04 16:08:28 +02:00
|
|
|
#include "utilpars.h"
|
2015-10-21 05:03:22 +02:00
|
|
|
|
|
|
|
#define FREE_CLEAR(p) if (p) { PORT_Free(p); p = NULL; }
|
|
|
|
|
|
|
|
static void
|
|
|
|
sftk_parseTokenFlags(char *tmp, sftk_token_parameters *parsed) {
|
2018-05-04 16:08:28 +02:00
|
|
|
parsed->readOnly = NSSUTIL_ArgHasFlag("flags","readOnly",tmp);
|
|
|
|
parsed->noCertDB = NSSUTIL_ArgHasFlag("flags","noCertDB",tmp);
|
|
|
|
parsed->noKeyDB = NSSUTIL_ArgHasFlag("flags","noKeyDB",tmp);
|
|
|
|
parsed->forceOpen = NSSUTIL_ArgHasFlag("flags","forceOpen",tmp);
|
|
|
|
parsed->pwRequired = NSSUTIL_ArgHasFlag("flags","passwordRequired",tmp);
|
|
|
|
parsed->optimizeSpace = NSSUTIL_ArgHasFlag("flags","optimizeSpace",tmp);
|
2015-10-21 05:03:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sftk_parseFlags(char *tmp, sftk_parameters *parsed) {
|
2018-05-04 16:08:28 +02:00
|
|
|
parsed->noModDB = NSSUTIL_ArgHasFlag("flags","noModDB",tmp);
|
|
|
|
parsed->readOnly = NSSUTIL_ArgHasFlag("flags","readOnly",tmp);
|
2015-10-21 05:03:22 +02:00
|
|
|
/* keep legacy interface working */
|
2018-05-04 16:08:28 +02:00
|
|
|
parsed->noCertDB = NSSUTIL_ArgHasFlag("flags","noCertDB",tmp);
|
|
|
|
parsed->forceOpen = NSSUTIL_ArgHasFlag("flags","forceOpen",tmp);
|
|
|
|
parsed->pwRequired = NSSUTIL_ArgHasFlag("flags","passwordRequired",tmp);
|
|
|
|
parsed->optimizeSpace = NSSUTIL_ArgHasFlag("flags","optimizeSpace",tmp);
|
2015-10-21 05:03:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CK_RV
|
|
|
|
sftk_parseTokenParameters(char *param, sftk_token_parameters *parsed)
|
|
|
|
{
|
|
|
|
int next;
|
2018-05-04 16:08:28 +02:00
|
|
|
char *tmp = NULL;
|
2015-10-21 05:03:22 +02:00
|
|
|
char *index;
|
2018-05-04 16:08:28 +02:00
|
|
|
index = NSSUTIL_ArgStrip(param);
|
2015-10-21 05:03:22 +02:00
|
|
|
|
|
|
|
while (*index) {
|
2018-05-04 16:08:28 +02:00
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->configdir,"configDir=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->updatedir,"updateDir=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->updCertPrefix,
|
|
|
|
"updateCertPrefix=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->updKeyPrefix,
|
|
|
|
"updateKeyPrefix=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->updateID,"updateID=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->certPrefix,"certPrefix=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->keyPrefix,"keyPrefix=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->tokdes,"tokenDescription=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->updtokdes,
|
2015-10-21 05:03:22 +02:00
|
|
|
"updateTokenDescription=",;)
|
2018-05-04 16:08:28 +02:00
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->slotdes,"slotDescription=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,tmp,"minPWLen=",
|
|
|
|
if(tmp) { parsed->minPW=atoi(tmp); PORT_Free(tmp); tmp = NULL; })
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,tmp,"flags=",
|
|
|
|
if(tmp) { sftk_parseTokenFlags(param,parsed); PORT_Free(tmp);
|
|
|
|
tmp = NULL; })
|
|
|
|
NSSUTIL_HANDLE_FINAL_ARG(index)
|
2015-10-21 05:03:22 +02:00
|
|
|
}
|
|
|
|
return CKR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sftk_parseTokens(char *tokenParams, sftk_parameters *parsed)
|
|
|
|
{
|
|
|
|
char *tokenIndex;
|
|
|
|
sftk_token_parameters *tokens = NULL;
|
|
|
|
int i=0,count = 0,next;
|
|
|
|
|
|
|
|
if ((tokenParams == NULL) || (*tokenParams == 0)) return;
|
|
|
|
|
|
|
|
/* first count the number of slots */
|
2018-05-04 16:08:28 +02:00
|
|
|
for (tokenIndex = NSSUTIL_ArgStrip(tokenParams); *tokenIndex;
|
|
|
|
tokenIndex = NSSUTIL_ArgStrip(NSSUTIL_ArgSkipParameter(tokenIndex))) {
|
2015-10-21 05:03:22 +02:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the data structures */
|
|
|
|
tokens = (sftk_token_parameters *)
|
|
|
|
PORT_ZAlloc(count*sizeof(sftk_token_parameters));
|
|
|
|
if (tokens == NULL) return;
|
|
|
|
|
2018-05-04 16:08:28 +02:00
|
|
|
for (tokenIndex = NSSUTIL_ArgStrip(tokenParams), i = 0;
|
2015-10-21 05:03:22 +02:00
|
|
|
*tokenIndex && i < count ; i++ ) {
|
|
|
|
char *name;
|
2018-05-04 16:08:28 +02:00
|
|
|
name = NSSUTIL_ArgGetLabel(tokenIndex,&next);
|
2015-10-21 05:03:22 +02:00
|
|
|
tokenIndex += next;
|
|
|
|
|
2018-05-04 16:08:28 +02:00
|
|
|
tokens[i].slotID = NSSUTIL_ArgDecodeNumber(name);
|
2015-10-21 05:03:22 +02:00
|
|
|
tokens[i].readOnly = PR_FALSE;
|
|
|
|
tokens[i].noCertDB = PR_FALSE;
|
|
|
|
tokens[i].noKeyDB = PR_FALSE;
|
2018-05-04 16:08:28 +02:00
|
|
|
if (!NSSUTIL_ArgIsBlank(*tokenIndex)) {
|
|
|
|
char *args = NSSUTIL_ArgFetchValue(tokenIndex,&next);
|
2015-10-21 05:03:22 +02:00
|
|
|
tokenIndex += next;
|
|
|
|
if (args) {
|
|
|
|
sftk_parseTokenParameters(args,&tokens[i]);
|
|
|
|
PORT_Free(args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (name) PORT_Free(name);
|
2018-05-04 16:08:28 +02:00
|
|
|
tokenIndex = NSSUTIL_ArgStrip(tokenIndex);
|
2015-10-21 05:03:22 +02:00
|
|
|
}
|
|
|
|
parsed->token_count = i;
|
|
|
|
parsed->tokens = tokens;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CK_RV
|
|
|
|
sftk_parseParameters(char *param, sftk_parameters *parsed, PRBool isFIPS)
|
|
|
|
{
|
|
|
|
int next;
|
2018-05-04 16:08:28 +02:00
|
|
|
char *tmp = NULL;
|
2015-10-21 05:03:22 +02:00
|
|
|
char *index;
|
|
|
|
char *certPrefix = NULL, *keyPrefix = NULL;
|
|
|
|
char *tokdes = NULL, *ptokdes = NULL, *pupdtokdes = NULL;
|
|
|
|
char *slotdes = NULL, *pslotdes = NULL;
|
|
|
|
char *fslotdes = NULL, *ftokdes = NULL;
|
|
|
|
char *minPW = NULL;
|
2018-05-04 16:08:28 +02:00
|
|
|
index = NSSUTIL_ArgStrip(param);
|
2015-10-21 05:03:22 +02:00
|
|
|
|
|
|
|
PORT_Memset(parsed, 0, sizeof(sftk_parameters));
|
|
|
|
|
|
|
|
while (*index) {
|
2018-05-04 16:08:28 +02:00
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->configdir,"configDir=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->updatedir,"updateDir=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->updateID,"updateID=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->secmodName,"secmod=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->man,"manufacturerID=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,parsed->libdes,"libraryDescription=",;)
|
2015-10-21 05:03:22 +02:00
|
|
|
/* constructed values, used so legacy interfaces still work */
|
2018-05-04 16:08:28 +02:00
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,certPrefix,"certPrefix=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,keyPrefix,"keyPrefix=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,tokdes,"cryptoTokenDescription=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,ptokdes,"dbTokenDescription=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,slotdes,"cryptoSlotDescription=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,pslotdes,"dbSlotDescription=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,fslotdes,"FIPSSlotDescription=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,ftokdes,"FIPSTokenDescription=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,pupdtokdes, "updateTokenDescription=",;)
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,minPW,"minPWLen=",;)
|
|
|
|
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,tmp,"flags=",
|
|
|
|
if(tmp) { sftk_parseFlags(param,parsed); PORT_Free(tmp);
|
|
|
|
tmp = NULL; })
|
|
|
|
NSSUTIL_HANDLE_STRING_ARG(index,tmp,"tokens=",
|
|
|
|
if(tmp) { sftk_parseTokens(tmp,parsed); PORT_Free(tmp); tmp = NULL; })
|
|
|
|
NSSUTIL_HANDLE_FINAL_ARG(index)
|
2015-10-21 05:03:22 +02:00
|
|
|
}
|
|
|
|
if (parsed->tokens == NULL) {
|
|
|
|
int count = isFIPS ? 1 : 2;
|
|
|
|
int index = count-1;
|
|
|
|
sftk_token_parameters *tokens = NULL;
|
|
|
|
|
|
|
|
tokens = (sftk_token_parameters *)
|
|
|
|
PORT_ZAlloc(count*sizeof(sftk_token_parameters));
|
|
|
|
if (tokens == NULL) {
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
parsed->tokens = tokens;
|
|
|
|
parsed->token_count = count;
|
|
|
|
tokens[index].slotID = isFIPS ? FIPS_SLOT_ID : PRIVATE_KEY_SLOT_ID;
|
|
|
|
tokens[index].certPrefix = certPrefix;
|
|
|
|
tokens[index].keyPrefix = keyPrefix;
|
|
|
|
tokens[index].minPW = minPW ? atoi(minPW) : 0;
|
|
|
|
tokens[index].readOnly = parsed->readOnly;
|
|
|
|
tokens[index].noCertDB = parsed->noCertDB;
|
|
|
|
tokens[index].noKeyDB = parsed->noCertDB;
|
|
|
|
tokens[index].forceOpen = parsed->forceOpen;
|
|
|
|
tokens[index].pwRequired = parsed->pwRequired;
|
|
|
|
tokens[index].optimizeSpace = parsed->optimizeSpace;
|
|
|
|
tokens[0].optimizeSpace = parsed->optimizeSpace;
|
|
|
|
certPrefix = NULL;
|
|
|
|
keyPrefix = NULL;
|
|
|
|
if (isFIPS) {
|
|
|
|
tokens[index].tokdes = ftokdes;
|
|
|
|
tokens[index].updtokdes = pupdtokdes;
|
|
|
|
tokens[index].slotdes = fslotdes;
|
|
|
|
fslotdes = NULL;
|
|
|
|
ftokdes = NULL;
|
|
|
|
pupdtokdes = NULL;
|
|
|
|
} else {
|
|
|
|
tokens[index].tokdes = ptokdes;
|
|
|
|
tokens[index].updtokdes = pupdtokdes;
|
|
|
|
tokens[index].slotdes = pslotdes;
|
|
|
|
tokens[0].slotID = NETSCAPE_SLOT_ID;
|
|
|
|
tokens[0].tokdes = tokdes;
|
|
|
|
tokens[0].slotdes = slotdes;
|
|
|
|
tokens[0].noCertDB = PR_TRUE;
|
|
|
|
tokens[0].noKeyDB = PR_TRUE;
|
|
|
|
pupdtokdes = NULL;
|
|
|
|
ptokdes = NULL;
|
|
|
|
pslotdes = NULL;
|
|
|
|
tokdes = NULL;
|
|
|
|
slotdes = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loser:
|
|
|
|
FREE_CLEAR(certPrefix);
|
|
|
|
FREE_CLEAR(keyPrefix);
|
|
|
|
FREE_CLEAR(tokdes);
|
|
|
|
FREE_CLEAR(ptokdes);
|
|
|
|
FREE_CLEAR(pupdtokdes);
|
|
|
|
FREE_CLEAR(slotdes);
|
|
|
|
FREE_CLEAR(pslotdes);
|
|
|
|
FREE_CLEAR(fslotdes);
|
|
|
|
FREE_CLEAR(ftokdes);
|
|
|
|
FREE_CLEAR(minPW);
|
|
|
|
return CKR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sftk_freeParams(sftk_parameters *params)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < params->token_count; i++) {
|
|
|
|
FREE_CLEAR(params->tokens[i].configdir);
|
|
|
|
FREE_CLEAR(params->tokens[i].certPrefix);
|
|
|
|
FREE_CLEAR(params->tokens[i].keyPrefix);
|
|
|
|
FREE_CLEAR(params->tokens[i].tokdes);
|
|
|
|
FREE_CLEAR(params->tokens[i].slotdes);
|
|
|
|
FREE_CLEAR(params->tokens[i].updatedir);
|
|
|
|
FREE_CLEAR(params->tokens[i].updCertPrefix);
|
|
|
|
FREE_CLEAR(params->tokens[i].updKeyPrefix);
|
|
|
|
FREE_CLEAR(params->tokens[i].updateID);
|
|
|
|
FREE_CLEAR(params->tokens[i].updtokdes);
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE_CLEAR(params->configdir);
|
|
|
|
FREE_CLEAR(params->secmodName);
|
|
|
|
FREE_CLEAR(params->man);
|
|
|
|
FREE_CLEAR(params->libdes);
|
|
|
|
FREE_CLEAR(params->tokens);
|
|
|
|
FREE_CLEAR(params->updatedir);
|
|
|
|
FREE_CLEAR(params->updateID);
|
|
|
|
}
|
|
|
|
|