Skip to content

Commit

Permalink
Bug 1395495, modutil: Initialize DB with empty password on -create, r…
Browse files Browse the repository at this point in the history
…=kaie
  • Loading branch information
ueno committed Sep 15, 2017
1 parent f82b6c3 commit 840ed75
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/modutil/error.h
Expand Up @@ -57,6 +57,7 @@ typedef enum {
UNSPECIFIED_ERR,
NOCERTDB_MISUSE_ERR,
NSS_INITIALIZE_FAILED_ERR,
INITPW_FAILED_ERR,

LAST_ERR /* must be last */
} Error;
Expand Down Expand Up @@ -110,7 +111,8 @@ static char *errStrings[] = {
"ERROR: Unable to read from standard input.\n",
"ERROR: Unknown error occurred.\n",
"ERROR: -nocertdb option can only be used with the -jar command.\n",
"ERROR: NSS_Initialize() failed.\n"
"ERROR: NSS_Initialize() failed.\n",
"ERROR: Unable to set initial password on the database.\n"
};

typedef enum {
Expand Down
2 changes: 1 addition & 1 deletion cmd/modutil/modutil.c
Expand Up @@ -865,7 +865,7 @@ main(int argc, char* argv[])
errcode = ChangePW(tokenName, pwFile, newpwFile);
break;
case CREATE_COMMAND:
/* The work was already done in init_crypto() */
errcode = InitPW();
break;
case DEFAULT_COMMAND:
errcode = SetDefaultModule(moduleName, slotName, mechanisms);
Expand Down
1 change: 1 addition & 0 deletions cmd/modutil/modutil.h
Expand Up @@ -29,6 +29,7 @@ Error AddModule(char *moduleName, char *libFile, char *ciphers,
Error DeleteModule(char *moduleName);
Error ListModule(char *moduleName);
Error ListModules();
Error InitPW(void);
Error ChangePW(char *tokenName, char *pwFile, char *newpwFile);
Error EnableModule(char *moduleName, char *slotName, PRBool enable);
Error RawAddModule(char *dbmodulespec, char *modulespec);
Expand Down
33 changes: 33 additions & 0 deletions cmd/modutil/pk11.c
Expand Up @@ -668,6 +668,39 @@ ListModule(char *moduleName)
return rv;
}

/************************************************************************
*
* I n i t P W
*/
Error
InitPW(void)
{
PK11SlotInfo *slot;
Error ret = UNSPECIFIED_ERR;

slot = PK11_GetInternalKeySlot();
if (!slot) {
PR_fprintf(PR_STDERR, errStrings[NO_SUCH_TOKEN_ERR], "internal");
return NO_SUCH_TOKEN_ERR;
}

/* Set the initial password to empty */
if (PK11_NeedUserInit(slot)) {
if (PK11_InitPin(slot, NULL, "") != SECSuccess) {
PR_fprintf(PR_STDERR, errStrings[INITPW_FAILED_ERR]);
ret = INITPW_FAILED_ERR;
goto loser;
}
}

ret = SUCCESS;

loser:
PK11_FreeSlot(slot);

return ret;
}

/************************************************************************
*
* C h a n g e P W
Expand Down
14 changes: 14 additions & 0 deletions tests/tools/tools.sh
Expand Up @@ -497,6 +497,19 @@ SIGNSCRIPT

}

tools_modutil()
{
echo "$SCRIPTNAME: Test if DB created by modutil -create is initialized"
mkdir -p ${R_TOOLSDIR}/moddir
modu -create -dbdir "${R_TOOLSDIR}/moddir" 2>&1
ret=$?
${BINDIR}/certutil -S -s 'CN=TestUser' -d "${TOOLSDIR}/moddir" -n TestUser \
-x -t ',,' -z "${R_NOISE_FILE}"
ret=$?
html_msg $ret 0 "Test if DB created by modutil -create is initialized"
check_tmpfile
}

############################## tools_cleanup ###########################
# local shell function to finish this script (no exit since it might be
# sourced)
Expand All @@ -513,6 +526,7 @@ tools_cleanup()
tools_init
tools_p12
tools_sign
tools_modutil
tools_cleanup


0 comments on commit 840ed75

Please sign in to comment.