mirror of git://anongit.mindrot.org/openssh.git
upstream: 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@ OpenBSD-Commit-ID: 0173bbb3a5cface77b0679d4dca0e15eb5600b77
This commit is contained in:
parent
421169d0e7
commit
8d514eea4a
21
sshkey.c
21
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) 2000, 2001 Markus Friedl. All rights reserved.
|
||||||
* Copyright (c) 2008 Alexander von Gernler. All rights reserved.
|
* Copyright (c) 2008 Alexander von Gernler. All rights reserved.
|
||||||
|
@ -4366,7 +4366,6 @@ sshkey_parse_private2(struct sshbuf *blob, int type, const char *passphrase,
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef WITH_OPENSSL
|
#ifdef WITH_OPENSSL
|
||||||
/* convert SSH v2 key to PEM or PKCS#8 format */
|
/* convert SSH v2 key to PEM or PKCS#8 format */
|
||||||
static int
|
static int
|
||||||
|
@ -4692,24 +4691,16 @@ sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type,
|
||||||
*commentp = NULL;
|
*commentp = NULL;
|
||||||
|
|
||||||
switch (type) {
|
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:
|
case KEY_ED25519:
|
||||||
#ifdef WITH_XMSS
|
|
||||||
case KEY_XMSS:
|
case KEY_XMSS:
|
||||||
#endif /* WITH_XMSS */
|
/* No fallback for new-format-only keys */
|
||||||
return sshkey_parse_private2(blob, type, passphrase,
|
return sshkey_parse_private2(blob, type, passphrase,
|
||||||
keyp, commentp);
|
keyp, commentp);
|
||||||
case KEY_UNSPEC:
|
default:
|
||||||
r = sshkey_parse_private2(blob, type, passphrase, keyp,
|
r = sshkey_parse_private2(blob, type, passphrase, keyp,
|
||||||
commentp);
|
commentp);
|
||||||
/* Do not fallback to PEM parser if only passphrase is wrong. */
|
/* Only fallback to PEM parser if a format error occurred. */
|
||||||
if (r == 0 || r == SSH_ERR_KEY_WRONG_PASSPHRASE)
|
if (r != SSH_ERR_INVALID_FORMAT)
|
||||||
return r;
|
return r;
|
||||||
#ifdef WITH_OPENSSL
|
#ifdef WITH_OPENSSL
|
||||||
return sshkey_parse_private_pem_fileblob(blob, type,
|
return sshkey_parse_private_pem_fileblob(blob, type,
|
||||||
|
@ -4717,8 +4708,6 @@ sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type,
|
||||||
#else
|
#else
|
||||||
return SSH_ERR_INVALID_FORMAT;
|
return SSH_ERR_INVALID_FORMAT;
|
||||||
#endif /* WITH_OPENSSL */
|
#endif /* WITH_OPENSSL */
|
||||||
default:
|
|
||||||
return SSH_ERR_KEY_TYPE_UNKNOWN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue