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 | if socket.respond_to?(:cert)
|
---|
25 | @server_cert = socket.cert || @config[:SSLCertificate]
|
---|
26 | @client_cert = socket.peer_cert
|
---|
27 | @client_cert_chain = socket.peer_cert_chain
|
---|
28 | @cipher = socket.cipher
|
---|
29 | end
|
---|
30 | orig_parse(socket)
|
---|
31 | end
|
---|
32 |
|
---|
33 | alias orig_parse_uri parse_uri
|
---|
34 |
|
---|
35 | def parse_uri(str, scheme="https")
|
---|
36 | if @server_cert
|
---|
37 | return orig_parse_uri(str, scheme)
|
---|
38 | end
|
---|
39 | return orig_parse_uri(str)
|
---|
40 | end
|
---|
41 |
|
---|
42 | alias orig_meta_vars meta_vars
|
---|
43 |
|
---|
44 | def meta_vars
|
---|
45 | meta = orig_meta_vars
|
---|
46 | if @server_cert
|
---|
47 | meta["HTTPS"] = "on"
|
---|
48 | meta["SSL_SERVER_CERT"] = @server_cert.to_pem
|
---|
49 | meta["SSL_CLIENT_CERT"] = @client_cert ? @client_cert.to_pem : ""
|
---|
50 | if @client_cert_chain
|
---|
51 | @client_cert_chain.each_with_index{|cert, i|
|
---|
52 | meta["SSL_CLIENT_CERT_CHAIN_#{i}"] = cert.to_pem
|
---|
53 | }
|
---|
54 | end
|
---|
55 | meta["SSL_CIPHER"] = @cipher[0]
|
---|
56 | meta["SSL_PROTOCOL"] = @cipher[1]
|
---|
57 | meta["SSL_CIPHER_USEKEYSIZE"] = @cipher[2].to_s
|
---|
58 | meta["SSL_CIPHER_ALGKEYSIZE"] = @cipher[3].to_s
|
---|
59 | end
|
---|
60 | meta
|
---|
61 | end
|
---|
62 | end
|
---|
63 | end
|
---|