Skip to content

Instantly share code, notes, and snippets.

@claudijd
Created February 4, 2014 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudijd/8795835 to your computer and use it in GitHub Desktop.
Save claudijd/8795835 to your computer and use it in GitHub Desktop.
Grab SSL Subject Helper
require 'socket'
require 'openssl'
module SSLHelpers
class Client
def initialize(host, port)
@host = host
@port = port
end
def connect
@ssl_context = OpenSSL::SSL::SSLContext.new
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
@tcp_client = TCPSocket.new(@host, @port)
@ssl_client = OpenSSL::SSL::SSLSocket.new @tcp_client, @ssl_context
@ssl_client.connect
end
def get_cert
@ssl_client.peer_cert
end
def get_cert_subject
get_cert.subject.to_s
end
end
end
# Example Usage
client = SSLHelpers::Client.new("www.google.com", 443)
client.connect
puts client.get_cert_subject
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment