| Summary: | Key parser should reflect errors from OpenSSL | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | Portable OpenSSH | Reporter: | Jakub Jelen <jjelen> | ||||||||
| Component: | ssh | Assignee: | Damien Miller <djm> | ||||||||
| Status: | CLOSED FIXED | ||||||||||
| Severity: | minor | CC: | djm, dtucker, horsley1953 | ||||||||
| Priority: | P3 | Keywords: | patch | ||||||||
| Version: | 7.1p1 | ||||||||||
| Hardware: | Other | ||||||||||
| OS: | Linux | ||||||||||
| Bug Depends on: | |||||||||||
| Bug Blocks: | 2523, 2647 | ||||||||||
| Attachments: |
|
||||||||||
|
Description
Jakub Jelen
2016-01-09 03:15:29 AEDT
Created attachment 2806 [details]
translate libcrypto error code on PEM_read_bio_PrivateKey failure
This patch translates a few more error codes, making that function return either SSH_ERR_KEY_WRONG_PASSPHRASE, SSH_ERR_INVALID_FORMAT or SSH_ERR_LIBCRYPTO_ERROR.
It also uses ERR_peek_last_error() which AFAIK is what we want. ERR_peek_error() might be confused by prior soft libcrypto errors in that process/thread's life.
Thanks (it was probably my first encounter with openssl API so excuse the brevity of my patch). Your looks good to me and works fine to the extent I was able to try. path applied. Will be released in openssh-7.3 - thanks! change was reverted as it caused regressions in pubkey auth. Needs more investigation I saw that reverted in the upstream CVS, but quite without any details, about use case which it breaks. Is there some more information I can have a look into or help? (In reply to Jakub Jelen from comment #5) > I saw that reverted in the upstream CVS, but quite without any > details, about use case which it breaks. Is there some more > information I can have a look into or help? The breakage seems to occur with keys that are new-format rather than PEM (ie generated with "ssh-keygen -o" or any ED25519 keys). one reproduction case was trying to read the key to convert it with ssh-keygen. $ ssh-keygen -y -f .ssh/id_rsa -vvv Load key ".ssh/id_bert": invalid format Created attachment 2844 [details]
Do not fallback to PEM parser, if only passphrase is wrong
Thank you for the details. Now I see. When the key in new format have a passphrase, it is not accepted.
There is assumption that sshkey_load_private returns SSH_ERR_KEY_WRONG_PASSPHRASE when the initial attempt without passphrase fails (which quite makes sense).
But parsing the key in sshkey_parse_private_fileblob_type goes through waterfall from parsing openssh format to parsing PEM format.
Current implementation depends on the assumption that sshkey_parse_private_pem_fileblob returns WRONG_PASSPHRASE for everything that it does not know which gets wrong with the above patch applied (sorry that I did miss that).
Proper solution would be to pass-through WRONG_PASSPHRASE return value from sshkey_parse_private2, which indicates that the parser knows the key type, but the passphrase it wrong and do not let it fall-through to the PEM parser (which does not know the key format).
I ran the tests from initial bug, from the last comments and the the regress and all test passed.
retarget unfinished bugs to next release retarget unfinished bugs to next release retarget unfinished bugs to next release retarget unfinished bugs to next release OpenSSH 7.4 release is closing; punt the bugs to 7.5 Comment on attachment 2844 [details]
Do not fallback to PEM parser, if only passphrase is wrong
Thanks for tracking this down. The fix looks fine to me and, with the error code translation re-applied, passes the test-cases that were failing previously.
I'd like to commit this and the original error code translation.
Comment on attachment 2844 [details]
Do not fallback to PEM parser, if only passphrase is wrong
third time's a charm?
Applied and will be in openssh-7.5. Thanks! commit 155d540d00ff55f063421ec182ec8ff2b7ab6cbe Author: djm@openbsd.org <djm@openbsd.org> Date: Fri Feb 10 04:34:50 2017 +0000 upstream commit bring back r1.34 that was backed out for problems loading public keys: translate OpenSSL error codes to something more meaninful; bz#2522 reported by Jakub Jelen, ok dtucker@ with additional fix from Jakub Jelen to solve the backout. bz#2525 bz#2523 re-ok dtucker@ Upstream-ID: a9d5bc0306f4473d9b4f4484f880e95f3c1cc031 *** Bug 2523 has been marked as a duplicate of this bug. *** Close all resolved bugs after release of OpenSSH 7.7. |