diff options
Diffstat (limited to 'src/pki/commands/pub.c')
-rw-r--r-- | src/pki/commands/pub.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/pki/commands/pub.c b/src/pki/commands/pub.c index 9912061f4..7f88055ef 100644 --- a/src/pki/commands/pub.c +++ b/src/pki/commands/pub.c @@ -51,6 +51,11 @@ static int pub() type = CRED_PRIVATE_KEY; subtype = KEY_ECDSA; } + else if (streq(arg, "pub")) + { + type = CRED_PUBLIC_KEY; + subtype = KEY_ANY; + } else if (streq(arg, "pkcs10")) { type = CRED_CERTIFICATE; @@ -96,13 +101,17 @@ static int pub() chunk = chunk_from_hex(chunk_create(keyid, strlen(keyid)), NULL); cred = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_ANY, - BUILD_PKCS11_KEYID, chunk, BUILD_END); + BUILD_PKCS11_KEYID, chunk, BUILD_END); free(chunk.ptr); } else { + chunk_t chunk; + + chunk = chunk_from_fd(0); cred = lib->creds->create(lib->creds, type, subtype, - BUILD_FROM_FD, 0, BUILD_END); + BUILD_BLOB, chunk, BUILD_END); + free(chunk.ptr); } if (type == CRED_PRIVATE_KEY) @@ -116,6 +125,15 @@ static int pub() public = private->get_public_key(private); private->destroy(private); } + else if (type == CRED_PUBLIC_KEY) + { + public = cred; + if (!public) + { + fprintf(stderr, "parsing public key failed\n"); + return 1; + } + } else { cert = cred; @@ -157,14 +175,14 @@ static void __attribute__ ((constructor))reg() command_register((command_t) { pub, 'p', "pub", "extract the public key from a private key/certificate", - {"[--in file|--keyid hex] [--type rsa|ecdsa|pkcs10|x509]", - "[--outform der|pem|pgp|dnskey]"}, + {"[--in file|--keyid hex] [--type rsa|ecdsa|pub|pkcs10|x509]", + "[--outform der|pem|dnskey|sshkey]"}, { {"help", 'h', 0, "show usage information"}, {"in", 'i', 1, "input file, default: stdin"}, {"keyid", 'x', 1, "keyid on smartcard of private key"}, {"type", 't', 1, "type of credential, default: rsa"}, - {"outform", 'f', 1, "encoding of extracted public key"}, + {"outform", 'f', 1, "encoding of extracted public key, default: der"}, } }); } |