openssl 3.3.2 → 4.0.0
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/CONTRIBUTING.md +3 -0
- data/History.md +85 -0
- data/README.md +12 -11
- data/ext/openssl/extconf.rb +30 -69
- data/ext/openssl/openssl_missing.h +0 -206
- data/ext/openssl/ossl.c +280 -301
- data/ext/openssl/ossl.h +15 -10
- data/ext/openssl/ossl_asn1.c +598 -406
- data/ext/openssl/ossl_asn1.h +15 -1
- data/ext/openssl/ossl_bio.c +3 -3
- data/ext/openssl/ossl_bn.c +286 -291
- data/ext/openssl/ossl_cipher.c +252 -203
- data/ext/openssl/ossl_cipher.h +10 -1
- data/ext/openssl/ossl_config.c +1 -6
- data/ext/openssl/ossl_digest.c +74 -43
- data/ext/openssl/ossl_digest.h +9 -1
- data/ext/openssl/ossl_engine.c +39 -103
- data/ext/openssl/ossl_hmac.c +30 -36
- data/ext/openssl/ossl_kdf.c +42 -53
- data/ext/openssl/ossl_ns_spki.c +31 -37
- data/ext/openssl/ossl_ocsp.c +214 -241
- data/ext/openssl/ossl_pkcs12.c +26 -26
- data/ext/openssl/ossl_pkcs7.c +175 -145
- data/ext/openssl/ossl_pkey.c +162 -178
- data/ext/openssl/ossl_pkey.h +99 -99
- data/ext/openssl/ossl_pkey_dh.c +31 -68
- data/ext/openssl/ossl_pkey_dsa.c +15 -54
- data/ext/openssl/ossl_pkey_ec.c +179 -237
- data/ext/openssl/ossl_pkey_rsa.c +56 -103
- data/ext/openssl/ossl_provider.c +0 -7
- data/ext/openssl/ossl_rand.c +7 -14
- data/ext/openssl/ossl_ssl.c +478 -353
- data/ext/openssl/ossl_ssl.h +8 -8
- data/ext/openssl/ossl_ssl_session.c +93 -97
- data/ext/openssl/ossl_ts.c +81 -127
- data/ext/openssl/ossl_x509.c +9 -28
- data/ext/openssl/ossl_x509attr.c +33 -54
- data/ext/openssl/ossl_x509cert.c +69 -100
- data/ext/openssl/ossl_x509crl.c +78 -89
- data/ext/openssl/ossl_x509ext.c +45 -66
- data/ext/openssl/ossl_x509name.c +63 -88
- data/ext/openssl/ossl_x509req.c +55 -62
- data/ext/openssl/ossl_x509revoked.c +27 -41
- data/ext/openssl/ossl_x509store.c +38 -56
- data/lib/openssl/buffering.rb +30 -24
- data/lib/openssl/digest.rb +1 -1
- data/lib/openssl/pkey.rb +71 -49
- data/lib/openssl/ssl.rb +12 -79
- data/lib/openssl/version.rb +2 -1
- data/lib/openssl/x509.rb +9 -0
- data/lib/openssl.rb +9 -6
- metadata +1 -3
- data/ext/openssl/openssl_missing.c +0 -40
- data/lib/openssl/asn1.rb +0 -188
data/lib/openssl/pkey.rb
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
require_relative 'marshal'
|
|
8
8
|
|
|
9
9
|
module OpenSSL::PKey
|
|
10
|
+
# Alias of PKeyError. Before version 4.0.0, this was a subclass of PKeyError.
|
|
11
|
+
DHError = PKeyError
|
|
12
|
+
|
|
10
13
|
class DH
|
|
11
14
|
include OpenSSL::Marshal
|
|
12
15
|
|
|
@@ -34,6 +37,18 @@ module OpenSSL::PKey
|
|
|
34
37
|
DH.new(to_der)
|
|
35
38
|
end
|
|
36
39
|
|
|
40
|
+
# :call-seq:
|
|
41
|
+
# dh.params -> hash
|
|
42
|
+
#
|
|
43
|
+
# Stores all parameters of key to a Hash.
|
|
44
|
+
#
|
|
45
|
+
# The hash has keys 'p', 'q', 'g', 'pub_key', and 'priv_key'.
|
|
46
|
+
def params
|
|
47
|
+
%w{p q g pub_key priv_key}.map { |name|
|
|
48
|
+
[name, send(name)]
|
|
49
|
+
}.to_h
|
|
50
|
+
end
|
|
51
|
+
|
|
37
52
|
# :call-seq:
|
|
38
53
|
# dh.compute_key(pub_bn) -> string
|
|
39
54
|
#
|
|
@@ -90,7 +105,7 @@ module OpenSSL::PKey
|
|
|
90
105
|
# puts dh0.pub_key == dh.pub_key #=> false
|
|
91
106
|
def generate_key!
|
|
92
107
|
if OpenSSL::OPENSSL_VERSION_NUMBER >= 0x30000000
|
|
93
|
-
raise
|
|
108
|
+
raise PKeyError, "OpenSSL::PKey::DH is immutable on OpenSSL 3.0; " \
|
|
94
109
|
"use OpenSSL::PKey.generate_key instead"
|
|
95
110
|
end
|
|
96
111
|
|
|
@@ -135,6 +150,9 @@ module OpenSSL::PKey
|
|
|
135
150
|
end
|
|
136
151
|
end
|
|
137
152
|
|
|
153
|
+
# Alias of PKeyError. Before version 4.0.0, this was a subclass of PKeyError.
|
|
154
|
+
DSAError = PKeyError
|
|
155
|
+
|
|
138
156
|
class DSA
|
|
139
157
|
include OpenSSL::Marshal
|
|
140
158
|
|
|
@@ -154,6 +172,18 @@ module OpenSSL::PKey
|
|
|
154
172
|
OpenSSL::PKey.read(public_to_der)
|
|
155
173
|
end
|
|
156
174
|
|
|
175
|
+
# :call-seq:
|
|
176
|
+
# dsa.params -> hash
|
|
177
|
+
#
|
|
178
|
+
# Stores all parameters of key to a Hash.
|
|
179
|
+
#
|
|
180
|
+
# The hash has keys 'p', 'q', 'g', 'pub_key', and 'priv_key'.
|
|
181
|
+
def params
|
|
182
|
+
%w{p q g pub_key priv_key}.map { |name|
|
|
183
|
+
[name, send(name)]
|
|
184
|
+
}.to_h
|
|
185
|
+
end
|
|
186
|
+
|
|
157
187
|
class << self
|
|
158
188
|
# :call-seq:
|
|
159
189
|
# DSA.generate(size) -> dsa
|
|
@@ -218,13 +248,9 @@ module OpenSSL::PKey
|
|
|
218
248
|
# sig = dsa.sign_raw(nil, digest)
|
|
219
249
|
# p dsa.verify_raw(nil, sig, digest) #=> true
|
|
220
250
|
def syssign(string)
|
|
221
|
-
q or raise
|
|
222
|
-
private? or raise
|
|
223
|
-
|
|
224
|
-
sign_raw(nil, string)
|
|
225
|
-
rescue OpenSSL::PKey::PKeyError
|
|
226
|
-
raise OpenSSL::PKey::DSAError, $!.message
|
|
227
|
-
end
|
|
251
|
+
q or raise PKeyError, "incomplete DSA"
|
|
252
|
+
private? or raise PKeyError, "Private DSA key needed!"
|
|
253
|
+
sign_raw(nil, string)
|
|
228
254
|
end
|
|
229
255
|
|
|
230
256
|
# :call-seq:
|
|
@@ -242,12 +268,13 @@ module OpenSSL::PKey
|
|
|
242
268
|
# A \DSA signature value.
|
|
243
269
|
def sysverify(digest, sig)
|
|
244
270
|
verify_raw(nil, sig, digest)
|
|
245
|
-
rescue OpenSSL::PKey::PKeyError
|
|
246
|
-
raise OpenSSL::PKey::DSAError, $!.message
|
|
247
271
|
end
|
|
248
272
|
end
|
|
249
273
|
|
|
250
274
|
if defined?(EC)
|
|
275
|
+
# Alias of PKeyError. Before version 4.0.0, this was a subclass of PKeyError.
|
|
276
|
+
ECError = PKeyError
|
|
277
|
+
|
|
251
278
|
class EC
|
|
252
279
|
include OpenSSL::Marshal
|
|
253
280
|
|
|
@@ -258,8 +285,6 @@ module OpenSSL::PKey
|
|
|
258
285
|
# Consider using PKey::PKey#sign_raw and PKey::PKey#verify_raw instead.
|
|
259
286
|
def dsa_sign_asn1(data)
|
|
260
287
|
sign_raw(nil, data)
|
|
261
|
-
rescue OpenSSL::PKey::PKeyError
|
|
262
|
-
raise OpenSSL::PKey::ECError, $!.message
|
|
263
288
|
end
|
|
264
289
|
|
|
265
290
|
# :call-seq:
|
|
@@ -269,8 +294,6 @@ module OpenSSL::PKey
|
|
|
269
294
|
# Consider using PKey::PKey#sign_raw and PKey::PKey#verify_raw instead.
|
|
270
295
|
def dsa_verify_asn1(data, sig)
|
|
271
296
|
verify_raw(nil, sig, data)
|
|
272
|
-
rescue OpenSSL::PKey::PKeyError
|
|
273
|
-
raise OpenSSL::PKey::ECError, $!.message
|
|
274
297
|
end
|
|
275
298
|
|
|
276
299
|
# :call-seq:
|
|
@@ -310,6 +333,9 @@ module OpenSSL::PKey
|
|
|
310
333
|
end
|
|
311
334
|
end
|
|
312
335
|
|
|
336
|
+
# Alias of PKeyError. Before version 4.0.0, this was a subclass of PKeyError.
|
|
337
|
+
RSAError = PKeyError
|
|
338
|
+
|
|
313
339
|
class RSA
|
|
314
340
|
include OpenSSL::Marshal
|
|
315
341
|
|
|
@@ -328,6 +354,18 @@ module OpenSSL::PKey
|
|
|
328
354
|
OpenSSL::PKey.read(public_to_der)
|
|
329
355
|
end
|
|
330
356
|
|
|
357
|
+
# :call-seq:
|
|
358
|
+
# rsa.params -> hash
|
|
359
|
+
#
|
|
360
|
+
# Stores all parameters of key to a Hash.
|
|
361
|
+
#
|
|
362
|
+
# The hash has keys 'n', 'e', 'd', 'p', 'q', 'dmp1', 'dmq1', and 'iqmp'.
|
|
363
|
+
def params
|
|
364
|
+
%w{n e d p q dmp1 dmq1 iqmp}.map { |name|
|
|
365
|
+
[name, send(name)]
|
|
366
|
+
}.to_h
|
|
367
|
+
end
|
|
368
|
+
|
|
331
369
|
class << self
|
|
332
370
|
# :call-seq:
|
|
333
371
|
# RSA.generate(size, exponent = 65537) -> RSA
|
|
@@ -371,15 +409,11 @@ module OpenSSL::PKey
|
|
|
371
409
|
# Consider using PKey::PKey#sign_raw and PKey::PKey#verify_raw, and
|
|
372
410
|
# PKey::PKey#verify_recover instead.
|
|
373
411
|
def private_encrypt(string, padding = PKCS1_PADDING)
|
|
374
|
-
n or raise
|
|
375
|
-
private? or raise
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
})
|
|
380
|
-
rescue OpenSSL::PKey::PKeyError
|
|
381
|
-
raise OpenSSL::PKey::RSAError, $!.message
|
|
382
|
-
end
|
|
412
|
+
n or raise PKeyError, "incomplete RSA"
|
|
413
|
+
private? or raise PKeyError, "private key needed."
|
|
414
|
+
sign_raw(nil, string, {
|
|
415
|
+
"rsa_padding_mode" => translate_padding_mode(padding),
|
|
416
|
+
})
|
|
383
417
|
end
|
|
384
418
|
|
|
385
419
|
# :call-seq:
|
|
@@ -394,14 +428,10 @@ module OpenSSL::PKey
|
|
|
394
428
|
# Consider using PKey::PKey#sign_raw and PKey::PKey#verify_raw, and
|
|
395
429
|
# PKey::PKey#verify_recover instead.
|
|
396
430
|
def public_decrypt(string, padding = PKCS1_PADDING)
|
|
397
|
-
n or raise
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
})
|
|
402
|
-
rescue OpenSSL::PKey::PKeyError
|
|
403
|
-
raise OpenSSL::PKey::RSAError, $!.message
|
|
404
|
-
end
|
|
431
|
+
n or raise PKeyError, "incomplete RSA"
|
|
432
|
+
verify_recover(nil, string, {
|
|
433
|
+
"rsa_padding_mode" => translate_padding_mode(padding),
|
|
434
|
+
})
|
|
405
435
|
end
|
|
406
436
|
|
|
407
437
|
# :call-seq:
|
|
@@ -416,14 +446,10 @@ module OpenSSL::PKey
|
|
|
416
446
|
# <b>Deprecated in version 3.0</b>.
|
|
417
447
|
# Consider using PKey::PKey#encrypt and PKey::PKey#decrypt instead.
|
|
418
448
|
def public_encrypt(data, padding = PKCS1_PADDING)
|
|
419
|
-
n or raise
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
})
|
|
424
|
-
rescue OpenSSL::PKey::PKeyError
|
|
425
|
-
raise OpenSSL::PKey::RSAError, $!.message
|
|
426
|
-
end
|
|
449
|
+
n or raise PKeyError, "incomplete RSA"
|
|
450
|
+
encrypt(data, {
|
|
451
|
+
"rsa_padding_mode" => translate_padding_mode(padding),
|
|
452
|
+
})
|
|
427
453
|
end
|
|
428
454
|
|
|
429
455
|
# :call-seq:
|
|
@@ -437,15 +463,11 @@ module OpenSSL::PKey
|
|
|
437
463
|
# <b>Deprecated in version 3.0</b>.
|
|
438
464
|
# Consider using PKey::PKey#encrypt and PKey::PKey#decrypt instead.
|
|
439
465
|
def private_decrypt(data, padding = PKCS1_PADDING)
|
|
440
|
-
n or raise
|
|
441
|
-
private? or raise
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
})
|
|
446
|
-
rescue OpenSSL::PKey::PKeyError
|
|
447
|
-
raise OpenSSL::PKey::RSAError, $!.message
|
|
448
|
-
end
|
|
466
|
+
n or raise PKeyError, "incomplete RSA"
|
|
467
|
+
private? or raise PKeyError, "private key needed."
|
|
468
|
+
decrypt(data, {
|
|
469
|
+
"rsa_padding_mode" => translate_padding_mode(padding),
|
|
470
|
+
})
|
|
449
471
|
end
|
|
450
472
|
|
|
451
473
|
PKCS1_PADDING = 1
|
|
@@ -464,7 +486,7 @@ module OpenSSL::PKey
|
|
|
464
486
|
when PKCS1_OAEP_PADDING
|
|
465
487
|
"oaep"
|
|
466
488
|
else
|
|
467
|
-
raise
|
|
489
|
+
raise PKeyError, "unsupported padding mode"
|
|
468
490
|
end
|
|
469
491
|
end
|
|
470
492
|
end
|
data/lib/openssl/ssl.rb
CHANGED
|
@@ -32,27 +32,7 @@ module OpenSSL
|
|
|
32
32
|
}.call
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
if
|
|
36
|
-
DH_ffdhe2048 = OpenSSL::PKey::DH.new <<-_end_of_pem_
|
|
37
|
-
-----BEGIN DH PARAMETERS-----
|
|
38
|
-
MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz
|
|
39
|
-
+8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a
|
|
40
|
-
87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7
|
|
41
|
-
YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi
|
|
42
|
-
7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD
|
|
43
|
-
ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
|
|
44
|
-
-----END DH PARAMETERS-----
|
|
45
|
-
_end_of_pem_
|
|
46
|
-
private_constant :DH_ffdhe2048
|
|
47
|
-
|
|
48
|
-
DEFAULT_TMP_DH_CALLBACK = lambda { |ctx, is_export, keylen| # :nodoc:
|
|
49
|
-
warn "using default DH parameters." if $VERBOSE
|
|
50
|
-
DH_ffdhe2048
|
|
51
|
-
}
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
if !(OpenSSL::OPENSSL_VERSION.start_with?("OpenSSL") &&
|
|
55
|
-
OpenSSL::OPENSSL_VERSION_NUMBER >= 0x10100000)
|
|
35
|
+
if !OpenSSL::OPENSSL_VERSION.start_with?("OpenSSL")
|
|
56
36
|
DEFAULT_PARAMS.merge!(
|
|
57
37
|
min_version: OpenSSL::SSL::TLS1_VERSION,
|
|
58
38
|
ciphers: %w{
|
|
@@ -86,26 +66,14 @@ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
|
|
|
86
66
|
AES256-SHA256
|
|
87
67
|
AES128-SHA
|
|
88
68
|
AES256-SHA
|
|
89
|
-
}.join(":"),
|
|
69
|
+
}.join(":").freeze,
|
|
90
70
|
)
|
|
91
71
|
end
|
|
72
|
+
DEFAULT_PARAMS.freeze
|
|
92
73
|
|
|
93
74
|
DEFAULT_CERT_STORE = OpenSSL::X509::Store.new # :nodoc:
|
|
94
75
|
DEFAULT_CERT_STORE.set_default_paths
|
|
95
76
|
|
|
96
|
-
# A callback invoked when DH parameters are required for ephemeral DH key
|
|
97
|
-
# exchange.
|
|
98
|
-
#
|
|
99
|
-
# The callback is invoked with the SSLSocket, a
|
|
100
|
-
# flag indicating the use of an export cipher and the keylength
|
|
101
|
-
# required.
|
|
102
|
-
#
|
|
103
|
-
# The callback must return an OpenSSL::PKey::DH instance of the correct
|
|
104
|
-
# key length.
|
|
105
|
-
#
|
|
106
|
-
# <b>Deprecated in version 3.0.</b> Use #tmp_dh= instead.
|
|
107
|
-
attr_accessor :tmp_dh_callback
|
|
108
|
-
|
|
109
77
|
# A callback invoked at connect time to distinguish between multiple
|
|
110
78
|
# server names.
|
|
111
79
|
#
|
|
@@ -147,49 +115,19 @@ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
|
|
|
147
115
|
params.each{|name, value| self.__send__("#{name}=", value) }
|
|
148
116
|
if self.verify_mode != OpenSSL::SSL::VERIFY_NONE
|
|
149
117
|
unless self.ca_file or self.ca_path or self.cert_store
|
|
150
|
-
|
|
118
|
+
if not defined?(Ractor) or Ractor.current == Ractor.main
|
|
119
|
+
self.cert_store = DEFAULT_CERT_STORE
|
|
120
|
+
else
|
|
121
|
+
self.cert_store = Ractor.current[:__openssl_default_store__] ||=
|
|
122
|
+
OpenSSL::X509::Store.new.tap { |store|
|
|
123
|
+
store.set_default_paths
|
|
124
|
+
}
|
|
125
|
+
end
|
|
151
126
|
end
|
|
152
127
|
end
|
|
153
128
|
return params
|
|
154
129
|
end
|
|
155
130
|
|
|
156
|
-
# call-seq:
|
|
157
|
-
# ctx.min_version = OpenSSL::SSL::TLS1_2_VERSION
|
|
158
|
-
# ctx.min_version = :TLS1_2
|
|
159
|
-
# ctx.min_version = nil
|
|
160
|
-
#
|
|
161
|
-
# Sets the lower bound on the supported SSL/TLS protocol version. The
|
|
162
|
-
# version may be specified by an integer constant named
|
|
163
|
-
# OpenSSL::SSL::*_VERSION, a Symbol, or +nil+ which means "any version".
|
|
164
|
-
#
|
|
165
|
-
# Be careful that you don't overwrite OpenSSL::SSL::OP_NO_{SSL,TLS}v*
|
|
166
|
-
# options by #options= once you have called #min_version= or
|
|
167
|
-
# #max_version=.
|
|
168
|
-
#
|
|
169
|
-
# === Example
|
|
170
|
-
# ctx = OpenSSL::SSL::SSLContext.new
|
|
171
|
-
# ctx.min_version = OpenSSL::SSL::TLS1_1_VERSION
|
|
172
|
-
# ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
|
|
173
|
-
#
|
|
174
|
-
# sock = OpenSSL::SSL::SSLSocket.new(tcp_sock, ctx)
|
|
175
|
-
# sock.connect # Initiates a connection using either TLS 1.1 or TLS 1.2
|
|
176
|
-
def min_version=(version)
|
|
177
|
-
set_minmax_proto_version(version, @max_proto_version ||= nil)
|
|
178
|
-
@min_proto_version = version
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
# call-seq:
|
|
182
|
-
# ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
|
|
183
|
-
# ctx.max_version = :TLS1_2
|
|
184
|
-
# ctx.max_version = nil
|
|
185
|
-
#
|
|
186
|
-
# Sets the upper bound of the supported SSL/TLS protocol version. See
|
|
187
|
-
# #min_version= for the possible values.
|
|
188
|
-
def max_version=(version)
|
|
189
|
-
set_minmax_proto_version(@min_proto_version ||= nil, version)
|
|
190
|
-
@max_proto_version = version
|
|
191
|
-
end
|
|
192
|
-
|
|
193
131
|
# call-seq:
|
|
194
132
|
# ctx.ssl_version = :TLSv1
|
|
195
133
|
# ctx.ssl_version = "SSLv23"
|
|
@@ -214,8 +152,7 @@ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
|
|
|
214
152
|
end
|
|
215
153
|
version = METHODS_MAP[meth.intern] or
|
|
216
154
|
raise ArgumentError, "unknown SSL method `%s'" % meth
|
|
217
|
-
|
|
218
|
-
@min_proto_version = @max_proto_version = version
|
|
155
|
+
self.min_version = self.max_version = version
|
|
219
156
|
end
|
|
220
157
|
|
|
221
158
|
METHODS_MAP = {
|
|
@@ -495,10 +432,6 @@ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
|
|
|
495
432
|
@context.client_cert_cb
|
|
496
433
|
end
|
|
497
434
|
|
|
498
|
-
def tmp_dh_callback
|
|
499
|
-
@context.tmp_dh_callback || OpenSSL::SSL::SSLContext::DEFAULT_TMP_DH_CALLBACK
|
|
500
|
-
end
|
|
501
|
-
|
|
502
435
|
def session_new_cb
|
|
503
436
|
@context.session_new_cb
|
|
504
437
|
end
|
data/lib/openssl/version.rb
CHANGED
data/lib/openssl/x509.rb
CHANGED
|
@@ -346,6 +346,15 @@ module OpenSSL
|
|
|
346
346
|
include Extension::CRLDistributionPoints
|
|
347
347
|
include Extension::AuthorityInfoAccess
|
|
348
348
|
|
|
349
|
+
def inspect
|
|
350
|
+
"#<#{self.class}: " \
|
|
351
|
+
"subject=#{subject.inspect}, " \
|
|
352
|
+
"issuer=#{issuer.inspect}, " \
|
|
353
|
+
"serial=#{serial.inspect}, " \
|
|
354
|
+
"not_before=#{not_before.inspect rescue "(error)"}, " \
|
|
355
|
+
"not_after=#{not_after.inspect rescue "(error)"}>"
|
|
356
|
+
end
|
|
357
|
+
|
|
349
358
|
def pretty_print(q)
|
|
350
359
|
q.object_group(self) {
|
|
351
360
|
q.breakable
|
data/lib/openssl.rb
CHANGED
|
@@ -13,23 +13,26 @@
|
|
|
13
13
|
require 'openssl.so'
|
|
14
14
|
|
|
15
15
|
require_relative 'openssl/bn'
|
|
16
|
-
require_relative 'openssl/asn1'
|
|
17
|
-
require_relative 'openssl/pkey'
|
|
18
16
|
require_relative 'openssl/cipher'
|
|
19
17
|
require_relative 'openssl/digest'
|
|
20
18
|
require_relative 'openssl/hmac'
|
|
21
|
-
require_relative 'openssl/x509'
|
|
22
|
-
require_relative 'openssl/ssl'
|
|
23
19
|
require_relative 'openssl/pkcs5'
|
|
20
|
+
require_relative 'openssl/pkey'
|
|
21
|
+
require_relative 'openssl/ssl'
|
|
24
22
|
require_relative 'openssl/version'
|
|
23
|
+
require_relative 'openssl/x509'
|
|
25
24
|
|
|
26
25
|
module OpenSSL
|
|
27
|
-
# call-seq:
|
|
28
|
-
#
|
|
26
|
+
# :call-seq:
|
|
27
|
+
# OpenSSL.secure_compare(string, string) -> true or false
|
|
29
28
|
#
|
|
30
29
|
# Constant time memory comparison. Inputs are hashed using SHA-256 to mask
|
|
31
30
|
# the length of the secret. Returns +true+ if the strings are identical,
|
|
32
31
|
# +false+ otherwise.
|
|
32
|
+
#
|
|
33
|
+
# This method is expensive due to the SHA-256 hashing. In most cases, where
|
|
34
|
+
# the input lengths are known to be equal or are not sensitive,
|
|
35
|
+
# OpenSSL.fixed_length_secure_compare should be used instead.
|
|
33
36
|
def self.secure_compare(a, b)
|
|
34
37
|
hashed_a = OpenSSL::Digest.digest('SHA256', a)
|
|
35
38
|
hashed_b = OpenSSL::Digest.digest('SHA256', b)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openssl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Martin Bosslet
|
|
@@ -30,7 +30,6 @@ files:
|
|
|
30
30
|
- History.md
|
|
31
31
|
- README.md
|
|
32
32
|
- ext/openssl/extconf.rb
|
|
33
|
-
- ext/openssl/openssl_missing.c
|
|
34
33
|
- ext/openssl/openssl_missing.h
|
|
35
34
|
- ext/openssl/ossl.c
|
|
36
35
|
- ext/openssl/ossl.h
|
|
@@ -86,7 +85,6 @@ files:
|
|
|
86
85
|
- ext/openssl/ossl_x509revoked.c
|
|
87
86
|
- ext/openssl/ossl_x509store.c
|
|
88
87
|
- lib/openssl.rb
|
|
89
|
-
- lib/openssl/asn1.rb
|
|
90
88
|
- lib/openssl/bn.rb
|
|
91
89
|
- lib/openssl/buffering.rb
|
|
92
90
|
- lib/openssl/cipher.rb
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* 'OpenSSL for Ruby' project
|
|
3
|
-
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
*/
|
|
6
|
-
/*
|
|
7
|
-
* This program is licensed under the same licence as Ruby.
|
|
8
|
-
* (See the file 'COPYING'.)
|
|
9
|
-
*/
|
|
10
|
-
#include RUBY_EXTCONF_H
|
|
11
|
-
|
|
12
|
-
#include <string.h> /* memcpy() */
|
|
13
|
-
#include <openssl/x509_vfy.h>
|
|
14
|
-
|
|
15
|
-
#include "openssl_missing.h"
|
|
16
|
-
|
|
17
|
-
/*** added in 1.1.0 ***/
|
|
18
|
-
#if !defined(HAVE_X509_CRL_GET0_SIGNATURE)
|
|
19
|
-
void
|
|
20
|
-
ossl_X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
|
|
21
|
-
const X509_ALGOR **palg)
|
|
22
|
-
{
|
|
23
|
-
if (psig != NULL)
|
|
24
|
-
*psig = crl->signature;
|
|
25
|
-
if (palg != NULL)
|
|
26
|
-
*palg = crl->sig_alg;
|
|
27
|
-
}
|
|
28
|
-
#endif
|
|
29
|
-
|
|
30
|
-
#if !defined(HAVE_X509_REQ_GET0_SIGNATURE)
|
|
31
|
-
void
|
|
32
|
-
ossl_X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig,
|
|
33
|
-
const X509_ALGOR **palg)
|
|
34
|
-
{
|
|
35
|
-
if (psig != NULL)
|
|
36
|
-
*psig = req->signature;
|
|
37
|
-
if (palg != NULL)
|
|
38
|
-
*palg = req->sig_alg;
|
|
39
|
-
}
|
|
40
|
-
#endif
|
data/lib/openssl/asn1.rb
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
#--
|
|
3
|
-
#
|
|
4
|
-
# = Ruby-space definitions that completes C-space funcs for ASN.1
|
|
5
|
-
#
|
|
6
|
-
# = Licence
|
|
7
|
-
# This program is licensed under the same licence as Ruby.
|
|
8
|
-
# (See the file 'COPYING'.)
|
|
9
|
-
#++
|
|
10
|
-
|
|
11
|
-
module OpenSSL
|
|
12
|
-
module ASN1
|
|
13
|
-
class ASN1Data
|
|
14
|
-
#
|
|
15
|
-
# Carries the value of a ASN.1 type.
|
|
16
|
-
# Please confer Constructive and Primitive for the mappings between
|
|
17
|
-
# ASN.1 data types and Ruby classes.
|
|
18
|
-
#
|
|
19
|
-
attr_accessor :value
|
|
20
|
-
|
|
21
|
-
# An Integer representing the tag number of this ASN1Data. Never +nil+.
|
|
22
|
-
attr_accessor :tag
|
|
23
|
-
|
|
24
|
-
# A Symbol representing the tag class of this ASN1Data. Never +nil+.
|
|
25
|
-
# See ASN1Data for possible values.
|
|
26
|
-
attr_accessor :tag_class
|
|
27
|
-
|
|
28
|
-
#
|
|
29
|
-
# Never +nil+. A boolean value indicating whether the encoding uses
|
|
30
|
-
# indefinite length (in the case of parsing) or whether an indefinite
|
|
31
|
-
# length form shall be used (in the encoding case).
|
|
32
|
-
# In DER, every value uses definite length form. But in scenarios where
|
|
33
|
-
# large amounts of data need to be transferred it might be desirable to
|
|
34
|
-
# have some kind of streaming support available.
|
|
35
|
-
# For example, huge OCTET STRINGs are preferably sent in smaller-sized
|
|
36
|
-
# chunks, each at a time.
|
|
37
|
-
# This is possible in BER by setting the length bytes of an encoding
|
|
38
|
-
# to zero and by this indicating that the following value will be
|
|
39
|
-
# sent in chunks. Indefinite length encodings are always constructed.
|
|
40
|
-
# The end of such a stream of chunks is indicated by sending a EOC
|
|
41
|
-
# (End of Content) tag. SETs and SEQUENCEs may use an indefinite length
|
|
42
|
-
# encoding, but also primitive types such as e.g. OCTET STRINGS or
|
|
43
|
-
# BIT STRINGS may leverage this functionality (cf. ITU-T X.690).
|
|
44
|
-
#
|
|
45
|
-
attr_accessor :indefinite_length
|
|
46
|
-
|
|
47
|
-
alias infinite_length indefinite_length
|
|
48
|
-
alias infinite_length= indefinite_length=
|
|
49
|
-
|
|
50
|
-
#
|
|
51
|
-
# :call-seq:
|
|
52
|
-
# OpenSSL::ASN1::ASN1Data.new(value, tag, tag_class) => ASN1Data
|
|
53
|
-
#
|
|
54
|
-
# _value_: Please have a look at Constructive and Primitive to see how Ruby
|
|
55
|
-
# types are mapped to ASN.1 types and vice versa.
|
|
56
|
-
#
|
|
57
|
-
# _tag_: An Integer indicating the tag number.
|
|
58
|
-
#
|
|
59
|
-
# _tag_class_: A Symbol indicating the tag class. Please cf. ASN1 for
|
|
60
|
-
# possible values.
|
|
61
|
-
#
|
|
62
|
-
# == Example
|
|
63
|
-
# asn1_int = OpenSSL::ASN1Data.new(42, 2, :UNIVERSAL) # => Same as OpenSSL::ASN1::Integer.new(42)
|
|
64
|
-
# tagged_int = OpenSSL::ASN1Data.new(42, 0, :CONTEXT_SPECIFIC) # implicitly 0-tagged INTEGER
|
|
65
|
-
#
|
|
66
|
-
def initialize(value, tag, tag_class)
|
|
67
|
-
raise ASN1Error, "invalid tag class" unless tag_class.is_a?(Symbol)
|
|
68
|
-
|
|
69
|
-
@tag = tag
|
|
70
|
-
@value = value
|
|
71
|
-
@tag_class = tag_class
|
|
72
|
-
@indefinite_length = false
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
module TaggedASN1Data
|
|
77
|
-
#
|
|
78
|
-
# May be used as a hint for encoding a value either implicitly or
|
|
79
|
-
# explicitly by setting it either to +:IMPLICIT+ or to +:EXPLICIT+.
|
|
80
|
-
# _tagging_ is not set when a ASN.1 structure is parsed using
|
|
81
|
-
# OpenSSL::ASN1.decode.
|
|
82
|
-
#
|
|
83
|
-
attr_accessor :tagging
|
|
84
|
-
|
|
85
|
-
# :call-seq:
|
|
86
|
-
# OpenSSL::ASN1::Primitive.new(value [, tag, tagging, tag_class ]) => Primitive
|
|
87
|
-
#
|
|
88
|
-
# _value_: is mandatory.
|
|
89
|
-
#
|
|
90
|
-
# _tag_: optional, may be specified for tagged values. If no _tag_ is
|
|
91
|
-
# specified, the UNIVERSAL tag corresponding to the Primitive sub-class
|
|
92
|
-
# is used by default.
|
|
93
|
-
#
|
|
94
|
-
# _tagging_: may be used as an encoding hint to encode a value either
|
|
95
|
-
# explicitly or implicitly, see ASN1 for possible values.
|
|
96
|
-
#
|
|
97
|
-
# _tag_class_: if _tag_ and _tagging_ are +nil+ then this is set to
|
|
98
|
-
# +:UNIVERSAL+ by default. If either _tag_ or _tagging_ are set then
|
|
99
|
-
# +:CONTEXT_SPECIFIC+ is used as the default. For possible values please
|
|
100
|
-
# cf. ASN1.
|
|
101
|
-
#
|
|
102
|
-
# == Example
|
|
103
|
-
# int = OpenSSL::ASN1::Integer.new(42)
|
|
104
|
-
# zero_tagged_int = OpenSSL::ASN1::Integer.new(42, 0, :IMPLICIT)
|
|
105
|
-
# private_explicit_zero_tagged_int = OpenSSL::ASN1::Integer.new(42, 0, :EXPLICIT, :PRIVATE)
|
|
106
|
-
#
|
|
107
|
-
def initialize(value, tag = nil, tagging = nil, tag_class = nil)
|
|
108
|
-
tag ||= ASN1.take_default_tag(self.class)
|
|
109
|
-
|
|
110
|
-
raise ASN1Error, "must specify tag number" unless tag
|
|
111
|
-
|
|
112
|
-
if tagging
|
|
113
|
-
raise ASN1Error, "invalid tagging method" unless tagging.is_a?(Symbol)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
tag_class ||= tagging ? :CONTEXT_SPECIFIC : :UNIVERSAL
|
|
117
|
-
|
|
118
|
-
raise ASN1Error, "invalid tag class" unless tag_class.is_a?(Symbol)
|
|
119
|
-
|
|
120
|
-
@tagging = tagging
|
|
121
|
-
super(value ,tag, tag_class)
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
class Primitive < ASN1Data
|
|
126
|
-
include TaggedASN1Data
|
|
127
|
-
|
|
128
|
-
undef_method :indefinite_length=
|
|
129
|
-
undef_method :infinite_length=
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
class Constructive < ASN1Data
|
|
133
|
-
include TaggedASN1Data
|
|
134
|
-
include Enumerable
|
|
135
|
-
|
|
136
|
-
# :call-seq:
|
|
137
|
-
# asn1_ary.each { |asn1| block } => asn1_ary
|
|
138
|
-
#
|
|
139
|
-
# Calls the given block once for each element in self, passing that element
|
|
140
|
-
# as parameter _asn1_. If no block is given, an enumerator is returned
|
|
141
|
-
# instead.
|
|
142
|
-
#
|
|
143
|
-
# == Example
|
|
144
|
-
# asn1_ary.each do |asn1|
|
|
145
|
-
# puts asn1
|
|
146
|
-
# end
|
|
147
|
-
#
|
|
148
|
-
def each(&blk)
|
|
149
|
-
@value.each(&blk)
|
|
150
|
-
|
|
151
|
-
self
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
class Boolean < Primitive ; end
|
|
156
|
-
class Integer < Primitive ; end
|
|
157
|
-
class Enumerated < Primitive ; end
|
|
158
|
-
|
|
159
|
-
class BitString < Primitive
|
|
160
|
-
attr_accessor :unused_bits
|
|
161
|
-
|
|
162
|
-
def initialize(*)
|
|
163
|
-
super
|
|
164
|
-
|
|
165
|
-
@unused_bits = 0
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
class EndOfContent < ASN1Data
|
|
170
|
-
def initialize
|
|
171
|
-
super("", 0, :UNIVERSAL)
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
# :nodoc:
|
|
176
|
-
def self.take_default_tag(klass)
|
|
177
|
-
tag = CLASS_TAG_MAP[klass]
|
|
178
|
-
|
|
179
|
-
return tag if tag
|
|
180
|
-
|
|
181
|
-
sklass = klass.superclass
|
|
182
|
-
|
|
183
|
-
return unless sklass
|
|
184
|
-
|
|
185
|
-
take_default_tag(sklass)
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
end
|