summaryrefslogtreecommitdiff
path: root/src/pki/commands/pub.c
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2013-11-01 13:32:07 +0100
committerYves-Alexis Perez <corsac@debian.org>2013-11-01 13:32:07 +0100
commit5313d2d78ca150515f7f5eb39801c100690b6b29 (patch)
treec78e420367283bb1b16f14210b12687cdfbd26eb /src/pki/commands/pub.c
parent6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349 (diff)
downloadvyos-strongswan-5313d2d78ca150515f7f5eb39801c100690b6b29.tar.gz
vyos-strongswan-5313d2d78ca150515f7f5eb39801c100690b6b29.zip
Imported Upstream version 5.1.1
Diffstat (limited to 'src/pki/commands/pub.c')
-rw-r--r--src/pki/commands/pub.c28
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"},
}
});
}