Skip to content

Commit db73356

Browse files
committed
Add support for wildcard client certificate config
1 parent 8433cfd commit db73356

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/rules/passthrough-handling-definitions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export interface PassThroughStepConnectionOptions {
6868

6969
/**
7070
* A mapping of hosts to client certificates to use, in the form of
71-
* `{ key, cert }` objects (none, by default)
71+
* `{ key, cert }` objects (none, by default). `*` can be used as a wildcard
72+
* to send a client certificate for all hosts that request it. If a wildcard
73+
* is present, specific hostname matches will still take precendence.
7274
*/
7375
clientCertificateHostMap?: {
7476
[host: string]: { pfx: Buffer, passphrase?: string }

src/rules/passthrough-handling.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function getUpstreamTlsOptions({
6767
const hostWithPort = `${hostname}:${port}`;
6868
const clientCert = clientCertificateHostMap[hostWithPort] ||
6969
clientCertificateHostMap[hostname] ||
70+
clientCertificateHostMap['*'] ||
7071
{};
7172

7273
return {

test/integration/proxying/https-proxying.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,42 @@ nodeOnly(() => {
459459

460460
expect(response).to.equal("OK");
461461
});
462+
463+
it("uses a wildcard client certificate for the hostname", async () => {
464+
await server.forAnyRequest().thenPassThrough({
465+
ignoreHostHttpsErrors: ['localhost'],
466+
clientCertificateHostMap: {
467+
['*']: {
468+
pfx: await fs.readFile('./test/fixtures/test-ca.pfx'),
469+
passphrase: 'test-passphrase'
470+
}
471+
}
472+
});
473+
474+
let response = await request.get(`https://localhost:${authenticatingServerPort}/`);
475+
476+
expect(response).to.equal("OK");
477+
});
478+
479+
it("uses a hostname-specific client certificate in preference over a wildcard", async () => {
480+
await server.forAnyRequest().thenPassThrough({
481+
ignoreHostHttpsErrors: ['localhost'],
482+
clientCertificateHostMap: {
483+
'*': { // If this were selected, it wouldn't work - passphrase is wrong
484+
pfx: await fs.readFile('./test/fixtures/test-ca.pfx'),
485+
passphrase: 'TOTALLY-WRONG-PASSPHRASE'
486+
},
487+
[`localhost:${authenticatingServerPort}`]: {
488+
pfx: await fs.readFile('./test/fixtures/test-ca.pfx'),
489+
passphrase: 'test-passphrase'
490+
}
491+
}
492+
});
493+
494+
let response = await request.get(`https://localhost:${authenticatingServerPort}/`);
495+
496+
expect(response).to.equal("OK");
497+
});
462498
});
463499
});
464500

0 commit comments

Comments
 (0)