httpclient 2.1.5 → 2.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +85 -0
  3. data/bin/httpclient +77 -0
  4. data/bin/jsonclient +85 -0
  5. data/lib/hexdump.rb +50 -0
  6. data/lib/http-access2.rb +6 -4
  7. data/lib/httpclient/auth.rb +575 -173
  8. data/lib/httpclient/cacert.pem +3952 -0
  9. data/lib/httpclient/cacert1024.pem +3866 -0
  10. data/lib/httpclient/connection.rb +6 -2
  11. data/lib/httpclient/cookie.rb +162 -504
  12. data/lib/httpclient/http.rb +334 -119
  13. data/lib/httpclient/include_client.rb +85 -0
  14. data/lib/httpclient/jruby_ssl_socket.rb +588 -0
  15. data/lib/httpclient/session.rb +385 -288
  16. data/lib/httpclient/ssl_config.rb +195 -155
  17. data/lib/httpclient/ssl_socket.rb +150 -0
  18. data/lib/httpclient/timeout.rb +14 -10
  19. data/lib/httpclient/util.rb +142 -6
  20. data/lib/httpclient/version.rb +3 -0
  21. data/lib/httpclient/webagent-cookie.rb +459 -0
  22. data/lib/httpclient.rb +509 -202
  23. data/lib/jsonclient.rb +63 -0
  24. data/lib/oauthclient.rb +111 -0
  25. data/sample/async.rb +8 -0
  26. data/sample/auth.rb +11 -0
  27. data/sample/cookie.rb +18 -0
  28. data/sample/dav.rb +103 -0
  29. data/sample/howto.rb +49 -0
  30. data/sample/jsonclient.rb +67 -0
  31. data/sample/oauth_buzz.rb +57 -0
  32. data/sample/oauth_friendfeed.rb +59 -0
  33. data/sample/oauth_twitter.rb +61 -0
  34. data/sample/ssl/0cert.pem +22 -0
  35. data/sample/ssl/0key.pem +30 -0
  36. data/sample/ssl/1000cert.pem +19 -0
  37. data/sample/ssl/1000key.pem +18 -0
  38. data/sample/ssl/htdocs/index.html +10 -0
  39. data/sample/ssl/ssl_client.rb +22 -0
  40. data/sample/ssl/webrick_httpsd.rb +29 -0
  41. data/sample/stream.rb +21 -0
  42. data/sample/thread.rb +27 -0
  43. data/sample/wcat.rb +21 -0
  44. data/test/ca-chain.pem +44 -0
  45. data/test/ca.cert +23 -0
  46. data/test/client-pass.key +18 -0
  47. data/test/client.cert +19 -0
  48. data/test/client.key +15 -0
  49. data/test/helper.rb +131 -0
  50. data/test/htdigest +1 -0
  51. data/test/htpasswd +2 -0
  52. data/test/jruby_ssl_socket/test_pemutils.rb +32 -0
  53. data/test/runner.rb +2 -0
  54. data/test/server.cert +19 -0
  55. data/test/server.key +15 -0
  56. data/test/sslsvr.rb +65 -0
  57. data/test/subca.cert +21 -0
  58. data/test/test_auth.rb +492 -0
  59. data/test/test_cookie.rb +309 -0
  60. data/test/test_hexdump.rb +14 -0
  61. data/test/test_http-access2.rb +508 -0
  62. data/test/test_httpclient.rb +2145 -0
  63. data/test/test_include_client.rb +52 -0
  64. data/test/test_jsonclient.rb +80 -0
  65. data/test/test_ssl.rb +559 -0
  66. data/test/test_webagent-cookie.rb +465 -0
  67. metadata +85 -44
  68. data/lib/httpclient/auth.rb.orig +0 -513
  69. data/lib/httpclient/cacert.p7s +0 -1579
  70. data/lib/httpclient.rb.orig +0 -1020
  71. data/lib/tags +0 -908
@@ -0,0 +1,18 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ Proc-Type: 4,ENCRYPTED
3
+ DEK-Info: DES-EDE3-CBC,5E9A9AC8F0F62A4A
4
+
5
+ 3/VDlc8E13xKZr+MXt+HVZCiuWN1gsVx1bTZE5fN5FVoJ45Bgy2zAegnqZiP1NNy
6
+ j/76Vy9Ru/G9HPh5QPbIPl+md+tOyJV2M23a+5jESk1tLuWt5lRqmTtHN000844l
7
+ uCgZPPhRV7nhYPC5f6Gqw/xDl/EZsElqJM/hl2JbqiVKfT5/1i0STU8LNkoaLWrJ
8
+ kQhc7hOR5ihmDPeD8mA99bmGD+UyyqzzLTtKvRbBObyi9dy7cQ5Q+iptQWTUuEKI
9
+ +W7b8f8/Iiin4JJZGpFuhQSx0ARjT0fuYNXddmz1L3Gu3sjzN1GvT2T3GlpiF4/7
10
+ ERS8Q43zjoCP8nC2MTSvdNRRoPMBg2SDS2ZIq4GSiKsKjeN+GnPCycAMeZSr5yG6
11
+ VMBJLoAJ7XIcl3se8gF6hH1AfhCzDaK/2pKLP9jH/W4g6VvUBazKEQCNbZXSTpQ4
12
+ 8EfvJBPpplFs3Zid6iwC/WjKhFBuBBfycwNJjXG9x1fMPkBM8HeiZXgrXoUXJMEP
13
+ RF05Beo0HPPEOPIxcG6EVmnpDvs8uC+xIQ6UE6DrLGK5TnR6kdz3BDpeAehujSss
14
+ wfZiOvuJQZQl+oovOH54pcwAwhicgRcNdIX47kHrXNL1vQMYTXte+ZzDGyoOXd0W
15
+ qf1CZbrjULT9nfJFWMMicTnLM/6iQx+3bTkXXvk0qP0qAoIPqtY4rwt6yHgq937A
16
+ LubDxudMWV0hqcnH8cBCPHfWdE4HELw4RcVXmQH43yHs1gwShyG9rTS+PCKoRr8u
17
+ bpssW6J0xJmilf1KprbNWJyof9i0CtSVOlUt6ttoinwqj8Me01dHqQ==
18
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,10 @@
1
+ <html>
2
+ <head>
3
+ <title>SSL test</title>
4
+ </head>
5
+ <body>
6
+ <p>
7
+ Verification succeeded?
8
+ </p>
9
+ </body>
10
+ </html>
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join('..', '..', 'lib'))
4
+ require 'httpclient'
5
+
6
+ url = ARGV.shift || 'https://localhost:8808/'
7
+ uri = URI.parse(url)
8
+
9
+ #ca_file = "0cert.pem"
10
+ #crl_file = '0crl.pem'
11
+
12
+ # create CA's cert in pem format and run 'c_rehash' in trust_certs dir. before
13
+ # using this.
14
+ ca_path = File.join(File.dirname(File.expand_path(__FILE__)), "trust_certs")
15
+
16
+ proxy = ENV['HTTP_PROXY'] || ENV['http_proxy'] || nil
17
+ h = HTTPClient.new(proxy)
18
+ #h.ssl_config.add_trust_ca(ca_file)
19
+ #h.ssl_config.add_crl(crl_file)
20
+ h.ssl_config.add_trust_ca(ca_path)
21
+
22
+ print h.get_content(url)
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'webrick/https'
4
+ require 'getopts'
5
+
6
+ getopts nil, 'r:', 'p:8808'
7
+
8
+ dir = File::dirname(File::expand_path(__FILE__))
9
+
10
+ # Pass phrase of '1000key.pem' is '1000'.
11
+ data = open(File::join(dir, "1000key.pem")){|io| io.read }
12
+ pkey = OpenSSL::PKey::RSA.new(data)
13
+ data = open(File::join(dir, "1000cert.pem")){|io| io.read }
14
+ cert = OpenSSL::X509::Certificate.new(data)
15
+
16
+ s = WEBrick::HTTPServer.new(
17
+ :BindAddress => "localhost",
18
+ :Port => $OPT_p.to_i,
19
+ :Logger => nil,
20
+ :DocumentRoot => $OPT_r || File::join(dir, "/htdocs"),
21
+ :SSLEnable => true,
22
+ :SSLVerifyClient => ::OpenSSL::SSL::VERIFY_NONE,
23
+ :SSLCertificate => cert,
24
+ :SSLPrivateKey => pkey,
25
+ :SSLCertName => nil,
26
+ :SSLCACertificateFile => "all.pem"
27
+ )
28
+ trap("INT"){ s.shutdown }
29
+ s.start
data/sample/stream.rb ADDED
@@ -0,0 +1,21 @@
1
+ $:.unshift(File.join('..', 'lib'))
2
+ require "httpclient"
3
+
4
+ c = HTTPClient.new
5
+
6
+ piper, pipew = IO.pipe
7
+ conn = c.post_async("http://localhost:8080/stream", piper)
8
+
9
+ Thread.new do
10
+ res = conn.pop
11
+ while str = res.content.read(10)
12
+ p str
13
+ end
14
+ end
15
+
16
+ p "type here"
17
+ while line = STDIN.gets
18
+ pipew << line
19
+ end
20
+ pipew.close
21
+ sleep 5
data/sample/thread.rb ADDED
@@ -0,0 +1,27 @@
1
+ $:.unshift(File.join('..', 'lib'))
2
+ require 'httpclient'
3
+
4
+ urlstr = ARGV.shift
5
+
6
+ proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
7
+ h = HTTPClient.new(proxy)
8
+
9
+ count = 20
10
+
11
+ res = []
12
+ g = []
13
+ for i in 0..count
14
+ g << Thread.new {
15
+ res[i] = h.get(urlstr)
16
+ }
17
+ end
18
+
19
+ g.each do |th|
20
+ th.join
21
+ end
22
+
23
+ for i in 0..(count - 1)
24
+ raise unless (res[i].content == res[i + 1].content)
25
+ end
26
+
27
+ puts 'ok'
data/sample/wcat.rb ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # wcat for http-access2
4
+ # Copyright (C) 2001 TAKAHASHI Masayoshi
5
+
6
+ $:.unshift(File.join('..', 'lib'))
7
+ require 'httpclient'
8
+
9
+ if ENV['HTTP_PROXY']
10
+ h = HTTPClient.new(ENV['HTTP_PROXY'])
11
+ else
12
+ h = HTTPClient.new()
13
+ end
14
+
15
+ while urlstr = ARGV.shift
16
+ response = h.get(urlstr){ |data|
17
+ print data
18
+ }
19
+ p response.contenttype
20
+ p response.peer_cert if /^https/i =~ urlstr
21
+ end
data/test/ca-chain.pem ADDED
@@ -0,0 +1,44 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIID0DCCArigAwIBAgIBADANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGDAJKUDES
3
+ MBAGA1UECgwJSklOLkdSLkpQMQwwCgYDVQQLDANSUlIxCzAJBgNVBAMMAkNBMB4X
4
+ DTA0MDEzMDAwNDIzMloXDTM2MDEyMjAwNDIzMlowPDELMAkGA1UEBgwCSlAxEjAQ
5
+ BgNVBAoMCUpJTi5HUi5KUDEMMAoGA1UECwwDUlJSMQswCQYDVQQDDAJDQTCCASIw
6
+ DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANbv0x42BTKFEQOE+KJ2XmiSdZpR
7
+ wjzQLAkPLRnLB98tlzs4xo+y4RyY/rd5TT9UzBJTIhP8CJi5GbS1oXEerQXB3P0d
8
+ L5oSSMwGGyuIzgZe5+vZ1kgzQxMEKMMKlzA73rbMd4Jx3u5+jdbP0EDrPYfXSvLY
9
+ bS04n2aX7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yLj4dO365ujLptWnVIWDHOE
7
+ uN0GeiZO+VzcCisT0WCq4tvtLeH8svrxzA8cbXIEyOK7NiECQQDwo2zPFyKAZ/Cu
8
+ lDJ6zKT+RjfWwW7DgWzirAlTrt4ViMaW+IaDH29TmQpb4V4NuR3Xi+2Xl4oicu6S
9
+ 36TW9+/FAkEA3rgfOQJuLlWSnw1RTGwvnC816a/W7iYYY7B+0U4cDbfWl7IoXT4y
10
+ M8nV/HESooviZLqBwzAYSoj3fFKYBKpGPwJAUO8GN5iWWA2dW3ooiDiv/X1sZmRk
11
+ dojfMFWgRW747tEzya8Ivq0h6kH8w+5GjeMG8Gn1nRiwsulo6Ckj7dEx6QJACyui
12
+ 7UIQ8qP6GZ4aYMHgVW4Mvy7Bkeo5OO7GPYs0Xv/EdJFL8vlGnVBXOjUVoS9w6Gpu
13
+ TbLg1QQvnX2rADjmEwJANxZO2GUkaWGsEif8aGW0x5g/IdaMGG27pTWk5zqix7P3
14
+ 1UDrdo/JOXhptovhRi06EppIxAxYmbh9vd9VN8Itlw==
15
+ -----END RSA PRIVATE KEY-----
data/test/helper.rb ADDED
@@ -0,0 +1,131 @@
1
+ # -*- encoding: utf-8 -*-
2
+ begin
3
+ require 'simplecov'
4
+ require 'simplecov-rcov'
5
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
6
+ SimpleCov.start
7
+ rescue LoadError
8
+ end
9
+ require 'test/unit'
10
+
11
+ require 'httpclient'
12
+ require 'webrick'
13
+ require 'webrick/httpproxy.rb'
14
+ require 'logger'
15
+ require 'stringio'
16
+ require 'cgi'
17
+ require 'webrick/httputils'
18
+
19
+
20
+ module Helper
21
+ Port = 17171
22
+ ProxyPort = 17172
23
+
24
+ def serverport
25
+ @serverport
26
+ end
27
+
28
+ def proxyport
29
+ @proxyport
30
+ end
31
+
32
+ def serverurl
33
+ "http://localhost:#{serverport}/"
34
+ end
35
+
36
+ def proxyurl
37
+ "http://localhost:#{proxyport}/"
38
+ end
39
+
40
+ def setup
41
+ @logger = Logger.new(STDERR)
42
+ @logger.level = Logger::Severity::FATAL
43
+ @proxyio = StringIO.new
44
+ @proxylogger = Logger.new(@proxyio)
45
+ @proxylogger.level = Logger::Severity::DEBUG
46
+ @server = @proxyserver = @client = nil
47
+ @server_thread = @proxyserver_thread = nil
48
+ @serverport = Port
49
+ @proxyport = ProxyPort
50
+ end
51
+
52
+ def teardown
53
+ teardown_client if @client
54
+ teardown_proxyserver if @proxyserver
55
+ teardown_server if @server
56
+ end
57
+
58
+ def setup_client
59
+ @client = HTTPClient.new
60
+ end
61
+
62
+ def escape_noproxy
63
+ backup = HTTPClient::NO_PROXY_HOSTS.dup
64
+ HTTPClient::NO_PROXY_HOSTS.clear
65
+ yield
66
+ ensure
67
+ HTTPClient::NO_PROXY_HOSTS.replace(backup)
68
+ end
69
+
70
+ def setup_proxyserver
71
+ @proxyserver = WEBrick::HTTPProxyServer.new(
72
+ :BindAddress => "localhost",
73
+ :Logger => @proxylogger,
74
+ :Port => 0,
75
+ :AccessLog => []
76
+ )
77
+ @proxyport = @proxyserver.config[:Port]
78
+ @proxyserver_thread = start_server_thread(@proxyserver)
79
+ end
80
+
81
+ def teardown_client
82
+ @client.reset_all
83
+ end
84
+
85
+ def teardown_server
86
+ @server.shutdown
87
+ #@server_thread.kill
88
+ end
89
+
90
+ def teardown_proxyserver
91
+ @proxyserver.shutdown
92
+ #@proxyserver_thread.kill
93
+ end
94
+
95
+ def start_server_thread(server)
96
+ t = Thread.new {
97
+ Thread.current.abort_on_exception = true
98
+ server.start
99
+ }
100
+ while server.status != :Running
101
+ Thread.pass
102
+ unless t.alive?
103
+ t.join
104
+ raise
105
+ end
106
+ end
107
+ t
108
+ end
109
+
110
+ def params(str)
111
+ HTTP::Message.parse(str).inject({}) { |r, (k, v)| r[k] = v.first; r }
112
+ end
113
+
114
+ def silent
115
+ begin
116
+ back, $VERBOSE = $VERBOSE, nil
117
+ yield
118
+ ensure
119
+ $VERBOSE = back
120
+ end
121
+ end
122
+
123
+ def escape_env
124
+ env = {}
125
+ env.update(ENV)
126
+ yield
127
+ ensure
128
+ ENV.clear
129
+ ENV.update(env)
130
+ end
131
+ end
data/test/htdigest ADDED
@@ -0,0 +1 @@
1
+ admin:auth:4302fe65caa32f27721949149ccd3083
data/test/htpasswd ADDED
@@ -0,0 +1,2 @@
1
+ admin:Qg266hq/YYKe2
2
+ guest:gbPc4vPCH.h12
@@ -0,0 +1,32 @@
1
+ require File.expand_path('helper', File.join(File.dirname(__FILE__), ".."))
2
+
3
+
4
+ class PEMUtilsTest < Test::Unit::TestCase
5
+ include Helper
6
+
7
+ def setup
8
+ @raw_cert = "-----BEGIN CERTIFICATE-----\nMIIDOTCCAiGgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBCMRMwEQYKCZImiZPyLGQB\nGRYDb3JnMRkwFwYKCZImiZPyLGQBGRYJcnVieS1sYW5nMRAwDgYDVQQDDAdSdWJ5\nIENBMB4XDTE2MDgxMDE3MjEzNFoXDTE3MDgxMDE3MjEzNFowSzETMBEGCgmSJomT\n8ixkARkWA29yZzEZMBcGCgmSJomT8ixkARkWCXJ1YnktbGFuZzEZMBcGA1UEAwwQ\nUnVieSBjZXJ0aWZpY2F0ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB\nAJCfsSXpSMpmZCVa+ZCM+QDgomnhDlvnrGDq6pasTaIspGTXgws+7r8Dt/cNe6EH\nHJpRH2cGRiO4yPcfcT9eS4X7k8OC4f33wHfACOmLu6LeoNE8ujmSk6L6WzLUI+sE\nnLZbFrXxoAo4XHsm8vEG9C+jEoXZ1p+47wrAGaDwDQTnzlMy4dT9pRQEJP2G/Rry\nUkuZn8SUWmh3/YS78iaSzsNF1cgE1ealHOrPPFDjiCGDaH/LHyUPYlbFSLZ/B7Qx\nLxi5sePLcywWq/EJrmWpgeVTDjtNijsdKv/A3qkY+fm/oD0pzt7XsfJaP9YKNyJO\nQFdxWZeiPcDF+Hwf+IwSr+kCAwEAAaMxMC8wDgYDVR0PAQH/BAQDAgeAMB0GA1Ud\nDgQWBBQNvzYzJyXemGhxbA8NMXLolDnPyjANBgkqhkiG9w0BAQsFAAOCAQEARIJV\noKejGlOTn71QutnNnu07UtTu0IHs6YqjYzzND+m4JXLN+wvYm72AFUG0b1L7dRg0\niK8XjQrlNQNVqP1Mc6tffchy20neOPOHeiO6qTdRU8P2S8D3Uwe+1qhgxjfE+cWc\nwZmWxYK4HA8c58PxWMqrkr2QqXDplG9KWLvOgrtPGiLLZcQSKhvvB63QzItHBDU6\nRayiJY3oPkK/HrIvFlySqFqzWmuyknkciOFywEHQMz/tcSFJ2QFpPj/tBz9VXohH\nZ8KscmfhZrTPBjo+ky1lz/WraWoz4LMiLnkC2ABczWLRSawu+v3Irx1NFJngt05e\npqwtqIUeg7j+JLiTaA==\n-----END CERTIFICATE-----"
9
+ end
10
+
11
+ def test_read_certificate
12
+ assert_nothing_raised do
13
+ binary = HTTPClient::JRubySSLSocket::PEMUtils.read_certificate(@raw_cert)
14
+ end
15
+ end
16
+
17
+ def test_read_certificate_works_with_random_ascii_text_outside_begin_end
18
+ raw_cert_with_ascii = "some text before begin\n" + @raw_cert + "\nsome text after end"
19
+ assert_nothing_raised do
20
+ binary = HTTPClient::JRubySSLSocket::PEMUtils.read_certificate(raw_cert_with_ascii)
21
+ end
22
+ end
23
+
24
+ def test_read_certificate_uses_all_content_if_missing_begin_end
25
+ cert = @raw_cert.sub(/-----BEGIN CERTIFICATE-----/, '').sub(/-----END CERTIFICATE-----/, '')
26
+ assert_nothing_raised do
27
+ binary = HTTPClient::JRubySSLSocket::PEMUtils.read_certificate(cert)
28
+ end
29
+ end
30
+
31
+
32
+ end
data/test/runner.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ exit Test::Unit::AutoRunner.run(true, File.dirname($0))
data/test/server.cert ADDED
@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIC/zCCAeegAwIBAgIBATANBgkqhki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iVtkM
18
+ rRlQ
19
+ -----END CERTIFICATE-----
data/test/server.key ADDED
@@ -0,0 +1,15 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIICXQIBAAKBgQDRSU8Vqrqd51fXbCQJLqflml5zzSM3KQAN6jBmQyUybH2vA7u2
3
+ cUz9FySuZhE7bQa5+9dXCcQLj9yo6p1vUr7WfZWNrFyemY+trDeS8Bt1VXtuXSNv
4
+ MkdRLGx4yeWY3/bZoIDAumpudncbh27ef7x6OJ4CbihP1PnnhkYrzJ+oBQIDAQAB
5
+ AoGBAIf4CstW2ltQO7+XYGoex7Hh8s9lTSW/G2vu5Hbr1LTHy3fzAvdq8MvVR12O
6
+ rk9fa+lU9vhzPc0NMB0GIDZ9GcHuhW5hD1Wg9OSCbTOkZDoH3CAFqonjh4Qfwv5W
7
+ IPAFn9KHukdqGXkwEMdErsUaPTy9A1V/aROVEaAY+HJgq/eZAkEA/BP1QMV04WEZ
8
+ Oynzz7/lLizJGGxp2AOvEVtqMoycA/Qk+zdKP8ufE0wbmCE3Qd6GoynavsHb6aGK
9
+ gQobb8zDZwJBANSK6MrXlrZTtEaeZuyOB4mAmRzGzOUVkUyULUjEx2GDT93ujAma
10
+ qm/2d3E+wXAkNSeRpjUmlQXy/2oSqnGvYbMCQQDRM+cYyEcGPUVpWpnj0shrF/QU
11
+ 9vSot/X1G775EMTyaw6+BtbyNxVgOIu2J+rqGbn3c+b85XqTXOPL0A2RLYkFAkAm
12
+ syhSDtE9X55aoWsCNZY/vi+i4rvaFoQ/WleogVQAeGVpdo7/DK9t9YWoFBIqth0L
13
+ mGSYFu9ZhvZkvQNV8eYrAkBJ+rOIaLDsmbrgkeDruH+B/9yrm4McDtQ/rgnOGYnH
14
+ LjLpLLOrgUxqpzLWe++EwSLwK2//dHO+SPsQJ4xsyQJy
15
+ -----END RSA PRIVATE KEY-----
data/test/sslsvr.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'webrick/https'
2
+ require 'logger'
3
+ require 'rbconfig'
4
+
5
+ PORT = 17171
6
+ DIR = File.dirname(File.expand_path(__FILE__))
7
+
8
+ def cert(filename)
9
+ OpenSSL::X509::Certificate.new(File.open(File.join(DIR, filename)) { |f|
10
+ f.read
11
+ })
12
+ end
13
+
14
+ def key(filename)
15
+ OpenSSL::PKey::RSA.new(File.open(File.join(DIR, filename)) { |f|
16
+ f.read
17
+ })
18
+ end
19
+
20
+ def do_hello(req, res)
21
+ res['content-type'] = 'text/html'
22
+ res.body = "hello"
23
+ end
24
+
25
+ logger = Logger.new(STDERR)
26
+ logger.level = Logger::Severity::FATAL # avoid logging SSLError (ERROR level)
27
+
28
+ server = WEBrick::HTTPServer.new(
29
+ :BindAddress => "localhost",
30
+ :Logger => logger,
31
+ :Port => PORT,
32
+ :AccessLog => [],
33
+ :DocumentRoot => DIR,
34
+ :SSLEnable => true,
35
+ :SSLCACertificateFile => File.join(DIR, 'ca.cert'),
36
+ :SSLCertificate => cert('server.cert'),
37
+ :SSLPrivateKey => key('server.key'),
38
+ :SSLVerifyClient => nil, #OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT|OpenSSL::SSL::VERIFY_PEER,
39
+ :SSLClientCA => cert('ca.cert'),
40
+ :SSLCertName => nil
41
+ )
42
+ trap(:INT) do
43
+ server.shutdown
44
+ end
45
+ [:hello].each do |sym|
46
+ server.mount(
47
+ "/#{sym}",
48
+ WEBrick::HTTPServlet::ProcHandler.new(method("do_#{sym}").to_proc)
49
+ )
50
+ end
51
+
52
+ t = Thread.new {
53
+ Thread.current.abort_on_exception = true
54
+ server.start
55
+ }
56
+ while server.status != :Running
57
+ sleep 0.1
58
+ unless t.alive?
59
+ t.join
60
+ raise
61
+ end
62
+ end
63
+ STDOUT.sync = true
64
+ puts $$
65
+ t.join
data/test/subca.cert ADDED
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDaDCCAlCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQG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