1
2
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
|
import json.encoder
import os
import re
import pytest
from .md_conf import MDConf
from .md_env import MDTestEnv
@pytest.mark.skipif(condition=not MDTestEnv.has_acme_eab(),
reason="ACME test server does not support External Account Binding")
class TestEab:
@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env, acme):
acme.start(config='eab')
env.check_acme()
env.clear_store()
MDConf(env).install()
assert env.apache_restart() == 0
@pytest.fixture(autouse=True, scope='function')
def _method_scope(self, env, request):
env.clear_store()
self.test_domain = env.get_request_domain(request)
def test_md_750_001(self, env):
# md without EAB configured
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
md = env.await_error(domain)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'urn:ietf:params:acme:error:externalAccountRequired'
def test_md_750_002(self, env):
# md with known EAB KID and non base64 hmac key configured
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add("MDExternalAccountBinding kid-1 äöüß")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
md = env.await_error(domain)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'apache:eab-hmac-invalid'
def test_md_750_003(self, env):
# md with empty EAB KID configured
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add("MDExternalAccountBinding \" \" bm90IGEgdmFsaWQgaG1hYwo=")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
md = env.await_error(domain)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'urn:ietf:params:acme:error:unauthorized'
def test_md_750_004(self, env):
# md with unknown EAB KID configured
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add("MDExternalAccountBinding key-x bm90IGEgdmFsaWQgaG1hYwo=")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
md = env.await_error(domain)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'urn:ietf:params:acme:error:unauthorized'
def test_md_750_005(self, env):
# md with known EAB KID but wrong HMAC configured
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add("MDExternalAccountBinding kid-1 bm90IGEgdmFsaWQgaG1hYwo=")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
md = env.await_error(domain)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'urn:ietf:params:acme:error:unauthorized'
def test_md_750_010(self, env):
# md with correct EAB configured
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
# this is one of the values in conf/pebble-eab.json
conf.add("MDExternalAccountBinding kid-1 zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
assert env.await_completion(domains)
def test_md_750_011(self, env):
# first one md with EAB, then one without, works only for the first
# as the second is unable to reuse the account
domain_a = f"a{self.test_domain}"
domain_b = f"b{self.test_domain}"
conf = MDConf(env)
conf.start_md([domain_a])
conf.add("MDExternalAccountBinding kid-1 zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W")
conf.end_md()
conf.add_vhost(domains=[domain_a])
conf.add_md([domain_b])
conf.add_vhost(domains=[domain_b])
conf.install()
assert env.apache_restart() == 0
assert env.await_completion([domain_a], restart=False)
md = env.await_error(domain_b)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'urn:ietf:params:acme:error:externalAccountRequired'
def test_md_750_012(self, env):
# first one md without EAB, then one with
# first one fails, second works
domain_a = f"a{self.test_domain}"
domain_b = f"b{self.test_domain}"
conf = MDConf(env)
conf.add_md([domain_a])
conf.add_vhost(domains=[domain_a])
conf.start_md([domain_b])
conf.add("MDExternalAccountBinding kid-1 zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W")
conf.end_md()
conf.add_vhost(domains=[domain_b])
conf.install()
assert env.apache_restart() == 0
assert env.await_completion([domain_b], restart=False)
md = env.await_error(domain_a)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'urn:ietf:params:acme:error:externalAccountRequired'
def test_md_750_013(self, env):
# 2 mds with the same EAB, should one create a single account
domain_a = f"a{self.test_domain}"
domain_b = f"b{self.test_domain}"
conf = MDConf(env)
conf.start_md([domain_a])
conf.add("MDExternalAccountBinding kid-1 zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W")
conf.end_md()
conf.add_vhost(domains=[domain_a])
conf.start_md([domain_b])
conf.add("MDExternalAccountBinding kid-1 zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W")
conf.end_md()
conf.add_vhost(domains=[domain_b])
conf.install()
assert env.apache_restart() == 0
assert env.await_completion([domain_a, domain_b])
md_a = env.get_md_status(domain_a)
md_b = env.get_md_status(domain_b)
assert md_a['ca'] == md_b['ca']
def test_md_750_014(self, env):
# md with correct EAB, get cert, change to another correct EAB
# needs to create a new account
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add("MDExternalAccountBinding kid-1 zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
assert env.await_completion(domains)
md_1 = env.get_md_status(domain)
conf = MDConf(env)
# this is another one of the values in conf/pebble-eab.json
# add a dns name to force renewal
domains = [domain, f'www.{domain}']
conf.add("MDExternalAccountBinding kid-2 b10lLJs8l1GPIzsLP0s6pMt8O0XVGnfTaCeROxQM0BIt2XrJMDHJZBM5NuQmQJQH")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
assert env.await_completion(domains)
md_2 = env.get_md_status(domain)
assert md_1['ca'] != md_2['ca']
def test_md_750_015(self, env):
# md with correct EAB, get cert, change to no EAB
# needs to fail
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add("MDExternalAccountBinding kid-1 zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
assert env.await_completion(domains)
conf = MDConf(env)
# this is another one of the values in conf/pebble-eab.json
# add a dns name to force renewal
domains = [domain, f'www.{domain}']
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
assert env.await_error(domain)
md = env.await_error(domain)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'urn:ietf:params:acme:error:externalAccountRequired'
def test_md_750_016(self, env):
# md with correct EAB, get cert, change to invalid EAB
# needs to fail
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add("MDExternalAccountBinding kid-1 zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
assert env.await_completion(domains)
conf = MDConf(env)
# this is another one of the values in conf/pebble-eab.json
# add a dns name to force renewal
domains = [domain, f'www.{domain}']
conf.add("MDExternalAccountBinding kid-invalud blablabalbalbla")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
assert env.await_error(domain)
md = env.await_error(domain)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'urn:ietf:params:acme:error:unauthorized'
def test_md_750_017(self, env):
# md without EAB explicitly set to none
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add("MDExternalAccountBinding kid-1 zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W")
conf.start_md(domains)
conf.add("MDExternalAccountBinding none")
conf.end_md()
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
md = env.await_error(domain)
assert md['renewal']['errors'] > 0
assert md['renewal']['last']['problem'] == 'urn:ietf:params:acme:error:externalAccountRequired'
def test_md_750_018(self, env):
# md with EAB file that does not exist
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
conf.add("MDExternalAccountBinding does-not-exist")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_fail() == 0
assert re.search(r'.*file not found:', env.apachectl_stderr), env.apachectl_stderr
def test_md_750_019(self, env):
# md with EAB file that is not valid JSON
domain = self.test_domain
domains = [domain]
eab_file = os.path.join(env.server_dir, 'eab.json')
with open(eab_file, 'w') as fd:
fd.write("something not JSON\n")
conf = MDConf(env)
conf.add("MDExternalAccountBinding eab.json")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_fail() == 0
assert re.search(r'.*error reading JSON file.*', env.apachectl_stderr), env.apachectl_stderr
def test_md_750_020(self, env):
# md with EAB file that is JSON, but missind kid
domain = self.test_domain
domains = [domain]
eab_file = os.path.join(env.server_dir, 'eab.json')
with open(eab_file, 'w') as fd:
eab = {'something': 1, 'other': 2}
fd.write(json.encoder.JSONEncoder().encode(eab))
conf = MDConf(env)
conf.add("MDExternalAccountBinding eab.json")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_fail() == 0
assert re.search(r'.*JSON does not contain \'kid\' element.*', env.apachectl_stderr), env.apachectl_stderr
def test_md_750_021(self, env):
# md with EAB file that is JSON, but missind hmac
domain = self.test_domain
domains = [domain]
eab_file = os.path.join(env.server_dir, 'eab.json')
with open(eab_file, 'w') as fd:
eab = {'kid': 'kid-1', 'other': 2}
fd.write(json.encoder.JSONEncoder().encode(eab))
conf = MDConf(env)
conf.add("MDExternalAccountBinding eab.json")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_fail() == 0
assert re.search(r'.*JSON does not contain \'hmac\' element.*', env.apachectl_stderr), env.apachectl_stderr
def test_md_750_022(self, env):
# md with EAB file that has correct values
domain = self.test_domain
domains = [domain]
eab_file = os.path.join(env.server_dir, 'eab.json')
with open(eab_file, 'w') as fd:
eab = {'kid': 'kid-1', 'hmac': 'zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W'}
fd.write(json.encoder.JSONEncoder().encode(eab))
domain = self.test_domain
domains = [domain]
conf = MDConf(env)
# this is one of the values in conf/pebble-eab.json
conf.add("MDExternalAccountBinding eab.json")
conf.add_md(domains)
conf.add_vhost(domains=domains)
conf.install()
assert env.apache_restart() == 0
assert env.await_completion(domains)
|