@@ -78,7 +78,8 @@ func (r *RSA) Verify(message, sig []byte, key interface{}) error {
78
78
// ECDSA Crypto interface implementation
79
79
const ecdsa256curveBits = 256
80
80
const ecdsa256keySize = 32
81
- const ecdsa256Asn1SizeBytes = 72
81
+ const ecdsa256Asn1SizeBytes = 70
82
+ const ecdsa256Asn1Padding = 2
82
83
83
84
type ECDSA256 struct {}
84
85
@@ -171,15 +172,14 @@ func UnmarshalECDSASignature(sig []byte) (r, s *big.Int, e error) {
171
172
// in case of a key supplied via PKCS#11 URI, we have no control over what the signature is
172
173
// since it is designed to be actually verified via the same mechanism (PKCS#11 URI).
173
174
// We know here that it is ECDSA key, and judging form the size we can assume
174
- // that it is ASN.1 encoded. If so, then it should be 72 bytes, the less or equal is here
175
- // to support keys of size 71 bytes (strangely seen in the wild). In other words:
175
+ // that it is ASN.1 encoded. If so, then it should be between 70 and 72 bytes.
176
+ // In other words:
176
177
// if the signature has not been created with MarshalECDSASignature, then we assume
177
178
// it is to be decoded via ASN.1, with the protection on the signature length.
178
- if len (sig ) == ecdsa256Asn1SizeBytes ||
179
- len (sig ) == ecdsa256Asn1SizeBytes - 1 {
179
+ if len (sig ) >= ecdsa256Asn1SizeBytes &&
180
+ len (sig ) <= ecdsa256Asn1SizeBytes + ecdsa256Asn1Padding {
180
181
return UnmarshalECDSASignatureASN1 (sig )
181
182
}
182
-
183
183
return nil , nil , errors .Errorf ("signer: invalid signature length: %d. " +
184
184
"For ECDSA only P-256 is supported." , len (sig ))
185
185
}
0 commit comments