1 #
2 # https.rb -- SSL/TLS enhancement for HTTPServer
3 #
4 # Author: IPR -- Internet Programming with Ruby -- writers
5 # Copyright (c) 2001 GOTOU Yuuzou
6 # Copyright (c) 2002 Internet Programming with Ruby writers. All rights
7 # reserved.
8 #
9 # $IPR: https.rb,v 1.15 2003/07/22 19:20:42 gotoyuzo Exp $
10
11 require 'webrick/ssl'
12
13 module WEBrick
14 module Config
15 HTTP.update(SSL)
16 end
17
18 class HTTPRequest
19 attr_reader :cipher, :server_cert, :client_cert
20
21 alias orig_parse parse
22
23 def parse(socket=nil)
24 @cipher = @server_cert = @client_cert = nil
25 if socket.respond_to?(:cert)
26 @server_cert = socket.cert || @config[:SSLCertificate]
27 @client_cert = socket.peer_cert
28 @client_cert_chain = socket.peer_cert_chain
29 @cipher = socket.cipher
30 end
31 orig_parse(socket)
32 end
33
34 alias orig_parse_uri parse_uri
35
36 def parse_uri(str, scheme="https")
37 if @server_cert
38 return orig_parse_uri(str, scheme)
39 end
40 return orig_parse_uri(str)
41 end
42
43 alias orig_meta_vars meta_vars
44
45 def meta_vars
46 meta = orig_meta_vars
47 if @server_cert
48 meta["HTTPS"] = "on"
49 meta["SSL_SERVER_CERT"] = @server_cert.to_pem
50 meta["SSL_CLIENT_CERT"] = @client_cert ? @client_cert.to_pem : ""
51 if @client_cert_chain
52 @client_cert_chain.each_with_index{|cert, i|
53 meta["SSL_CLIENT_CERT_CHAIN_#{i}"] = cert.to_pem
54 }
55 end
56 meta["SSL_CIPHER"] = @cipher[0]
57 meta["SSL_PROTOCOL"] = @cipher[1]
58 meta["SSL_CIPHER_USEKEYSIZE"] = @cipher[2].to_s
59 meta["SSL_CIPHER_ALGKEYSIZE"] = @cipher[3].to_s
60 end
61 meta
62 end
63 end
64 end