38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/right_support/net/ssl/open_ssl_patch.rb', line 38
def enable!
return if @enabled
@enabled = true
OpenSSL::SSL.module_exec do
def verify_certificate_identity(cert, hostname)
if RightSupport::Net::SSL::OpenSSLPatch.enabled?
actual_hostname = RightSupport::Net::SSL.expected_hostname
end
actual_hostname ||= hostname
verify_certificate_identity_without_hack(cert, actual_hostname)
end
module_function :verify_certificate_identity
def verify_certificate_identity_without_hack(cert, hostname)
should_verify_common_name = true
cert.extensions.each{|ext|
next if ext.oid != "subjectAltName"
ext.value.split(/,\s+/).each{|general_name|
if /\ADNS:(.*)/ =~ general_name
should_verify_common_name = false
reg = Regexp.escape($1).gsub(/\\\*/, "[^.]+")
return true if /\A#{reg}\z/i =~ hostname
elsif /\AIP Address:(.*)/ =~ general_name
should_verify_common_name = false
return true if $1 == hostname
end
}
}
if should_verify_common_name
cert.subject.to_a.each{|oid, value|
if oid == "CN"
reg = Regexp.escape(value).gsub(/\\\*/, "[^.]+")
return true if /\A#{reg}\z/i =~ hostname
end
}
end
return false
end
module_function :verify_certificate_identity_without_hack
end
end
|