rubysl-openssl 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -6
  3. data/ext/rubysl/openssl/.gitignore +3 -0
  4. data/ext/rubysl/openssl/deprecation.rb +21 -0
  5. data/ext/rubysl/openssl/extconf.rb +45 -32
  6. data/ext/rubysl/openssl/openssl_missing.c +20 -7
  7. data/ext/rubysl/openssl/openssl_missing.h +22 -15
  8. data/ext/rubysl/openssl/ossl.c +610 -61
  9. data/ext/rubysl/openssl/ossl.h +31 -17
  10. data/ext/rubysl/openssl/ossl_asn1.c +974 -183
  11. data/ext/rubysl/openssl/ossl_asn1.h +3 -3
  12. data/ext/rubysl/openssl/ossl_bio.c +4 -3
  13. data/ext/rubysl/openssl/ossl_bio.h +1 -1
  14. data/ext/rubysl/openssl/ossl_bn.c +32 -28
  15. data/ext/rubysl/openssl/ossl_bn.h +1 -1
  16. data/ext/rubysl/openssl/ossl_cipher.c +494 -93
  17. data/ext/rubysl/openssl/ossl_cipher.h +1 -1
  18. data/ext/rubysl/openssl/ossl_config.c +4 -5
  19. data/ext/rubysl/openssl/ossl_config.h +1 -1
  20. data/ext/rubysl/openssl/ossl_digest.c +206 -24
  21. data/ext/rubysl/openssl/ossl_digest.h +1 -1
  22. data/ext/rubysl/openssl/ossl_engine.c +48 -26
  23. data/ext/rubysl/openssl/ossl_engine.h +1 -1
  24. data/ext/rubysl/openssl/ossl_hmac.c +40 -38
  25. data/ext/rubysl/openssl/ossl_hmac.h +1 -1
  26. data/ext/rubysl/openssl/ossl_ns_spki.c +157 -25
  27. data/ext/rubysl/openssl/ossl_ns_spki.h +1 -1
  28. data/ext/rubysl/openssl/ossl_ocsp.c +57 -40
  29. data/ext/rubysl/openssl/ossl_ocsp.h +1 -1
  30. data/ext/rubysl/openssl/ossl_pkcs12.c +15 -13
  31. data/ext/rubysl/openssl/ossl_pkcs12.h +1 -1
  32. data/ext/rubysl/openssl/ossl_pkcs5.c +108 -18
  33. data/ext/rubysl/openssl/ossl_pkcs7.c +44 -37
  34. data/ext/rubysl/openssl/ossl_pkcs7.h +1 -1
  35. data/ext/rubysl/openssl/ossl_pkey.c +211 -15
  36. data/ext/rubysl/openssl/ossl_pkey.h +19 -9
  37. data/ext/rubysl/openssl/ossl_pkey_dh.c +180 -47
  38. data/ext/rubysl/openssl/ossl_pkey_dsa.c +184 -47
  39. data/ext/rubysl/openssl/ossl_pkey_ec.c +177 -93
  40. data/ext/rubysl/openssl/ossl_pkey_rsa.c +209 -102
  41. data/ext/rubysl/openssl/ossl_rand.c +15 -15
  42. data/ext/rubysl/openssl/ossl_rand.h +1 -1
  43. data/ext/rubysl/openssl/ossl_ssl.c +939 -192
  44. data/ext/rubysl/openssl/ossl_ssl.h +6 -6
  45. data/ext/rubysl/openssl/ossl_ssl_session.c +78 -62
  46. data/ext/rubysl/openssl/ossl_version.h +2 -2
  47. data/ext/rubysl/openssl/ossl_x509.c +1 -1
  48. data/ext/rubysl/openssl/ossl_x509.h +1 -1
  49. data/ext/rubysl/openssl/ossl_x509attr.c +20 -19
  50. data/ext/rubysl/openssl/ossl_x509cert.c +169 -67
  51. data/ext/rubysl/openssl/ossl_x509crl.c +41 -39
  52. data/ext/rubysl/openssl/ossl_x509ext.c +51 -38
  53. data/ext/rubysl/openssl/ossl_x509name.c +139 -29
  54. data/ext/rubysl/openssl/ossl_x509req.c +42 -40
  55. data/ext/rubysl/openssl/ossl_x509revoked.c +20 -20
  56. data/ext/rubysl/openssl/ossl_x509store.c +99 -47
  57. data/ext/rubysl/openssl/ruby_missing.h +3 -16
  58. data/lib/openssl/bn.rb +19 -19
  59. data/lib/openssl/buffering.rb +222 -14
  60. data/lib/openssl/cipher.rb +20 -20
  61. data/lib/openssl/config.rb +1 -4
  62. data/lib/openssl/digest.rb +47 -19
  63. data/lib/openssl/ssl.rb +197 -1
  64. data/lib/openssl/x509.rb +162 -1
  65. data/lib/rubysl/openssl.rb +4 -8
  66. data/lib/rubysl/openssl/version.rb +1 -1
  67. data/rubysl-openssl.gemspec +1 -2
  68. metadata +16 -34
  69. data/ext/rubysl/openssl/extconf.h +0 -50
  70. data/lib/openssl/net/ftptls.rb +0 -53
  71. data/lib/openssl/net/telnets.rb +0 -251
  72. data/lib/openssl/pkcs7.rb +0 -25
  73. data/lib/openssl/ssl-internal.rb +0 -187
  74. data/lib/openssl/x509-internal.rb +0 -153
@@ -1,25 +0,0 @@
1
- =begin
2
- = $RCSfile$ -- PKCS7
3
-
4
- = Licence
5
- This program is licenced under the same licence as Ruby.
6
- (See the file 'LICENCE'.)
7
-
8
- = Version
9
- $Id: digest.rb 12148 2007-04-05 05:59:22Z technorama $
10
- =end
11
-
12
- module OpenSSL
13
- class PKCS7
14
- # This class is only provided for backwards compatibility. Use OpenSSL::PKCS7 in the future.
15
- class PKCS7 < PKCS7
16
- def initialize(*args)
17
- super(*args)
18
-
19
- warn("Warning: OpenSSL::PKCS7::PKCS7 is deprecated after Ruby 1.9; use OpenSSL::PKCS7 instead")
20
- end
21
- end
22
-
23
- end # PKCS7
24
- end # OpenSSL
25
-
@@ -1,187 +0,0 @@
1
- =begin
2
- = $RCSfile$ -- Ruby-space definitions that completes C-space funcs for SSL
3
-
4
- = Info
5
- 'OpenSSL for Ruby 2' project
6
- Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org>
7
- All rights reserved.
8
-
9
- = Licence
10
- This program is licenced under the same licence as Ruby.
11
- (See the file 'LICENCE'.)
12
-
13
- = Version
14
- $Id$
15
- =end
16
-
17
- require "openssl/buffering"
18
- require "fcntl"
19
-
20
- module OpenSSL
21
- module SSL
22
- class SSLContext
23
- DEFAULT_PARAMS = {
24
- :ssl_version => "SSLv23",
25
- :verify_mode => OpenSSL::SSL::VERIFY_PEER,
26
- :ciphers => "ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW",
27
- :options => OpenSSL::SSL::OP_ALL,
28
- }
29
-
30
- DEFAULT_CERT_STORE = OpenSSL::X509::Store.new
31
- DEFAULT_CERT_STORE.set_default_paths
32
- if defined?(OpenSSL::X509::V_FLAG_CRL_CHECK_ALL)
33
- DEFAULT_CERT_STORE.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL
34
- end
35
-
36
- def set_params(params={})
37
- params = DEFAULT_PARAMS.merge(params)
38
- # ssl_version need to be set at first.
39
- self.ssl_version = params.delete(:ssl_version)
40
- params.each{|name, value| self.__send__("#{name}=", value) }
41
- if self.verify_mode != OpenSSL::SSL::VERIFY_NONE
42
- unless self.ca_file or self.ca_path or self.cert_store
43
- self.cert_store = DEFAULT_CERT_STORE
44
- end
45
- end
46
- return params
47
- end
48
- end
49
-
50
- module SocketForwarder
51
- def addr
52
- to_io.addr
53
- end
54
-
55
- def peeraddr
56
- to_io.peeraddr
57
- end
58
-
59
- def setsockopt(level, optname, optval)
60
- to_io.setsockopt(level, optname, optval)
61
- end
62
-
63
- def getsockopt(level, optname)
64
- to_io.getsockopt(level, optname)
65
- end
66
-
67
- def fcntl(*args)
68
- to_io.fcntl(*args)
69
- end
70
-
71
- def closed?
72
- to_io.closed?
73
- end
74
-
75
- def do_not_reverse_lookup=(flag)
76
- to_io.do_not_reverse_lookup = flag
77
- end
78
- end
79
-
80
- module Nonblock
81
- def initialize(*args)
82
- flag = File::NONBLOCK
83
- flag |= @io.fcntl(Fcntl::F_GETFL) if defined?(Fcntl::F_GETFL)
84
- @io.fcntl(Fcntl::F_SETFL, flag)
85
- super
86
- end
87
- end
88
-
89
- def verify_certificate_identity(cert, hostname)
90
- should_verify_common_name = true
91
- cert.extensions.each{|ext|
92
- next if ext.oid != "subjectAltName"
93
- ostr = OpenSSL::ASN1.decode(ext.to_der).value.last
94
- sequence = OpenSSL::ASN1.decode(ostr.value)
95
- sequence.value.each{|san|
96
- case san.tag
97
- when 2 # dNSName in GeneralName (RFC5280)
98
- should_verify_common_name = false
99
- reg = Regexp.escape(san.value).gsub(/\\\*/, "[^.]+")
100
- return true if /\A#{reg}\z/i =~ hostname
101
- when 7 # iPAddress in GeneralName (RFC5280)
102
- should_verify_common_name = false
103
- # follows GENERAL_NAME_print() in x509v3/v3_alt.c
104
- if san.value.size == 4
105
- return true if san.value.unpack('C*').join('.') == hostname
106
- elsif san.value.size == 16
107
- return true if san.value.unpack('n*').map { |e| sprintf("%X", e) }.join(':') == hostname
108
- end
109
- end
110
- }
111
- }
112
- if should_verify_common_name
113
- cert.subject.to_a.each{|oid, value|
114
- if oid == "CN"
115
- reg = Regexp.escape(value).gsub(/\\\*/, "[^.]+")
116
- return true if /\A#{reg}\z/i =~ hostname
117
- end
118
- }
119
- end
120
- return false
121
- end
122
- module_function :verify_certificate_identity
123
-
124
- class SSLSocket
125
- include Buffering
126
- include SocketForwarder
127
- include Nonblock
128
-
129
- def post_connection_check(hostname)
130
- unless OpenSSL::SSL.verify_certificate_identity(peer_cert, hostname)
131
- raise SSLError, "hostname was not match with the server certificate"
132
- end
133
- return true
134
- end
135
-
136
- def session
137
- SSL::Session.new(self)
138
- rescue SSL::Session::SessionError
139
- nil
140
- end
141
- end
142
-
143
- class SSLServer
144
- include SocketForwarder
145
- attr_accessor :start_immediately
146
-
147
- def initialize(svr, ctx)
148
- @svr = svr
149
- @ctx = ctx
150
- unless ctx.session_id_context
151
- session_id = OpenSSL::Digest::MD5.hexdigest($0)
152
- @ctx.session_id_context = session_id
153
- end
154
- @start_immediately = true
155
- end
156
-
157
- def to_io
158
- @svr
159
- end
160
-
161
- def listen(backlog=5)
162
- @svr.listen(backlog)
163
- end
164
-
165
- def shutdown(how=Socket::SHUT_RDWR)
166
- @svr.shutdown(how)
167
- end
168
-
169
- def accept
170
- sock = @svr.accept
171
- begin
172
- ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx)
173
- ssl.sync_close = true
174
- ssl.accept if @start_immediately
175
- ssl
176
- rescue SSLError => ex
177
- sock.close
178
- raise ex
179
- end
180
- end
181
-
182
- def close
183
- @svr.close
184
- end
185
- end
186
- end
187
- end
@@ -1,153 +0,0 @@
1
- =begin
2
- = $RCSfile$ -- Ruby-space definitions that completes C-space funcs for X509 and subclasses
3
-
4
- = Info
5
- 'OpenSSL for Ruby 2' project
6
- Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
7
- All rights reserved.
8
-
9
- = Licence
10
- This program is licenced under the same licence as Ruby.
11
- (See the file 'LICENCE'.)
12
-
13
- = Version
14
- $Id$
15
- =end
16
-
17
- module OpenSSL
18
- module X509
19
- class ExtensionFactory
20
- def create_extension(*arg)
21
- if arg.size > 1
22
- create_ext(*arg)
23
- else
24
- send("create_ext_from_"+arg[0].class.name.downcase, arg[0])
25
- end
26
- end
27
-
28
- def create_ext_from_array(ary)
29
- raise ExtensionError, "unexpected array form" if ary.size > 3
30
- create_ext(ary[0], ary[1], ary[2])
31
- end
32
-
33
- def create_ext_from_string(str) # "oid = critical, value"
34
- oid, value = str.split(/=/, 2)
35
- oid.strip!
36
- value.strip!
37
- create_ext(oid, value)
38
- end
39
-
40
- def create_ext_from_hash(hash)
41
- create_ext(hash["oid"], hash["value"], hash["critical"])
42
- end
43
- end
44
-
45
- class Extension
46
- def to_s # "oid = critical, value"
47
- str = self.oid
48
- str << " = "
49
- str << "critical, " if self.critical?
50
- str << self.value.gsub(/\n/, ", ")
51
- end
52
-
53
- def to_h # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
54
- {"oid"=>self.oid,"value"=>self.value,"critical"=>self.critical?}
55
- end
56
-
57
- def to_a
58
- [ self.oid, self.value, self.critical? ]
59
- end
60
- end
61
-
62
- class Name
63
- module RFC2253DN
64
- Special = ',=+<>#;'
65
- HexChar = /[0-9a-fA-F]/
66
- HexPair = /#{HexChar}#{HexChar}/
67
- HexString = /#{HexPair}+/
68
- Pair = /\\(?:[#{Special}]|\\|"|#{HexPair})/
69
- StringChar = /[^#{Special}\\"]/
70
- QuoteChar = /[^\\"]/
71
- AttributeType = /[a-zA-Z][0-9a-zA-Z]*|[0-9]+(?:\.[0-9]+)*/
72
- AttributeValue = /
73
- (?!["#])((?:#{StringChar}|#{Pair})*)|
74
- \#(#{HexString})|
75
- "((?:#{QuoteChar}|#{Pair})*)"
76
- /x
77
- TypeAndValue = /\A(#{AttributeType})=#{AttributeValue}/
78
-
79
- module_function
80
-
81
- def expand_pair(str)
82
- return nil unless str
83
- return str.gsub(Pair){
84
- pair = $&
85
- case pair.size
86
- when 2 then pair[1,1]
87
- when 3 then Integer("0x#{pair[1,2]}").chr
88
- else raise OpenSSL::X509::NameError, "invalid pair: #{str}"
89
- end
90
- }
91
- end
92
-
93
- def expand_hexstring(str)
94
- return nil unless str
95
- der = str.gsub(HexPair){$&.to_i(16).chr }
96
- a1 = OpenSSL::ASN1.decode(der)
97
- return a1.value, a1.tag
98
- end
99
-
100
- def expand_value(str1, str2, str3)
101
- value = expand_pair(str1)
102
- value, tag = expand_hexstring(str2) unless value
103
- value = expand_pair(str3) unless value
104
- return value, tag
105
- end
106
-
107
- def scan(dn)
108
- str = dn
109
- ary = []
110
- while true
111
- if md = TypeAndValue.match(str)
112
- matched = md.to_s
113
- remain = md.post_match
114
- type = md[1]
115
- value, tag = expand_value(md[2], md[3], md[4]) rescue nil
116
- if value
117
- type_and_value = [type, value]
118
- type_and_value.push(tag) if tag
119
- ary.unshift(type_and_value)
120
- if remain.length > 2 && remain[0] == ?,
121
- str = remain[1..-1]
122
- next
123
- elsif remain.length > 2 && remain[0] == ?+
124
- raise OpenSSL::X509::NameError,
125
- "multi-valued RDN is not supported: #{dn}"
126
- elsif remain.empty?
127
- break
128
- end
129
- end
130
- end
131
- msg_dn = dn[0, dn.length - str.length] + " =>" + str
132
- raise OpenSSL::X509::NameError, "malformed RDN: #{msg_dn}"
133
- end
134
- return ary
135
- end
136
- end
137
-
138
- class <<self
139
- def parse_rfc2253(str, template=OBJECT_TYPE_TEMPLATE)
140
- ary = OpenSSL::X509::Name::RFC2253DN.scan(str)
141
- self.new(ary, template)
142
- end
143
-
144
- def parse_openssl(str, template=OBJECT_TYPE_TEMPLATE)
145
- ary = str.scan(/\s*([^\/,]+)\s*/).collect{|i| i[0].split("=", 2) }
146
- self.new(ary, template)
147
- end
148
-
149
- alias parse parse_openssl
150
- end
151
- end
152
- end
153
- end