Skip to content

Instantly share code, notes, and snippets.

@timshadel
Created August 10, 2009 16:56
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 timshadel/165286 to your computer and use it in GitHub Desktop.
Save timshadel/165286 to your computer and use it in GitHub Desktop.
require 'socket'
require 'openssl'
# port can be anything. here it's ldaps
socket = TCPSocket.new("some.secure.server.com", 636)
ssl_context = OpenSSL::SSL::SSLContext.new()
unless ssl_context.verify_mode
warn "warning: peer certificate won't be verified this session."
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
sslsocket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
sslsocket.sync_close = true
sslsocket.connect
# Dump the server's cert to the desktop so I can install it
File.open("/Users/user/Desktop/cert.der", "w+") do |f|
f.write sslsocket.peer_cert.to_der
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment