ssl_allow_cname 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ssl_allow_cname.rb +31 -21
- data/lib/ssl_allow_cname/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd9a1a0a538978860ac3c85759c5b63e123353e1
|
4
|
+
data.tar.gz: 38374a3700d5292652387643fcc9ad404faed984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbaa6fd49e2bd2d432e021726a31601e3a31d1e4c993784370230ce228142f2ed39c99120df3e8ef6ccc1bad93b370f654b8d70e1e0d37ae23de3550b5949aa1
|
7
|
+
data.tar.gz: 651865332f539e2aa1db220ff46eb45d58dc7eb9326bb8f92c5e55f961505d5e2608dcd8a68e67349f2ff88a65dd16681f3010e69609a3f10061332225a267cd
|
data/lib/ssl_allow_cname.rb
CHANGED
@@ -2,33 +2,43 @@ require "ssl_allow_cname/version"
|
|
2
2
|
require 'openssl'
|
3
3
|
|
4
4
|
module SslAllowCname
|
5
|
-
module
|
5
|
+
module SSLContext
|
6
|
+
attr_accessor :allow_cname
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
def
|
9
|
-
return
|
10
|
-
|
11
|
-
|
9
|
+
module SSLSocket
|
10
|
+
def post_connection_check(hostname)
|
11
|
+
return super if context.allow_cname.nil?
|
12
|
+
|
13
|
+
cname = peer_cert.subject.to_a.map do |oid, value|
|
14
|
+
oid == 'CN' ? value : nil
|
15
|
+
end.compact.first
|
12
16
|
|
13
|
-
|
14
|
-
Array(@allow_cname).each do |test|
|
17
|
+
passed = Array(context.allow_cname).any? do |test|
|
15
18
|
case test
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
when String, Regexp
|
20
|
+
test === cname
|
21
|
+
when Proc
|
22
|
+
(test.arity == 1) ? test.call(cname)
|
23
|
+
: test.call(cname, hostname)
|
24
|
+
when :match
|
25
|
+
begin
|
26
|
+
super
|
27
|
+
true
|
28
|
+
rescue SSLError
|
29
|
+
false
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|
26
|
-
|
33
|
+
|
34
|
+
unless passed
|
35
|
+
fail OpenSSL::SSL::SSLError, "Peer certificate did not match any " +
|
36
|
+
"predicate in :allow_cname. Use :match " +
|
37
|
+
"to get normal CommonName/Host validation"
|
38
|
+
end
|
27
39
|
end
|
28
40
|
end
|
29
41
|
end
|
30
42
|
|
31
|
-
|
32
|
-
|
33
|
-
prepend SslAllowCname::MonkeyPatch
|
34
|
-
end
|
43
|
+
OpenSSL::SSL::SSLContext.prepend(SslAllowCname::SSLContext)
|
44
|
+
OpenSSL::SSL::SSLSocket.prepend(SslAllowCname::SSLSocket)
|