@distilled.cloud/acme 1.0.0-rc.14 → 1.0.0-rc.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/credentials.d.ts +4 -4
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +39 -33
- package/lib/credentials.js.map +1 -1
- package/lib/errors.d.ts +26 -26
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +33 -33
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +22 -22
- package/lib/jose.d.ts +2 -2
- package/lib/jose.d.ts.map +1 -1
- package/lib/jose.js +22 -22
- package/lib/jose.js.map +1 -1
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +61 -58
- package/lib/protocol.js.map +1 -1
- package/lib/retry.d.ts +1 -1
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +26 -25
- package/lib/retry.js.map +1 -1
- package/lib/services/acme.d.ts +47 -82
- package/lib/services/acme.d.ts.map +1 -1
- package/lib/services/acme.js +151 -530
- package/lib/traits.d.ts +2 -2
- package/lib/traits.js +10 -10
- package/package.json +7 -7
- package/src/credentials.ts +31 -26
- package/src/errors.ts +25 -24
- package/src/index.ts +1 -1
- package/src/jose.ts +3 -3
- package/src/protocol.ts +25 -20
- package/src/retry.ts +6 -4
- package/src/services/acme.ts +332 -289
- package/src/traits.ts +2 -2
- package/lib/protocol.test.d.ts +0 -2
- package/lib/protocol.test.d.ts.map +0 -1
- package/lib/protocol.test.js +0 -533
- package/lib/protocol.test.js.map +0 -1
- package/lib/services/acme.js.map +0 -1
- package/src/protocol.test.ts +0 -806
package/src/protocol.test.ts
DELETED
|
@@ -1,806 +0,0 @@
|
|
|
1
|
-
import { InternalServerError, NotFound } from "@distilled.cloud/core/errors";
|
|
2
|
-
import * as Duration from "effect/Duration";
|
|
3
|
-
import * as Effect from "effect/Effect";
|
|
4
|
-
import * as HttpClient from "effect/http/HttpClient";
|
|
5
|
-
import type * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
6
|
-
import * as HttpClientResponse from "effect/http/HttpClientResponse";
|
|
7
|
-
import * as Layer from "effect/Layer";
|
|
8
|
-
import * as Redacted from "effect/Redacted";
|
|
9
|
-
import { beforeEach, describe, expect, test } from "vitest";
|
|
10
|
-
import { layer as credentialsLayer, type Config } from "./credentials.ts";
|
|
11
|
-
import { AcmeParseError, UnknownAcmeError } from "./errors.ts";
|
|
12
|
-
import { base64url, base64urlDecode, generateAccountKey, type Jwk } from "./jose.ts";
|
|
13
|
-
import { resetProtocolCaches, type AcmeOpContext } from "./protocol.ts";
|
|
14
|
-
import * as Retry from "./retry.ts";
|
|
15
|
-
import {
|
|
16
|
-
AcmeBadNonce,
|
|
17
|
-
AcmeMalformed,
|
|
18
|
-
AcmeRateLimited,
|
|
19
|
-
downloadCertificate,
|
|
20
|
-
getDirectory,
|
|
21
|
-
getOrder,
|
|
22
|
-
newAccount,
|
|
23
|
-
newNonce,
|
|
24
|
-
newOrder,
|
|
25
|
-
revokeCertificate,
|
|
26
|
-
} from "./services/acme.ts";
|
|
27
|
-
|
|
28
|
-
interface Recorded {
|
|
29
|
-
readonly method: string;
|
|
30
|
-
readonly url: string;
|
|
31
|
-
readonly headers: Record<string, string>;
|
|
32
|
-
readonly body: string | undefined;
|
|
33
|
-
readonly contentType: string | undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface Jws {
|
|
37
|
-
readonly protected: string;
|
|
38
|
-
readonly payload: string;
|
|
39
|
-
readonly signature: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface ProtectedHeader {
|
|
43
|
-
readonly alg: string;
|
|
44
|
-
readonly nonce?: string;
|
|
45
|
-
readonly url: string;
|
|
46
|
-
readonly kid?: string;
|
|
47
|
-
readonly jwk?: Record<string, unknown>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
type Handler = (request: Recorded) => Response;
|
|
51
|
-
|
|
52
|
-
const decoder = new TextDecoder();
|
|
53
|
-
|
|
54
|
-
const bodyOf = (request: HttpClientRequest.HttpClientRequest) => {
|
|
55
|
-
const body = request.body;
|
|
56
|
-
if (body._tag === "Uint8Array") {
|
|
57
|
-
return { text: decoder.decode(body.body), contentType: body.contentType };
|
|
58
|
-
}
|
|
59
|
-
return { text: undefined, contentType: undefined };
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
let ca = 0;
|
|
63
|
-
|
|
64
|
-
/** A scripted CA: each test gets its own directory URL so process-wide caches never leak. */
|
|
65
|
-
const makeCa = () => {
|
|
66
|
-
const base = `https://ca${++ca}.test`;
|
|
67
|
-
const urls = {
|
|
68
|
-
directory: `${base}/directory`,
|
|
69
|
-
newNonce: `${base}/acme/new-nonce`,
|
|
70
|
-
newAccount: `${base}/acme/new-acct`,
|
|
71
|
-
newOrder: `${base}/acme/new-order`,
|
|
72
|
-
revokeCert: `${base}/acme/revoke-cert`,
|
|
73
|
-
account: `${base}/acme/acct/1`,
|
|
74
|
-
order: `${base}/acme/order/1`,
|
|
75
|
-
cert: `${base}/acme/cert/1`,
|
|
76
|
-
};
|
|
77
|
-
const directory = {
|
|
78
|
-
newNonce: urls.newNonce,
|
|
79
|
-
newAccount: urls.newAccount,
|
|
80
|
-
newOrder: urls.newOrder,
|
|
81
|
-
revokeCert: urls.revokeCert,
|
|
82
|
-
meta: { termsOfService: `${base}/tos` },
|
|
83
|
-
};
|
|
84
|
-
const requests: Recorded[] = [];
|
|
85
|
-
let nonceCounter = 0;
|
|
86
|
-
const handlers = new Map<string, Handler>();
|
|
87
|
-
handlers.set(`GET ${urls.directory}`, () => Response.json(directory));
|
|
88
|
-
handlers.set(
|
|
89
|
-
`HEAD ${urls.newNonce}`,
|
|
90
|
-
() =>
|
|
91
|
-
new Response(null, { status: 200, headers: { "Replay-Nonce": `head-${++nonceCounter}` } }),
|
|
92
|
-
);
|
|
93
|
-
const client = HttpClient.make((request) =>
|
|
94
|
-
Effect.sync(() => {
|
|
95
|
-
const { text, contentType } = bodyOf(request);
|
|
96
|
-
const recorded: Recorded = {
|
|
97
|
-
method: request.method,
|
|
98
|
-
url: request.url,
|
|
99
|
-
headers: { ...request.headers },
|
|
100
|
-
body: text,
|
|
101
|
-
contentType,
|
|
102
|
-
};
|
|
103
|
-
requests.push(recorded);
|
|
104
|
-
const handler = handlers.get(`${request.method} ${request.url}`);
|
|
105
|
-
const response = handler ? handler(recorded) : new Response("no route", { status: 599 });
|
|
106
|
-
return HttpClientResponse.fromWeb(request, response);
|
|
107
|
-
}),
|
|
108
|
-
);
|
|
109
|
-
return { urls, directory, requests, handlers, client };
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
type Ca = ReturnType<typeof makeCa>;
|
|
113
|
-
|
|
114
|
-
const run = <A, E>(
|
|
115
|
-
ca: Ca,
|
|
116
|
-
config: Omit<Config, "directoryUrl">,
|
|
117
|
-
operation: Effect.Effect<A, E, AcmeOpContext>,
|
|
118
|
-
) =>
|
|
119
|
-
Effect.runPromise(
|
|
120
|
-
operation.pipe(
|
|
121
|
-
Retry.none,
|
|
122
|
-
Effect.provide(
|
|
123
|
-
Layer.mergeAll(
|
|
124
|
-
Layer.succeed(HttpClient.HttpClient, ca.client),
|
|
125
|
-
credentialsLayer({ ...config, directoryUrl: ca.urls.directory }),
|
|
126
|
-
),
|
|
127
|
-
),
|
|
128
|
-
),
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const runError = <A, E>(
|
|
132
|
-
ca: Ca,
|
|
133
|
-
config: Omit<Config, "directoryUrl">,
|
|
134
|
-
operation: Effect.Effect<A, E, AcmeOpContext>,
|
|
135
|
-
) => run(ca, config, Effect.flip(operation));
|
|
136
|
-
|
|
137
|
-
const json = (value: unknown, init: ResponseInit = {}) =>
|
|
138
|
-
new Response(JSON.stringify(value), {
|
|
139
|
-
...init,
|
|
140
|
-
headers: { "Content-Type": "application/json", ...init.headers },
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
const problem = (value: Record<string, unknown>, init: ResponseInit = {}) =>
|
|
144
|
-
new Response(JSON.stringify(value), {
|
|
145
|
-
...init,
|
|
146
|
-
headers: { "Content-Type": "application/problem+json", ...init.headers },
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const parseJws = (request: Recorded) => {
|
|
150
|
-
expect(request.method).toBe("POST");
|
|
151
|
-
expect(request.contentType).toBe("application/jose+json");
|
|
152
|
-
const jws = JSON.parse(request.body!) as Jws;
|
|
153
|
-
expect(Object.keys(jws).sort()).toEqual(["payload", "protected", "signature"]);
|
|
154
|
-
const header = JSON.parse(decoder.decode(base64urlDecode(jws.protected))) as ProtectedHeader;
|
|
155
|
-
const payload =
|
|
156
|
-
jws.payload === "" ? undefined : JSON.parse(decoder.decode(base64urlDecode(jws.payload)));
|
|
157
|
-
return { jws, header, payload };
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const verify = async (jws: Jws, publicKey: JsonWebKey, alg: "ES256" | "RS256" | "HS256") => {
|
|
161
|
-
const data = new TextEncoder().encode(`${jws.protected}.${jws.payload}`);
|
|
162
|
-
const signature = base64urlDecode(jws.signature) as Uint8Array<ArrayBuffer>;
|
|
163
|
-
if (alg === "HS256") {
|
|
164
|
-
const key = await crypto.subtle.importKey(
|
|
165
|
-
"raw",
|
|
166
|
-
base64urlDecode(publicKey.k!) as Uint8Array<ArrayBuffer>,
|
|
167
|
-
{ name: "HMAC", hash: "SHA-256" },
|
|
168
|
-
false,
|
|
169
|
-
["verify"],
|
|
170
|
-
);
|
|
171
|
-
return crypto.subtle.verify("HMAC", key, signature, data);
|
|
172
|
-
}
|
|
173
|
-
const key = await crypto.subtle.importKey(
|
|
174
|
-
"jwk",
|
|
175
|
-
publicKey,
|
|
176
|
-
alg === "ES256"
|
|
177
|
-
? { name: "ECDSA", namedCurve: "P-256" }
|
|
178
|
-
: { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" },
|
|
179
|
-
false,
|
|
180
|
-
["verify"],
|
|
181
|
-
);
|
|
182
|
-
return crypto.subtle.verify(
|
|
183
|
-
alg === "ES256" ? { name: "ECDSA", hash: "SHA-256" } : { name: "RSASSA-PKCS1-v1_5" },
|
|
184
|
-
key,
|
|
185
|
-
signature,
|
|
186
|
-
data,
|
|
187
|
-
);
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const publicOf = (jwk: Jwk): JsonWebKey =>
|
|
191
|
-
jwk.kty === "RSA"
|
|
192
|
-
? { kty: "RSA", n: jwk.n, e: jwk.e }
|
|
193
|
-
: { kty: "EC", crv: jwk.crv, x: jwk.x, y: jwk.y };
|
|
194
|
-
|
|
195
|
-
const posts = (ca: Ca) => ca.requests.filter((r) => r.method === "POST");
|
|
196
|
-
const heads = (ca: Ca) => ca.requests.filter((r) => r.method === "HEAD");
|
|
197
|
-
const directoryGets = (ca: Ca) =>
|
|
198
|
-
ca.requests.filter((r) => r.method === "GET" && r.url === ca.urls.directory);
|
|
199
|
-
|
|
200
|
-
const order = (ca: Ca) => ({
|
|
201
|
-
status: "pending",
|
|
202
|
-
identifiers: [{ type: "dns", value: "example.test" }],
|
|
203
|
-
authorizations: [`${ca.urls.order}/authz`],
|
|
204
|
-
finalize: `${ca.urls.order}/finalize`,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
let ecKey: Redacted.Redacted<string>;
|
|
208
|
-
let ecJwk: Jwk;
|
|
209
|
-
|
|
210
|
-
beforeEach(async () => {
|
|
211
|
-
resetProtocolCaches();
|
|
212
|
-
ecKey ??= await Effect.runPromise(generateAccountKey("ES256"));
|
|
213
|
-
ecJwk ??= JSON.parse(Redacted.value(ecKey)) as Jwk;
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
describe("JWS request signing", () => {
|
|
217
|
-
test("newAccount is a flattened JWS embedding the public JWK, signed by the account key", async () => {
|
|
218
|
-
const ca = makeCa();
|
|
219
|
-
ca.handlers.set(`POST ${ca.urls.newAccount}`, () =>
|
|
220
|
-
json({ status: "valid" }, { status: 201, headers: { Location: ca.urls.account } }),
|
|
221
|
-
);
|
|
222
|
-
const result = await run(
|
|
223
|
-
ca,
|
|
224
|
-
{ accountKey: ecKey },
|
|
225
|
-
newAccount({ contact: ["mailto:ops@example.test"], termsOfServiceAgreed: true }),
|
|
226
|
-
);
|
|
227
|
-
expect(result).toEqual({ status: "valid", location: ca.urls.account });
|
|
228
|
-
|
|
229
|
-
expect(ca.requests.map((r) => `${r.method} ${r.url}`)).toEqual([
|
|
230
|
-
`GET ${ca.urls.directory}`,
|
|
231
|
-
`HEAD ${ca.urls.newNonce}`,
|
|
232
|
-
`POST ${ca.urls.newAccount}`,
|
|
233
|
-
]);
|
|
234
|
-
const post = posts(ca)[0]!;
|
|
235
|
-
expect(post.headers["accept"]).toBe("application/json, application/pem-certificate-chain");
|
|
236
|
-
const { jws, header, payload } = parseJws(post);
|
|
237
|
-
expect(header).toEqual({
|
|
238
|
-
alg: "ES256",
|
|
239
|
-
nonce: "head-1",
|
|
240
|
-
url: ca.urls.newAccount,
|
|
241
|
-
jwk: { crv: "P-256", kty: "EC", x: ecJwk.x, y: ecJwk.y },
|
|
242
|
-
});
|
|
243
|
-
expect(header.jwk).not.toHaveProperty("d");
|
|
244
|
-
expect(payload).toEqual({
|
|
245
|
-
contact: ["mailto:ops@example.test"],
|
|
246
|
-
termsOfServiceAgreed: true,
|
|
247
|
-
});
|
|
248
|
-
expect(await verify(jws, publicOf(ecJwk), "ES256")).toBe(true);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
test("the signature does not verify under a different key or a tampered payload", async () => {
|
|
252
|
-
const ca = makeCa();
|
|
253
|
-
ca.handlers.set(`POST ${ca.urls.newAccount}`, () => json({ status: "valid" }));
|
|
254
|
-
await run(ca, { accountKey: ecKey }, newAccount({ termsOfServiceAgreed: true }));
|
|
255
|
-
const { jws } = parseJws(posts(ca)[0]!);
|
|
256
|
-
const other = JSON.parse(
|
|
257
|
-
Redacted.value(await Effect.runPromise(generateAccountKey("ES256"))),
|
|
258
|
-
) as Jwk;
|
|
259
|
-
expect(await verify(jws, publicOf(other), "ES256")).toBe(false);
|
|
260
|
-
const tampered = {
|
|
261
|
-
...jws,
|
|
262
|
-
payload: base64url(new TextEncoder().encode(JSON.stringify({ termsOfServiceAgreed: false }))),
|
|
263
|
-
};
|
|
264
|
-
expect(await verify(tampered, publicOf(ecJwk), "ES256")).toBe(false);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
test("with a known account URL, later requests carry `kid` and no `jwk`", async () => {
|
|
268
|
-
const ca = makeCa();
|
|
269
|
-
ca.handlers.set(`POST ${ca.urls.newOrder}`, () =>
|
|
270
|
-
json(order(ca), { status: 201, headers: { Location: ca.urls.order } }),
|
|
271
|
-
);
|
|
272
|
-
const result = await run(
|
|
273
|
-
ca,
|
|
274
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
275
|
-
newOrder({ identifiers: [{ type: "dns", value: "example.test" }] }),
|
|
276
|
-
);
|
|
277
|
-
expect(result.location).toBe(ca.urls.order);
|
|
278
|
-
expect(result.status).toBe("pending");
|
|
279
|
-
const { jws, header, payload } = parseJws(posts(ca)[0]!);
|
|
280
|
-
expect(header).toEqual({
|
|
281
|
-
alg: "ES256",
|
|
282
|
-
nonce: "head-1",
|
|
283
|
-
url: ca.urls.newOrder,
|
|
284
|
-
kid: ca.urls.account,
|
|
285
|
-
});
|
|
286
|
-
expect(payload).toEqual({ identifiers: [{ type: "dns", value: "example.test" }] });
|
|
287
|
-
expect(await verify(jws, publicOf(ecJwk), "ES256")).toBe(true);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
test("newAccount embeds the JWK even when an account URL is configured", async () => {
|
|
291
|
-
const ca = makeCa();
|
|
292
|
-
ca.handlers.set(`POST ${ca.urls.newAccount}`, () => json({ status: "valid" }));
|
|
293
|
-
await run(
|
|
294
|
-
ca,
|
|
295
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
296
|
-
newAccount({ onlyReturnExisting: true }),
|
|
297
|
-
);
|
|
298
|
-
const { header } = parseJws(posts(ca)[0]!);
|
|
299
|
-
expect(header.kid).toBeUndefined();
|
|
300
|
-
expect(header.jwk).toEqual({ crv: "P-256", kty: "EC", x: ecJwk.x, y: ecJwk.y });
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
test("without an account URL, non-newAccount requests embed the JWK", async () => {
|
|
304
|
-
const ca = makeCa();
|
|
305
|
-
ca.handlers.set(`POST ${ca.urls.revokeCert}`, () => new Response(null, { status: 200 }));
|
|
306
|
-
await run(ca, { accountKey: ecKey }, revokeCertificate({ certificate: "MIIB", reason: 4 }));
|
|
307
|
-
const { header, payload } = parseJws(posts(ca)[0]!);
|
|
308
|
-
expect(header.url).toBe(ca.urls.revokeCert);
|
|
309
|
-
expect(header.kid).toBeUndefined();
|
|
310
|
-
expect(header.jwk).toBeDefined();
|
|
311
|
-
expect(payload).toEqual({ certificate: "MIIB", reason: 4 });
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
test("POST-as-GET reads sign an empty payload to the label URL", async () => {
|
|
315
|
-
const ca = makeCa();
|
|
316
|
-
ca.handlers.set(`POST ${ca.urls.order}`, () => json(order(ca)));
|
|
317
|
-
const result = await run(
|
|
318
|
-
ca,
|
|
319
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
320
|
-
getOrder({ url: ca.urls.order }),
|
|
321
|
-
);
|
|
322
|
-
expect(result.finalize).toBe(`${ca.urls.order}/finalize`);
|
|
323
|
-
const { jws, header, payload } = parseJws(posts(ca)[0]!);
|
|
324
|
-
expect(jws.payload).toBe("");
|
|
325
|
-
expect(payload).toBeUndefined();
|
|
326
|
-
expect(header.url).toBe(ca.urls.order);
|
|
327
|
-
expect(header.kid).toBe(ca.urls.account);
|
|
328
|
-
expect(await verify(jws, publicOf(ecJwk), "ES256")).toBe(true);
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
test("an RSA account key signs with RS256", async () => {
|
|
332
|
-
const rsaKey = await Effect.runPromise(generateAccountKey("RS256"));
|
|
333
|
-
const rsaJwk = JSON.parse(Redacted.value(rsaKey)) as Jwk;
|
|
334
|
-
const ca = makeCa();
|
|
335
|
-
ca.handlers.set(`POST ${ca.urls.newAccount}`, () => json({ status: "valid" }));
|
|
336
|
-
await run(ca, { accountKey: rsaKey }, newAccount({ termsOfServiceAgreed: true }));
|
|
337
|
-
const { jws, header } = parseJws(posts(ca)[0]!);
|
|
338
|
-
expect(header.alg).toBe("RS256");
|
|
339
|
-
expect(header.jwk).toEqual({ e: rsaJwk.e, kty: "RSA", n: rsaJwk.n });
|
|
340
|
-
expect(await verify(jws, publicOf(rsaJwk), "RS256")).toBe(true);
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
test("an External Account Binding from the credentials is attached to newAccount", async () => {
|
|
344
|
-
const hmacKey = base64url(crypto.getRandomValues(new Uint8Array(32)));
|
|
345
|
-
const ca = makeCa();
|
|
346
|
-
ca.handlers.set(`POST ${ca.urls.newAccount}`, () => json({ status: "valid" }));
|
|
347
|
-
await run(
|
|
348
|
-
ca,
|
|
349
|
-
{
|
|
350
|
-
accountKey: ecKey,
|
|
351
|
-
externalAccountBinding: { keyId: "eab-kid", hmacKey: Redacted.make(hmacKey) },
|
|
352
|
-
},
|
|
353
|
-
newAccount({ termsOfServiceAgreed: true }),
|
|
354
|
-
);
|
|
355
|
-
const { jws, payload } = parseJws(posts(ca)[0]!);
|
|
356
|
-
expect(await verify(jws, publicOf(ecJwk), "ES256")).toBe(true);
|
|
357
|
-
const eab = payload.externalAccountBinding as Jws;
|
|
358
|
-
const eabHeader = JSON.parse(decoder.decode(base64urlDecode(eab.protected)));
|
|
359
|
-
expect(eabHeader).toEqual({ alg: "HS256", kid: "eab-kid", url: ca.urls.newAccount });
|
|
360
|
-
expect(JSON.parse(decoder.decode(base64urlDecode(eab.payload)))).toEqual({
|
|
361
|
-
crv: "P-256",
|
|
362
|
-
kty: "EC",
|
|
363
|
-
x: ecJwk.x,
|
|
364
|
-
y: ecJwk.y,
|
|
365
|
-
});
|
|
366
|
-
expect(await verify(eab, { kty: "oct", k: hmacKey }, "HS256")).toBe(true);
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
test("a caller-built External Account Binding is not replaced", async () => {
|
|
370
|
-
const ca = makeCa();
|
|
371
|
-
ca.handlers.set(`POST ${ca.urls.newAccount}`, () => json({ status: "valid" }));
|
|
372
|
-
const own = { protected: "p", payload: "q", signature: "s" };
|
|
373
|
-
await run(
|
|
374
|
-
ca,
|
|
375
|
-
{
|
|
376
|
-
accountKey: ecKey,
|
|
377
|
-
externalAccountBinding: { keyId: "eab-kid", hmacKey: Redacted.make("AAAA") },
|
|
378
|
-
},
|
|
379
|
-
newAccount({ externalAccountBinding: own }),
|
|
380
|
-
);
|
|
381
|
-
expect(parseJws(posts(ca)[0]!).payload.externalAccountBinding).toEqual(own);
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
test("an account key that is not a JWK fails with JoseError before any POST", async () => {
|
|
385
|
-
const ca = makeCa();
|
|
386
|
-
const error = await runError(
|
|
387
|
-
ca,
|
|
388
|
-
{ accountKey: Redacted.make("not json") },
|
|
389
|
-
newAccount({ termsOfServiceAgreed: true }),
|
|
390
|
-
);
|
|
391
|
-
expect(error).toMatchObject({ _tag: "JoseError" });
|
|
392
|
-
expect(posts(ca)).toHaveLength(0);
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
describe("Directory and nonce management", () => {
|
|
397
|
-
test("the directory is fetched once per CA and reused", async () => {
|
|
398
|
-
const ca = makeCa();
|
|
399
|
-
ca.handlers.set(`POST ${ca.urls.order}`, () => json(order(ca)));
|
|
400
|
-
const config = { accountKey: ecKey, accountUrl: ca.urls.account };
|
|
401
|
-
await run(ca, config, getOrder({ url: ca.urls.order }));
|
|
402
|
-
await run(ca, config, getOrder({ url: ca.urls.order }));
|
|
403
|
-
expect(directoryGets(ca)).toHaveLength(1);
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
test("Replay-Nonce from a response is used for the next request instead of HEAD newNonce", async () => {
|
|
407
|
-
const ca = makeCa();
|
|
408
|
-
let n = 0;
|
|
409
|
-
ca.handlers.set(`POST ${ca.urls.order}`, () =>
|
|
410
|
-
json(order(ca), { headers: { "Replay-Nonce": `reply-${++n}` } }),
|
|
411
|
-
);
|
|
412
|
-
const config = { accountKey: ecKey, accountUrl: ca.urls.account };
|
|
413
|
-
await run(ca, config, getOrder({ url: ca.urls.order }));
|
|
414
|
-
await run(ca, config, getOrder({ url: ca.urls.order }));
|
|
415
|
-
await run(ca, config, getOrder({ url: ca.urls.order }));
|
|
416
|
-
expect(heads(ca)).toHaveLength(1);
|
|
417
|
-
expect(posts(ca).map((r) => parseJws(r).header.nonce)).toEqual([
|
|
418
|
-
"head-1",
|
|
419
|
-
"reply-1",
|
|
420
|
-
"reply-2",
|
|
421
|
-
]);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
test("a nonce is single-use: without a Replay-Nonce the next request fetches a fresh one", async () => {
|
|
425
|
-
const ca = makeCa();
|
|
426
|
-
ca.handlers.set(`POST ${ca.urls.order}`, () => json(order(ca)));
|
|
427
|
-
const config = { accountKey: ecKey, accountUrl: ca.urls.account };
|
|
428
|
-
await run(ca, config, getOrder({ url: ca.urls.order }));
|
|
429
|
-
await run(ca, config, getOrder({ url: ca.urls.order }));
|
|
430
|
-
expect(heads(ca)).toHaveLength(2);
|
|
431
|
-
expect(posts(ca).map((r) => parseJws(r).header.nonce)).toEqual(["head-1", "head-2"]);
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
test("a Replay-Nonce on the directory response seeds the cache", async () => {
|
|
435
|
-
const ca = makeCa();
|
|
436
|
-
ca.handlers.set(`GET ${ca.urls.directory}`, () =>
|
|
437
|
-
json(ca.directory, { headers: { "Replay-Nonce": "from-directory" } }),
|
|
438
|
-
);
|
|
439
|
-
ca.handlers.set(`POST ${ca.urls.newAccount}`, () => json({ status: "valid" }));
|
|
440
|
-
await run(ca, { accountKey: ecKey }, newAccount({ termsOfServiceAgreed: true }));
|
|
441
|
-
expect(heads(ca)).toHaveLength(0);
|
|
442
|
-
expect(parseJws(posts(ca)[0]!).header.nonce).toBe("from-directory");
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
test("a Replay-Nonce on an error response is still cached", async () => {
|
|
446
|
-
const ca = makeCa();
|
|
447
|
-
let first = true;
|
|
448
|
-
ca.handlers.set(`POST ${ca.urls.order}`, () => {
|
|
449
|
-
if (first) {
|
|
450
|
-
first = false;
|
|
451
|
-
return problem(
|
|
452
|
-
{ type: "urn:ietf:params:acme:error:malformed", detail: "bad" },
|
|
453
|
-
{ status: 400, headers: { "Replay-Nonce": "after-error" } },
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
return json(order(ca));
|
|
457
|
-
});
|
|
458
|
-
const config = { accountKey: ecKey, accountUrl: ca.urls.account };
|
|
459
|
-
await runError(ca, config, getOrder({ url: ca.urls.order }));
|
|
460
|
-
await run(ca, config, getOrder({ url: ca.urls.order }));
|
|
461
|
-
expect(heads(ca)).toHaveLength(1);
|
|
462
|
-
expect(parseJws(posts(ca)[1]!).header.nonce).toBe("after-error");
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
test("HEAD newNonce without a Replay-Nonce header fails with UnknownAcmeError", async () => {
|
|
466
|
-
const ca = makeCa();
|
|
467
|
-
ca.handlers.set(`HEAD ${ca.urls.newNonce}`, () => new Response(null, { status: 200 }));
|
|
468
|
-
const error = await runError(
|
|
469
|
-
ca,
|
|
470
|
-
{ accountKey: ecKey },
|
|
471
|
-
newAccount({ termsOfServiceAgreed: true }),
|
|
472
|
-
);
|
|
473
|
-
expect(error).toBeInstanceOf(UnknownAcmeError);
|
|
474
|
-
expect(posts(ca)).toHaveLength(0);
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
test("newNonce issues HEAD to the directory's newNonce URL and returns the header", async () => {
|
|
478
|
-
const ca = makeCa();
|
|
479
|
-
const result = await run(ca, { accountKey: ecKey }, newNonce({}));
|
|
480
|
-
expect(result).toEqual({ replayNonce: "head-1" });
|
|
481
|
-
expect(ca.requests.map((r) => `${r.method} ${r.url}`)).toEqual([
|
|
482
|
-
`GET ${ca.urls.directory}`,
|
|
483
|
-
`HEAD ${ca.urls.newNonce}`,
|
|
484
|
-
]);
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
test("getDirectory is an unsigned GET of the directory URL", async () => {
|
|
488
|
-
const ca = makeCa();
|
|
489
|
-
const result = await run(ca, { accountKey: ecKey }, getDirectory({}));
|
|
490
|
-
expect(result).toEqual(ca.directory);
|
|
491
|
-
expect(ca.requests).toHaveLength(1);
|
|
492
|
-
expect(ca.requests[0]).toMatchObject({
|
|
493
|
-
method: "GET",
|
|
494
|
-
url: ca.urls.directory,
|
|
495
|
-
body: undefined,
|
|
496
|
-
});
|
|
497
|
-
expect(ca.requests[0]!.headers["accept"]).toBe("application/json");
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
test("a directory missing required URLs fails with AcmeParseError", async () => {
|
|
501
|
-
const ca = makeCa();
|
|
502
|
-
ca.handlers.set(`GET ${ca.urls.directory}`, () => json({ newNonce: ca.urls.newNonce }));
|
|
503
|
-
const error = await runError(
|
|
504
|
-
ca,
|
|
505
|
-
{ accountKey: ecKey },
|
|
506
|
-
newAccount({ termsOfServiceAgreed: true }),
|
|
507
|
-
);
|
|
508
|
-
expect(error).toBeInstanceOf(AcmeParseError);
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
test("a failing directory fetch surfaces UnknownAcmeError with its status", async () => {
|
|
512
|
-
const ca = makeCa();
|
|
513
|
-
ca.handlers.set(`GET ${ca.urls.directory}`, () => new Response("down", { status: 503 }));
|
|
514
|
-
const error = await runError(
|
|
515
|
-
ca,
|
|
516
|
-
{ accountKey: ecKey },
|
|
517
|
-
newAccount({ termsOfServiceAgreed: true }),
|
|
518
|
-
);
|
|
519
|
-
expect(error).toBeInstanceOf(UnknownAcmeError);
|
|
520
|
-
expect(error).toMatchObject({ status: 503 });
|
|
521
|
-
});
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
describe("badNonce retry", () => {
|
|
525
|
-
const badNonce = (nonce: string) =>
|
|
526
|
-
problem(
|
|
527
|
-
{
|
|
528
|
-
type: "urn:ietf:params:acme:error:badNonce",
|
|
529
|
-
detail: "JWS has an invalid anti-replay nonce",
|
|
530
|
-
},
|
|
531
|
-
{ status: 400, headers: { "Replay-Nonce": nonce } },
|
|
532
|
-
);
|
|
533
|
-
|
|
534
|
-
test("re-signs with the rejection's Replay-Nonce and succeeds", async () => {
|
|
535
|
-
const ca = makeCa();
|
|
536
|
-
let n = 0;
|
|
537
|
-
ca.handlers.set(`POST ${ca.urls.newOrder}`, () =>
|
|
538
|
-
++n === 1 ? badNonce("retry-1") : json(order(ca), { status: 201 }),
|
|
539
|
-
);
|
|
540
|
-
const result = await run(
|
|
541
|
-
ca,
|
|
542
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
543
|
-
newOrder({ identifiers: [{ type: "dns", value: "example.test" }] }),
|
|
544
|
-
);
|
|
545
|
-
expect(result.status).toBe("pending");
|
|
546
|
-
const signed = posts(ca).map(parseJws);
|
|
547
|
-
expect(signed.map((s) => s.header.nonce)).toEqual(["head-1", "retry-1"]);
|
|
548
|
-
expect(signed[1]!.header.url).toBe(ca.urls.newOrder);
|
|
549
|
-
expect(signed[1]!.payload).toEqual(signed[0]!.payload);
|
|
550
|
-
expect(await verify(signed[1]!.jws, publicOf(ecJwk), "ES256")).toBe(true);
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
test("gives up after two retries with AcmeBadNonce", async () => {
|
|
554
|
-
const ca = makeCa();
|
|
555
|
-
let n = 0;
|
|
556
|
-
ca.handlers.set(`POST ${ca.urls.newOrder}`, () => badNonce(`retry-${++n}`));
|
|
557
|
-
const error = await runError(
|
|
558
|
-
ca,
|
|
559
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
560
|
-
newOrder({ identifiers: [{ type: "dns", value: "example.test" }] }),
|
|
561
|
-
);
|
|
562
|
-
expect(error).toBeInstanceOf(AcmeBadNonce);
|
|
563
|
-
expect(error).toMatchObject({
|
|
564
|
-
code: 400,
|
|
565
|
-
type: "urn:ietf:params:acme:error:badNonce",
|
|
566
|
-
detail: "JWS has an invalid anti-replay nonce",
|
|
567
|
-
});
|
|
568
|
-
expect(posts(ca).map((r) => parseJws(r).header.nonce)).toEqual([
|
|
569
|
-
"head-1",
|
|
570
|
-
"retry-1",
|
|
571
|
-
"retry-2",
|
|
572
|
-
]);
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
test("the final rejection nonce is not cached for the next request", async () => {
|
|
576
|
-
const ca = makeCa();
|
|
577
|
-
let n = 0;
|
|
578
|
-
ca.handlers.set(`POST ${ca.urls.newOrder}`, () => badNonce(`retry-${++n}`));
|
|
579
|
-
ca.handlers.set(`POST ${ca.urls.order}`, () => json(order(ca)));
|
|
580
|
-
const config = { accountKey: ecKey, accountUrl: ca.urls.account };
|
|
581
|
-
await runError(ca, config, newOrder({ identifiers: [{ type: "dns", value: "x.test" }] }));
|
|
582
|
-
await run(ca, config, getOrder({ url: ca.urls.order }));
|
|
583
|
-
expect(heads(ca)).toHaveLength(2);
|
|
584
|
-
expect(parseJws(posts(ca).at(-1)!).header.nonce).toBe("head-2");
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
test("a badNonce without a Replay-Nonce is surfaced immediately", async () => {
|
|
588
|
-
const ca = makeCa();
|
|
589
|
-
ca.handlers.set(`POST ${ca.urls.newOrder}`, () =>
|
|
590
|
-
problem({ type: "urn:ietf:params:acme:error:badNonce", detail: "stale" }, { status: 400 }),
|
|
591
|
-
);
|
|
592
|
-
const error = await runError(
|
|
593
|
-
ca,
|
|
594
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
595
|
-
newOrder({ identifiers: [{ type: "dns", value: "example.test" }] }),
|
|
596
|
-
);
|
|
597
|
-
expect(error).toBeInstanceOf(AcmeBadNonce);
|
|
598
|
-
expect(posts(ca)).toHaveLength(1);
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
test("a badNonce without detail is still retried", async () => {
|
|
602
|
-
const ca = makeCa();
|
|
603
|
-
let n = 0;
|
|
604
|
-
ca.handlers.set(`POST ${ca.urls.newOrder}`, () =>
|
|
605
|
-
++n === 1
|
|
606
|
-
? problem(
|
|
607
|
-
{ type: "urn:ietf:params:acme:error:badNonce" },
|
|
608
|
-
{ status: 400, headers: { "Replay-Nonce": "retry-1" } },
|
|
609
|
-
)
|
|
610
|
-
: json(order(ca), { status: 201 }),
|
|
611
|
-
);
|
|
612
|
-
const result = await run(
|
|
613
|
-
ca,
|
|
614
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
615
|
-
newOrder({ identifiers: [{ type: "dns", value: "example.test" }] }),
|
|
616
|
-
);
|
|
617
|
-
expect(result.status).toBe("pending");
|
|
618
|
-
expect(posts(ca).map((r) => parseJws(r).header.nonce)).toEqual(["head-1", "retry-1"]);
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
test("a badNonce without detail gives up with AcmeBadNonce", async () => {
|
|
622
|
-
const ca = makeCa();
|
|
623
|
-
let n = 0;
|
|
624
|
-
ca.handlers.set(`POST ${ca.urls.newOrder}`, () =>
|
|
625
|
-
problem(
|
|
626
|
-
{ type: "urn:ietf:params:acme:error:badNonce" },
|
|
627
|
-
{ status: 400, headers: { "Replay-Nonce": `retry-${++n}` } },
|
|
628
|
-
),
|
|
629
|
-
);
|
|
630
|
-
const error = await runError(
|
|
631
|
-
ca,
|
|
632
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
633
|
-
newOrder({ identifiers: [{ type: "dns", value: "example.test" }] }),
|
|
634
|
-
);
|
|
635
|
-
expect(error).toBeInstanceOf(AcmeBadNonce);
|
|
636
|
-
expect(error).toMatchObject({
|
|
637
|
-
code: 400,
|
|
638
|
-
message: "urn:ietf:params:acme:error:badNonce",
|
|
639
|
-
type: "urn:ietf:params:acme:error:badNonce",
|
|
640
|
-
});
|
|
641
|
-
expect((error as AcmeBadNonce).detail).toBeUndefined();
|
|
642
|
-
expect(posts(ca)).toHaveLength(3);
|
|
643
|
-
});
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
describe("Problem document errors", () => {
|
|
647
|
-
const getOrderFails = async (response: () => Response) => {
|
|
648
|
-
const ca = makeCa();
|
|
649
|
-
ca.handlers.set(`POST ${ca.urls.order}`, response);
|
|
650
|
-
return runError(
|
|
651
|
-
ca,
|
|
652
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
653
|
-
getOrder({ url: ca.urls.order }),
|
|
654
|
-
);
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
test("a known URN maps to its typed class with code, type and detail", async () => {
|
|
658
|
-
const error = await getOrderFails(() =>
|
|
659
|
-
problem(
|
|
660
|
-
{ type: "urn:ietf:params:acme:error:malformed", detail: "Request body was invalid" },
|
|
661
|
-
{ status: 400 },
|
|
662
|
-
),
|
|
663
|
-
);
|
|
664
|
-
expect(error).toBeInstanceOf(AcmeMalformed);
|
|
665
|
-
expect(error).toMatchObject({
|
|
666
|
-
code: 400,
|
|
667
|
-
message: "Request body was invalid",
|
|
668
|
-
type: "urn:ietf:params:acme:error:malformed",
|
|
669
|
-
detail: "Request body was invalid",
|
|
670
|
-
});
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
test("a known URN without detail maps to its typed class", async () => {
|
|
674
|
-
const error = await getOrderFails(() =>
|
|
675
|
-
problem({ type: "urn:ietf:params:acme:error:malformed" }, { status: 400 }),
|
|
676
|
-
);
|
|
677
|
-
expect(error).toBeInstanceOf(AcmeMalformed);
|
|
678
|
-
expect(error).toMatchObject({
|
|
679
|
-
code: 400,
|
|
680
|
-
message: "urn:ietf:params:acme:error:malformed",
|
|
681
|
-
type: "urn:ietf:params:acme:error:malformed",
|
|
682
|
-
});
|
|
683
|
-
expect((error as AcmeMalformed).detail).toBeUndefined();
|
|
684
|
-
});
|
|
685
|
-
|
|
686
|
-
test("rateLimited without detail keeps the Retry-After hint", async () => {
|
|
687
|
-
const error = await getOrderFails(() =>
|
|
688
|
-
problem(
|
|
689
|
-
{ type: "urn:ietf:params:acme:error:rateLimited" },
|
|
690
|
-
{ status: 429, headers: { "Retry-After": "30" } },
|
|
691
|
-
),
|
|
692
|
-
);
|
|
693
|
-
expect(error).toBeInstanceOf(AcmeRateLimited);
|
|
694
|
-
expect((error as AcmeRateLimited).detail).toBeUndefined();
|
|
695
|
-
expect(Duration.toSeconds((error as AcmeRateLimited).retryAfter!)).toBe(30);
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
test("an unknown URN without detail is UnknownAcmeError messaged by its type", async () => {
|
|
699
|
-
const error = await getOrderFails(() =>
|
|
700
|
-
problem({ type: "urn:example:custom" }, { status: 403 }),
|
|
701
|
-
);
|
|
702
|
-
expect(error).toBeInstanceOf(UnknownAcmeError);
|
|
703
|
-
expect(error).toMatchObject({
|
|
704
|
-
type: "urn:example:custom",
|
|
705
|
-
message: "urn:example:custom",
|
|
706
|
-
status: 403,
|
|
707
|
-
});
|
|
708
|
-
expect((error as UnknownAcmeError).detail).toBeUndefined();
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
test("rateLimited carries the Retry-After hint", async () => {
|
|
712
|
-
const error = await getOrderFails(() =>
|
|
713
|
-
problem(
|
|
714
|
-
{ type: "urn:ietf:params:acme:error:rateLimited", detail: "too many" },
|
|
715
|
-
{ status: 429, headers: { "Retry-After": "30" } },
|
|
716
|
-
),
|
|
717
|
-
);
|
|
718
|
-
expect(error).toBeInstanceOf(AcmeRateLimited);
|
|
719
|
-
expect(Duration.toSeconds((error as AcmeRateLimited).retryAfter!)).toBe(30);
|
|
720
|
-
});
|
|
721
|
-
|
|
722
|
-
test("an unknown URN is UnknownAcmeError with the problem fields", async () => {
|
|
723
|
-
const subproblems = [
|
|
724
|
-
{ type: "urn:ietf:params:acme:error:dns", identifier: { type: "dns", value: "a.test" } },
|
|
725
|
-
];
|
|
726
|
-
const error = await getOrderFails(() =>
|
|
727
|
-
problem(
|
|
728
|
-
{ type: "urn:example:custom", detail: "custom failure", subproblems },
|
|
729
|
-
{ status: 403 },
|
|
730
|
-
),
|
|
731
|
-
);
|
|
732
|
-
expect(error).toBeInstanceOf(UnknownAcmeError);
|
|
733
|
-
expect(error).toMatchObject({
|
|
734
|
-
type: "urn:example:custom",
|
|
735
|
-
detail: "custom failure",
|
|
736
|
-
message: "custom failure",
|
|
737
|
-
status: 403,
|
|
738
|
-
subproblems,
|
|
739
|
-
});
|
|
740
|
-
expect(Redacted.isRedacted((error as UnknownAcmeError).body)).toBe(true);
|
|
741
|
-
});
|
|
742
|
-
|
|
743
|
-
test("a URN typed on a different operation does not match here", async () => {
|
|
744
|
-
// badCSR is only declared on finalizeOrder.
|
|
745
|
-
const error = await getOrderFails(() =>
|
|
746
|
-
problem({ type: "urn:ietf:params:acme:error:badCSR" }, { status: 400 }),
|
|
747
|
-
);
|
|
748
|
-
expect(error).toBeInstanceOf(UnknownAcmeError);
|
|
749
|
-
expect(error).toMatchObject({ type: "urn:ietf:params:acme:error:badCSR" });
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
test("a non-problem 404 maps to the core NotFound", async () => {
|
|
753
|
-
const error = await getOrderFails(() => new Response("missing", { status: 404 }));
|
|
754
|
-
expect(error).toBeInstanceOf(NotFound);
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
test("a non-problem 5xx maps to the core status class", async () => {
|
|
758
|
-
const error = await getOrderFails(() => new Response("boom", { status: 500 }));
|
|
759
|
-
expect(error).toBeInstanceOf(InternalServerError);
|
|
760
|
-
});
|
|
761
|
-
});
|
|
762
|
-
|
|
763
|
-
describe("Response decoding", () => {
|
|
764
|
-
test("a PEM chain is returned as text with Link alternates", async () => {
|
|
765
|
-
const ca = makeCa();
|
|
766
|
-
const pem = "-----BEGIN CERTIFICATE-----\nMIIB\n-----END CERTIFICATE-----\n";
|
|
767
|
-
ca.handlers.set(
|
|
768
|
-
`POST ${ca.urls.cert}`,
|
|
769
|
-
() =>
|
|
770
|
-
new Response(pem, {
|
|
771
|
-
headers: {
|
|
772
|
-
"Content-Type": "application/pem-certificate-chain",
|
|
773
|
-
Link: `<${ca.urls.cert}/1>;rel="alternate", <${ca.urls.directory}>;rel="index", <${ca.urls.cert}/2>; rel=alternate`,
|
|
774
|
-
},
|
|
775
|
-
}),
|
|
776
|
-
);
|
|
777
|
-
const result = await run(
|
|
778
|
-
ca,
|
|
779
|
-
{ accountKey: ecKey, accountUrl: ca.urls.account },
|
|
780
|
-
downloadCertificate({ url: ca.urls.cert }),
|
|
781
|
-
);
|
|
782
|
-
expect(result).toEqual({
|
|
783
|
-
chain: pem,
|
|
784
|
-
alternates: [`${ca.urls.cert}/1`, `${ca.urls.cert}/2`],
|
|
785
|
-
});
|
|
786
|
-
expect(parseJws(posts(ca)[0]!).jws.payload).toBe("");
|
|
787
|
-
});
|
|
788
|
-
|
|
789
|
-
test("the Location header is folded into the output", async () => {
|
|
790
|
-
const ca = makeCa();
|
|
791
|
-
ca.handlers.set(`POST ${ca.urls.newAccount}`, () =>
|
|
792
|
-
json(
|
|
793
|
-
{ status: "valid", orders: `${ca.urls.account}/orders` },
|
|
794
|
-
{
|
|
795
|
-
headers: { Location: ca.urls.account },
|
|
796
|
-
},
|
|
797
|
-
),
|
|
798
|
-
);
|
|
799
|
-
const result = await run(ca, { accountKey: ecKey }, newAccount({ onlyReturnExisting: true }));
|
|
800
|
-
expect(result).toEqual({
|
|
801
|
-
status: "valid",
|
|
802
|
-
orders: `${ca.urls.account}/orders`,
|
|
803
|
-
location: ca.urls.account,
|
|
804
|
-
});
|
|
805
|
-
});
|
|
806
|
-
});
|