]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
pki: Optionally extract public key from given private key in --issue
authorTobias Brunner <tobias@strongswan.org>
Tue, 7 Jul 2015 08:53:22 +0000 (10:53 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 10 Aug 2015 10:33:02 +0000 (12:33 +0200)
Fixes #618.

src/pki/commands/issue.c
src/pki/man/pki---issue.1.in

index 6a2d09d7806bf7800ca34ac796abdc300628adc7..70afc01f562f4ac2f43f7773ce042db202dee901 100644 (file)
@@ -64,6 +64,8 @@ static int issue()
        certificate_t *cert_req = NULL, *cert = NULL, *ca =NULL;
        private_key_t *private = NULL;
        public_key_t *public = NULL;
+       credential_type_t type = CRED_PUBLIC_KEY;
+       key_type_t subtype = KEY_ANY;
        bool pkcs10 = FALSE;
        char *file = NULL, *dn = NULL, *hex = NULL, *cacert = NULL, *cakey = NULL;
        char *error = NULL, *keyid = NULL;
@@ -100,6 +102,21 @@ static int issue()
                                {
                                        pkcs10 = TRUE;
                                }
+                               else if (streq(arg, "rsa"))
+                               {
+                                       type = CRED_PRIVATE_KEY;
+                                       subtype = KEY_RSA;
+                               }
+                               else if (streq(arg, "ecdsa"))
+                               {
+                                       type = CRED_PRIVATE_KEY;
+                                       subtype = KEY_ECDSA;
+                               }
+                               else if (streq(arg, "bliss"))
+                               {
+                                       type = CRED_PRIVATE_KEY;
+                                       subtype = KEY_BLISS;
+                               }
                                else if (!streq(arg, "pub"))
                                {
                                        error = "invalid input type";
@@ -447,10 +464,10 @@ static int issue()
        }
        else
        {
-               DBG2(DBG_LIB, "Reading public key:");
+               DBG2(DBG_LIB, "Reading key:");
                if (file)
                {
-                       public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
+                       public = lib->creds->create(lib->creds, type, subtype,
                                                                                BUILD_FROM_FILE, file, BUILD_END);
                }
                else
@@ -460,13 +477,19 @@ static int issue()
                        if (!chunk_from_fd(0, &chunk))
                        {
                                fprintf(stderr, "%s: ", strerror(errno));
-                               error = "reading public key failed";
+                               error = "reading key failed";
                                goto end;
                        }
-                       public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
+                       public = lib->creds->create(lib->creds, type, subtype,
                                                                                 BUILD_BLOB, chunk, BUILD_END);
                        free(chunk.ptr);
                }
+               if (public && type == CRED_PRIVATE_KEY)
+               {
+                       private_key_t *priv = (private_key_t*)public;
+                       public = priv->get_public_key(priv);
+                       priv->destroy(priv);
+               }
        }
        if (!public)
        {
index 3a89059c8b323618e30be0e301da43d7f2aab666..20238b73df7ec485b190dc20015d069f047bcc79 100644 (file)
@@ -67,8 +67,9 @@ Public key or PKCS#10 certificate request file to issue. If not given the
 key/request is read from \fISTDIN\fR.
 .TP
 .BI "\-t, \-\-type " type
-Type of the input. Either \fIpub\fR for a public key, or \fIpkcs10\fR for a
-PKCS#10 certificate request, defaults to \fIpub\fR.
+Type of the input. One of \fIpub\fR (public key), \fIrsa\fR (RSA private key),
+\fIecdsa\fR (ECDSA private key), or \fIpkcs10\fR (PKCS#10 certificate request),
+defaults to \fIpub\fR.
 .TP
 .BI "\-k, \-\-cakey " file
 CA private key file. Either this or