Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong error returned for unsupported hash algorithms #36

Open
hslatman opened this issue Dec 11, 2024 · 0 comments
Open

Wrong error returned for unsupported hash algorithms #36

hslatman opened this issue Dec 11, 2024 · 0 comments

Comments

@hslatman
Copy link
Member

hslatman commented Dec 11, 2024

In case MD5 is used as the digest algorithm the error returned is pkcs7: cannot decrypt data: only RSA, DES, DES-EDE3, AES-256-CBC and AES-128-GCM supported. This is an unexpected error message, and can lead to confusion. It's returned here:

pkcs7/pkcs7.go

Lines 94 to 108 in fbab67b

func getHashForOID(oid asn1.ObjectIdentifier) (crypto.Hash, error) {
switch {
case oid.Equal(OIDDigestAlgorithmSHA1), oid.Equal(OIDDigestAlgorithmECDSASHA1),
oid.Equal(OIDDigestAlgorithmDSA), oid.Equal(OIDDigestAlgorithmDSASHA1),
oid.Equal(OIDEncryptionAlgorithmRSA):
return crypto.SHA1, nil
case oid.Equal(OIDDigestAlgorithmSHA256), oid.Equal(OIDDigestAlgorithmECDSASHA256):
return crypto.SHA256, nil
case oid.Equal(OIDDigestAlgorithmSHA384), oid.Equal(OIDDigestAlgorithmECDSASHA384):
return crypto.SHA384, nil
case oid.Equal(OIDDigestAlgorithmSHA512), oid.Equal(OIDDigestAlgorithmECDSASHA512):
return crypto.SHA512, nil
}
return crypto.Hash(0), ErrUnsupportedAlgorithm
}
. It should likely become a different sentinel error message, but we may need a new version for that, because it's currently exported, and could thus be a backwards incompatible change.

Also see smallstep/certificates#2100.

Another case: micromdm/scep#224.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant