Created
          June 28, 2013 14:40 
        
      - 
      
- 
        Save claudijd/5885193 to your computer and use it in GitHub Desktop. 
    Ruby OpenSSL using verify peer and system cert store.
  
        
  
    
      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
  
            
For anyone else who arrives here.. this won't verify the cert's hostname.
The two lines marked ❗ are also required.