ssh: reject unencrypted keys from ParsePrivateKeyWithPassphrase

The behavior of ParsePrivateKeyWithPassphrase when the key is
unencrypted is unspecified. Currently, it just parses them like
ParsePrivateKey, which is unlikely to be what anyone wants: for us to
ignore a passphrase that they explicitly passed. It also makes the
implementation of encrypted OpenSSH keys in the next CL more confused.

Instead, make ParsePrivateKey return a PassphraseNeededError, so the
application logic can be ParsePrivateKey -> detect encrypted key ->
obtain passphrase -> ParsePrivateKeyWithPassphrase. That error will also
let us return the public key for OpenSSH keys.

Change-Id: Ife4fb2499ae538bef36e353adf9bc8e902662386
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/207599
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
This commit is contained in:
Filippo Valsorda
2019-12-05 16:18:47 +00:00
committed by Filippo Valsorda
parent 86a70503ff
commit 0a08dada0f
3 changed files with 68 additions and 56 deletions
+4 -3
View File
@@ -164,9 +164,10 @@ var SSHCertificates = map[string][]byte{
}
var PEMEncryptedKeys = []struct {
Name string
EncryptionKey string
PEMBytes []byte
Name string
EncryptionKey string
IncludesPublicKey bool
PEMBytes []byte
}{
0: {
Name: "rsa-encrypted",