2003-07-23 12:51:36 -04:00
|
|
|
#
|
|
|
|
# https.rb -- SSL/TLS enhancement for HTTPServer
|
|
|
|
#
|
|
|
|
# Author: IPR -- Internet Programming with Ruby -- writers
|
|
|
|
# Copyright (c) 2001 GOTOU Yuuzou
|
|
|
|
# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
|
|
|
|
# reserved.
|
|
|
|
#
|
|
|
|
# $IPR: https.rb,v 1.15 2003/07/22 19:20:42 gotoyuzo Exp $
|
|
|
|
|
2003-08-19 02:00:36 -04:00
|
|
|
require 'webrick/ssl'
|
2003-07-23 12:51:36 -04:00
|
|
|
|
|
|
|
module WEBrick
|
|
|
|
module Config
|
2003-08-19 02:00:36 -04:00
|
|
|
HTTP.update(SSL)
|
2003-07-23 12:51:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class HTTPRequest
|
|
|
|
attr_reader :cipher, :server_cert, :client_cert
|
|
|
|
|
|
|
|
alias orig_parse parse
|
|
|
|
|
|
|
|
def parse(socket=nil)
|
2003-08-19 02:00:36 -04:00
|
|
|
if socket && socket.is_a?(OpenSSL::SSL::SSLSocket)
|
|
|
|
@server_cert = @config[:SSLCertificate]
|
|
|
|
@client_cert = socket.peer_cert
|
|
|
|
@cipher = socket.cipher
|
|
|
|
end
|
2003-07-23 12:51:36 -04:00
|
|
|
orig_parse(socket)
|
|
|
|
end
|
|
|
|
|
|
|
|
alias orig_parse_uri parse_uri
|
|
|
|
|
|
|
|
def parse_uri(str, scheme="https")
|
2003-08-19 02:00:36 -04:00
|
|
|
if @server_cert
|
2003-07-23 12:51:36 -04:00
|
|
|
return orig_parse_uri(str, scheme)
|
|
|
|
end
|
|
|
|
return orig_parse_uri(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
alias orig_meta_vars meta_vars
|
|
|
|
|
|
|
|
def meta_vars
|
|
|
|
meta = orig_meta_vars
|
2003-08-19 02:00:36 -04:00
|
|
|
if @server_cert
|
2003-07-23 12:51:36 -04:00
|
|
|
meta["HTTPS"] = "on"
|
2003-08-19 02:00:36 -04:00
|
|
|
meta["SSL_SERVER_CERT"] = @server_cert.to_pem
|
2003-07-23 12:51:36 -04:00
|
|
|
meta["SSL_CLIENT_CERT"] = @client_cert ? @client_cert.to_pem : ""
|
2003-08-19 02:00:36 -04:00
|
|
|
meta["SSL_CIPHER"] = @cipher[0]
|
2003-07-23 12:51:36 -04:00
|
|
|
end
|
|
|
|
meta
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|