@@ -34,9 +34,9 @@ module SSL
3434
3535 SSL_ST_OK = 0x03
3636 begin
37- attach_function :SSL_library_init , [ ] , :int
3837 attach_function :SSL_load_error_strings , [ ] , :void
3938 attach_function :ERR_load_crypto_strings , [ ] , :void
39+ attach_function :SSL_library_init , [ ] , :int
4040
4141 attach_function :SSL_state , [ :ssl ] , :int
4242 def self . SSL_is_init_finished ( ssl )
@@ -76,7 +76,9 @@ def self.SSL_is_init_finished(ssl)
7676 attach_function :BIO_free , [ :bio ] , :int
7777
7878 # GetPeerCert
79- attach_function :SSL_get_peer_certificate , [ :ssl ] , :x509
79+ attach_function :SSL_get1_peer_certificate , [ :ssl ] , :x509
80+
81+ attach_function :SSL_CTX_set_security_level , [ :ssl , :int ] , :void
8082
8183
8284 # PutPlaintext
@@ -207,6 +209,8 @@ def self.SSL_CTX_set_tlsext_servername_callback(ctx, callback)
207209 attach_function :SSL_CTX_use_PrivateKey_file , [ :ssl_ctx , :string , :int ] , :int , :blocking => true
208210 attach_function :SSL_CTX_use_PrivateKey , [ :ssl_ctx , :pointer ] , :int
209211 attach_function :ERR_print_errors_fp , [ :pointer ] , :void # Pointer == File Handle
212+ attach_function :ERR_get_error , [ ] , :long
213+ attach_function :ERR_reason_error_string , [ :ulong ] , :string
210214 attach_function :SSL_CTX_use_certificate_chain_file , [ :ssl_ctx , :string ] , :int , :blocking => true
211215 attach_function :SSL_CTX_use_certificate , [ :ssl_ctx , :x509 ] , :int
212216 attach_function :SSL_CTX_set_cipher_list , [ :ssl_ctx , :string ] , :int
@@ -310,13 +314,18 @@ def self.SSL_CTX_set_tlsext_servername_callback(ctx, callback)
310314 @init_required ||= false
311315 unless @init_required
312316 if OPENSSL_V1_1
313- self . OPENSSL_init_ssl ( OPENSSL_INIT_LOAD_SSL_STRINGS , ::FFI ::Pointer ::NULL )
317+ # self.OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, ::FFI::Pointer::NULL)
314318 else
315- self . SSL_load_error_strings
316- self . SSL_library_init
317- self . ERR_load_crypto_strings
319+ # self.SSL_load_error_strings
320+ # self.SSL_library_init
321+ # self.ERR_load_crypto_strings
318322 end
319323
324+ # self.SSL_load_error_strings
325+ # self.SSL_library_init
326+ # self.ERR_load_crypto_strings
327+ self . OPENSSL_init_ssl ( OPENSSL_INIT_LOAD_SSL_STRINGS , ::FFI ::Pointer ::NULL )
328+
320329 # Setup multi-threaded support
321330 #SSL_LOCKS = []
322331 #num_locks = self.CRYPTO_num_locks
@@ -325,7 +334,6 @@ def self.SSL_CTX_set_tlsext_servername_callback(ctx, callback)
325334 #self.CRYPTO_set_locking_callback(LockingCB)
326335 #self.CRYPTO_set_id_callback(ThreadIdCB)
327336
328-
329337 bio = self . BIO_new_mem_buf ( PrivateMaterials , PrivateMaterials . bytesize )
330338
331339 # Get the private key structure
@@ -384,11 +392,13 @@ def initialize(server, options = {})
384392
385393 if @is_server
386394 @ssl_ctx = SSL . SSL_CTX_new ( SSL . TLS_server_method )
395+ SSL . SSL_CTX_set_security_level ( @ssl_ctx , 0 )
387396 set_private_key ( options [ :private_key ] || SSL ::DEFAULT_PRIVATE )
388397 set_certificate ( options [ :cert_chain ] || SSL ::DEFAULT_CERT )
389398 set_client_ca ( options [ :client_ca ] )
390399 else
391400 @ssl_ctx = SSL . SSL_CTX_new ( SSL . TLS_client_method )
401+ SSL . SSL_CTX_set_security_level ( @ssl_ctx , 0 )
392402 end
393403
394404 SSL . SSL_CTX_set_options ( @ssl_ctx , SSL ::SSL_OP_ALL )
@@ -517,8 +527,10 @@ def set_certificate(cert)
517527 end
518528
519529 if err <= 0
530+ error_code = SSL . ERR_get_error
531+ reason = SSL . ERR_reason_error_string ( error_code )
520532 cleanup
521- raise ' invalid certificate or file not found'
533+ raise " invalid certificate or file not found: #{ err } #{ reason } "
522534 end
523535 end
524536
@@ -616,7 +628,7 @@ def remove_host(host_name)
616628
617629 def get_peer_cert
618630 return '' unless @ready
619- SSL . SSL_get_peer_certificate ( @ssl )
631+ SSL . SSL_get1_peer_certificate ( @ssl )
620632 end
621633
622634 def negotiated_protocol
@@ -657,7 +669,7 @@ def encrypt(data)
657669 def decrypt ( data )
658670 return unless @ready
659671
660- put_cipher_text data
672+ result = put_cipher_text data
661673
662674 if not SSL . SSL_is_init_finished ( @ssl )
663675 resp = @is_server ? SSL . SSL_accept ( @ssl ) : SSL . SSL_connect ( @ssl )
@@ -754,7 +766,8 @@ def get_plain_text(buffer, ready)
754766 if size >= 0
755767 size
756768 else
757- SSL . SSL_get_error ( @ssl , size ) == SSL_ERROR_WANT_READ ? 0 : -1
769+ error_code = SSL . SSL_get_error ( @ssl , size )
770+ error_code == SSL_ERROR_WANT_READ ? 0 : -1
758771 end
759772 end
760773
@@ -795,7 +808,7 @@ def put_cipher_text(data)
795808 SSL_ERROR_WANT_WRITE = 3
796809 def put_plain_text ( data )
797810 @write_queue . push ( data ) if data
798- return 0 unless SSL . SSL_is_init_finished ( @ssl )
811+ # return 0 unless SSL.SSL_is_init_finished(@ssl)
799812
800813 fatal = false
801814 did_work = false
0 commit comments