openssl 2.1.4 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +9 -7
- data/History.md +68 -37
- data/README.md +2 -2
- data/ext/openssl/extconf.rb +43 -41
- data/ext/openssl/openssl_missing.h +36 -1
- data/ext/openssl/ossl.c +49 -23
- data/ext/openssl/ossl.h +7 -4
- data/ext/openssl/ossl_asn1.c +25 -0
- data/ext/openssl/ossl_bn.c +16 -23
- data/ext/openssl/ossl_cipher.c +33 -24
- data/ext/openssl/ossl_digest.c +18 -57
- data/ext/openssl/ossl_engine.c +2 -12
- data/ext/openssl/ossl_hmac.c +5 -11
- data/ext/openssl/ossl_kdf.c +3 -19
- data/ext/openssl/ossl_ns_spki.c +1 -1
- data/ext/openssl/ossl_ocsp.c +6 -11
- data/ext/openssl/ossl_ocsp.h +3 -3
- data/ext/openssl/ossl_pkcs7.c +3 -19
- data/ext/openssl/ossl_pkcs7.h +16 -0
- data/ext/openssl/ossl_pkey.c +180 -14
- data/ext/openssl/ossl_pkey_dsa.c +2 -2
- data/ext/openssl/ossl_pkey_ec.c +37 -8
- data/ext/openssl/ossl_pkey_rsa.c +17 -9
- data/ext/openssl/ossl_rand.c +2 -32
- data/ext/openssl/ossl_ssl.c +78 -72
- data/ext/openssl/ossl_ts.c +1514 -0
- data/ext/openssl/ossl_ts.h +16 -0
- data/ext/openssl/ossl_x509cert.c +2 -2
- data/ext/openssl/ossl_x509ext.c +14 -0
- data/ext/openssl/ossl_x509name.c +7 -3
- data/ext/openssl/ossl_x509store.c +20 -39
- data/lib/openssl/bn.rb +1 -1
- data/lib/openssl/buffering.rb +28 -5
- data/lib/openssl/cipher.rb +1 -1
- data/lib/openssl/config.rb +17 -8
- data/lib/openssl/digest.rb +10 -12
- data/lib/openssl/hmac.rb +13 -0
- data/lib/openssl/marshal.rb +30 -0
- data/lib/openssl/pkcs5.rb +1 -1
- data/lib/openssl/pkey.rb +18 -1
- data/lib/openssl/ssl.rb +40 -2
- data/lib/openssl/version.rb +5 -0
- data/lib/openssl/x509.rb +155 -1
- data/lib/openssl.rb +25 -9
- metadata +13 -24
- data/ext/openssl/deprecation.rb +0 -27
- data/ext/openssl/ossl_version.h +0 -15
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright (C) 2010 Martin Bosslet <Martin.Bosslet@googlemail.com>
|
4
|
+
* All rights reserved.
|
5
|
+
*/
|
6
|
+
/*
|
7
|
+
* This program is licenced under the same licence as Ruby.
|
8
|
+
* (See the file 'LICENCE'.)
|
9
|
+
*/
|
10
|
+
|
11
|
+
#if !defined(_OSSL_TS_H_)
|
12
|
+
#define _OSSL_TS_H_
|
13
|
+
|
14
|
+
void Init_ossl_ts(void);
|
15
|
+
|
16
|
+
#endif
|
data/ext/openssl/ossl_x509cert.c
CHANGED
@@ -788,7 +788,7 @@ Init_ossl_x509cert(void)
|
|
788
788
|
* root_ca.add_extension(ef.create_extension("keyUsage","keyCertSign, cRLSign", true))
|
789
789
|
* root_ca.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false))
|
790
790
|
* root_ca.add_extension(ef.create_extension("authorityKeyIdentifier","keyid:always",false))
|
791
|
-
* root_ca.sign(root_key, OpenSSL::Digest
|
791
|
+
* root_ca.sign(root_key, OpenSSL::Digest.new('SHA256'))
|
792
792
|
*
|
793
793
|
* The next step is to create the end-entity certificate using the root CA
|
794
794
|
* certificate.
|
@@ -807,7 +807,7 @@ Init_ossl_x509cert(void)
|
|
807
807
|
* ef.issuer_certificate = root_ca
|
808
808
|
* cert.add_extension(ef.create_extension("keyUsage","digitalSignature", true))
|
809
809
|
* cert.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false))
|
810
|
-
* cert.sign(root_key, OpenSSL::Digest
|
810
|
+
* cert.sign(root_key, OpenSSL::Digest.new('SHA256'))
|
811
811
|
*
|
812
812
|
*/
|
813
813
|
cX509Cert = rb_define_class_under(mX509, "Certificate", rb_cObject);
|
data/ext/openssl/ossl_x509ext.c
CHANGED
@@ -402,6 +402,19 @@ ossl_x509ext_get_value(VALUE obj)
|
|
402
402
|
return ret;
|
403
403
|
}
|
404
404
|
|
405
|
+
static VALUE
|
406
|
+
ossl_x509ext_get_value_der(VALUE obj)
|
407
|
+
{
|
408
|
+
X509_EXTENSION *ext;
|
409
|
+
ASN1_OCTET_STRING *value;
|
410
|
+
|
411
|
+
GetX509Ext(obj, ext);
|
412
|
+
if ((value = X509_EXTENSION_get_data(ext)) == NULL)
|
413
|
+
ossl_raise(eX509ExtError, NULL);
|
414
|
+
|
415
|
+
return rb_str_new((const char *)value->data, value->length);
|
416
|
+
}
|
417
|
+
|
405
418
|
static VALUE
|
406
419
|
ossl_x509ext_get_critical(VALUE obj)
|
407
420
|
{
|
@@ -472,6 +485,7 @@ Init_ossl_x509ext(void)
|
|
472
485
|
rb_define_method(cX509Ext, "critical=", ossl_x509ext_set_critical, 1);
|
473
486
|
rb_define_method(cX509Ext, "oid", ossl_x509ext_get_oid, 0);
|
474
487
|
rb_define_method(cX509Ext, "value", ossl_x509ext_get_value, 0);
|
488
|
+
rb_define_method(cX509Ext, "value_der", ossl_x509ext_get_value_der, 0);
|
475
489
|
rb_define_method(cX509Ext, "critical?", ossl_x509ext_get_critical, 0);
|
476
490
|
rb_define_method(cX509Ext, "to_der", ossl_x509ext_to_der, 0);
|
477
491
|
}
|
data/ext/openssl/ossl_x509name.c
CHANGED
@@ -387,17 +387,21 @@ ossl_x509name_cmp0(VALUE self, VALUE other)
|
|
387
387
|
|
388
388
|
/*
|
389
389
|
* call-seq:
|
390
|
-
* name.cmp(other) -> -1 | 0 | 1
|
391
|
-
* name <=> other -> -1 | 0 | 1
|
390
|
+
* name.cmp(other) -> -1 | 0 | 1 | nil
|
391
|
+
* name <=> other -> -1 | 0 | 1 | nil
|
392
392
|
*
|
393
393
|
* Compares this Name with _other_ and returns +0+ if they are the same and +-1+
|
394
394
|
* or ++1+ if they are greater or less than each other respectively.
|
395
|
+
* Returns +nil+ if they are not comparable (i.e. different types).
|
395
396
|
*/
|
396
397
|
static VALUE
|
397
398
|
ossl_x509name_cmp(VALUE self, VALUE other)
|
398
399
|
{
|
399
400
|
int result;
|
400
401
|
|
402
|
+
if (!rb_obj_is_kind_of(other, cX509Name))
|
403
|
+
return Qnil;
|
404
|
+
|
401
405
|
result = ossl_x509name_cmp0(self, other);
|
402
406
|
if (result < 0) return INT2FIX(-1);
|
403
407
|
if (result > 0) return INT2FIX(1);
|
@@ -494,7 +498,7 @@ ossl_x509name_to_der(VALUE self)
|
|
494
498
|
* You can create a Name by parsing a distinguished name String or by
|
495
499
|
* supplying the distinguished name as an Array.
|
496
500
|
*
|
497
|
-
* name = OpenSSL::X509::Name.parse 'CN=nobody/DC=example'
|
501
|
+
* name = OpenSSL::X509::Name.parse '/CN=nobody/DC=example'
|
498
502
|
*
|
499
503
|
* name = OpenSSL::X509::Name.new [['CN', 'nobody'], ['DC', 'example']]
|
500
504
|
*/
|
@@ -105,13 +105,6 @@ VALUE cX509Store;
|
|
105
105
|
VALUE cX509StoreContext;
|
106
106
|
VALUE eX509StoreError;
|
107
107
|
|
108
|
-
static void
|
109
|
-
ossl_x509store_mark(void *ptr)
|
110
|
-
{
|
111
|
-
X509_STORE *store = ptr;
|
112
|
-
rb_gc_mark((VALUE)X509_STORE_get_ex_data(store, store_ex_verify_cb_idx));
|
113
|
-
}
|
114
|
-
|
115
108
|
static void
|
116
109
|
ossl_x509store_free(void *ptr)
|
117
110
|
{
|
@@ -121,7 +114,7 @@ ossl_x509store_free(void *ptr)
|
|
121
114
|
static const rb_data_type_t ossl_x509store_type = {
|
122
115
|
"OpenSSL/X509/STORE",
|
123
116
|
{
|
124
|
-
|
117
|
+
0, ossl_x509store_free,
|
125
118
|
},
|
126
119
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
127
120
|
};
|
@@ -464,15 +457,22 @@ ossl_x509store_verify(int argc, VALUE *argv, VALUE self)
|
|
464
457
|
}
|
465
458
|
|
466
459
|
/*
|
467
|
-
*
|
460
|
+
* Public Functions
|
468
461
|
*/
|
469
|
-
static void
|
470
|
-
|
471
|
-
{
|
472
|
-
X509_STORE_CTX *ctx = ptr;
|
473
|
-
rb_gc_mark((VALUE)X509_STORE_CTX_get_ex_data(ctx, stctx_ex_verify_cb_idx));
|
474
|
-
}
|
462
|
+
static void ossl_x509stctx_free(void*);
|
463
|
+
|
475
464
|
|
465
|
+
static const rb_data_type_t ossl_x509stctx_type = {
|
466
|
+
"OpenSSL/X509/STORE_CTX",
|
467
|
+
{
|
468
|
+
0, ossl_x509stctx_free,
|
469
|
+
},
|
470
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
471
|
+
};
|
472
|
+
|
473
|
+
/*
|
474
|
+
* Private functions
|
475
|
+
*/
|
476
476
|
static void
|
477
477
|
ossl_x509stctx_free(void *ptr)
|
478
478
|
{
|
@@ -484,14 +484,6 @@ ossl_x509stctx_free(void *ptr)
|
|
484
484
|
X509_STORE_CTX_free(ctx);
|
485
485
|
}
|
486
486
|
|
487
|
-
static const rb_data_type_t ossl_x509stctx_type = {
|
488
|
-
"OpenSSL/X509/STORE_CTX",
|
489
|
-
{
|
490
|
-
ossl_x509stctx_mark, ossl_x509stctx_free,
|
491
|
-
},
|
492
|
-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
493
|
-
};
|
494
|
-
|
495
487
|
static VALUE
|
496
488
|
ossl_x509stctx_alloc(VALUE klass)
|
497
489
|
{
|
@@ -525,9 +517,7 @@ static VALUE ossl_x509stctx_set_time(VALUE, VALUE);
|
|
525
517
|
|
526
518
|
/*
|
527
519
|
* call-seq:
|
528
|
-
* StoreContext.new(store, cert = nil,
|
529
|
-
*
|
530
|
-
* Sets up a StoreContext for a verification of the X.509 certificate _cert_.
|
520
|
+
* StoreContext.new(store, cert = nil, chain = nil)
|
531
521
|
*/
|
532
522
|
static VALUE
|
533
523
|
ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
|
@@ -537,24 +527,15 @@ ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
|
|
537
527
|
X509_STORE *x509st;
|
538
528
|
X509 *x509 = NULL;
|
539
529
|
STACK_OF(X509) *x509s = NULL;
|
540
|
-
int state;
|
541
530
|
|
542
531
|
rb_scan_args(argc, argv, "12", &store, &cert, &chain);
|
543
532
|
GetX509StCtx(self, ctx);
|
544
533
|
GetX509Store(store, x509st);
|
545
|
-
if
|
546
|
-
|
547
|
-
if
|
548
|
-
x509s = ossl_protect_x509_ary2sk(chain, &state);
|
549
|
-
if (state) {
|
550
|
-
X509_free(x509);
|
551
|
-
rb_jump_tag(state);
|
552
|
-
}
|
553
|
-
}
|
554
|
-
if (X509_STORE_CTX_init(ctx, x509st, x509, x509s) != 1){
|
555
|
-
X509_free(x509);
|
534
|
+
if(!NIL_P(cert)) x509 = DupX509CertPtr(cert); /* NEED TO DUP */
|
535
|
+
if(!NIL_P(chain)) x509s = ossl_x509_ary2sk(chain);
|
536
|
+
if(X509_STORE_CTX_init(ctx, x509st, x509, x509s) != 1){
|
556
537
|
sk_X509_pop_free(x509s, X509_free);
|
557
|
-
ossl_raise(eX509StoreError,
|
538
|
+
ossl_raise(eX509StoreError, NULL);
|
558
539
|
}
|
559
540
|
if (!NIL_P(t = rb_iv_get(store, "@time")))
|
560
541
|
ossl_x509stctx_set_time(self, t);
|
data/lib/openssl/bn.rb
CHANGED
data/lib/openssl/buffering.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: binary
|
2
|
-
# frozen_string_literal:
|
2
|
+
# frozen_string_literal: true
|
3
3
|
#--
|
4
4
|
#= Info
|
5
5
|
# 'OpenSSL for Ruby 2' project
|
@@ -22,6 +22,29 @@
|
|
22
22
|
module OpenSSL::Buffering
|
23
23
|
include Enumerable
|
24
24
|
|
25
|
+
# A buffer which will retain binary encoding.
|
26
|
+
class Buffer < String
|
27
|
+
BINARY = Encoding::BINARY
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
super
|
31
|
+
|
32
|
+
force_encoding(BINARY)
|
33
|
+
end
|
34
|
+
|
35
|
+
def << string
|
36
|
+
if string.encoding == BINARY
|
37
|
+
super(string)
|
38
|
+
else
|
39
|
+
super(string.b)
|
40
|
+
end
|
41
|
+
|
42
|
+
return self
|
43
|
+
end
|
44
|
+
|
45
|
+
alias concat <<
|
46
|
+
end
|
47
|
+
|
25
48
|
##
|
26
49
|
# The "sync mode" of the SSLSocket.
|
27
50
|
#
|
@@ -40,7 +63,7 @@ module OpenSSL::Buffering
|
|
40
63
|
def initialize(*)
|
41
64
|
super
|
42
65
|
@eof = false
|
43
|
-
@rbuffer =
|
66
|
+
@rbuffer = Buffer.new
|
44
67
|
@sync = @io.sync
|
45
68
|
end
|
46
69
|
|
@@ -312,7 +335,7 @@ module OpenSSL::Buffering
|
|
312
335
|
# buffer is flushed to the underlying socket.
|
313
336
|
|
314
337
|
def do_write(s)
|
315
|
-
@wbuffer =
|
338
|
+
@wbuffer = Buffer.new unless defined? @wbuffer
|
316
339
|
@wbuffer << s
|
317
340
|
@wbuffer.force_encoding(Encoding::BINARY)
|
318
341
|
@sync ||= false
|
@@ -398,7 +421,7 @@ module OpenSSL::Buffering
|
|
398
421
|
# See IO#puts for full details.
|
399
422
|
|
400
423
|
def puts(*args)
|
401
|
-
s =
|
424
|
+
s = Buffer.new
|
402
425
|
if args.empty?
|
403
426
|
s << "\n"
|
404
427
|
end
|
@@ -416,7 +439,7 @@ module OpenSSL::Buffering
|
|
416
439
|
# See IO#print for full details.
|
417
440
|
|
418
441
|
def print(*args)
|
419
|
-
s =
|
442
|
+
s = Buffer.new
|
420
443
|
args.each{ |arg| s << arg.to_s }
|
421
444
|
do_write(s)
|
422
445
|
nil
|
data/lib/openssl/cipher.rb
CHANGED
data/lib/openssl/config.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
=begin
|
3
3
|
= Ruby-space definitions that completes C-space funcs for Config
|
4
4
|
|
@@ -37,7 +37,7 @@ module OpenSSL
|
|
37
37
|
def parse(string)
|
38
38
|
c = new()
|
39
39
|
parse_config(StringIO.new(string)).each do |section, hash|
|
40
|
-
c
|
40
|
+
c.set_section(section, hash)
|
41
41
|
end
|
42
42
|
c
|
43
43
|
end
|
@@ -53,9 +53,8 @@ module OpenSSL
|
|
53
53
|
def parse_config(io)
|
54
54
|
begin
|
55
55
|
parse_config_lines(io)
|
56
|
-
rescue
|
57
|
-
|
58
|
-
raise
|
56
|
+
rescue => error
|
57
|
+
raise ConfigError, "error in line #{io.lineno}: " + error.message
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
@@ -267,7 +266,7 @@ module OpenSSL
|
|
267
266
|
if filename
|
268
267
|
File.open(filename.to_s) do |file|
|
269
268
|
Config.parse_config(file).each do |section, hash|
|
270
|
-
|
269
|
+
set_section(section, hash)
|
271
270
|
end
|
272
271
|
end
|
273
272
|
end
|
@@ -316,6 +315,8 @@ module OpenSSL
|
|
316
315
|
end
|
317
316
|
|
318
317
|
##
|
318
|
+
# *Deprecated in v2.2.0*. This method will be removed in a future release.
|
319
|
+
#
|
319
320
|
# Set the target _key_ with a given _value_ under a specific _section_.
|
320
321
|
#
|
321
322
|
# Given the following configurating file being loaded:
|
@@ -370,6 +371,8 @@ module OpenSSL
|
|
370
371
|
end
|
371
372
|
|
372
373
|
##
|
374
|
+
# *Deprecated in v2.2.0*. This method will be removed in a future release.
|
375
|
+
#
|
373
376
|
# Sets a specific _section_ name with a Hash _pairs_.
|
374
377
|
#
|
375
378
|
# Given the following configuration being created:
|
@@ -395,9 +398,13 @@ module OpenSSL
|
|
395
398
|
#
|
396
399
|
def []=(section, pairs)
|
397
400
|
check_modify
|
398
|
-
|
401
|
+
set_section(section, pairs)
|
402
|
+
end
|
403
|
+
|
404
|
+
def set_section(section, pairs) # :nodoc:
|
405
|
+
hash = @data[section] ||= {}
|
399
406
|
pairs.each do |key, value|
|
400
|
-
|
407
|
+
hash[key] = value
|
401
408
|
end
|
402
409
|
end
|
403
410
|
|
@@ -482,6 +489,8 @@ module OpenSSL
|
|
482
489
|
end
|
483
490
|
|
484
491
|
def check_modify
|
492
|
+
warn "#{caller(2, 1)[0]}: warning: do not modify OpenSSL::Config; this " \
|
493
|
+
"method is deprecated and will be removed in a future release."
|
485
494
|
raise TypeError.new("Insecure: can't modify OpenSSL config") if frozen?
|
486
495
|
end
|
487
496
|
|
data/lib/openssl/digest.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#--
|
3
3
|
# = Ruby-space predefined Digest subclasses
|
4
4
|
#
|
@@ -15,11 +15,6 @@
|
|
15
15
|
module OpenSSL
|
16
16
|
class Digest
|
17
17
|
|
18
|
-
alg = %w(MD2 MD4 MD5 MDC2 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512)
|
19
|
-
if OPENSSL_VERSION_NUMBER < 0x10100000
|
20
|
-
alg += %w(DSS DSS1 SHA)
|
21
|
-
end
|
22
|
-
|
23
18
|
# Return the hash value computed with _name_ Digest. _name_ is either the
|
24
19
|
# long name or short name of a supported digest algorithm.
|
25
20
|
#
|
@@ -29,23 +24,26 @@ module OpenSSL
|
|
29
24
|
#
|
30
25
|
# which is equivalent to:
|
31
26
|
#
|
32
|
-
# OpenSSL::Digest
|
27
|
+
# OpenSSL::Digest.digest('SHA256', "abc")
|
33
28
|
|
34
29
|
def self.digest(name, data)
|
35
30
|
super(data, name)
|
36
31
|
end
|
37
32
|
|
38
|
-
|
33
|
+
%w(MD4 MD5 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512).each do |name|
|
39
34
|
klass = Class.new(self) {
|
40
35
|
define_method(:initialize, ->(data = nil) {super(name, data)})
|
41
36
|
}
|
37
|
+
|
42
38
|
singleton = (class << klass; self; end)
|
39
|
+
|
43
40
|
singleton.class_eval{
|
44
|
-
define_method(:digest){|data| new.digest(data)
|
45
|
-
define_method(:hexdigest){|data| new.hexdigest(data)
|
41
|
+
define_method(:digest) {|data| new.digest(data)}
|
42
|
+
define_method(:hexdigest) {|data| new.hexdigest(data)}
|
46
43
|
}
|
47
|
-
|
48
|
-
|
44
|
+
|
45
|
+
const_set(name.tr('-', '_'), klass)
|
46
|
+
end
|
49
47
|
|
50
48
|
# Deprecated.
|
51
49
|
#
|
data/lib/openssl/hmac.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenSSL
|
4
|
+
class HMAC
|
5
|
+
# Securely compare with another HMAC instance in constant time.
|
6
|
+
def ==(other)
|
7
|
+
return false unless HMAC === other
|
8
|
+
return false unless self.digest.bytesize == other.digest.bytesize
|
9
|
+
|
10
|
+
OpenSSL.fixed_length_secure_compare(self.digest, other.digest)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#--
|
3
|
+
# = Ruby-space definitions to add DER (de)serialization to classes
|
4
|
+
#
|
5
|
+
# = Info
|
6
|
+
# 'OpenSSL for Ruby 2' project
|
7
|
+
# Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# = Licence
|
11
|
+
# This program is licensed under the same licence as Ruby.
|
12
|
+
# (See the file 'LICENCE'.)
|
13
|
+
#++
|
14
|
+
module OpenSSL
|
15
|
+
module Marshal
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def _load(string)
|
22
|
+
new(string)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def _dump(_level)
|
27
|
+
to_der
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/openssl/pkcs5.rb
CHANGED
data/lib/openssl/pkey.rb
CHANGED
@@ -1,11 +1,24 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#--
|
3
3
|
# Ruby/OpenSSL Project
|
4
4
|
# Copyright (C) 2017 Ruby/OpenSSL Project Authors
|
5
5
|
#++
|
6
6
|
|
7
|
+
require_relative 'marshal'
|
8
|
+
|
7
9
|
module OpenSSL::PKey
|
10
|
+
class DH
|
11
|
+
include OpenSSL::Marshal
|
12
|
+
end
|
13
|
+
|
14
|
+
class DSA
|
15
|
+
include OpenSSL::Marshal
|
16
|
+
end
|
17
|
+
|
8
18
|
if defined?(EC)
|
19
|
+
class EC
|
20
|
+
include OpenSSL::Marshal
|
21
|
+
end
|
9
22
|
class EC::Point
|
10
23
|
# :call-seq:
|
11
24
|
# point.to_bn([conversion_form]) -> OpenSSL::BN
|
@@ -22,4 +35,8 @@ module OpenSSL::PKey
|
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
38
|
+
|
39
|
+
class RSA
|
40
|
+
include OpenSSL::Marshal
|
41
|
+
end
|
25
42
|
end
|
data/lib/openssl/ssl.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
=begin
|
3
3
|
= Info
|
4
4
|
'OpenSSL for Ruby 2' project
|
@@ -13,6 +13,7 @@
|
|
13
13
|
require "openssl/buffering"
|
14
14
|
require "io/nonblock"
|
15
15
|
require "ipaddr"
|
16
|
+
require "socket"
|
16
17
|
|
17
18
|
module OpenSSL
|
18
19
|
module SSL
|
@@ -231,6 +232,11 @@ YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3
|
|
231
232
|
end
|
232
233
|
|
233
234
|
module SocketForwarder
|
235
|
+
# The file descriptor for the socket.
|
236
|
+
def fileno
|
237
|
+
to_io.fileno
|
238
|
+
end
|
239
|
+
|
234
240
|
def addr
|
235
241
|
to_io.addr
|
236
242
|
end
|
@@ -435,6 +441,38 @@ YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3
|
|
435
441
|
def session_get_cb
|
436
442
|
@context.session_get_cb
|
437
443
|
end
|
444
|
+
|
445
|
+
class << self
|
446
|
+
|
447
|
+
# call-seq:
|
448
|
+
# open(remote_host, remote_port, local_host=nil, local_port=nil, context: nil)
|
449
|
+
#
|
450
|
+
# Creates a new instance of SSLSocket.
|
451
|
+
# _remote\_host_ and _remote\_port_ are used to open TCPSocket.
|
452
|
+
# If _local\_host_ and _local\_port_ are specified,
|
453
|
+
# then those parameters are used on the local end to establish the connection.
|
454
|
+
# If _context_ is provided,
|
455
|
+
# the SSL Sockets initial params will be taken from the context.
|
456
|
+
#
|
457
|
+
# === Examples
|
458
|
+
#
|
459
|
+
# sock = OpenSSL::SSL::SSLSocket.open('localhost', 443)
|
460
|
+
# sock.connect # Initiates a connection to localhost:443
|
461
|
+
#
|
462
|
+
# with SSLContext:
|
463
|
+
#
|
464
|
+
# ctx = OpenSSL::SSL::SSLContext.new
|
465
|
+
# sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, context: ctx)
|
466
|
+
# sock.connect # Initiates a connection to localhost:443 with SSLContext
|
467
|
+
def open(remote_host, remote_port, local_host=nil, local_port=nil, context: nil)
|
468
|
+
sock = ::TCPSocket.open(remote_host, remote_port, local_host, local_port)
|
469
|
+
if context.nil?
|
470
|
+
return OpenSSL::SSL::SSLSocket.new(sock)
|
471
|
+
else
|
472
|
+
return OpenSSL::SSL::SSLSocket.new(sock, context)
|
473
|
+
end
|
474
|
+
end
|
475
|
+
end
|
438
476
|
end
|
439
477
|
|
440
478
|
##
|
@@ -465,7 +503,7 @@ YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3
|
|
465
503
|
end
|
466
504
|
|
467
505
|
# See TCPServer#listen for details.
|
468
|
-
def listen(backlog=
|
506
|
+
def listen(backlog=Socket::SOMAXCONN)
|
469
507
|
@svr.listen(backlog)
|
470
508
|
end
|
471
509
|
|