Created
February 4, 2014 01:23
-
-
Save claudijd/8795835 to your computer and use it in GitHub Desktop.
Grab SSL Subject Helper
This file contains 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' | |
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