bifurcation / mint

A Minimal TLS 1.3 Implementation in Go
MIT License
225 stars 36 forks source link

Add check for matching group in CertificateSelection #218

Open tatianab opened 4 years ago

tatianab commented 4 years ago

Currently, the CertificateSelection function calls the schemeValidForKey function, which checks if the signature type (RSA_PKCS1, RSA_PSS, or ECDSA) is correct for the given key, but does not check if the underlying group is correct for the signature algorithm in the ECDSA case. This causes the function to sometimes output a signature algorithm incompatible with the chosen certificate.

I propose to add the following check inside schemeValidForKey:

func schemeValidForKey(alg SignatureScheme, key crypto.Signer) bool {
        ...
    case *ecdsa.PrivateKey:
        // proposed check
        if curveFromNamedGroup(curveMap[alg]) != key.Public().(*ecdsa.PublicKey).Curve {
            return false
        }
       ...

If you agree, I will submit a PR with this change.

@chris-wood