|
3 | 3 | require 'ffi' |
4 | 4 | require 'ffi-compiler/loader' |
5 | 5 | require 'thread' |
6 | | -require 'thread_safe' |
| 6 | +require 'concurrent' |
7 | 7 |
|
8 | 8 |
|
9 | 9 | module RubyTls |
@@ -141,6 +141,14 @@ def self.SSL_CTX_sess_set_cache_size(ssl_ctx, op) |
141 | 141 | SSL_CTX_ctrl(ssl_ctx, SSL_CTRL_SET_SESS_CACHE_SIZE, op, nil) |
142 | 142 | end |
143 | 143 |
|
| 144 | + attach_function :SSL_ctrl, [:ssl, :int, :long, :pointer], :long |
| 145 | + SSL_CTRL_SET_TLSEXT_HOSTNAME = 55 |
| 146 | + TLSEXT_NAMETYPE_host_name = 0 |
| 147 | + def self.SSL_set_tlsext_host_name(ssl, host_name) |
| 148 | + name = FFI::MemoryPointer.from_string(host_name) |
| 149 | + SSL_ctrl(ssl, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, name) |
| 150 | + end |
| 151 | + |
144 | 152 | attach_function :SSL_CTX_use_PrivateKey_file, [:ssl_ctx, :string, :int], :int, :blocking => true |
145 | 153 | attach_function :SSL_CTX_use_PrivateKey, [:ssl_ctx, :pointer], :int |
146 | 154 | attach_function :ERR_print_errors_fp, [:pointer], :void # Pointer == File Handle |
@@ -295,7 +303,7 @@ class Context |
295 | 303 | SESSION = 'ruby-tls' |
296 | 304 |
|
297 | 305 |
|
298 | | - ALPN_LOOKUP = ThreadSafe::Cache.new |
| 306 | + ALPN_LOOKUP = ::Concurrent::Map.new |
299 | 307 | ALPN_Select_CB = FFI::Function.new(:int, [ |
300 | 308 | # array of str, unit8 out,uint8 in, *arg |
301 | 309 | :pointer, :pointer, :pointer, :string, :uint, :pointer |
@@ -429,7 +437,7 @@ def set_client_ca(ca) |
429 | 437 |
|
430 | 438 |
|
431 | 439 | class Box |
432 | | - InstanceLookup = ThreadSafe::Cache.new |
| 440 | + InstanceLookup = ::Concurrent::Map.new |
433 | 441 |
|
434 | 442 | READ_BUFFER = 2048 |
435 | 443 |
|
@@ -461,6 +469,12 @@ def initialize(server, transport, options = {}) |
461 | 469 | SSL.SSL_set_verify(@ssl, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, VerifyCB) |
462 | 470 | end |
463 | 471 |
|
| 472 | + # Add Server Name Indication (SNI) for client connections |
| 473 | + # TODO:: Server support for SNI |
| 474 | + if !server && options[:host_name] |
| 475 | + SSL.SSL_set_tlsext_host_name(@ssl, options[:host_name]) |
| 476 | + end |
| 477 | + |
464 | 478 | SSL.SSL_connect(@ssl) unless server |
465 | 479 | end |
466 | 480 |
|
|
0 commit comments