Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created December 23, 2018 04:37
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 gr33n7007h/4df6066af03398d6edc887b7e6e784fe to your computer and use it in GitHub Desktop.
Save gr33n7007h/4df6066af03398d6edc887b7e6e784fe to your computer and use it in GitHub Desktop.
SNI test
>> require 'net/imap'
=> true
>> Net::IMAP.new "imap.gmail.com", 993, true
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate)
from /usr/lib/ruby/2.5.0/net/protocol.rb:44:in `connect_nonblock'
>> m = <<~SNI_test
| def start_tls_session(params = {})
| unless defined?(OpenSSL::SSL)
| raise "SSL extension not installed"
| end
| if @sock.kind_of?(OpenSSL::SSL::SSLSocket)
| raise RuntimeError, "already using SSL"
| end
| begin
| params = params.to_hash
| rescue NoMethodError
| params = {}
| end
| context = SSLContext.new
| context.set_params(params)
| if defined?(VerifyCallbackProc)
| context.verify_callback = VerifyCallbackProc
| end
| @sock = SSLSocket.new(@sock, context)
| @sock.sync_close = true
| # added OpenSSL::SSL::SSLSocket#hostname= for SNI
| @sock.hostname = @host
| ssl_socket_connect(@sock, @open_timeout)
| if context.verify_mode != VERIFY_NONE
| @sock.post_connection_check(@host)
| end
| end
| SNI_test
=> "def start_tls_session(params = {})\n unless defined?(OpenSSL::SSL)\n raise \"SSL extension not installed\"\n end\n if @sock.kind_of?(OpenSSL::SSL::SSLSocket)\n raise RuntimeError, \"already using SSL\"\n end\n begin\n params = params.to_hash\n rescue NoMethodError\n params = {}\n end\n context = SSLContext.new\n context.set_params(params)\n if defined?(VerifyCallbackProc)\n context.verify_callback = VerifyCallbackProc\n end\n @sock = SSLSocket.new(@sock, context)\n @sock.sync_close = true\n # added OpenSSL::SSL::SSLSocket#hostname= for SNI\n @sock.hostname = @host\n ssl_socket_connect(@sock, @open_timeout)\n if context.verify_mode != VERIFY_NONE\n @sock.post_connection_check(@host)\n end\n end\n"
>> Net::IMAP.module_eval m
=> :start_tls_session
>>
>> Net::IMAP.new "imap.gmail.com", 993, true
=> #<Net::IMAP:0x00005641dfc09ff0
@client_thread=#<Thread:0x00005641dd664b88 run>,
@continuation_request_arrival=#<MonitorMixin::ConditionVariable:0x00005641dfc088f8 @cond=#<Thread::ConditionVariable:0x00005641dfc088d0>, @monitor=#<Net::IMAP:0x00005641dfc09ff0 ...>>,
@continuation_request_exception=nil,
@continued_command_tag=nil,
@debug_output_bol=true,
@exception=nil,
@greeting=
#<struct Net::IMAP::UntaggedResponse
name="OK",
data=#<struct Net::IMAP::ResponseText code=nil, text="Gimap ready for requests from 90.195.240.250 o23mb482518366wmf">,
raw_data="* OK Gimap ready for requests from 90.195.240.250 o23mb482518366wmf\r\n">,
@host="imap.gmail.com",
@idle_done_cond=nil,
@logout_command_tag=nil,
@mon_count=0,
@mon_mutex=#<Thread::Mutex:0x00005641dfc09fa0>,
@mon_owner=nil,
@open_timeout=30,
@parser=#<Net::IMAP::ResponseParser:0x00005641dfc09e10 @flag_symbols={}, @lex_state=:EXPR_BEG, @pos=69, @str="* OK Gimap ready for requests from 90.195.240.250 o23mb482518366wmf\r\n", @token=nil>,
@port=993,
@receiver_thread=#<Thread:0x00005641dfbf7df0@/usr/lib/ruby/2.5.0/net/imap.rb:1118 sleep>,
@receiver_thread_terminating=false,
@response_handlers=[],
@responses={},
@sock=
#<OpenSSL::SSL::SSLSocket:0x00005641dfc09ac8
@context=
#<OpenSSL::SSL::SSLContext:0x00005641dfc09c08
@cert_store=#<OpenSSL::X509::Store:0x00005641dfad83c0 @chain=nil, @error=nil, @error_string=nil, @time=nil, @verify_callback=nil>,
@max_proto_version=nil,
@min_proto_version=769,
@verify_hostname=true,
@verify_mode=1>,
@eof=false,
@hostname="imap.gmail.com",
@io=#<Socket:fd 10>,
@rbuffer="",
@sync=true,
@sync_close=true>,
@tag_prefix="RUBY",
@tagged_response_arrival=#<MonitorMixin::ConditionVariable:0x00005641dfc08948 @cond=#<Thread::ConditionVariable:0x00005641dfc08920>, @monitor=#<Net::IMAP:0x00005641dfc09ff0 ...>>,
@tagged_responses={},
@tagno=0,
@usessl=true>
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment