Skip to content

Commit 3f61fd2

Browse files
hoihochanSean-Der
authored andcommittedNov 4, 2024·
Fix RSA signature verification issue
Both verifyKeySignature() and verifyCertificateVerify() has a bug when handling RSA signature as it looks at the signature algorithm of the certificate to determine whether to verify with RSA PKCSv1.5. This will cause issues if the certificate's issuing CA uses something other than RSA (e.g. ECDSA) to sign the certificate. Since DTLS v1.2 does not support RSA-PSS [1], we can just use RSA PKCSv1.5 verification directly if the public key of the certificate is RSA. [1] https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
1 parent d796437 commit 3f61fd2

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed
 

‎crypto.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,11 @@ func verifyKeySignature(message, remoteKeySignature []byte, hashAlgorithm hash.A
8989
}
9090
return nil
9191
case *rsa.PublicKey:
92-
switch certificate.SignatureAlgorithm {
93-
case x509.SHA1WithRSA, x509.SHA256WithRSA, x509.SHA384WithRSA, x509.SHA512WithRSA:
94-
hashed := hashAlgorithm.Digest(message)
95-
return rsa.VerifyPKCS1v15(p, hashAlgorithm.CryptoHash(), hashed, remoteKeySignature)
96-
default:
97-
return errKeySignatureVerifyUnimplemented
92+
hashed := hashAlgorithm.Digest(message)
93+
if rsa.VerifyPKCS1v15(p, hashAlgorithm.CryptoHash(), hashed, remoteKeySignature) != nil {
94+
return errKeySignatureMismatch
9895
}
96+
return nil
9997
}
10098

10199
return errKeySignatureVerifyUnimplemented
@@ -158,13 +156,11 @@ func verifyCertificateVerify(handshakeBodies []byte, hashAlgorithm hash.Algorith
158156
}
159157
return nil
160158
case *rsa.PublicKey:
161-
switch certificate.SignatureAlgorithm {
162-
case x509.SHA1WithRSA, x509.SHA256WithRSA, x509.SHA384WithRSA, x509.SHA512WithRSA:
163-
hash := hashAlgorithm.Digest(handshakeBodies)
164-
return rsa.VerifyPKCS1v15(p, hashAlgorithm.CryptoHash(), hash, remoteKeySignature)
165-
default:
166-
return errKeySignatureVerifyUnimplemented
159+
hash := hashAlgorithm.Digest(handshakeBodies)
160+
if rsa.VerifyPKCS1v15(p, hashAlgorithm.CryptoHash(), hash, remoteKeySignature) != nil {
161+
return errKeySignatureMismatch
167162
}
163+
return nil
168164
}
169165

170166
return errKeySignatureVerifyUnimplemented

0 commit comments

Comments
 (0)
Please sign in to comment.