/tools/Ruby/lib/ruby/1.8/webrick/https.rb

http://github.com/agross/netopenspace · Ruby · 64 lines · 46 code · 9 blank · 9 comment · 5 complexity · 3a86dc4a5c6472aa7160ad1dcefcac0d MD5 · raw file

  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. require 'webrick/ssl'
  11. module WEBrick
  12. module Config
  13. HTTP.update(SSL)
  14. end
  15. class HTTPRequest
  16. attr_reader :cipher, :server_cert, :client_cert
  17. alias orig_parse parse
  18. def parse(socket=nil)
  19. @cipher = @server_cert = @client_cert = nil
  20. if socket.respond_to?(:cert)
  21. @server_cert = socket.cert || @config[:SSLCertificate]
  22. @client_cert = socket.peer_cert
  23. @client_cert_chain = socket.peer_cert_chain
  24. @cipher = socket.cipher
  25. end
  26. orig_parse(socket)
  27. end
  28. alias orig_parse_uri parse_uri
  29. def parse_uri(str, scheme="https")
  30. if @server_cert
  31. return orig_parse_uri(str, scheme)
  32. end
  33. return orig_parse_uri(str)
  34. end
  35. alias orig_meta_vars meta_vars
  36. def meta_vars
  37. meta = orig_meta_vars
  38. if @server_cert
  39. meta["HTTPS"] = "on"
  40. meta["SSL_SERVER_CERT"] = @server_cert.to_pem
  41. meta["SSL_CLIENT_CERT"] = @client_cert ? @client_cert.to_pem : ""
  42. if @client_cert_chain
  43. @client_cert_chain.each_with_index{|cert, i|
  44. meta["SSL_CLIENT_CERT_CHAIN_#{i}"] = cert.to_pem
  45. }
  46. end
  47. meta["SSL_CIPHER"] = @cipher[0]
  48. meta["SSL_PROTOCOL"] = @cipher[1]
  49. meta["SSL_CIPHER_USEKEYSIZE"] = @cipher[2].to_s
  50. meta["SSL_CIPHER_ALGKEYSIZE"] = @cipher[3].to_s
  51. end
  52. meta
  53. end
  54. end
  55. end