Add TLS and SSL flags to modutil.

Allow the Default flag to work specifically on a slot.
This commit is contained in:
relyea%netscape.com 2000-05-16 17:27:29 +00:00
parent 673272c023
commit edb6ec0cf5
5 changed files with 707 additions and 354 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,3 @@
#define OPENBRACE 257
#define CLOSEBRACE 258
#define STRING 259
# define OPENBRACE 257
# define CLOSEBRACE 258
# define STRING 259

View File

@ -659,6 +659,7 @@ usage()
"-create Create a new set of security databases\n"
"-default MODULE Make the given module a default provider\n"
" -mechanisms MECHANISM_LIST of the given mechanisms\n"
" [-slot SLOT] limit change to only the given slot\n"
"-delete MODULE Remove the named module from the module\n"
" database\n"
"-disable MODULE Disable the named module\n"
@ -679,6 +680,7 @@ usage()
" or about all modules if none is specified\n"
"-undefault MODULE The given module is NOT a default provider\n"
" -mechanisms MECHANISM_LIST of the listed mechanisms\n"
" [-slot SLOT] limit change to only the given slot\n"
"---------------------------------------------------------------------------\n"
"\n"
" OPTIONS\n"
@ -689,7 +691,8 @@ usage()
"---------------------------------------------------------------------------\n"
"\n"
"Mechanism lists are colon-separated. The following mechanisms are recognized:\n"
"RSA, DSA, RC2, RC4, RC5, DES, DH, FORTEZZA, SHA1, MD5, MD2, RANDOM, FRIENDLY\n"
"RSA, DSA, RC2, RC4, RC5, DES, DH, FORTEZZA, SHA1, MD5, MD2, SSL, TLS, RANDOM,\n"
" FRIENDLY\n"
"\n"
"Cipher lists are colon-separated. The following ciphers are recognized:\n"
"FORTEZZA\n"
@ -774,7 +777,7 @@ main(int argc, char *argv[])
/* The work was already done in init_crypto() */
break;
case DEFAULT_COMMAND:
errcode = SetDefaultModule(moduleName, mechanisms);
errcode = SetDefaultModule(moduleName, slotName, mechanisms);
break;
case DELETE_COMMAND:
errcode = DeleteModule(moduleName);
@ -801,7 +804,7 @@ main(int argc, char *argv[])
}
break;
case UNDEFAULT_COMMAND:
errcode = UnsetDefaultModule(moduleName, mechanisms);
errcode = UnsetDefaultModule(moduleName, slotName, mechanisms);
break;
default:
PR_fprintf(PR_STDERR, "This command is not supported yet.\n");

View File

@ -57,8 +57,8 @@ Error ListModule(char *moduleName);
Error ListModules();
Error ChangePW(char *tokenName, char *pwFile, char *newpwFile);
Error EnableModule(char *moduleName, char *slotName, PRBool enable);
Error SetDefaultModule(char *moduleName, char *mechanisms);
Error UnsetDefaultModule(char *moduleName, char *mechanisms);
Error SetDefaultModule(char *moduleName, char *slotName, char *mechanisms);
Error UnsetDefaultModule(char *moduleName, char *slotName, char *mechanisms);
void out_of_memory(void);
#endif /*MODUTIL_H*/

View File

@ -111,6 +111,8 @@ static MaskString mechanismStrings[] = {
{"SHA1", PUBLIC_MECH_SHA1_FLAG},
{"MD5", PUBLIC_MECH_MD5_FLAG},
{"MD2", PUBLIC_MECH_MD2_FLAG},
{"SSL", PUBLIC_MECH_SSL_FLAG},
{"TLS", PUBLIC_MECH_TLS_FLAG},
{"RANDOM", PUBLIC_MECH_RANDOM_FLAG},
{"FRIENDLY", PUBLIC_MECH_FRIENDLY_FLAG}
};
@ -447,6 +449,12 @@ ListModule(char *moduleName)
/* Slot Info */
PR_fprintf(PR_STDOUT, "\n"PAD"Slot: %s\n", PK11_GetSlotName(slot));
mechanisms = getStringFromFlags(slot->defaultFlags,
mechanismStrings, numMechanismStrings);
if(mechanisms[0] =='\0') {
mechanisms = "None";
}
PR_fprintf(PR_STDOUT, PAD"Slot Mechanism Flags: %s\n", mechanisms);
PR_fprintf(PR_STDOUT, PAD"Manufacturer: %.32s\n",
slotinfo.manufacturerID);
if(slot->isHW) {
@ -671,13 +679,14 @@ EnableModule(char *moduleName, char *slotName, PRBool enable)
*
*/
Error
SetDefaultModule(char *moduleName, char *mechanisms)
SetDefaultModule(char *moduleName, char *slotName, char *mechanisms)
{
SECMODModule *module;
PK11SlotInfo *slot;
int s, i;
unsigned long mechFlags = getFlagsFromString(mechanisms, mechanismStrings,
numMechanismStrings);
PRBool found = PR_FALSE;
Error errcode = UNSPECIFIED_ERR;
mechFlags = SECMOD_PubMechFlagstoInternal(mechFlags);
@ -693,6 +702,15 @@ SetDefaultModule(char *moduleName, char *mechanisms)
for(s=0; s < module->slotCount; s++) {
slot = module->slots[s];
if ((slotName != NULL) &&
!((strcmp(PK11_GetSlotName(slot),slotName) == 0) ||
(strcmp(PK11_GetTokenName(slot),slotName) == 0)) ) {
/* we are only interested in changing the one slot */
continue;
}
found = PR_TRUE;
/* Go through each mechanism */
for(i=0; i < num_pk11_default_mechanisms; i++) {
if(PK11_DefaultArray[i].flag & mechFlags) {
@ -702,6 +720,11 @@ SetDefaultModule(char *moduleName, char *mechanisms)
}
}
}
if (slotName && !found) {
PR_fprintf(PR_STDERR, errStrings[NO_SUCH_SLOT_ERR], slotName);
errcode = NO_SUCH_SLOT_ERR;
goto loser;
}
/* Delete and re-add module to save changes */
if( SECMOD_DeletePermDB(module) != SECSuccess ) {
@ -730,13 +753,14 @@ loser:
* U n s e t D e f a u l t M o d u l e
*/
Error
UnsetDefaultModule(char *moduleName, char *mechanisms)
UnsetDefaultModule(char *moduleName, char *slotName, char *mechanisms)
{
SECMODModule * module;
PK11SlotInfo *slot;
int s, i;
unsigned long mechFlags = getFlagsFromString(mechanisms,
mechanismStrings, numMechanismStrings);
PRBool found = PR_FALSE;
mechFlags = SECMOD_PubMechFlagstoInternal(mechFlags);
@ -748,6 +772,12 @@ UnsetDefaultModule(char *moduleName, char *mechanisms)
for(s=0; s < module->slotCount; s++) {
slot = module->slots[s];
if ((slotName != NULL) &&
!((strcmp(PK11_GetSlotName(slot),slotName) == 0) ||
(strcmp(PK11_GetTokenName(slot),slotName) == 0)) ) {
/* we are only interested in changing the one slot */
continue;
}
for(i=0; i <num_pk11_default_mechanisms; i++) {
if(PK11_DefaultArray[i].flag & mechFlags) {
PK11_UpdateSlotAttribute(slot, &(PK11_DefaultArray[i]),
@ -755,6 +785,10 @@ UnsetDefaultModule(char *moduleName, char *mechanisms)
}
}
}
if (slotName && !found) {
PR_fprintf(PR_STDERR, errStrings[NO_SUCH_SLOT_ERR], slotName);
return NO_SUCH_SLOT_ERR;
}
/* Delete and re-add module to save changes */
if( SECMOD_DeletePermDB(module) != SECSuccess ) {