golang/go

x/crypto/ssh: ParseRawPrivateKeyWithPassphrase doesn't support PKCS#8 encrypted keys

Open

#43.387 aberto em 26 de dez. de 2020

Ver no GitHub
 (3 comments) (0 reactions) (0 assignees)Go (19.008 forks)batch import
NeedsInvestigationhelp wanted

Métricas do repositório

Stars
 (133.883 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

What version of Go are you using (go version)?

Does this issue reproduce with the latest release? Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64" GOOS="darwin"

What did you do?

When decrypting a private key PEM block, using ssh package, there are two methods:
ParseRawPrivateKeyWithPassphrase. ParseRawPrivateKey.

ParseRawPrivateKey accepts PEM blocks with type "PRIVATE KEY" (with no other qualifier) and decrypts using x509.ParsePKCS8PrivateKey however ParseRawPrivateKeyWithPassphrase does not. Both accept blocks with "RSA PRIVATE KEY", "EC PRIVATE KEY", "DSA PRIVATE KEY" and "OPENSSH PRIVATE KEY" but ParseRawPrivateKeyWithPassphrase seems to be missing the 'case' for "PRIVATE KEY" on its own.
As methods perform the same task, just with the addition of decrypting, should they not be aligned in the keys they support?

https://play.golang.org/p/D_CtEEAqO7i

What did you expect to see?

ParseRawPrivateKeyWithPassphrase parses pem block of type "Private Key" using x509.ParsePKCS8PrivateKey

What did you see instead?

Error: ssh: unsupported key type "PRIVATE KEY"

Looking at ssh/keys.go line: 1172 a switch block for the types appears to be missing the "PRIVATE KEY" case, reflected in the ParseRawPrivateKey switch block.

Suggested fix is a simple insertion of: case "PRIVATE KEY": return x509.ParsePKCS8PrivateKey(buf)

Guia do colaborador