-
Notifications
You must be signed in to change notification settings - Fork 18k
crypto/x509: Verify failed on some valid certificates with SubjectAlternateNames #24293
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
Comments
Found the corresponding commit: @agl your comment is:
Why should CN be ignored, even if no DNS names where present? As our certificate is validated correctly by most other tool, it is not clear to me which approach is correct. |
I don't have a definitive RFC reference at hand, but https://www.digicert.com/subject-alternative-name-compatibility.htm says: "If a SSL Certificate has a Subject Alternative Name (SAN) field, then SSL clients are supposed to ignore the Common Name value and seek a match in the SAN list. This is why DigiCert always repeats the common name as the first SAN in our certificates." I also find among StackExchange search hits the following -
See also https://tools.ietf.org/html/rfc6125#section-6.4.4 "Checking of Common Names":
|
Hmm ok. Seems legit. I didn't know that SubjectAlternateNames superseeds the CommonName. Now i understand why our certificate in fact is valid, but will never match the real hostname. Thanks! Please close this issue! |
What version of Go are you using (
go version
)?Using Docker 17.12. compiled with golang 1.9.4.
Does this issue reproduce with the latest release?
The causative lines of code are still present in the master branch. So i think yes.
What operating system and processor architecture are you using (
go env
)?x86 Centos 7 (as VM in VirtualBox on Windows 7)
What did you do?
I want to connect to a docker registry which has an server certificate. The certificate should be validated.
Our certificate has the following attributes:
I don't know if this is a valid combination, but every other tool says this certificate is valid.
According to http://www.alvestrand.no/objectid/2.5.29.17.html SubjectAlternateNamens can have different types of items (e.g. IP-Addresses and DNS-Names)
What did you expect to see?
golang should verify this certificate as valid.
What did you see instead?
golang throws an error: "x509: certificate is not valid for any names, but wanted to match our.company.registry"
What is the cause?
Checking the hostname against the certificate causes the Problem:
(https://github.com/golang/go/blob/release-branch.go1.9/src/crypto/x509/verify.go)
Line 90 checks for presence of SubjectAlternateNamens extension (which is present). Line 91 will join all DNSNames, even if they are not present. So valid will be empty and the error will be thrown.
These lines of code have actually changed between golang 1.8 and golang 1.9. In golang 1.8, the following was executed:
(https://github.com/golang/go/blob/release-branch.go1.8/src/crypto/x509/verify.go)
Here, the if clause does not match, and the c.Subject.CommonName is used. (and is valid).
So we dont have problems using docker 17.09, wich was compiled against go1.8.3.
What could be the solution?
I can not imagine why the if clause has changed in that way. But in my opinion, before using c.DNSNames it should be checked if they are present.
The text was updated successfully, but these errors were encountered: