367910 pk11mode added to build and fips.sh r=neil

This commit is contained in:
glen.beasley%sun.com 2007-01-25 19:04:57 +00:00
Родитель 335d80c9fe
Коммит d0f7b575b6
2 изменённых файлов: 207 добавлений и 82 удалений

Просмотреть файл

@ -63,6 +63,7 @@ DIRS = lib \
p7sign \
p7verify \
pk12util \
pk11mode \
pp \
rsaperf \
sdrtest \

Просмотреть файл

@ -51,9 +51,10 @@
#ifdef _WIN32
#include <windows.h>
#define LIB_NAME "softokn3.dll"
#else
#include "prlink.h"
#endif
#include "prlink.h"
#include "prprf.h"
#include "plgetopt.h"
#include "pkcs11.h"
@ -325,7 +326,8 @@ int MODE = FIPSMODE;
CK_BBOOL true = CK_TRUE;
CK_BBOOL false = CK_FALSE;
static const CK_BYTE PLAINTEXT[] = {"Firefox Rules!"};
static const CK_BYTE PLAINTEXT_PAD[] = {"Firefox and thunderbird rule the world!"};
static const CK_BYTE PLAINTEXT_PAD[] =
{"Firefox and thunderbird rule the world!"};
CK_ULONG NUMTESTS = 0;
static const char * slotFlagName[] = {
@ -462,7 +464,8 @@ CK_RV PKM_SecretKey(CK_FUNCTION_LIST_PTR pFunctionList, CK_SLOT_ID *pSlotList,
CK_ULONG slotID, CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen);
CK_RV PKM_PublicKey(CK_FUNCTION_LIST_PTR pFunctionList, CK_SLOT_ID *pSlotList,
CK_ULONG slotID, CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen);
CK_RV PKM_HybridMode(CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen);
CK_RV PKM_HybridMode(CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen,
CK_C_INITIALIZE_ARGS_NSS *initArgs);
CK_RV PKM_FindAllObjects(CK_FUNCTION_LIST_PTR pFunctionList,
CK_SLOT_ID * pSlotList, CK_ULONG slotID,
CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen);
@ -510,7 +513,8 @@ CK_RV PKM_DualFuncDigest(CK_FUNCTION_LIST_PTR pFunctionList,
CK_RV PKM_PubKeySign(CK_FUNCTION_LIST_PTR pFunctionList,
CK_SESSION_HANDLE hRwSession,
CK_OBJECT_HANDLE hPubKey, CK_OBJECT_HANDLE hPrivKey,
CK_MECHANISM *signMech, const CK_BYTE * pData, CK_ULONG dataLen);
CK_MECHANISM *signMech, const CK_BYTE * pData,
CK_ULONG dataLen);
CK_RV PKM_SecKeyCrypt(CK_FUNCTION_LIST_PTR pFunctionList,
CK_SESSION_HANDLE hSession,
CK_OBJECT_HANDLE hSymKey, CK_MECHANISM *cryptMech,
@ -535,6 +539,9 @@ CK_RV PKM_RecoverFunctions(CK_FUNCTION_LIST_PTR pFunctionList,
CK_OBJECT_HANDLE hPubKey, CK_OBJECT_HANDLE hPrivKey,
CK_MECHANISM *signMech, const CK_BYTE * pData,
CK_ULONG pDataLen);
void PKM_Help();
void PKM_CheckPath(char *string);
char *PKM_FilePasswd(char *pwFile);
int main(int argc, char **argv)
{
@ -543,25 +550,63 @@ int main(int argc, char **argv)
CK_RV crv = CKR_OK;
CK_C_INITIALIZE_ARGS_NSS initArgs;
CK_SLOT_ID *pSlotList = NULL;
CK_UTF8CHAR pwd[] ="1Mozilla";
CK_TOKEN_INFO tokenInfo;
CK_ULONG slotID;
CK_ULONG slotID = 0; /* slotID == 0 for FIPSMODE */
slotID = 0;
if (argc == 2) {
if (strcmp(argv[1], "FIPS") == 0) {
MODE = FIPSMODE;
} else {
CK_UTF8CHAR *pwd = NULL;
CK_ULONG pwdLen = 0;
char *moduleSpec = NULL;
char *configDir = NULL;
char *dbPrefix = NULL;
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "nh::f:d:p:");
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
if (PL_OPT_BAD == os) continue;
switch (opt->option)
{
case 'n': /* non fips mode */
MODE = NONFIPSMODE;
slotID = 1;
break;
case 'f': /* password file */
pwd = (CK_UTF8CHAR *) PKM_FilePasswd((char *)opt->value);
if (!pwd) PKM_Help();
break;
case 'd': /* opt_CertDir */
if (!opt->value) PKM_Help();
configDir = strdup(opt->value);
PKM_CheckPath(configDir);
break;
case 'p': /* opt_DBPrefix */
if (!opt->value) PKM_Help();
dbPrefix = strdup(opt->value);
break;
case 'h': /* help message */
default:
PKM_Help();
break;
}
} else MODE = FIPSMODE;
}
PL_DestroyOptState(opt);
if (!pwd) {
pwd = (CK_UTF8CHAR *)strdup("1Mozilla");
}
pwdLen = strlen((const char*)pwd);
if (!configDir) {
configDir = strdup(".");
}
if (!dbPrefix) {
dbPrefix = strdup("");
}
#ifdef _WIN32
hModule = LoadLibrary(LIB_NAME);
if (hModule == NULL) {
PKM_Error( "cannot load %s\n", LIB_NAME);
exit(1);
goto cleanup;
}
if (MODE == FIPSMODE) {
/* FIPS mode == FC_GetFunctionList */
@ -580,7 +625,7 @@ int main(int argc, char **argv)
}
if (pC_GetFunctionList == NULL) {
PKM_Error( "cannot load %s\n", LIB_NAME);
exit(1);
goto cleanup;
}
#else
{
@ -613,8 +658,10 @@ int main(int argc, char **argv)
initArgs.LockMutex = NULL;
initArgs.UnlockMutex = NULL;
initArgs.flags = CKF_OS_LOCKING_OK;
initArgs.LibraryParameters = (CK_CHAR_PTR *)
"configdir='.' certPrefix='' keyPrefix='' secmod='secmod.db' flags= ";
moduleSpec = PR_smprintf("configdir='%s' certPrefix='%s' "
"keyPrefix='%s' secmod='secmod.db' flags= ",
configDir, dbPrefix, dbPrefix);
initArgs.LibraryParameters = (CK_CHAR_PTR *) moduleSpec;
initArgs.pReserved = NULL;
/*DebugBreak();*/
@ -629,7 +676,7 @@ int main(int argc, char **argv)
} else {
PKM_Error( "C_Initialize failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_ShowInfo(pFunctionList, slotID);
if (crv == CKR_OK) {
@ -637,12 +684,12 @@ int main(int argc, char **argv)
} else {
PKM_Error( "PKM_ShowInfo failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
pSlotList = PKM_GetSlotList(pFunctionList, slotID);
if (pSlotList == NULL) {
PKM_Error( "PKM_GetSlotList failed with \n");
exit(1);
goto cleanup;
}
crv = pFunctionList->C_GetTokenInfo(pSlotList[slotID], &tokenInfo);
if (crv == CKR_OK) {
@ -650,13 +697,13 @@ int main(int argc, char **argv)
} else {
PKM_Error( "C_GetTokenInfo failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
if (!(tokenInfo.flags & CKF_USER_PIN_INITIALIZED)) {
PKM_LogIt("Initing PW for DB\n");
PKM_InitPWforDB(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd));
pwd, pwdLen);
} else {
PKM_LogIt("using existing DB\n");
}
@ -668,7 +715,7 @@ int main(int argc, char **argv)
} else {
PKM_Error( "PKM_Mechanism failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
/* RNG example without Login */
crv = PKM_RNG(pFunctionList, pSlotList, slotID);
@ -677,17 +724,17 @@ int main(int argc, char **argv)
} else {
PKM_Error( "PKM_RNG failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_SessionLogin(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd));
pwd, pwdLen);
if (crv == CKR_OK) {
PKM_LogIt("PKM_SessionLogin succeeded\n\n");
} else {
PKM_Error( "PKM_SessionLogin failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
/*
@ -696,62 +743,63 @@ int main(int argc, char **argv)
* then does digest, hmac, encrypt/decrypt, signing operations.
*/
crv = PKM_KeyTests(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd));
pwd, pwdLen);
if (crv == CKR_OK) {
PKM_LogIt("PKM_KeyTests succeeded\n\n");
} else {
PKM_Error( "PKM_KeyTest failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_SecretKey(pFunctionList, pSlotList, slotID, pwd, sizeof(pwd));
crv = PKM_SecretKey(pFunctionList, pSlotList, slotID, pwd,
pwdLen);
if (crv == CKR_OK) {
PKM_LogIt("PKM_SecretKey succeeded\n\n");
} else {
PKM_Error( "PKM_SecretKey failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_PublicKey(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd));
pwd, pwdLen);
if (crv == CKR_OK) {
PKM_LogIt("PKM_PublicKey succeeded\n\n");
} else {
PKM_Error( "PKM_PublicKey failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_OperationalState(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd));
pwd, pwdLen);
if (crv == CKR_OK) {
PKM_LogIt("PKM_OperationalState succeeded\n\n");
} else {
PKM_Error( "PKM_OperationalState failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_MultiObjectManagement(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd));
pwd, pwdLen);
if (crv == CKR_OK) {
PKM_LogIt("PKM_MultiObjectManagement succeeded\n\n");
} else {
PKM_Error( "PKM_MultiObjectManagement failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_LegacyFunctions(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd));
pwd, pwdLen);
if (crv == CKR_OK) {
PKM_LogIt("PKM_LegacyFunctions succeeded\n\n");
} else {
PKM_Error( "PKM_LegacyFunctions failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_TLSKeyAndMacDerive(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd),
pwd, pwdLen,
CKM_TLS_KEY_AND_MAC_DERIVE, CORRECT);
if (crv == CKR_OK) {
@ -759,36 +807,38 @@ int main(int argc, char **argv)
} else {
PKM_Error( "PKM_TLSKeyAndMacDerive failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_TLSMasterKeyDerive(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd),CKM_TLS_MASTER_KEY_DERIVE,
pwd, pwdLen,
CKM_TLS_MASTER_KEY_DERIVE,
CORRECT);
if (crv == CKR_OK) {
PKM_LogIt("PKM_TLSMasterKeyDerive succeeded\n\n");
} else {
PKM_Error( "PKM_TLSMasterKeyDerive failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_TLSMasterKeyDerive(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd),CKM_TLS_MASTER_KEY_DERIVE_DH,
pwd, pwdLen,
CKM_TLS_MASTER_KEY_DERIVE_DH,
CORRECT);
if (crv == CKR_OK) {
PKM_LogIt("PKM_TLSMasterKeyDerive succeeded\n\n");
} else {
PKM_Error( "PKM_TLSMasterKeyDerive failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = PKM_FindAllObjects(pFunctionList, pSlotList, slotID,
pwd, sizeof(pwd));
pwd, pwdLen);
if (crv == CKR_OK) {
PKM_LogIt("PKM_FindAllObjects succeeded\n\n");
} else {
PKM_Error( "PKM_FindAllObjects failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
crv = pFunctionList->C_Finalize(NULL);
if (crv == CKR_OK) {
@ -796,7 +846,7 @@ int main(int argc, char **argv)
} else {
PKM_Error( "C_Finalize failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
if (pSlotList) free(pSlotList);
@ -806,19 +856,34 @@ int main(int argc, char **argv)
/* mode to FIPS mode */
PKM_LogIt("Testing Hybrid mode \n");
crv = PKM_HybridMode(pwd, sizeof(pwd));
crv = PKM_HybridMode(pwd, pwdLen, &initArgs);
if (crv == CKR_OK) {
PKM_LogIt("PKM_HybridMode succeeded\n");
} else {
PKM_Error( "PKM_HybridMode failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
goto cleanup;
}
PKM_LogIt("**** ALL TESTS PASSED ****\n");
PKM_LogIt("**** Total number of TESTS %d. ****\n", NUMTESTS);
PKM_LogIt("unloading NSS PKCS # 11 softoken and exiting\n");
cleanup:
if (pwd) {
free(pwd);
}
if (configDir) {
free(configDir);
}
if (dbPrefix) {
free(dbPrefix);
}
if (moduleSpec) {
free(moduleSpec);
}
#ifdef _WIN32
FreeLibrary(hModule);
#else
@ -1147,8 +1212,9 @@ CK_RV PKM_KeyTests(CK_FUNCTION_LIST_PTR pFunctionList,
PKM_Error("C_GenerateKeyPair succeeded when not logged in.\n");
return CKR_GENERAL_ERROR;
} else {
PKM_LogIt("C_GenerateKeyPair failed as EXPECTED with 0x%08X, %-26s\n"
"since not logged in\n", crv, PKM_CK_RVtoStr(crv));
PKM_LogIt("C_GenerateKeyPair failed as EXPECTED with 0x%08X, "
"%-26s\n since not logged in\n", crv,
PKM_CK_RVtoStr(crv));
}
}
@ -1348,7 +1414,7 @@ CK_RV PKM_KeyTests(CK_FUNCTION_LIST_PTR pFunctionList,
} else {
PKM_Error( "PKM_RecoverFunctions failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
exit(1);
return crv;
}
mech.pParameter = NULL;
@ -1650,7 +1716,6 @@ void PKM_Error(const char *fmt, ...) {
} else fprintf(stderr, "NOMODE PKM_Error: ");
vfprintf(stderr, fmt, args);
va_end(args);
exit(1);
}
CK_SLOT_ID *PKM_GetSlotList(CK_FUNCTION_LIST_PTR pFunctionList,
CK_ULONG slotID) {
@ -1755,7 +1820,7 @@ CK_RV PKM_InitPWforDB(CK_FUNCTION_LIST_PTR pFunctionList,
PKM_LogIt("CKU_USER 0x%08X \n", CKU_USER);
crv = pFunctionList->C_Login(hSession, CKU_USER, (CK_UTF8CHAR *) testPin,
sizeof(testPin));
strlen((const char *)testPin));
if (crv != CKR_OK) {
PKM_Error( "C_Login failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
@ -1764,9 +1829,9 @@ CK_RV PKM_InitPWforDB(CK_FUNCTION_LIST_PTR pFunctionList,
if (MODE == FIPSMODE) {
crv = pFunctionList->C_SetPIN(
hSession, (CK_UTF8CHAR *) testPin,
sizeof(testPin),
strlen((const char *)testPin),
(CK_UTF8CHAR *) weakPin,
sizeof(weakPin));
strlen((const char *)weakPin));
if (crv == CKR_OK) {
PKM_Error( "C_SetPIN with a weak password succeeded\n");
return crv;
@ -1777,7 +1842,7 @@ CK_RV PKM_InitPWforDB(CK_FUNCTION_LIST_PTR pFunctionList,
}
crv = pFunctionList->C_SetPIN(
hSession, (CK_UTF8CHAR *) testPin,
sizeof(testPin),
strlen((const char *)testPin),
pwd, pwdLen);
if (crv != CKR_OK) {
PKM_Error( "C_CSetPin failed with 0x%08X, %-26s\n", crv,
@ -1927,7 +1992,8 @@ CK_RV PKM_ShowInfo(CK_FUNCTION_LIST_PTR pFunctionList, CK_ULONG slotID) {
/* is inactive. */
/* PKM_HybridMode demostrates how an application can switch between the */
/* two modes: FIPS Approved mode and NONFIPS mode. */
CK_RV PKM_HybridMode(CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen) {
CK_RV PKM_HybridMode(CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen,
CK_C_INITIALIZE_ARGS_NSS *initArgs) {
CK_C_GetFunctionList pC_GetFunctionList; /* NONFIPSMode */
CK_FUNCTION_LIST_PTR pC_FunctionList;
@ -1941,7 +2007,6 @@ CK_RV PKM_HybridMode(CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen) {
CK_RV crv = CKR_OK;
CK_C_INITIALIZE_ARGS_NSS initArgs;
CK_SESSION_HANDLE hSession;
NUMTESTS++; /* increment NUMTESTS */
@ -1964,17 +2029,8 @@ CK_RV PKM_HybridMode(CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen) {
crv = (*pC_GetFunctionList)(&pC_FunctionList);
assert(crv == CKR_OK);
initArgs.CreateMutex = NULL;
initArgs.DestroyMutex = NULL;
initArgs.LockMutex = NULL;
initArgs.UnlockMutex = NULL;
initArgs.flags = CKF_OS_LOCKING_OK;
initArgs.LibraryParameters = (CK_CHAR_PTR *)
"configdir='.' certPrefix='' keyPrefix='' secmod='secmod.db' flags= ";
initArgs.pReserved = NULL;
/* invoke C_Initialize as pC_FunctionList->C_Initialize */
crv = pC_FunctionList->C_Initialize(&initArgs);
crv = pC_FunctionList->C_Initialize(initArgs);
if (crv == CKR_OK) {
PKM_LogIt("C_Initialize succeeded\n");
} else {
@ -2044,7 +2100,7 @@ CK_RV PKM_HybridMode(CK_UTF8CHAR_PTR pwd, CK_ULONG pwdLen) {
assert(crv == CKR_OK);
/* invoke FC_Initialize as pFunctionList->C_Initialize */
crv = pFC_FunctionList->C_Initialize(&initArgs);
crv = pFC_FunctionList->C_Initialize(initArgs);
if (crv == CKR_OK) {
PKM_LogIt("FC_Initialize succeeded\n");
} else {
@ -2279,30 +2335,33 @@ CK_RV PKM_SessionLogin(CK_FUNCTION_LIST_PTR pFunctionList,
return crv;
}
crv = pFunctionList->C_Login(hSession, CKU_USER, (unsigned char *) "netscape", 8);
crv = pFunctionList->C_Login(hSession, CKU_USER, (unsigned char *)
"netscape", 8);
if (crv == CKR_OK) {
PKM_Error( "C_Login with wrong password succeeded\n");
return crv;
} else {
PKM_LogIt("C_Login with wrong password failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
PKM_LogIt("C_Login with wrong password failed with 0x%08X, "
"%-26s\n", crv, PKM_CK_RVtoStr(crv));
}
crv = pFunctionList->C_Login(hSession, CKU_USER, (unsigned char *) "red hat", 7);
crv = pFunctionList->C_Login(hSession, CKU_USER, (unsigned char *)
"red hat", 7);
if (crv == CKR_OK) {
PKM_Error( "C_Login with wrong password succeeded\n");
return crv;
} else {
PKM_LogIt("C_Login with wrong password failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
PKM_LogIt("C_Login with wrong password failed with 0x%08X, %-26s\n",
crv, PKM_CK_RVtoStr(crv));
}
crv = pFunctionList->C_Login(hSession, CKU_USER, (unsigned char *) "sun", 3);
crv = pFunctionList->C_Login(hSession, CKU_USER,
(unsigned char *) "sun", 3);
if (crv == CKR_OK) {
PKM_Error( "C_Login with wrong password succeeded\n");
return crv;
} else {
PKM_LogIt("C_Login with wrong password failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
PKM_LogIt("C_Login with wrong password failed with 0x%08X, %-26s\n",
crv, PKM_CK_RVtoStr(crv));
}
crv = pFunctionList->C_Login(hSession, CKU_USER, pwd, pwdLen);
if (crv == CKR_OK) {
@ -2852,7 +2911,8 @@ CK_RV PKM_SecretKey(CK_FUNCTION_LIST_PTR pFunctionList,
return crv;
}
ciphertextLen = sizeof(ciphertext);
crv = pFunctionList->C_Encrypt(hSession, (CK_BYTE *) PLAINTEXT, sizeof(PLAINTEXT),
crv = pFunctionList->C_Encrypt(hSession, (CK_BYTE *) PLAINTEXT,
sizeof(PLAINTEXT),
ciphertext, &ciphertextLen);
if (crv != CKR_OK) {
PKM_Error( "C_Encrypt failed with 0x%08X, %-26s\n", crv,
@ -3054,7 +3114,8 @@ CK_RV PKM_PubKeySign(CK_FUNCTION_LIST_PTR pFunctionList,
PKM_CK_RVtoStr(crv));
return crv;
}
crv = pFunctionList->C_VerifyUpdate(hRwSession, (CK_BYTE * ) pData, pDataLen);
crv = pFunctionList->C_VerifyUpdate(hRwSession, (CK_BYTE * ) pData,
pDataLen);
if (crv != CKR_OK) {
PKM_Error( "C_VerifyUpdate failed with 0x%08X, %-26s\n", crv,
PKM_CK_RVtoStr(crv));
@ -4096,7 +4157,8 @@ CK_RV PKM_OperationalState(CK_FUNCTION_LIST_PTR pFunctionList,
static const CK_UTF8CHAR *plaintext = (CK_UTF8CHAR *)"Firefox rules.";
static const CK_UTF8CHAR *plaintext_1 = (CK_UTF8CHAR *)"Thunderbird rules.";
static const CK_UTF8CHAR *plaintext_2 = (CK_UTF8CHAR *)"Firefox and Thunderbird.";
static const CK_UTF8CHAR *plaintext_2 = (CK_UTF8CHAR *)
"Firefox and Thunderbird.";
char digest[MAX_DIGEST_SZ], digest_1[MAX_DIGEST_SZ];
char sign[MAX_SIG_SZ];
@ -5196,3 +5258,65 @@ CK_RV PKM_Digest(CK_FUNCTION_LIST_PTR pFunctionList,
}
char * PKM_FilePasswd(char *pwFile)
{
unsigned char phrase[200];
PRFileDesc *fd;
PRInt32 nb;
int i;
if (!pwFile)
return 0;
fd = PR_Open(pwFile, PR_RDONLY, 0);
if (!fd) {
fprintf(stderr, "No password file \"%s\" exists.\n", pwFile);
return NULL;
}
nb = PR_Read(fd, phrase, sizeof(phrase));
PR_Close(fd);
/* handle the Windows EOL case */
i = 0;
while (phrase[i] != '\r' && phrase[i] != '\n' && i < nb) i++;
phrase[i] = '\0';
if (nb == 0) {
fprintf(stderr,"password file contains no data\n");
return NULL;
}
return (char*) strdup((char*)phrase);
}
void PKM_Help()
{
PRFileDesc *debug_out = PR_GetSpecialFD(PR_StandardError);
PR_fprintf(debug_out, "pk11mode test program usage:\n");
PR_fprintf(debug_out, "\t-f <file> Password File : echo pw > file \n");
PR_fprintf(debug_out, "\t-n Non Fips Mode \n");
PR_fprintf(debug_out, "\t-d <path> Database path location)\n");
PR_fprintf(debug_out, "\t-p <prefix> DataBase prefix)\n");
PR_fprintf(debug_out, "\t-h this help message\n");
exit(1);
}
void PKM_CheckPath(char *string)
{
char *src;
char *dest;
/*
* windows support convert any back slashes to
* forward slashes.
*/
for (src=string, dest=string; *src; src++,dest++) {
if (*src == '\\') {
*dest = '/';
}
}
dest--;
/* if the last char is a / set it to 0 */
if (*dest == '/')
*dest = 0;
}