File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -384,13 +384,24 @@ SSL/TLS サーバに接続して write します。
384384 require 'openssl'
385385 include OpenSSL
386386
387+ ctx = OpenSSL::SSL::SSLContext.new
388+ ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER, verify_hostname: true)
389+
387390 soc = TCPSocket.new('www.example.com', 443)
388- ssl = SSL::SSLSocket.new(soc)
391+ ssl = SSL::SSLSocket.new(soc, ctx)
392+ ssl.hostname = 'www.example.com' # SNI
389393 ssl.connect
390394 ssl.post_connection_check('www.example.com')
391395 raise "verification error" if ssl.verify_result != OpenSSL::X509::V_OK
392- ssl.write('hoge')
393396 print ssl.peer_cert.to_text
397+
398+ # HTTP リクエストを送信
399+ ssl.write("GET / HTTP/1.1\r\n")
400+ ssl.write("Host: www.example.com\r\n")
401+ ssl.write("Connection: close\r\n")
402+ ssl.write("\r\n")
403+ print ssl.read
404+
394405 ssl.close
395406 soc.close
396407
You can’t perform that action at this time.
0 commit comments