diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2018-10-09 05:42:24 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2018-10-09 05:42:24 +0000 |
commit | a4d4a5830ea717bea06c25d0830675eb2340d733 (patch) | |
tree | a05d94a3a0b817ecdab8352ed99e4f03af01055b /usr.bin/ssh/sshkey.c | |
parent | 40e8359ea1a423862d01fae8e0c3f08d6aeb1002 (diff) |
Treat all PEM_read_bio_PrivateKey() errors when a passphrase is specified
as "incorrect passphrase" instead of trying to choose between that and
"invalid format".
libcrypto can return ASN1 parsing errors rather than the expected
decrypt error in certain infrequent cases when trying to decrypt/parse
PEM private keys when supplied with an invalid passphrase.
Report and repro recipe from Thomas Deutschmann in bz#2901
ok markus@
Diffstat (limited to 'usr.bin/ssh/sshkey.c')
-rw-r--r-- | usr.bin/ssh/sshkey.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/usr.bin/ssh/sshkey.c b/usr.bin/ssh/sshkey.c index f7c09fbe100..cc52a41506b 100644 --- a/usr.bin/ssh/sshkey.c +++ b/usr.bin/ssh/sshkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshkey.c,v 1.70 2018/09/14 04:17:44 djm Exp $ */ +/* $OpenBSD: sshkey.c,v 1.71 2018/10/09 05:42:23 djm Exp $ */ /* * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. * Copyright (c) 2008 Alexander von Gernler. All rights reserved. @@ -3866,7 +3866,16 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, clear_libcrypto_errors(); if ((pk = PEM_read_bio_PrivateKey(bio, NULL, NULL, (char *)passphrase)) == NULL) { - r = convert_libcrypto_error(); + /* + * libcrypto may return various ASN.1 errors when attempting + * to parse a key with an incorrect passphrase. + * Treat all format errors as "incorrect passphrase" if a + * passphrase was supplied. + */ + if (passphrase != NULL && *passphrase != '\0') + r = SSH_ERR_KEY_WRONG_PASSPHRASE; + else + r = convert_libcrypto_error(); goto out; } if (EVP_PKEY_base_id(pk) == EVP_PKEY_RSA && |