Last active
March 27, 2018 08:08
-
-
Save Paxa/b0517fa467b8da0bc94152490f7f9ddc to your computer and use it in GitHub Desktop.
Ruby SSL Socket connection with self signed client certificate. For https://medium.com/@pavelevstigneev/setting-nginx-with-letsencrypt-and-client-ssl-certificates-3ae608bb0e66
This file contains hidden or 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
tcp_socket = Socket.tcp("mysite.com", 32500, connect_timeout: 60) | |
ssl_context = OpenSSL::SSL::SSLContext.new() | |
ssl_context.client_cert_cb = Proc.new do | |
[ | |
OpenSSL::X509::Certificate.new(File.open("./client.crt")), | |
OpenSSL::PKey.read(File.open("./client.key")) | |
] | |
end | |
ssl_context.verify_callback = Proc.new do |passed, store_context| | |
if !passed | |
puts "SSL Verification Error: #{store_context.error} - #{store_context.error_string}" | |
end | |
end | |
ssl_socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl_context) | |
ssl_socket.connect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment