]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
swanctl: Support any key type for decrypted keys
authorTobias Brunner <tobias@strongswan.org>
Thu, 8 Oct 2020 07:40:12 +0000 (09:40 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 27 Oct 2020 10:17:44 +0000 (11:17 +0100)
The previous code required explicit support for a particular key type,
of which Ed25519 and Ed448 were missing.  While a fallback to `any` would
have been possible (this is already the case for unencrypted keys in the
`private` and `pkcs8` directories, which are not parsed by swanctl), it's
not necessary (as long as swanctl and the daemon are from the same release)
and does not require the daemon to detect the key type again.

Fixes #3586.

src/swanctl/commands/load_creds.c

index c592d3b7f3e322f35fdaa7af7980c68413b29f22..2c1947dd1eaddf6fc386c2bb1bd76a098c285f8a 100644 (file)
@@ -195,26 +195,21 @@ static bool load_key_anytype(load_ctx_t *ctx, char *path,
 {
        bool loaded = FALSE;
        chunk_t encoding;
+       char *type;
 
        if (!private->get_encoding(private, PRIVKEY_ASN1_DER, &encoding))
        {
                fprintf(stderr, "encoding private key from '%s' failed\n", path);
                return FALSE;
        }
-       switch (private->get_type(private))
+       type = enum_to_name(key_type_names, private->get_type(private));
+       if (type)
        {
-               case KEY_RSA:
-                       loaded = load_key(ctx, path, "rsa", encoding);
-                       break;
-               case KEY_ECDSA:
-                       loaded = load_key(ctx, path, "ecdsa", encoding);
-                       break;
-               case KEY_BLISS:
-                       loaded = load_key(ctx, path, "bliss", encoding);
-                       break;
-               default:
-                       fprintf(stderr, "unsupported key type in '%s'\n", path);
-                       break;
+               loaded = load_key(ctx, path, type, encoding);
+       }
+       if (!loaded)
+       {
+               fprintf(stderr, "unsupported key type in '%s'\n", path);
        }
        chunk_clear(&encoding);
        return loaded;