Debian Codegraph @

sample/ssl/webrick_httpsd.rb

raw
1 #!/usr/bin/env ruby
2
3 require 'webrick/https'
4 require 'getopts'
5
6 getopts nil, 'r:', 'p:8808'
7
8 dir = File::dirname(File::expand_path(__FILE__))
9
10 # Pass phrase of '1000key.pem' is '1000'.
11 data = open(File::join(dir, "1000key.pem")){|io| io.read }
12 pkey = OpenSSL::PKey::RSA.new(data)
13 data = open(File::join(dir, "1000cert.pem")){|io| io.read }
14 cert = OpenSSL::X509::Certificate.new(data)
15
16 s = WEBrick::HTTPServer.new(
17 :BindAddress => "localhost",
18 :Port => $OPT_p.to_i,
19 :Logger => nil,
20 :DocumentRoot => $OPT_r || File::join(dir, "/htdocs"),
21 :SSLEnable => true,
22 :SSLVerifyClient => ::OpenSSL::SSL::VERIFY_NONE,
23 :SSLCertificate => cert,
24 :SSLPrivateKey => pkey,
25 :SSLCertName => nil,
26 :SSLCACertificateFile => "all.pem"
27 )
28 trap("INT"){ s.shutdown }
29 s.start