Skip to content

x/crypto/ssh: doesn't always return x509.IncorrectPasswordError when it should #62265

Closed
@sqweek

Description

@sqweek

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

$ go version
go version go1.21.0 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GOARCH='amd64'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOOS='linux'
GOAMD64='v1'

What did you do?

I'm working with SSH private keys encrypted by passphrases, and thus using ssh.ParseRawPrivateKeyWithPassphrase during the decryption process. In some cases when an incorrect passphrase is provided, the function does not honour its interface.

What did you expect to see?

The documentation for the function says:

If the passphrase is wrong, it will return x509.IncorrectPasswordError.

What did you see instead?

With one specific passphrase/key combination, I instead saw this error:

asn1: structure error: length too large

This is a key I use every day with normal SSH tools so I know it is valid. Also if I provide the correct passphrase to the function then everything works, and other incorrect passhprases do result in an x509.IncorrectPasswordError as expected -- it's quite an obscure failure.

Unfortunately I cannot provide the key itself to reproduce, for obvious reasons. I spent some time tracing the decryption code path but was unable to get clarity myself. It may relate to the slightly antiquated/odd structure of my SSH key, which I am happy to share:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,«32 bytes redacted»

«24 lines * 64 bytes redacted»
-----END RSA PRIVATE KEY-----

No idea how I generated this one, it was a long time ago. The incorrect passphrase which generated the asn1 structure error was ooooo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions