#!/usr/local/bin/ruby # sample of HTTPS server spawned from inetd. log = open("/var/log/webrick/httpsd.log", "a") STDERR.reopen(log) # do not send stderr to client. require 'webrick/https' require 'getopts' getopts nil, 'r:' pkey = cert = cert_name = nil begin data = open(dir + "/conf/sample.key"){|io| io.read } pkey = OpenSSL::PKey::RSA.new(data) data = open(dir + "/conf/sample.crt"){|io| io.read } cert = OpenSSL::X509::Certificate.new(data) rescue $stderr.puts "Switching to use self-signed certificate" cert_name = [ ["C","JP"], ["O","WEBrick.Org"], ["CN", "WWW"] ] end sock = TCPSocket.for_fd(0, "w+") # create TCPSocket from fd. port = sock.addr[1] s=WEBrick::HTTPServer.new( :DoNotListen => true, :Port => port, :Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG), :DocumentRoot => $OPT_r || "/usr/local/webrick/htdocs", :SSLEnable => true, :SSLVerifyClient => ::OpenSSL::SSL::VERIFY_NONE, :SSLCertificate => cert, :SSLPrivateKey => pkey, :SSLCertName => cert_name ) s.run(sock)