@@ -21,6 +21,7 @@ import (
2121 "github.com/runZeroInc/excrypto/crypto/ecdsa"
2222 "github.com/runZeroInc/excrypto/crypto/ed25519"
2323 "github.com/runZeroInc/excrypto/crypto/elliptic"
24+ "github.com/runZeroInc/excrypto/crypto/internal/fips140only"
2425 "github.com/runZeroInc/excrypto/crypto/rsa"
2526 "github.com/runZeroInc/excrypto/crypto/sha256"
2627 "github.com/runZeroInc/excrypto/crypto/x509/pkix"
@@ -31,6 +32,16 @@ import (
3132 cryptobyte_asn1 "github.com/runZeroInc/excrypto/x/crypto/cryptobyte/asn1"
3233)
3334
35+ // signatureUsesNonFIPSHash reports whether the given signature algorithm
36+ // uses a hash (MD5, SHA-1) that panics in FIPS 140-only mode.
37+ func signatureUsesNonFIPSHash (algo SignatureAlgorithm ) bool {
38+ switch algo {
39+ case MD2WithRSA , MD5WithRSA , SHA1WithRSA , DSAWithSHA1 , ECDSAWithSHA1 :
40+ return true
41+ }
42+ return false
43+ }
44+
3445// isPrintable reports whether the given b is in the ASN.1 PrintableString set.
3546// This is a simplified version of encoding/asn1.isPrintable.
3647func isPrintable (b byte ) bool {
@@ -1288,8 +1299,12 @@ func parseCertificate(in *certificate) (*Certificate, error) {
12881299 // zcrypto: Check if self-signed
12891300 if bytes .Equal (cert .RawSubject , cert .RawIssuer ) {
12901301 // Possibly self-signed, check the signature against itself.
1291- if err := cert .CheckSignature (cert .SignatureAlgorithm , cert .RawTBSCertificate , cert .Signature ); err == nil {
1292- cert .SelfSigned = true
1302+ // Skip in FIPS 140-only mode when the signature algorithm uses
1303+ // a hash that panics (MD5, SHA-1). The self-signed flag is informational.
1304+ if ! fips140only .Enforced () || ! signatureUsesNonFIPSHash (cert .SignatureAlgorithm ) {
1305+ if err := cert .CheckSignature (cert .SignatureAlgorithm , cert .RawTBSCertificate , cert .Signature ); err == nil {
1306+ cert .SelfSigned = true
1307+ }
12931308 }
12941309 }
12951310
0 commit comments