4 require File.join(File.dirname(__FILE__), "utils.rb")
9 if /^-----BEGIN / =~ line
16 if /^-----END / =~ line
25 return OpenSSL::PKey::RSA.new(pem)
27 return OpenSSL::PKey::DSA.new(pem)
31 ca_cert = OpenSSL::X509::Certificate.new(get_pem)
32 ssl_cert = OpenSSL::X509::Certificate.new(get_pem)
33 ssl_key = make_key(get_pem)
34 port = Integer(ARGV.shift)
35 verify_mode = Integer(ARGV.shift)
36 start_immediately = (/yes/ =~ ARGV.shift)
38 store = OpenSSL::X509::Store.new
39 store.add_cert(ca_cert)
40 store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
41 ctx = OpenSSL::SSL::SSLContext.new
42 ctx.cert_store = store
43 #ctx.extra_chain_cert = [ ca_cert ]
46 ctx.verify_mode = verify_mode
48 Socket.do_not_reverse_lookup = true
52 tcps = TCPServer.new("0.0.0.0", port+i)
55 rescue Errno::EADDRINUSE
59 ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx)
60 ssls.start_immediately = start_immediately
63 $stdout.puts Process.pid
67 ssl = ssls.accept rescue next
70 th = Thread.start{ ssl.write(q.shift) while true }
72 if line =~ /^STARTTLS$/