7 options = ARGV.getopts("p:c:k:C:")
9 host = ARGV[0] || "localhost"
10 port = options["p"] || "2000"
11 cert_file = options["c"]
12 key_file = options["k"]
13 ca_path = options["C"]
15 ctx = OpenSSL::SSL::SSLContext.new()
16 if cert_file && key_file
17 ctx.cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
18 ctx.key = OpenSSL::PKey::RSA.new(File::read(key_file))
21 ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
24 $stderr.puts "!!! WARNING: PEER CERTIFICATE WON'T BE VERIFIED !!!"
27 s = TCPSocket.new(host, port)
28 ssl = OpenSSL::SSL::SSLSocket.new(s, ctx)
29 ssl.connect # start SSL session
32 OpenSSL::X509.constants.grep(/^V_(ERR_|OK)/).each do |name|
33 errors[OpenSSL::X509.const_get(name)] = name
35 p errors[ssl.verify_result]
37 ssl.sync_close = true # if true the underlying socket will be
38 # closed in SSLSocket#close. (default: false)
39 while line = $stdin.gets