Added comments and fix indentation
This commit is contained in:
parent
d33501a69b
commit
dc25540c1c
54
keyutil.c
54
keyutil.c
|
@ -1438,6 +1438,10 @@ static int keyutil_main(
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
if (cert_to_renew && input_key_file) {
|
if (cert_to_renew && input_key_file) {
|
||||||
|
/*
|
||||||
|
* This certificate request is for a renewal,
|
||||||
|
* using existing keys.
|
||||||
|
*/
|
||||||
CK_SLOT_ID slotID = 1;
|
CK_SLOT_ID slotID = 1;
|
||||||
char slotname[32];
|
char slotname[32];
|
||||||
char nickname[256];
|
char nickname[256];
|
||||||
|
@ -1447,17 +1451,17 @@ static int keyutil_main(
|
||||||
/* Remove the path part */
|
/* Remove the path part */
|
||||||
n = strrchr(cert_to_renew, '/');
|
n = strrchr(cert_to_renew, '/');
|
||||||
if (!n)
|
if (!n)
|
||||||
n = cert_to_renew;
|
n = cert_to_renew;
|
||||||
else
|
else
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
snprintf(slotname, 32, "PEM Token #%ld", slotID);
|
snprintf(slotname, 32, "PEM Token #%ld", slotID);
|
||||||
snprintf(nickname, 256, "PEM Token #%ld:%s", slotID, n);
|
snprintf(nickname, 256, "PEM Token #%ld:%s", slotID, n);
|
||||||
slot = PK11_FindSlotByName(slotname);
|
slot = PK11_FindSlotByName(slotname);
|
||||||
if (!slot) {
|
if (!slot) {
|
||||||
printf("%s: Can't find slot for %s\n", progName, slotname);
|
printf("%s: Can't find slot for %s\n", progName, slotname);
|
||||||
rv = 255;
|
rv = 255;
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = loadCertAndKey(slot,
|
rv = loadCertAndKey(slot,
|
||||||
|
@ -1465,8 +1469,8 @@ static int keyutil_main(
|
||||||
&pwdata);
|
&pwdata);
|
||||||
|
|
||||||
if (rv != SECSuccess) {
|
if (rv != SECSuccess) {
|
||||||
printf("%s: Can't load the key or cert, bailing out\n", progName);
|
printf("%s: Can't load the key or cert, bailing out\n", progName);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = extractRSAKeysAndSubject(nickname,
|
rv = extractRSAKeysAndSubject(nickname,
|
||||||
|
@ -1484,27 +1488,29 @@ static int keyutil_main(
|
||||||
assert(subject);
|
assert(subject);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
|
* This a certificate request for a bran-new cert,
|
||||||
|
* will generate a key pair
|
||||||
|
*/
|
||||||
|
slot = PK11_GetInternalKeySlot(); /* PK11_GetInternalSlot() ? */
|
||||||
|
|
||||||
slot = PK11_GetInternalKeySlot(); /* PK11_GetInternalSlot() ? */
|
privkey = GenerateRSAPrivateKey(keytype, slot,
|
||||||
|
|
||||||
privkey = GenerateRSAPrivateKey(keytype, slot,
|
|
||||||
keysize, 65537L, (char *)noisefile, &pubkey, &pwdata);
|
keysize, 65537L, (char *)noisefile, &pubkey, &pwdata);
|
||||||
|
|
||||||
if (!privkey) {
|
if (!privkey) {
|
||||||
PR_fprintf(PR_STDERR,
|
PR_fprintf(PR_STDERR,
|
||||||
"%s Keypair generation failed: \"%d\"\n",
|
"%s Keypair generation failed: \"%d\"\n",
|
||||||
progName, PORT_GetError());
|
progName, PORT_GetError());
|
||||||
rv = 255;
|
rv = 255;
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
subject = CERT_AsciiToName((char *)subjectstr);
|
subject = CERT_AsciiToName((char *)subjectstr);
|
||||||
if (!subject) {
|
if (!subject) {
|
||||||
PR_fprintf(PR_STDERR, "%s -s: improperly formatted name: \"%s\"\n",
|
PR_fprintf(PR_STDERR, "%s -s: improperly formatted name: \"%s\"\n",
|
||||||
progName, subjectstr);
|
progName, subjectstr);
|
||||||
rv = 255;
|
rv = 255;
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
PR_fprintf(PR_STDOUT, "%s Got a key\n", progName);
|
PR_fprintf(PR_STDOUT, "%s Got a key\n", progName);
|
||||||
|
|
||||||
|
@ -1654,7 +1660,7 @@ shutdown:
|
||||||
return rv == SECSuccess ? 0 : 255;
|
return rv == SECSuccess ? 0 : 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: keyutil.c,v 1.4 2008/05/11 02:53:02 emaldonado Exp $ */
|
/* $Id: keyutil.c,v 1.5 2008/10/01 21:22:49 emaldonado Exp $ */
|
||||||
|
|
||||||
/* Key generation, encryption, and certificate utility code, based on
|
/* Key generation, encryption, and certificate utility code, based on
|
||||||
* code from NSS's security utilities and the certutil application.
|
* code from NSS's security utilities and the certutil application.
|
||||||
|
@ -1768,7 +1774,7 @@ int main(int argc, char **argv)
|
||||||
printf("output key written to %s\n", keyoutfile);
|
printf("output key written to %s\n", keyoutfile);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
Usage(progName);
|
Usage(progName);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Bad arguments\n");
|
printf("Bad arguments\n");
|
||||||
|
|
Loading…
Reference in New Issue