pki: Reformat PKCS#12 output and add an index for each certificate/key

This commit is contained in:
Tobias Brunner
2014-12-12 13:11:29 +01:00
parent 374b569ed0
commit c20f962732
2 changed files with 17 additions and 14 deletions
+14 -11
View File
@@ -28,9 +28,9 @@ static int show(pkcs12_t *pkcs12)
enumerator_t *enumerator; enumerator_t *enumerator;
certificate_t *cert; certificate_t *cert;
private_key_t *key; private_key_t *key;
int index = 1;
printf("PKCS#12 contents:\n"); printf("Certificates:\n");
enumerator = pkcs12->create_cert_enumerator(pkcs12); enumerator = pkcs12->create_cert_enumerator(pkcs12);
while (enumerator->enumerate(enumerator, &cert)) while (enumerator->enumerate(enumerator, &cert))
{ {
@@ -38,18 +38,21 @@ static int show(pkcs12_t *pkcs12)
if (x509->get_flags(x509) & X509_CA) if (x509->get_flags(x509) & X509_CA)
{ {
printf(" CA certificate \"%Y\"\n", cert->get_subject(cert)); printf("[%2d] \"%Y\" (CA)\n", index++, cert->get_subject(cert));
} }
else else
{ {
printf(" Certificate \"%Y\"\n", cert->get_subject(cert)); printf("[%2d] \"%Y\"\n", index++, cert->get_subject(cert));
} }
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
printf("Private keys:\n");
enumerator = pkcs12->create_key_enumerator(pkcs12); enumerator = pkcs12->create_key_enumerator(pkcs12);
while (enumerator->enumerate(enumerator, &key)) while (enumerator->enumerate(enumerator, &key))
{ {
printf(" %N private key\n", key_type_names, key->get_type(key)); printf("[%2d] %N %d bits\n", index++, key_type_names,
key->get_type(key), key->get_keysize(key));
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
return 0; return 0;
@@ -65,7 +68,7 @@ static int pkcs12()
int res = 1; int res = 1;
enum { enum {
OP_NONE, OP_NONE,
OP_SHOW, OP_LIST,
} op = OP_NONE; } op = OP_NONE;
while (TRUE) while (TRUE)
@@ -77,12 +80,12 @@ static int pkcs12()
case 'i': case 'i':
file = arg; file = arg;
continue; continue;
case 'p': case 'l':
if (op != OP_NONE) if (op != OP_NONE)
{ {
goto invalid; goto invalid;
} }
op = OP_SHOW; op = OP_LIST;
continue; continue;
case EOF: case EOF:
break; break;
@@ -93,7 +96,7 @@ static int pkcs12()
break; break;
} }
if (op != OP_SHOW) if (op != OP_LIST)
{ {
return command_usage(NULL); return command_usage(NULL);
} }
@@ -140,11 +143,11 @@ static void __attribute__ ((constructor))reg()
{ {
command_register((command_t) { command_register((command_t) {
pkcs12, 'u', "pkcs12", "PKCS#12 functions", pkcs12, 'u', "pkcs12", "PKCS#12 functions",
{"--show [--in file]"}, {"--list [--in file]"},
{ {
{"help", 'h', 0, "show usage information"}, {"help", 'h', 0, "show usage information"},
{"show", 'p', 0, "show info about PKCS#12, print certificates and keys"},
{"in", 'i', 1, "input file, default: stdin"}, {"in", 'i', 1, "input file, default: stdin"},
{"list", 'l', 0, "list certificates and keys"},
} }
}); });
} }
+3 -3
View File
@@ -7,7 +7,7 @@ pki \-\-pkcs12 \- Provides PKCS#12 functions
.SH "SYNOPSIS" .SH "SYNOPSIS"
. .
.SY pki\ \-\-pkcs12 .SY pki\ \-\-pkcs12
.BR \-\-show .BR \-\-list
.OP \-\-in file .OP \-\-in file
.OP \-\-debug level .OP \-\-debug level
.YS .YS
@@ -40,8 +40,8 @@ Set debug level, default: 1.
.BI "\-+, \-\-options " file .BI "\-+, \-\-options " file
Read command line options from \fIfile\fR. Read command line options from \fIfile\fR.
.TP .TP
.BI "\-p, \-\-show" .BI "\-l, \-\-list"
Show information about PKCS#12 container, list certificates and keys. List certificates and keys contained in a PKCS#12 container.
.TP .TP
.BI "\-i, \-\-in " file .BI "\-i, \-\-in " file
PKCS#12 input file. If not given the input is read from \fISTDIN\fR. PKCS#12 input file. If not given the input is read from \fISTDIN\fR.