openssl 2.1.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +35 -45
  3. data/History.md +302 -1
  4. data/README.md +2 -2
  5. data/ext/openssl/extconf.rb +77 -62
  6. data/ext/openssl/openssl_missing.c +0 -66
  7. data/ext/openssl/openssl_missing.h +59 -43
  8. data/ext/openssl/ossl.c +110 -64
  9. data/ext/openssl/ossl.h +33 -10
  10. data/ext/openssl/ossl_asn1.c +51 -13
  11. data/ext/openssl/ossl_bn.c +275 -146
  12. data/ext/openssl/ossl_bn.h +2 -1
  13. data/ext/openssl/ossl_cipher.c +39 -31
  14. data/ext/openssl/ossl_config.c +412 -41
  15. data/ext/openssl/ossl_config.h +4 -7
  16. data/ext/openssl/ossl_digest.c +25 -60
  17. data/ext/openssl/ossl_engine.c +18 -27
  18. data/ext/openssl/ossl_hmac.c +60 -145
  19. data/ext/openssl/ossl_kdf.c +14 -22
  20. data/ext/openssl/ossl_ns_spki.c +1 -1
  21. data/ext/openssl/ossl_ocsp.c +11 -64
  22. data/ext/openssl/ossl_ocsp.h +3 -3
  23. data/ext/openssl/ossl_pkcs12.c +21 -3
  24. data/ext/openssl/ossl_pkcs7.c +45 -78
  25. data/ext/openssl/ossl_pkcs7.h +16 -0
  26. data/ext/openssl/ossl_pkey.c +1295 -178
  27. data/ext/openssl/ossl_pkey.h +36 -73
  28. data/ext/openssl/ossl_pkey_dh.c +130 -340
  29. data/ext/openssl/ossl_pkey_dsa.c +100 -405
  30. data/ext/openssl/ossl_pkey_ec.c +192 -335
  31. data/ext/openssl/ossl_pkey_rsa.c +110 -489
  32. data/ext/openssl/ossl_rand.c +2 -32
  33. data/ext/openssl/ossl_ssl.c +556 -442
  34. data/ext/openssl/ossl_ssl_session.c +28 -29
  35. data/ext/openssl/ossl_ts.c +1539 -0
  36. data/ext/openssl/ossl_ts.h +16 -0
  37. data/ext/openssl/ossl_x509.c +0 -6
  38. data/ext/openssl/ossl_x509cert.c +169 -13
  39. data/ext/openssl/ossl_x509crl.c +13 -10
  40. data/ext/openssl/ossl_x509ext.c +15 -2
  41. data/ext/openssl/ossl_x509name.c +15 -4
  42. data/ext/openssl/ossl_x509req.c +13 -10
  43. data/ext/openssl/ossl_x509revoked.c +3 -3
  44. data/ext/openssl/ossl_x509store.c +154 -70
  45. data/lib/openssl/bn.rb +1 -1
  46. data/lib/openssl/buffering.rb +37 -5
  47. data/lib/openssl/cipher.rb +1 -1
  48. data/lib/openssl/digest.rb +10 -12
  49. data/lib/openssl/hmac.rb +78 -0
  50. data/lib/openssl/marshal.rb +30 -0
  51. data/lib/openssl/pkcs5.rb +1 -1
  52. data/lib/openssl/pkey.rb +447 -1
  53. data/lib/openssl/ssl.rb +52 -9
  54. data/lib/openssl/version.rb +5 -0
  55. data/lib/openssl/x509.rb +177 -1
  56. data/lib/openssl.rb +24 -9
  57. metadata +10 -79
  58. data/ext/openssl/deprecation.rb +0 -27
  59. data/ext/openssl/ossl_version.h +0 -15
  60. data/ext/openssl/ruby_missing.h +0 -24
  61. data/lib/openssl/config.rb +0 -492
@@ -1,492 +0,0 @@
1
- # frozen_string_literal: false
2
- =begin
3
- = Ruby-space definitions that completes C-space funcs for Config
4
-
5
- = Info
6
- Copyright (C) 2010 Hiroshi Nakamura <nahi@ruby-lang.org>
7
-
8
- = Licence
9
- This program is licensed under the same licence as Ruby.
10
- (See the file 'LICENCE'.)
11
-
12
- =end
13
-
14
- require 'stringio'
15
-
16
- module OpenSSL
17
- ##
18
- # = OpenSSL::Config
19
- #
20
- # Configuration for the openssl library.
21
- #
22
- # Many system's installation of openssl library will depend on your system
23
- # configuration. See the value of OpenSSL::Config::DEFAULT_CONFIG_FILE for
24
- # the location of the file for your host.
25
- #
26
- # See also http://www.openssl.org/docs/apps/config.html
27
- class Config
28
- include Enumerable
29
-
30
- class << self
31
-
32
- ##
33
- # Parses a given _string_ as a blob that contains configuration for
34
- # OpenSSL.
35
- #
36
- # If the source of the IO is a file, then consider using #parse_config.
37
- def parse(string)
38
- c = new()
39
- parse_config(StringIO.new(string)).each do |section, hash|
40
- c[section] = hash
41
- end
42
- c
43
- end
44
-
45
- ##
46
- # load is an alias to ::new
47
- alias load new
48
-
49
- ##
50
- # Parses the configuration data read from _io_, see also #parse.
51
- #
52
- # Raises a ConfigError on invalid configuration data.
53
- def parse_config(io)
54
- begin
55
- parse_config_lines(io)
56
- rescue ConfigError => e
57
- e.message.replace("error in line #{io.lineno}: " + e.message)
58
- raise
59
- end
60
- end
61
-
62
- def get_key_string(data, section, key) # :nodoc:
63
- if v = data[section] && data[section][key]
64
- return v
65
- elsif section == 'ENV'
66
- if v = ENV[key]
67
- return v
68
- end
69
- end
70
- if v = data['default'] && data['default'][key]
71
- return v
72
- end
73
- end
74
-
75
- private
76
-
77
- def parse_config_lines(io)
78
- section = 'default'
79
- data = {section => {}}
80
- io_stack = [io]
81
- while definition = get_definition(io_stack)
82
- definition = clear_comments(definition)
83
- next if definition.empty?
84
- case definition
85
- when /\A\[/
86
- if /\[([^\]]*)\]/ =~ definition
87
- section = $1.strip
88
- data[section] ||= {}
89
- else
90
- raise ConfigError, "missing close square bracket"
91
- end
92
- when /\A\.include (\s*=\s*)?(.+)\z/
93
- path = $2
94
- if File.directory?(path)
95
- files = Dir.glob(File.join(path, "*.{cnf,conf}"), File::FNM_EXTGLOB)
96
- else
97
- files = [path]
98
- end
99
-
100
- files.each do |filename|
101
- begin
102
- io_stack << StringIO.new(File.read(filename))
103
- rescue
104
- raise ConfigError, "could not include file '%s'" % filename
105
- end
106
- end
107
- when /\A([^:\s]*)(?:::([^:\s]*))?\s*=(.*)\z/
108
- if $2
109
- section = $1
110
- key = $2
111
- else
112
- key = $1
113
- end
114
- value = unescape_value(data, section, $3)
115
- (data[section] ||= {})[key] = value.strip
116
- else
117
- raise ConfigError, "missing equal sign"
118
- end
119
- end
120
- data
121
- end
122
-
123
- # escape with backslash
124
- QUOTE_REGEXP_SQ = /\A([^'\\]*(?:\\.[^'\\]*)*)'/
125
- # escape with backslash and doubled dq
126
- QUOTE_REGEXP_DQ = /\A([^"\\]*(?:""[^"\\]*|\\.[^"\\]*)*)"/
127
- # escaped char map
128
- ESCAPE_MAP = {
129
- "r" => "\r",
130
- "n" => "\n",
131
- "b" => "\b",
132
- "t" => "\t",
133
- }
134
-
135
- def unescape_value(data, section, value)
136
- scanned = []
137
- while m = value.match(/['"\\$]/)
138
- scanned << m.pre_match
139
- c = m[0]
140
- value = m.post_match
141
- case c
142
- when "'"
143
- if m = value.match(QUOTE_REGEXP_SQ)
144
- scanned << m[1].gsub(/\\(.)/, '\\1')
145
- value = m.post_match
146
- else
147
- break
148
- end
149
- when '"'
150
- if m = value.match(QUOTE_REGEXP_DQ)
151
- scanned << m[1].gsub(/""/, '').gsub(/\\(.)/, '\\1')
152
- value = m.post_match
153
- else
154
- break
155
- end
156
- when "\\"
157
- c = value.slice!(0, 1)
158
- scanned << (ESCAPE_MAP[c] || c)
159
- when "$"
160
- ref, value = extract_reference(value)
161
- refsec = section
162
- if ref.index('::')
163
- refsec, ref = ref.split('::', 2)
164
- end
165
- if v = get_key_string(data, refsec, ref)
166
- scanned << v
167
- else
168
- raise ConfigError, "variable has no value"
169
- end
170
- else
171
- raise 'must not reaced'
172
- end
173
- end
174
- scanned << value
175
- scanned.join
176
- end
177
-
178
- def extract_reference(value)
179
- rest = ''
180
- if m = value.match(/\(([^)]*)\)|\{([^}]*)\}/)
181
- value = m[1] || m[2]
182
- rest = m.post_match
183
- elsif [?(, ?{].include?(value[0])
184
- raise ConfigError, "no close brace"
185
- end
186
- if m = value.match(/[a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]*)?/)
187
- return m[0], m.post_match + rest
188
- else
189
- raise
190
- end
191
- end
192
-
193
- def clear_comments(line)
194
- # FCOMMENT
195
- if m = line.match(/\A([\t\n\f ]*);.*\z/)
196
- return m[1]
197
- end
198
- # COMMENT
199
- scanned = []
200
- while m = line.match(/[#'"\\]/)
201
- scanned << m.pre_match
202
- c = m[0]
203
- line = m.post_match
204
- case c
205
- when '#'
206
- line = nil
207
- break
208
- when "'", '"'
209
- regexp = (c == "'") ? QUOTE_REGEXP_SQ : QUOTE_REGEXP_DQ
210
- scanned << c
211
- if m = line.match(regexp)
212
- scanned << m[0]
213
- line = m.post_match
214
- else
215
- scanned << line
216
- line = nil
217
- break
218
- end
219
- when "\\"
220
- scanned << c
221
- scanned << line.slice!(0, 1)
222
- else
223
- raise 'must not reaced'
224
- end
225
- end
226
- scanned << line
227
- scanned.join
228
- end
229
-
230
- def get_definition(io_stack)
231
- if line = get_line(io_stack)
232
- while /[^\\]\\\z/ =~ line
233
- if extra = get_line(io_stack)
234
- line += extra
235
- else
236
- break
237
- end
238
- end
239
- return line.strip
240
- end
241
- end
242
-
243
- def get_line(io_stack)
244
- while io = io_stack.last
245
- if line = io.gets
246
- return line.gsub(/[\r\n]*/, '')
247
- end
248
- io_stack.pop
249
- end
250
- end
251
- end
252
-
253
- ##
254
- # Creates an instance of OpenSSL's configuration class.
255
- #
256
- # This can be used in contexts like OpenSSL::X509::ExtensionFactory.config=
257
- #
258
- # If the optional _filename_ parameter is provided, then it is read in and
259
- # parsed via #parse_config.
260
- #
261
- # This can raise IO exceptions based on the access, or availability of the
262
- # file. A ConfigError exception may be raised depending on the validity of
263
- # the data being configured.
264
- #
265
- def initialize(filename = nil)
266
- @data = {}
267
- if filename
268
- File.open(filename.to_s) do |file|
269
- Config.parse_config(file).each do |section, hash|
270
- self[section] = hash
271
- end
272
- end
273
- end
274
- end
275
-
276
- ##
277
- # Gets the value of _key_ from the given _section_
278
- #
279
- # Given the following configurating file being loaded:
280
- #
281
- # config = OpenSSL::Config.load('foo.cnf')
282
- # #=> #<OpenSSL::Config sections=["default"]>
283
- # puts config.to_s
284
- # #=> [ default ]
285
- # # foo=bar
286
- #
287
- # You can get a specific value from the config if you know the _section_
288
- # and _key_ like so:
289
- #
290
- # config.get_value('default','foo')
291
- # #=> "bar"
292
- #
293
- def get_value(section, key)
294
- if section.nil?
295
- raise TypeError.new('nil not allowed')
296
- end
297
- section = 'default' if section.empty?
298
- get_key_string(section, key)
299
- end
300
-
301
- ##
302
- #
303
- # *Deprecated*
304
- #
305
- # Use #get_value instead
306
- def value(arg1, arg2 = nil) # :nodoc:
307
- warn('Config#value is deprecated; use Config#get_value')
308
- if arg2.nil?
309
- section, key = 'default', arg1
310
- else
311
- section, key = arg1, arg2
312
- end
313
- section ||= 'default'
314
- section = 'default' if section.empty?
315
- get_key_string(section, key)
316
- end
317
-
318
- ##
319
- # Set the target _key_ with a given _value_ under a specific _section_.
320
- #
321
- # Given the following configurating file being loaded:
322
- #
323
- # config = OpenSSL::Config.load('foo.cnf')
324
- # #=> #<OpenSSL::Config sections=["default"]>
325
- # puts config.to_s
326
- # #=> [ default ]
327
- # # foo=bar
328
- #
329
- # You can set the value of _foo_ under the _default_ section to a new
330
- # value:
331
- #
332
- # config.add_value('default', 'foo', 'buzz')
333
- # #=> "buzz"
334
- # puts config.to_s
335
- # #=> [ default ]
336
- # # foo=buzz
337
- #
338
- def add_value(section, key, value)
339
- check_modify
340
- (@data[section] ||= {})[key] = value
341
- end
342
-
343
- ##
344
- # Get a specific _section_ from the current configuration
345
- #
346
- # Given the following configurating file being loaded:
347
- #
348
- # config = OpenSSL::Config.load('foo.cnf')
349
- # #=> #<OpenSSL::Config sections=["default"]>
350
- # puts config.to_s
351
- # #=> [ default ]
352
- # # foo=bar
353
- #
354
- # You can get a hash of the specific section like so:
355
- #
356
- # config['default']
357
- # #=> {"foo"=>"bar"}
358
- #
359
- def [](section)
360
- @data[section] || {}
361
- end
362
-
363
- ##
364
- # Deprecated
365
- #
366
- # Use #[] instead
367
- def section(name) # :nodoc:
368
- warn('Config#section is deprecated; use Config#[]')
369
- @data[name] || {}
370
- end
371
-
372
- ##
373
- # Sets a specific _section_ name with a Hash _pairs_.
374
- #
375
- # Given the following configuration being created:
376
- #
377
- # config = OpenSSL::Config.new
378
- # #=> #<OpenSSL::Config sections=[]>
379
- # config['default'] = {"foo"=>"bar","baz"=>"buz"}
380
- # #=> {"foo"=>"bar", "baz"=>"buz"}
381
- # puts config.to_s
382
- # #=> [ default ]
383
- # # foo=bar
384
- # # baz=buz
385
- #
386
- # It's important to note that this will essentially merge any of the keys
387
- # in _pairs_ with the existing _section_. For example:
388
- #
389
- # config['default']
390
- # #=> {"foo"=>"bar", "baz"=>"buz"}
391
- # config['default'] = {"foo" => "changed"}
392
- # #=> {"foo"=>"changed"}
393
- # config['default']
394
- # #=> {"foo"=>"changed", "baz"=>"buz"}
395
- #
396
- def []=(section, pairs)
397
- check_modify
398
- @data[section] ||= {}
399
- pairs.each do |key, value|
400
- self.add_value(section, key, value)
401
- end
402
- end
403
-
404
- ##
405
- # Get the names of all sections in the current configuration
406
- def sections
407
- @data.keys
408
- end
409
-
410
- ##
411
- # Get the parsable form of the current configuration
412
- #
413
- # Given the following configuration being created:
414
- #
415
- # config = OpenSSL::Config.new
416
- # #=> #<OpenSSL::Config sections=[]>
417
- # config['default'] = {"foo"=>"bar","baz"=>"buz"}
418
- # #=> {"foo"=>"bar", "baz"=>"buz"}
419
- # puts config.to_s
420
- # #=> [ default ]
421
- # # foo=bar
422
- # # baz=buz
423
- #
424
- # You can parse get the serialized configuration using #to_s and then parse
425
- # it later:
426
- #
427
- # serialized_config = config.to_s
428
- # # much later...
429
- # new_config = OpenSSL::Config.parse(serialized_config)
430
- # #=> #<OpenSSL::Config sections=["default"]>
431
- # puts new_config
432
- # #=> [ default ]
433
- # foo=bar
434
- # baz=buz
435
- #
436
- def to_s
437
- ary = []
438
- @data.keys.sort.each do |section|
439
- ary << "[ #{section} ]\n"
440
- @data[section].keys.each do |key|
441
- ary << "#{key}=#{@data[section][key]}\n"
442
- end
443
- ary << "\n"
444
- end
445
- ary.join
446
- end
447
-
448
- ##
449
- # For a block.
450
- #
451
- # Receive the section and its pairs for the current configuration.
452
- #
453
- # config.each do |section, key, value|
454
- # # ...
455
- # end
456
- #
457
- def each
458
- @data.each do |section, hash|
459
- hash.each do |key, value|
460
- yield [section, key, value]
461
- end
462
- end
463
- end
464
-
465
- ##
466
- # String representation of this configuration object, including the class
467
- # name and its sections.
468
- def inspect
469
- "#<#{self.class.name} sections=#{sections.inspect}>"
470
- end
471
-
472
- protected
473
-
474
- def data # :nodoc:
475
- @data
476
- end
477
-
478
- private
479
-
480
- def initialize_copy(other)
481
- @data = other.data.dup
482
- end
483
-
484
- def check_modify
485
- raise TypeError.new("Insecure: can't modify OpenSSL config") if frozen?
486
- end
487
-
488
- def get_key_string(section, key)
489
- Config.get_key_string(@data, section, key)
490
- end
491
- end
492
- end