r509-ocsp-responder 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +112 -17
- data/doc/R509.html +6 -6
- data/doc/R509/Ocsp.html +10 -10
- data/doc/R509/Ocsp/Helper.html +9 -9
- data/doc/R509/Ocsp/Helper/RequestChecker.html +73 -73
- data/doc/R509/Ocsp/Helper/ResponseSigner.html +59 -59
- data/doc/R509/Ocsp/Responder.html +10 -10
- data/doc/R509/Ocsp/Responder/OcspConfig.html +31 -31
- data/doc/R509/Ocsp/Responder/Server.html +9 -9
- data/doc/R509/Ocsp/Responder/StatusError.html +9 -9
- data/doc/R509/Ocsp/Signer.html +36 -44
- data/doc/_index.html +23 -23
- data/doc/class_list.html +2 -2
- data/doc/css/style.css +10 -0
- data/doc/file.README.html +120 -28
- data/doc/file_list.html +1 -1
- data/doc/frames.html +1 -1
- data/doc/index.html +120 -28
- data/doc/js/full_list.js +6 -1
- data/doc/method_list.html +28 -56
- data/doc/top-level-namespace.html +5 -5
- data/lib/r509/ocsp/responder/ocsp-config.rb +27 -27
- data/lib/r509/ocsp/responder/server.rb +129 -131
- data/lib/r509/ocsp/responder/version.rb +4 -4
- data/lib/r509/ocsp/signer.rb +219 -219
- data/spec/fixtures.rb +145 -190
- data/spec/fixtures/test_ca_ec.cer +14 -0
- data/spec/fixtures/test_ca_ec.key +6 -0
- data/spec/server_spec.rb +405 -397
- data/spec/signer_spec.rb +262 -249
- data/spec/spec_helper.rb +2 -2
- metadata +10 -8
data/spec/fixtures.rb
CHANGED
@@ -3,194 +3,149 @@ require 'pathname'
|
|
3
3
|
require 'r509/io_helpers'
|
4
4
|
|
5
5
|
module TestFixtures
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
ret.set_profile("server_with_subject_item_policy", self.test_ca_server_profile_with_subject_item_policy)
|
152
|
-
|
153
|
-
ret
|
154
|
-
end
|
155
|
-
|
156
|
-
# @return [R509::Config::CaConfig]
|
157
|
-
def self.test_ca_subroot_config
|
158
|
-
crl_list_sio = StringIO.new
|
159
|
-
crl_list_sio.set_encoding("BINARY") if crl_list_sio.respond_to?(:set_encoding)
|
160
|
-
crl_number_sio = StringIO.new
|
161
|
-
crl_number_sio.set_encoding("BINARY") if crl_number_sio.respond_to?(:set_encoding)
|
162
|
-
|
163
|
-
opts = {
|
164
|
-
:ca_cert => test_ca_subroot_cert(),
|
165
|
-
:cdp_location => 'URI:http://crl.domain.com/test_ca.crl',
|
166
|
-
:ocsp_location => 'URI:http://ocsp.domain.com',
|
167
|
-
:ocsp_start_skew_seconds => 3600,
|
168
|
-
:ocsp_validity_hours => 48,
|
169
|
-
:crl_list_file => crl_list_sio,
|
170
|
-
:crl_number_file => crl_number_sio
|
171
|
-
}
|
172
|
-
ret = R509::Config::CaConfig.new(opts)
|
173
|
-
|
174
|
-
ret.set_profile("server", self.test_ca_server_profile)
|
175
|
-
ret.set_profile("subroot", self.test_ca_subroot_profile)
|
176
|
-
ret.set_profile("ocspsigner", self.test_ca_ocspsigner_profile)
|
177
|
-
ret.set_profile("server_with_subject_item_policy", self.test_ca_server_profile_with_subject_item_policy)
|
178
|
-
|
179
|
-
ret
|
180
|
-
end
|
181
|
-
|
182
|
-
# @return [R509::Config::CaConfig] secondary config
|
183
|
-
def self.second_ca_config
|
184
|
-
opts = {
|
185
|
-
:ca_cert => second_ca_cert(),
|
186
|
-
:cdp_location => 'URI:http://crl.domain.com/test_ca.crl',
|
187
|
-
:ocsp_location => 'URI:http://ocsp.domain.com'
|
188
|
-
}
|
189
|
-
ret = R509::Config::CaConfig.new(opts)
|
190
|
-
|
191
|
-
ret.set_profile("server", self.second_ca_server_profile)
|
192
|
-
ret.set_profile("subroot", self.second_ca_subroot_profile)
|
193
|
-
|
194
|
-
ret
|
195
|
-
end
|
6
|
+
extend R509::IOHelpers
|
7
|
+
|
8
|
+
FIXTURES_PATH = Pathname.new(__FILE__).dirname + "fixtures"
|
9
|
+
|
10
|
+
def self.read_fixture(filename)
|
11
|
+
read_data((FIXTURES_PATH + filename).to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
#Trustwave cert for langui.sh
|
15
|
+
CERT = read_fixture('cert1.pem')
|
16
|
+
|
17
|
+
#Trustwave root cert
|
18
|
+
STCA_CERT = read_fixture('stca.pem')
|
19
|
+
|
20
|
+
|
21
|
+
TEST_CA_CERT = read_fixture('test_ca.cer')
|
22
|
+
TEST_CA_KEY = read_fixture('test_ca.key')
|
23
|
+
|
24
|
+
TEST_CA_OCSP_CERT = read_fixture('test_ca_ocsp.cer')
|
25
|
+
TEST_CA_OCSP_KEY = read_fixture('test_ca_ocsp.key')
|
26
|
+
|
27
|
+
TEST_CA_SUBROOT_CERT = read_fixture('test_ca_subroot.cer')
|
28
|
+
TEST_CA_SUBROOT_KEY = read_fixture('test_ca_subroot.key')
|
29
|
+
|
30
|
+
TEST_CA_SUBROOT_OCSP_CERT = read_fixture('test_ca_subroot_ocsp.cer')
|
31
|
+
TEST_CA_SUBROOT_OCSP_KEY = read_fixture('test_ca_subroot_ocsp.key')
|
32
|
+
|
33
|
+
SECOND_CA_CERT = read_fixture('second_ca.cer')
|
34
|
+
SECOND_CA_KEY = read_fixture('second_ca.key')
|
35
|
+
|
36
|
+
OCSP_TEST_CERT = read_fixture('ocsptest.r509.local.pem')
|
37
|
+
|
38
|
+
STCA_OCSP_REQUEST = read_fixture('stca_ocsp_request.der')
|
39
|
+
STCA_OCSP_RESPONSE = read_fixture('stca_ocsp_response.der')
|
40
|
+
|
41
|
+
TEST_CA_EC_CERT = read_fixture('test_ca_ec.cer')
|
42
|
+
TEST_CA_EC_KEY = read_fixture('test_ca_ec.key')
|
43
|
+
|
44
|
+
def self.test_ca_cert
|
45
|
+
R509::Cert.new(:cert => TEST_CA_CERT, :key => TEST_CA_KEY)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.test_ca_ec_cert
|
49
|
+
R509::Cert.new(:cert => TEST_CA_EC_CERT, :key => TEST_CA_EC_KEY)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.test_ca_subroot_cert
|
53
|
+
R509::Cert.new(:cert => TEST_CA_SUBROOT_CERT, :key => TEST_CA_SUBROOT_KEY)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.test_ca_server_profile
|
57
|
+
R509::Config::CAProfile.new(
|
58
|
+
:basic_constraints => { "ca" => false },
|
59
|
+
:key_usage => ["digitalSignature","keyEncipherment"],
|
60
|
+
:extended_key_usage => ["serverAuth"]
|
61
|
+
)
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.second_ca_cert
|
66
|
+
R509::Cert.new(:cert => SECOND_CA_CERT, :key => SECOND_CA_KEY)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.second_ca_server_profile
|
70
|
+
R509::Config::CAProfile.new(
|
71
|
+
:basic_constraints => { "ca" => false },
|
72
|
+
:key_usage => ["digitalSignature","keyEncipherment"],
|
73
|
+
:extended_key_usage => ["serverAuth"]
|
74
|
+
)
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
# @return [R509::Config::CAConfig]
|
79
|
+
def self.test_ca_config
|
80
|
+
crl_list_sio = StringIO.new
|
81
|
+
crl_list_sio.set_encoding("BINARY") if crl_list_sio.respond_to?(:set_encoding)
|
82
|
+
crl_number_sio = StringIO.new
|
83
|
+
crl_number_sio.set_encoding("BINARY") if crl_number_sio.respond_to?(:set_encoding)
|
84
|
+
|
85
|
+
opts = {
|
86
|
+
:ca_cert => test_ca_cert(),
|
87
|
+
:ocsp_start_skew_seconds => 3600,
|
88
|
+
:ocsp_validity_hours => 48,
|
89
|
+
:crl_list_file => crl_list_sio,
|
90
|
+
:crl_number_file => crl_number_sio
|
91
|
+
}
|
92
|
+
ret = R509::Config::CAConfig.new(opts)
|
93
|
+
|
94
|
+
ret.set_profile("server", self.test_ca_server_profile)
|
95
|
+
|
96
|
+
ret
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [R509::Config::CAConfig]
|
100
|
+
def self.test_ca_ec_config
|
101
|
+
crl_list_sio = StringIO.new
|
102
|
+
crl_list_sio.set_encoding("BINARY") if crl_list_sio.respond_to?(:set_encoding)
|
103
|
+
crl_number_sio = StringIO.new
|
104
|
+
crl_number_sio.set_encoding("BINARY") if crl_number_sio.respond_to?(:set_encoding)
|
105
|
+
|
106
|
+
opts = {
|
107
|
+
:ca_cert => test_ca_ec_cert(),
|
108
|
+
:ocsp_start_skew_seconds => 3600,
|
109
|
+
:ocsp_validity_hours => 48,
|
110
|
+
:crl_list_file => crl_list_sio,
|
111
|
+
:crl_number_file => crl_number_sio
|
112
|
+
}
|
113
|
+
ret = R509::Config::CAConfig.new(opts)
|
114
|
+
|
115
|
+
ret.set_profile("server", self.test_ca_server_profile)
|
116
|
+
ret
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [R509::Config::CAConfig]
|
120
|
+
def self.test_ca_subroot_config
|
121
|
+
crl_list_sio = StringIO.new
|
122
|
+
crl_list_sio.set_encoding("BINARY") if crl_list_sio.respond_to?(:set_encoding)
|
123
|
+
crl_number_sio = StringIO.new
|
124
|
+
crl_number_sio.set_encoding("BINARY") if crl_number_sio.respond_to?(:set_encoding)
|
125
|
+
|
126
|
+
opts = {
|
127
|
+
:ca_cert => test_ca_subroot_cert(),
|
128
|
+
:ocsp_start_skew_seconds => 3600,
|
129
|
+
:ocsp_validity_hours => 48,
|
130
|
+
:crl_list_file => crl_list_sio,
|
131
|
+
:crl_number_file => crl_number_sio
|
132
|
+
}
|
133
|
+
ret = R509::Config::CAConfig.new(opts)
|
134
|
+
|
135
|
+
ret.set_profile("server", self.test_ca_server_profile)
|
136
|
+
|
137
|
+
ret
|
138
|
+
end
|
139
|
+
|
140
|
+
# @return [R509::Config::CAConfig] secondary config
|
141
|
+
def self.second_ca_config
|
142
|
+
opts = {
|
143
|
+
:ca_cert => second_ca_cert(),
|
144
|
+
}
|
145
|
+
ret = R509::Config::CAConfig.new(opts)
|
146
|
+
|
147
|
+
ret.set_profile("server", self.second_ca_server_profile)
|
148
|
+
|
149
|
+
ret
|
150
|
+
end
|
196
151
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIICJzCCAaygAwIBAgITBhgGAz3nZpKHtz6KQjnGF3l8IzAKBggqhkjOPQQDAjBb
|
3
|
+
MQswCQYDVQQGEwJVUzERMA8GA1UECAwISWxsaW5vaXMxEDAOBgNVBAcMB0NoaWNh
|
4
|
+
Z28xETAPBgNVBAoMCHI1MDkgTExDMRQwEgYDVQQDDAtyNTA5IEVDQyBDQTAeFw0x
|
5
|
+
MzAxMjMxNDE1MjBaFw0zMzAxMTgyMDE1MjBaMFsxCzAJBgNVBAYTAlVTMREwDwYD
|
6
|
+
VQQIDAhJbGxpbm9pczEQMA4GA1UEBwwHQ2hpY2FnbzERMA8GA1UECgwIcjUwOSBM
|
7
|
+
TEMxFDASBgNVBAMMC3I1MDkgRUNDIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE
|
8
|
+
FoGSwxFhGtPcBRnmKSwVnYRhniE86GmTTCGyb02ch5ZENzmjdTuR4MoeBmG5RXzH
|
9
|
+
mX1I6rcFW5sJWnmOncE0zcl7qGxash/+3wFm3qwwR1YUpDZ+TeYtezqkEegN+I2T
|
10
|
+
ozIwMDAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBS27qtirnzRTXfTrJOA46dI
|
11
|
+
r1hc4jAKBggqhkjOPQQDAgNpADBmAjEAgy6c00RdXZ5wmRo5uFOu9aa5kUJo912+
|
12
|
+
hiHmddmFVCyQcvsX+hq2GvFKLhwxty9jAjEA4e4WY48QArCidovB/iYXRkvE5efL
|
13
|
+
oqXZOHh/QzwiNz66ZIGR8tv2iLoRXoG4fiWG
|
14
|
+
-----END CERTIFICATE-----
|
@@ -0,0 +1,6 @@
|
|
1
|
+
-----BEGIN EC PRIVATE KEY-----
|
2
|
+
MIGkAgEBBDCVvOkiIED5VN04e0/zOjv2UHZ94vRt4NP939/UnPkxxoy8yQRCDW9v
|
3
|
+
vJp4kJ2uz12gBwYFK4EEACKhZANiAAQWgZLDEWEa09wFGeYpLBWdhGGeITzoaZNM
|
4
|
+
IbJvTZyHlkQ3OaN1O5Hgyh4GYblFfMeZfUjqtwVbmwlaeY6dwTTNyXuobFqyH/7f
|
5
|
+
AWberDBHVhSkNn5N5i17OqQR6A34jZM=
|
6
|
+
-----END EC PRIVATE KEY-----
|
data/spec/server_spec.rb
CHANGED
@@ -1,400 +1,408 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
require 'time'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
3
|
+
require 'r509/validity/redis'
|
4
|
+
|
5
|
+
|
6
|
+
describe R509::OCSP::Responder::Server do
|
7
|
+
before :all do
|
8
|
+
@test_ca_cert = OpenSSL::X509::Certificate.new(File.read(Pathname.new(__FILE__).dirname + "fixtures/test_ca.cer"))
|
9
|
+
@second_ca_cert = OpenSSL::X509::Certificate.new(File.read(Pathname.new(__FILE__).dirname + "fixtures/second_ca.cer"))
|
10
|
+
end
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
# clear the dependo before each test
|
14
|
+
Dependo::Registry.clear
|
15
|
+
Dependo::Registry[:log] = Logger.new(nil)
|
16
|
+
|
17
|
+
# we always want to mock with a new redis
|
18
|
+
@redis = double("redis")
|
19
|
+
Dependo::Registry[:validity_checker] = R509::Validity::Redis::Checker.new @redis
|
20
|
+
|
21
|
+
# and we want to mock the stats recorder
|
22
|
+
@stats = double("stats")
|
23
|
+
Dependo::Registry[:stats] = @stats
|
24
|
+
|
25
|
+
# default value for :copy_nonce is false (can override on a per-test basis)
|
26
|
+
Dependo::Registry[:copy_nonce] = false
|
27
|
+
|
28
|
+
# default value for :cache_headers is false (can override on a per-test basis)
|
29
|
+
Dependo::Registry[:cache_headers] = false
|
30
|
+
|
31
|
+
# default value for :max_cache_age is nil (can override on a per-test basis)
|
32
|
+
Dependo::Registry[:max_cache_age] = nil
|
33
|
+
|
34
|
+
# read the config.yaml
|
35
|
+
@config_pool = R509::Config::CAConfigPool.from_yaml("certificate_authorities", File.read(File.dirname(__FILE__)+"/fixtures/test_config.yaml"))
|
36
|
+
end
|
37
|
+
|
38
|
+
def app
|
39
|
+
# this is executed after the code in each test, so if we change something in the dependo registry, it'll show up here (we will set :copy_nonce in some tests)
|
40
|
+
Dependo::Registry[:ocsp_signer] = R509::OCSP::Signer.new(
|
41
|
+
:configs => @config_pool,
|
42
|
+
:validity_checker => Dependo::Registry[:validity_checker],
|
43
|
+
:copy_nonce => Dependo::Registry[:copy_nonce]
|
44
|
+
)
|
45
|
+
@app ||= R509::OCSP::Responder::Server
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return unauthorized on a GET which does not match any configured CA" do
|
49
|
+
get '/MFEwTzBNMEswSTAJBgUrDgMCGgUABBQ1mI4Ww4R5LZiQ295pj4OF%2F44yyAQUyk7dWyc1Kdn27sPlU%2B%2BkwBmWHa8CEFqb7H4xpqYH6ed2G0%2BPMG4%3D'
|
50
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
51
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_UNAUTHORIZED
|
52
|
+
last_response.content_type.should == "application/ocsp-response"
|
53
|
+
last_response.should be_ok
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return a valid (UNKNOWN) response on a GET request from the test_ca CA" do
|
57
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:1051177536915098490149656742929223623669143613238").and_return({})
|
58
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "1051177536915098490149656742929223623669143613238", "UNKNOWN")
|
59
|
+
|
60
|
+
get '/MFYwVDBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQC4IG5U4zC4RYb4VQ%2B2f0zCoFCvNg%3D%3D'
|
61
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
62
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
|
63
|
+
ocsp_response.basic.status[0][1].should == OpenSSL::OCSP::V_CERTSTATUS_UNKNOWN
|
64
|
+
ocsp_response.basic.status[0][0].serial.should == 1051177536915098490149656742929223623669143613238
|
65
|
+
ocsp_response.verify(@test_ca_cert).should == true
|
66
|
+
last_response.content_type.should == "application/ocsp-response"
|
67
|
+
last_response.should be_ok
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return a valid (REVOKED) response on a GET request from the test_ca CA" do
|
71
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:1051177536915098490149656742929223623669143613238").and_return({"status" => R509::Validity::REVOKED})
|
72
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "1051177536915098490149656742929223623669143613238", "REVOKED")
|
73
|
+
|
74
|
+
get '/MFYwVDBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQC4IG5U4zC4RYb4VQ%2B2f0zCoFCvNg%3D%3D'
|
75
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
76
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
|
77
|
+
ocsp_response.basic.status[0][1].should == OpenSSL::OCSP::V_CERTSTATUS_REVOKED
|
78
|
+
ocsp_response.basic.status[0][0].serial.should == 1051177536915098490149656742929223623669143613238
|
79
|
+
ocsp_response.verify(@test_ca_cert).should == true
|
80
|
+
last_response.content_type.should == "application/ocsp-response"
|
81
|
+
last_response.should be_ok
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return a valid (VALID) response on a GET request from the test_ca CA" do
|
85
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:1051177536915098490149656742929223623669143613238").and_return({"status" => R509::Validity::VALID})
|
86
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "1051177536915098490149656742929223623669143613238", "VALID")
|
87
|
+
|
88
|
+
get '/MFYwVDBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQC4IG5U4zC4RYb4VQ%2B2f0zCoFCvNg%3D%3D'
|
89
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
90
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
|
91
|
+
ocsp_response.basic.status[0][1].should == OpenSSL::OCSP::V_CERTSTATUS_GOOD
|
92
|
+
ocsp_response.basic.status[0][0].serial.should == 1051177536915098490149656742929223623669143613238
|
93
|
+
ocsp_response.verify(@test_ca_cert).should == true
|
94
|
+
last_response.content_type.should == "application/ocsp-response"
|
95
|
+
last_response.should be_ok
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return a valid (VALID) response on a GET request with extra leading slashes from the test_ca CA" do
|
99
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:1051177536915098490149656742929223623669143613238").and_return({"status" => R509::Validity::VALID})
|
100
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "1051177536915098490149656742929223623669143613238", "VALID")
|
101
|
+
|
102
|
+
get '/%2F%2FMFYwVDBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQC4IG5U4zC4RYb4VQ%2B2f0zCoFCvNg%3D%3D'
|
103
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
104
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
|
105
|
+
ocsp_response.basic.status[0][1].should == OpenSSL::OCSP::V_CERTSTATUS_GOOD
|
106
|
+
ocsp_response.basic.status[0][0].serial.should == 1051177536915098490149656742929223623669143613238
|
107
|
+
ocsp_response.verify(@test_ca_cert).should == true
|
108
|
+
last_response.content_type.should == "application/ocsp-response"
|
109
|
+
last_response.should be_ok
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return a valid (VALID) response on a GET request from a second configured CA (second_ca)" do
|
113
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA:773553085290984246110251380739025914079776985795").and_return({"status" => R509::Validity::VALID})
|
114
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA", "773553085290984246110251380739025914079776985795", "VALID")
|
115
|
+
|
116
|
+
get '/MFYwVDBSMFAwTjAJBgUrDgMCGgUABBT1kOLWHXbHiKP3sVPVxVziq%2FMqIwQUP8ezIf8yhMLgHnccSKJLQdhDaVkCFQCHf1HsjUAACwcp3qQL4IxclfXSww%3D%3D'
|
117
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
118
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
|
119
|
+
ocsp_response.basic.status[0][1].should == OpenSSL::OCSP::V_CERTSTATUS_GOOD
|
120
|
+
ocsp_response.basic.status[0][0].serial.should == 773553085290984246110251380739025914079776985795
|
121
|
+
ocsp_response.verify(@test_ca_cert).should == false
|
122
|
+
ocsp_response.verify(@second_ca_cert).should == true
|
123
|
+
last_response.content_type.should == "application/ocsp-response"
|
124
|
+
last_response.should be_ok
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return unauthorized on a POST which does not match any configured CA" do
|
128
|
+
der = Base64.decode64(URI.decode("MFEwTzBNMEswSTAJBgUrDgMCGgUABBQ1mI4Ww4R5LZiQ295pj4OF%2F44yyAQUyk7dWyc1Kdn27sPlU%2B%2BkwBmWHa8CEFqb7H4xpqYH6ed2G0%2BPMG4%3D"))
|
129
|
+
post '/', der, "CONTENT_TYPE" => "application/ocsp-request"
|
130
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
131
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_UNAUTHORIZED
|
132
|
+
last_response.content_type.should == "application/ocsp-response"
|
133
|
+
last_response.should be_ok
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should return a valid (UNKNOWN) response on a POST request from the test_ca CA" do
|
137
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:1051177536915098490149656742929223623669143613238").and_return({})
|
138
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "1051177536915098490149656742929223623669143613238", "UNKNOWN")
|
139
|
+
|
140
|
+
der = Base64.decode64(URI.decode("MFYwVDBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQC4IG5U4zC4RYb4VQ%2B2f0zCoFCvNg%3D%3D"))
|
141
|
+
post '/', der, "CONTENT_TYPE" => "application/ocsp-request"
|
142
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
143
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
|
144
|
+
ocsp_response.basic.status[0][1].should == OpenSSL::OCSP::V_CERTSTATUS_UNKNOWN
|
145
|
+
ocsp_response.basic.status[0][0].serial.should == 1051177536915098490149656742929223623669143613238
|
146
|
+
ocsp_response.verify(@test_ca_cert).should == true
|
147
|
+
last_response.content_type.should == "application/ocsp-response"
|
148
|
+
last_response.should be_ok
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return a valid (REVOKED) response on a POST request from the test_ca CA" do
|
152
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:1051177536915098490149656742929223623669143613238").and_return({"status" => R509::Validity::REVOKED})
|
153
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "1051177536915098490149656742929223623669143613238", "REVOKED")
|
154
|
+
|
155
|
+
der = Base64.decode64(URI.decode("MFYwVDBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQC4IG5U4zC4RYb4VQ%2B2f0zCoFCvNg%3D%3D"))
|
156
|
+
post '/', der, "CONTENT_TYPE" => "application/ocsp-request"
|
157
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
158
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
|
159
|
+
ocsp_response.basic.status[0][1].should == OpenSSL::OCSP::V_CERTSTATUS_REVOKED
|
160
|
+
ocsp_response.basic.status[0][0].serial.should == 1051177536915098490149656742929223623669143613238
|
161
|
+
ocsp_response.verify(@test_ca_cert).should == true
|
162
|
+
last_response.content_type.should == "application/ocsp-response"
|
163
|
+
last_response.should be_ok
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should return a valid (VALID) response on a POST request from the test_ca CA" do
|
167
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:1051177536915098490149656742929223623669143613238").and_return({"status" => R509::Validity::VALID})
|
168
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "1051177536915098490149656742929223623669143613238", "VALID")
|
169
|
+
|
170
|
+
der = Base64.decode64(URI.decode("MFYwVDBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQC4IG5U4zC4RYb4VQ%2B2f0zCoFCvNg%3D%3D"))
|
171
|
+
post '/', der, "CONTENT_TYPE" => "application/ocsp-request"
|
172
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
173
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
|
174
|
+
ocsp_response.basic.status[0][1].should == OpenSSL::OCSP::V_CERTSTATUS_GOOD
|
175
|
+
ocsp_response.basic.status[0][0].serial.should == 1051177536915098490149656742929223623669143613238
|
176
|
+
ocsp_response.verify(@test_ca_cert).should == true
|
177
|
+
last_response.content_type.should == "application/ocsp-response"
|
178
|
+
last_response.should be_ok
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should return a valid (VALID) response on a POST request from a second configured CA (second_ca)" do
|
182
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA:773553085290984246110251380739025914079776985795").and_return({"status" => R509::Validity::VALID})
|
183
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA", "773553085290984246110251380739025914079776985795", "VALID")
|
184
|
+
|
185
|
+
der = Base64.decode64(URI.decode("MFYwVDBSMFAwTjAJBgUrDgMCGgUABBT1kOLWHXbHiKP3sVPVxVziq%2FMqIwQUP8ezIf8yhMLgHnccSKJLQdhDaVkCFQCHf1HsjUAACwcp3qQL4IxclfXSww%3D%3D"))
|
186
|
+
post '/', der, "CONTENT_TYPE" => "application/ocsp-request"
|
187
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
188
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL
|
189
|
+
ocsp_response.basic.status[0][1].should == OpenSSL::OCSP::V_CERTSTATUS_GOOD
|
190
|
+
ocsp_response.basic.status[0][0].serial.should == 773553085290984246110251380739025914079776985795
|
191
|
+
ocsp_response.verify(@test_ca_cert).should == false
|
192
|
+
ocsp_response.verify(@second_ca_cert).should == true
|
193
|
+
last_response.content_type.should == "application/ocsp-response"
|
194
|
+
last_response.should be_ok
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should return 200 OK when querying status and redis is available" do
|
198
|
+
@redis.should_receive(:ping).and_return("PONG")
|
199
|
+
get '/status'
|
200
|
+
last_response.should be_ok
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should return 500 DOWN when querying status with redis unavailable" do
|
204
|
+
@redis.should_receive(:ping).and_raise(StandardError)
|
205
|
+
get '/status'
|
206
|
+
last_response.should_not be_ok
|
207
|
+
last_response.body.should == "Down"
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should return 500 DOWN when querying status with redis responding incorrectly" do
|
211
|
+
@redis.should_receive(:ping).and_return("")
|
212
|
+
get '/status'
|
213
|
+
last_response.should_not be_ok
|
214
|
+
last_response.body.should == "Down"
|
215
|
+
end
|
216
|
+
|
217
|
+
it "a malformed request should return a proper OCSP response (GET)" do
|
218
|
+
get '/Msdfsfsdf'
|
219
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
220
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_MALFORMEDREQUEST
|
221
|
+
last_response.content_type.should == "application/ocsp-response"
|
222
|
+
last_response.should be_ok
|
223
|
+
end
|
224
|
+
|
225
|
+
it "a malformed request should return a proper OCSP response (POST)" do
|
226
|
+
post '/', 'Mdskfsdf', "CONTENT_TYPE" => "application/ocsp-request"
|
227
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
228
|
+
ocsp_response.status.should == OpenSSL::OCSP::RESPONSE_STATUS_MALFORMEDREQUEST
|
229
|
+
last_response.content_type.should == "application/ocsp-response"
|
230
|
+
last_response.should be_ok
|
231
|
+
end
|
232
|
+
|
233
|
+
it "copies nonce when copy_nonce is true" do
|
234
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:872625873161273451176241581705670534707360122361").and_return({"status" => R509::Validity::VALID})
|
235
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "872625873161273451176241581705670534707360122361", "VALID")
|
236
|
+
|
237
|
+
# set to true for this test (this works because the app doesn't get set up until after this code)
|
238
|
+
Dependo::Registry[:copy_nonce] = true
|
239
|
+
|
240
|
+
get '/MHsweTBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQCY2eXAtMNzVS33fF0PHrUSjklF%2BaIjMCEwHwYJKwYBBQUHMAECBBIEEDTJniOQonxCRmmHAHCVstw%3D'
|
241
|
+
request = OpenSSL::OCSP::Request.new(Base64.decode64("MHsweTBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQCY2eXAtMNzVS33fF0PHrUSjklF+aIjMCEwHwYJKwYBBQUHMAECBBIEEDTJniOQonxCRmmHAHCVstw="))
|
242
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
243
|
+
request.check_nonce(ocsp_response.basic).should == R509::OCSP::Request::Nonce::PRESENT_AND_EQUAL
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
it "doesn't copy nonce when copy_nonce is false" do
|
248
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:872625873161273451176241581705670534707360122361").and_return({"status" => R509::Validity::VALID})
|
249
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "872625873161273451176241581705670534707360122361", "VALID")
|
250
|
+
|
251
|
+
# set to false for this test (this works because the app doesn't get set up until after this code)
|
252
|
+
Dependo::Registry[:copy_nonce] = false
|
253
|
+
|
254
|
+
get '/MHsweTBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQCY2eXAtMNzVS33fF0PHrUSjklF%2BaIjMCEwHwYJKwYBBQUHMAECBBIEEDTJniOQonxCRmmHAHCVstw%3D'
|
255
|
+
request = OpenSSL::OCSP::Request.new(Base64.decode64("MHsweTBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQCY2eXAtMNzVS33fF0PHrUSjklF+aIjMCEwHwYJKwYBBQUHMAECBBIEEDTJniOQonxCRmmHAHCVstw="))
|
256
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
257
|
+
request.check_nonce(ocsp_response.basic).should == R509::OCSP::Request::Nonce::REQUEST_ONLY
|
258
|
+
end
|
259
|
+
|
260
|
+
it "returns caching headers for GET when cache_headers is true and no nonce is present" do
|
261
|
+
Dependo::Registry[:cache_headers] = true
|
262
|
+
|
263
|
+
now = Time.now
|
264
|
+
Time.stub!(:now).and_return(now)
|
265
|
+
|
266
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA:773553085290984246110251380739025914079776985795").and_return({"status" => R509::Validity::VALID})
|
267
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA", "773553085290984246110251380739025914079776985795", "VALID")
|
268
|
+
|
269
|
+
get '/MFYwVDBSMFAwTjAJBgUrDgMCGgUABBT1kOLWHXbHiKP3sVPVxVziq%2FMqIwQUP8ezIf8yhMLgHnccSKJLQdhDaVkCFQCHf1HsjUAACwcp3qQL4IxclfXSww%3D%3D'
|
270
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
271
|
+
last_response.headers.size.should == 6
|
272
|
+
last_response.headers["Last-Modified"].should == Time.now.httpdate
|
273
|
+
last_response.headers["ETag"].should == OpenSSL::Digest::SHA1.new(ocsp_response.to_der).to_s
|
274
|
+
last_response.headers["Expires"].should == ocsp_response.basic.status[0][5].httpdate
|
275
|
+
max_age = ocsp_response.basic.status[0][5] - now
|
276
|
+
last_response.headers["Cache-Control"].should == "max-age=#{max_age.to_i}, public, no-transform, must-revalidate"
|
277
|
+
end
|
278
|
+
|
279
|
+
it "returns no caching headers for GET when cache_headers is false and no nonce is present" do
|
280
|
+
Dependo::Registry[:cache_headers] = false
|
281
|
+
|
282
|
+
now = Time.now
|
283
|
+
Time.stub!(:now).and_return(now)
|
284
|
+
|
285
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA:773553085290984246110251380739025914079776985795").and_return({"status" => R509::Validity::VALID})
|
286
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA", "773553085290984246110251380739025914079776985795", "VALID")
|
287
|
+
|
288
|
+
get '/MFYwVDBSMFAwTjAJBgUrDgMCGgUABBT1kOLWHXbHiKP3sVPVxVziq%2FMqIwQUP8ezIf8yhMLgHnccSKJLQdhDaVkCFQCHf1HsjUAACwcp3qQL4IxclfXSww%3D%3D'
|
289
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
290
|
+
last_response.headers.size.should == 2
|
291
|
+
end
|
292
|
+
|
293
|
+
it "returns no caching headers for GET when cache_headers is true and a nonce is present" do
|
294
|
+
Dependo::Registry[:cache_headers] = true
|
295
|
+
|
296
|
+
now = Time.now
|
297
|
+
Time.stub!(:now).and_return(now)
|
298
|
+
|
299
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:872625873161273451176241581705670534707360122361").and_return({"status" => R509::Validity::VALID})
|
300
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "872625873161273451176241581705670534707360122361", "VALID")
|
301
|
+
|
302
|
+
get '/MHsweTBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQCY2eXAtMNzVS33fF0PHrUSjklF%2BaIjMCEwHwYJKwYBBQUHMAECBBIEEDTJniOQonxCRmmHAHCVstw%3D'
|
303
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
304
|
+
last_response.headers.size.should == 2
|
305
|
+
end
|
306
|
+
|
307
|
+
it "returns no caching headers for GET when cache_headers is false and a nonce is present" do
|
308
|
+
Dependo::Registry[:cache_headers] = false
|
309
|
+
|
310
|
+
now = Time.now
|
311
|
+
Time.stub!(:now).and_return(now)
|
312
|
+
|
313
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:872625873161273451176241581705670534707360122361").and_return({"status" => R509::Validity::VALID})
|
314
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "872625873161273451176241581705670534707360122361", "VALID")
|
315
|
+
|
316
|
+
get '/MHsweTBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQCY2eXAtMNzVS33fF0PHrUSjklF%2BaIjMCEwHwYJKwYBBQUHMAECBBIEEDTJniOQonxCRmmHAHCVstw%3D'
|
317
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
318
|
+
last_response.headers.size.should == 2
|
319
|
+
end
|
320
|
+
|
321
|
+
it "returns custom max_cache_age when it's set properly" do
|
322
|
+
Dependo::Registry[:cache_headers] = true
|
323
|
+
Dependo::Registry[:max_cache_age] = 600
|
324
|
+
|
325
|
+
now = Time.now
|
326
|
+
Time.stub!(:now).and_return(now)
|
327
|
+
|
328
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA:773553085290984246110251380739025914079776985795").and_return({"status" => R509::Validity::VALID})
|
329
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA", "773553085290984246110251380739025914079776985795", "VALID")
|
330
|
+
|
331
|
+
get '/MFYwVDBSMFAwTjAJBgUrDgMCGgUABBT1kOLWHXbHiKP3sVPVxVziq%2FMqIwQUP8ezIf8yhMLgHnccSKJLQdhDaVkCFQCHf1HsjUAACwcp3qQL4IxclfXSww%3D%3D'
|
332
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
333
|
+
last_response.headers.size.should == 6
|
334
|
+
last_response.headers["Last-Modified"].should == now.httpdate
|
335
|
+
last_response.headers["ETag"].should == OpenSSL::Digest::SHA1.new(ocsp_response.to_der).to_s
|
336
|
+
last_response.headers["Expires"].should == ocsp_response.basic.status[0][5].httpdate
|
337
|
+
last_response.headers["Cache-Control"].should == "max-age=600, public, no-transform, must-revalidate"
|
338
|
+
end
|
339
|
+
|
340
|
+
it "returns default max_cache_age if custom age is too large" do
|
341
|
+
Dependo::Registry[:cache_headers] = true
|
342
|
+
Dependo::Registry[:max_cache_age] = 950000
|
343
|
+
|
344
|
+
now = Time.now
|
345
|
+
Time.stub!(:now).and_return(now)
|
346
|
+
|
347
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA:773553085290984246110251380739025914079776985795").and_return({"status" => R509::Validity::VALID})
|
348
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA", "773553085290984246110251380739025914079776985795", "VALID")
|
349
|
+
|
350
|
+
get '/MFYwVDBSMFAwTjAJBgUrDgMCGgUABBT1kOLWHXbHiKP3sVPVxVziq%2FMqIwQUP8ezIf8yhMLgHnccSKJLQdhDaVkCFQCHf1HsjUAACwcp3qQL4IxclfXSww%3D%3D'
|
351
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
352
|
+
last_response.headers.size.should == 6
|
353
|
+
last_response.headers["Last-Modified"].should == now.httpdate
|
354
|
+
last_response.headers["ETag"].should == OpenSSL::Digest::SHA1.new(ocsp_response.to_der).to_s
|
355
|
+
last_response.headers["Expires"].should == ocsp_response.basic.status[0][5].httpdate
|
356
|
+
max_age = ocsp_response.basic.status[0][5] - now
|
357
|
+
last_response.headers["Cache-Control"].should == "max-age=#{max_age.to_i}, public, no-transform, must-revalidate"
|
358
|
+
end
|
359
|
+
|
360
|
+
it "returns no caching headers for GET when cache_headers is false" do
|
361
|
+
Dependo::Registry[:cache_headers] = false
|
362
|
+
|
363
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA:773553085290984246110251380739025914079776985795").and_return({"status" => R509::Validity::VALID})
|
364
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=R509, Ltd/CN=R509 Secondary Test CA", "773553085290984246110251380739025914079776985795", "VALID")
|
365
|
+
|
366
|
+
get '/MFYwVDBSMFAwTjAJBgUrDgMCGgUABBT1kOLWHXbHiKP3sVPVxVziq%2FMqIwQUP8ezIf8yhMLgHnccSKJLQdhDaVkCFQCHf1HsjUAACwcp3qQL4IxclfXSww%3D%3D'
|
367
|
+
last_response.content_type.should == "application/ocsp-response"
|
368
|
+
last_response.headers.size.should == 2
|
369
|
+
last_response.should be_ok
|
370
|
+
end
|
371
|
+
|
372
|
+
it "returns no caching headers for POST when cache_headers is true" do
|
373
|
+
Dependo::Registry[:cache_headers] = true
|
374
|
+
|
375
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:1051177536915098490149656742929223623669143613238").and_return({"status" => R509::Validity::VALID})
|
376
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "1051177536915098490149656742929223623669143613238", "VALID")
|
377
|
+
|
378
|
+
der = Base64.decode64(URI.decode("MFYwVDBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQC4IG5U4zC4RYb4VQ%2B2f0zCoFCvNg%3D%3D"))
|
379
|
+
post '/', der, "CONTENT_TYPE" => "application/ocsp-request"
|
380
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
381
|
+
last_response.content_type.should == "application/ocsp-response"
|
382
|
+
last_response.headers.size.should == 2
|
383
|
+
last_response.should be_ok
|
384
|
+
end
|
385
|
+
|
386
|
+
it "returns no caching headers for POST when cache_headers is false" do
|
387
|
+
Dependo::Registry[:cache_headers] = false
|
388
|
+
|
389
|
+
@redis.should_receive(:hgetall).with("cert:/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA:1051177536915098490149656742929223623669143613238").and_return({"status" => R509::Validity::VALID})
|
390
|
+
@stats.should_receive(:record).with("/C=US/ST=Illinois/L=Chicago/O=Ruby CA Project/CN=Test CA", "1051177536915098490149656742929223623669143613238", "VALID")
|
391
|
+
|
392
|
+
der = Base64.decode64(URI.decode("MFYwVDBSMFAwTjAJBgUrDgMCGgUABBQ4ykaMB0SN9IGWx21tTHBRnmCnvQQUeXW7hDrLLN56Cb4xG0O8HCpNU1gCFQC4IG5U4zC4RYb4VQ%2B2f0zCoFCvNg%3D%3D"))
|
393
|
+
post '/', der, "CONTENT_TYPE" => "application/ocsp-request"
|
394
|
+
ocsp_response = R509::OCSP::Response.parse(last_response.body)
|
395
|
+
last_response.content_type.should == "application/ocsp-response"
|
396
|
+
last_response.headers.size.should == 2
|
397
|
+
last_response.should be_ok
|
398
|
+
end
|
399
|
+
|
400
|
+
it "should reload and print config when receiving a SIGUSR2" do
|
401
|
+
config = double("config")
|
402
|
+
stub_const("R509::OCSP::Responder::OCSPConfig",config)
|
403
|
+
#R509::OCSP::Responder::OCSPConfig = double("config")
|
404
|
+
R509::OCSP::Responder::OCSPConfig.should_receive(:load_config)
|
405
|
+
R509::OCSP::Responder::OCSPConfig.should_receive(:print_config)
|
406
|
+
Process.kill :USR2, Process.pid
|
407
|
+
end
|
400
408
|
end
|