diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2020-04-08 00:07:20 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2020-04-08 00:07:20 +0000 |
commit | 50599c2ffff50fd974d2e3754471c5afe48f4d45 (patch) | |
tree | 3045ee61c02ff85f791006de2f0367705fc58f6a /usr.bin/ssh | |
parent | 4a38a41d4ad881851fbce28cb3c2b14b44a1b2f0 (diff) |
simplify sshkey_parse_private_fileblob_type()
Try new format parser for all key types first, fall back to PEM
parser only for invalid format errors.
ok markus@
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r-- | usr.bin/ssh/sshkey.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/usr.bin/ssh/sshkey.c b/usr.bin/ssh/sshkey.c index 51562200355..4ad146b3382 100644 --- a/usr.bin/ssh/sshkey.c +++ b/usr.bin/ssh/sshkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshkey.c,v 1.105 2020/04/08 00:05:59 djm Exp $ */ +/* $OpenBSD: sshkey.c,v 1.106 2020/04/08 00:07:19 djm Exp $ */ /* * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. * Copyright (c) 2008 Alexander von Gernler. All rights reserved. @@ -4311,7 +4311,6 @@ sshkey_parse_private2(struct sshbuf *blob, int type, const char *passphrase, return r; } - #ifdef WITH_OPENSSL /* convert SSH v2 key to PEM or PKCS#8 format */ static int @@ -4619,24 +4618,16 @@ sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type, *commentp = NULL; switch (type) { -#ifdef WITH_OPENSSL - case KEY_DSA: - case KEY_ECDSA: - case KEY_RSA: - return sshkey_parse_private_pem_fileblob(blob, type, - passphrase, keyp); -#endif /* WITH_OPENSSL */ case KEY_ED25519: -#ifdef WITH_XMSS case KEY_XMSS: -#endif /* WITH_XMSS */ + /* No fallback for new-format-only keys */ return sshkey_parse_private2(blob, type, passphrase, keyp, commentp); - case KEY_UNSPEC: + default: r = sshkey_parse_private2(blob, type, passphrase, keyp, commentp); - /* Do not fallback to PEM parser if only passphrase is wrong. */ - if (r == 0 || r == SSH_ERR_KEY_WRONG_PASSPHRASE) + /* Only fallback to PEM parser if a format error occurred. */ + if (r != SSH_ERR_INVALID_FORMAT) return r; #ifdef WITH_OPENSSL return sshkey_parse_private_pem_fileblob(blob, type, @@ -4644,8 +4635,6 @@ sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type, #else return SSH_ERR_INVALID_FORMAT; #endif /* WITH_OPENSSL */ - default: - return SSH_ERR_KEY_TYPE_UNKNOWN; } } |