-
Notifications
You must be signed in to change notification settings - Fork 81
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
Support more complex SANs in verify_certificate_identity
#325
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,26 +270,21 @@ def verify_certificate_identity(cert, hostname) | |
should_verify_common_name = true | ||
cert.extensions.each{|ext| | ||
next if ext.oid != "subjectAltName" | ||
ext.value.split(/,\s+/).each { |general_name| | ||
#case san.tag | ||
# MRI 2.2.3 (JRuby parses ASN.1 differently) | ||
#when 2 # dNSName in GeneralName (RFC5280) | ||
if /\ADNS:(.*)/ =~ general_name | ||
ostr = OpenSSL::ASN1.decode(ext.to_der).value.last | ||
sequence = OpenSSL::ASN1.decode(ostr.value) | ||
sequence.value.each{|san| | ||
case san.tag | ||
when 2 # dNSName in GeneralName (RFC5280) | ||
should_verify_common_name = false | ||
return true if verify_hostname(hostname, $1) | ||
# MRI 2.2.3 (JRuby parses ASN.1 differently) | ||
#when 7 # iPAddress in GeneralName (RFC5280) | ||
elsif /\AIP(?: Address)?:(.*)/ =~ general_name | ||
return true if verify_hostname(hostname, san.value.last.value) | ||
when 7 # iPAddress in GeneralName (RFC5280) | ||
should_verify_common_name = false | ||
return true if $1 == hostname | ||
# NOTE: bellow logic makes little sense JRuby reads exts differently | ||
# follows GENERAL_NAME_print() in x509v3/v3_alt.c | ||
# if san.value.size == 4 || san.value.size == 16 | ||
# begin | ||
# return true if $1 == IPAddr.new(hostname).to_s | ||
# rescue IPAddr::InvalidAddressError | ||
# end | ||
# end | ||
if san.value.last.value.size == 4 || san.value.last.value.size == 16 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
begin | ||
return true if san.value.last.value == IPAddr.new(hostname).hton | ||
rescue IPAddr::InvalidAddressError | ||
end | ||
end | ||
end | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ req ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't work out how to generate a test certificate with the
|
||
distinguished_name = req_distinguished_name | ||
req_extensions = req_ext | ||
prompt = no | ||
|
||
[ req_distinguished_name ] | ||
CN = TestOtherName | ||
|
||
[ req_ext ] | ||
subjectAltName = @alt_names | ||
|
||
[ alt_names ] | ||
otherName.1 = 1.3.6.1.4.1.311.20.2.3;UTF8:example-other-name@localdomain | ||
DNS.2 = localhost.localdomain | ||
IP.3 = 127.0.0.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDDzCCAfegAwIBAgIJALtkg6B2cBoDMA0GCSqGSIb3DQEBCwUAMBgxFjAUBgNV | ||
BAMMDVRlc3RPdGhlck5hbWUwIBcNMjUwMTAzMTQ1MDA5WhgPMjEyNDEyMTAxNDUw | ||
MDlaMBgxFjAUBgNVBAMMDVRlc3RPdGhlck5hbWUwggEiMA0GCSqGSIb3DQEBAQUA | ||
A4IBDwAwggEKAoIBAQCbLUib/ie6WijVTtHsHo4hTK3cG1xsrpb1W8JpmNMGh/AA | ||
hC9qpqEgH0tjrDCYWt8BYFwv5xrp54JzssslSdTgmtXg5TeLn90BtyFtBURmvO/U | ||
uRM9qCkwewZodv22sZ8+D6I+zEUbGBkwrJsWB65MBxGqcjUCATgKn2BdTlJEVSSA | ||
oZeuDFfLlfgJmSQALlkFHmacV6qVYIbOQ4iANodwjZezmQuJZNByVwzkUh4b3KlF | ||
xDoEKkzAJFssxk2ONFCrA7TIwuVFpu1QHWDyDAYDCMatLo20fjrBbaabIa5ORM8R | ||
qDXlJs+OU1/fI+lrWaPuGcG3m66QZgsuXaB4EfrnAgMBAAGjWjBYMFYGA1UdEQRP | ||
ME2gLgYKKwYBBAGCNxQCA6AgDB5leGFtcGxlLW90aGVyLW5hbWVAbG9jYWxkb21h | ||
aW6CFWxvY2FsaG9zdC5sb2NhbGRvbWFpbocEfwAAATANBgkqhkiG9w0BAQsFAAOC | ||
AQEAc8u8+FNMOonSns+eeUxfeqERcdBsHhxagOVwN+D5U8nIUZ5Ys3AT3DqlIIpC | ||
O/HmUqkY2YR7iWck91BO9OryTCqc6z5Lk/yCksjKpMjzWm4dUDqXB3wm3TGrdXJ2 | ||
LkPk7oDPyUqP12ZE/kFaUhThpOWqQa/ga1kvi40St1F8nI8Fagk9Ls5LMklAEEQ0 | ||
/HyqXDvh2nUC0nmTybLVU/ShOiZRP4+t1r8TOEQouoGz+XQVu2FlZNGsz0w7UL5U | ||
3WDftyU3oSaYFN2E3pV1ZWQ2OUsESeCwCjMpJEF1L3lQBFKXmXQhLaGppXu/G4gF | ||
PtwVm0nkXHe6qd+icwNMYon6Rg== | ||
-----END CERTIFICATE----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCbLUib/ie6WijV | ||
TtHsHo4hTK3cG1xsrpb1W8JpmNMGh/AAhC9qpqEgH0tjrDCYWt8BYFwv5xrp54Jz | ||
ssslSdTgmtXg5TeLn90BtyFtBURmvO/UuRM9qCkwewZodv22sZ8+D6I+zEUbGBkw | ||
rJsWB65MBxGqcjUCATgKn2BdTlJEVSSAoZeuDFfLlfgJmSQALlkFHmacV6qVYIbO | ||
Q4iANodwjZezmQuJZNByVwzkUh4b3KlFxDoEKkzAJFssxk2ONFCrA7TIwuVFpu1Q | ||
HWDyDAYDCMatLo20fjrBbaabIa5ORM8RqDXlJs+OU1/fI+lrWaPuGcG3m66QZgsu | ||
XaB4EfrnAgMBAAECggEAU+bxKn8K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YbQvcunj2AZMCvpLGg61AoGBALDXcv0+vrSXwFDDyWLw | ||
RG4wVwU1xdjXPq0YJWKQC21vpCgLykBbae8INfPCQFnH0ArQF5K08d3LqqjD6lfE | ||
04PY2xuJiqhplsCyMeLWeuRpKoOOIo+V8L2qdVpySobAv2dHvNfQ/vcyGF/Jq6O9 | ||
gvuz+L76RzERQpLm1lzixC4p | ||
-----END PRIVATE KEY----- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
ruby-openssl
this wasverify_hostname(hostname, san.value)
, but I've had to add.last.value
to get this to work here, as I'm getting a single element Array returned instead of a plain string. Maybe this isn't the right solution though. Shouldsan.value
instead return the exact same thing across both implementations?? I've not worked out where this is done though, and maybe it'd break loads of other things...