Sha256: 2ee293c96258ce8591ca5c35da48ceff781d13c9a5b4f6045a8ce482ecc3df76

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'net/https'
require 'openssl'
require 'httpclient'


module Ciphersurfer
  class Scanner
    
    attr_reader :ok_ciphers, :ok_bits
    attr_reader :peer_cert

    def initialize(options={})
      @host=options[:host]
      @port=options[:port] ||= 443
      @proto=options[:proto]
      @ok_ciphers=[]
      @ok_bits=[]
    end

    def self.cert(host, port)
      client=HTTPClient.new
      response=client.get("https://#{host}:#{port}")
      peer_cert = response.peer_cert
    end

    def self.alive?(host, port)
      request = Net::HTTP.new(host, port)
      request.use_ssl = true
      request.verify_mode = OpenSSL::SSL::VERIFY_NONE
      begin
        response = request.get("/")
        return true
      rescue Errno::ECONNREFUSED => e
        return false
      rescue OpenSSL::SSL::SSLError => e
        return false
      rescue 
        return false
      end
    end
   
    def go
      context=OpenSSL::SSL::SSLContext.new(@proto)
      cipher_set = context.ciphers
      cipher_set.each do |cipher_name, cipher_version, bits, algorithm_bits|

        request = Net::HTTP.new(@host, @port)
        request.use_ssl = true
        
        request.ca_file='/Users/thesp0nge/src/hacking/ciphersurfer/cacert.pem'
        request.verify_mode = OpenSSL::SSL::VERIFY_NONE
        request.ciphers= cipher_name
        begin
          response = request.get("/")
          @ok_bits << bits
          @ok_ciphers << {:bits=>bits, :name=>cipher_name}
        rescue OpenSSL::SSL::SSLError => e
          # Quietly discard SSLErrors, really I don't care if the cipher has
          # not been accepted
        rescue 
          # Quietly discard all other errors... you must perform all error
          # chekcs in the calling program
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ciphersurfer-1.0.0.rc1 lib/ciphersurfer/scanner.rb