Changeset 4854

Show
Ignore:
Timestamp:
05/03/07 15:01:54 (1 year ago)
Author:
hdm
Message:

Improvements to the SSL socket support in Rex, fixes #102, and a HTTP client response parsing bug

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework3/tags/framework-3.0/lib/rex/socket/ssl_tcp.rb

    r3453 r4854  
    5050                # Build the SSL connection 
    5151                self.sslctx  = OpenSSL::SSL::SSLContext.new 
     52                 
     53                # Configure the SSL context 
     54                # TODO: Allow the user to specify the verify mode and callback 
     55                # Valid modes: 
     56                #  VERIFY_CLIENT_ONCE 
     57                #  VERIFY_FAIL_IF_NO_PEER_CERT  
     58                #  VERIFY_NONE 
     59                #  VERIFY_PEER 
     60                self.sslctx.verify_mode = OpenSSL::SSL::VERIFY_PEER 
     61                self.sslctx.options = OpenSSL::SSL::OP_ALL 
     62                 
     63                # Set the verification callback 
     64                self.sslctx.verify_callback = Proc.new do |valid, store| 
     65                        self.peer_verified = valid 
     66                        true 
     67                end 
     68                 
     69                # Tie the context to a socket 
    5270                self.sslsock = OpenSSL::SSL::SSLSocket.new(self, self.sslctx) 
     71                 
    5372                # XXX - enabling this causes infinite recursion, so disable for now 
    5473                # self.sslsock.sync_close = true 
     74                 
     75                # Negotiate the connection 
    5576                self.sslsock.connect 
    5677        end 
     
    90111        end 
    91112 
     113        #  
     114        # Ignore shutdown requests 
     115        # 
     116        def shutdown(how=0) 
     117                # Calling shutdown() on an SSL socket can lead to bad things 
     118                # Cause of http://metasploit.com/dev/trac/ticket/102 
     119        end 
     120         
     121        # 
     122        # Access to peer cert 
     123        # 
     124        def peer_cert 
     125                sslsock.peer_cert if sslsock 
     126        end 
     127         
     128        # 
     129        # Access to peer cert chain 
     130        # 
     131        def peer_cert_chain 
     132                sslsock.peer_cert_chain if sslsock 
     133        end 
     134         
     135        # 
     136        # Access to the current cipher 
     137        # 
     138        def cipher 
     139                sslsock.cipher if sslsock 
     140        end 
     141 
     142 
     143 
     144        attr_reader :peer_verified # :nodoc: 
    92145protected 
    93146 
    94147        attr_accessor :sslsock, :sslctx # :nodoc: 
     148        attr_writer :peer_verified # :nodoc: 
    95149 
    96150rescue LoadError