-
-
Save apsoto/6897455 to your computer and use it in GitHub Desktop.
SSL wrapped socket connection in ruby. NOTE: * default is to NOT verify the certs (ssl_context.verify_mode => nil)
* Default is also to have an empty cert store (ssl_context.cert_store => nil) This gist fixes that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> require 'socket' | |
=> true | |
>> require 'openssl' | |
=> true | |
>> | |
?> ssl_context = OpenSSL::SSL::SSLContext.new | |
=> #<OpenSSL::SSL::SSLContext:0x007ffc9a9deb00> | |
>> ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
=> 1 | |
>> cert_store = OpenSSL::X509::Store.new | |
=> #<OpenSSL::X509::Store:0x007ffc9a9eb328> | |
>> cert_store.set_default_paths | |
=> nil | |
>> ssl_context.cert_store = cert_store | |
=> #<OpenSSL::X509::Store:0x007ffc9a9eb328> | |
>> | |
?> tcp_client = TCPSocket.new ‘server.trustwave.com', 443 | |
=> #<TCPSocket:fd 5> | |
>> ssl_client = OpenSSL::SSL::SSLSocket.new tcp_client, ssl_context | |
=> #<OpenSSL::SSL::SSLSocket:0x007ffc9aa05520> | |
>> ssl_client.connect | |
=> #<OpenSSL::SSL::SSLSocket:0x007ffc9aa05520> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment