Skip to content

Commit 49b180b

Browse files
committed
Update Mockttp for wildcard client certs & SOCKS fixes
1 parent 9c1f23b commit 49b180b

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"mime-types": "^2.1.27",
8585
"mobx": "^6.3.5",
8686
"mockrtc": "^0.5.0",
87-
"mockttp": "^4.0.1",
87+
"mockttp": "^4.1.0",
8888
"node-fetch": "^2.6.1",
8989
"node-forge": "^1.3.0",
9090
"node-gsettings-wrapper": "^0.5.0",

src/client/http-client.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as https from 'https';
1010
import type * as Mockttp from 'mockttp';
1111
import {
1212
getDnsLookupFunction,
13-
shouldUseStrictHttps,
1413
getUpstreamTlsOptions as getUpstreamMockttpTlsOptions
1514
} from 'mockttp/dist/rules/passthrough-handling';
1615
import { getAgent } from 'mockttp/dist/rules/http-agents';
@@ -58,15 +57,6 @@ export class HttpClient {
5857
JSON.stringify(dnsServers)
5958
);
6059

61-
getCaConfig(additionalCAs?: Array<{ cert: string }>) {
62-
if (!additionalCAs) return {};
63-
else return {
64-
ca: tls.rootCertificates.concat(
65-
additionalCAs.map(({ cert }) => cert)
66-
)
67-
};
68-
}
69-
7060
async sendRequest(
7161
requestDefn: RequestDefinition,
7262
options: RequestOptions
@@ -78,16 +68,7 @@ export class HttpClient {
7868
// here, since the UI controls the passthrough options directly already.
7969

8070
const effectivePort = getEffectivePort(url);
81-
82-
const strictHttpsChecks = shouldUseStrictHttps(
83-
url.hostname!,
84-
effectivePort,
85-
options.ignoreHostHttpsErrors ?? []
86-
);
87-
const caConfig = this.getCaConfig(
88-
options.additionalTrustedCAs ||
89-
options.trustAdditionalCAs
90-
);
71+
const additionalCAs = options.additionalTrustedCAs || options.trustAdditionalCAs;
9172

9273
const agent = await getAgent({
9374
protocol: url.protocol as 'http:' | 'https:',
@@ -107,9 +88,18 @@ export class HttpClient {
10788
lookup: this.getDns(options.lookupOptions?.servers),
10889

10990
// TLS options (should be effectively identical to Mockttp's passthrough config)
110-
...getUpstreamMockttpTlsOptions(strictHttpsChecks),
111-
...caConfig,
112-
...options.clientCertificate
91+
...getUpstreamMockttpTlsOptions({
92+
hostname: url.hostname!,
93+
port: effectivePort,
94+
95+
ignoreHostHttpsErrors: options.ignoreHostHttpsErrors ?? [],
96+
clientCertificateHostMap: options.clientCertificate
97+
? { '*': options.clientCertificate }
98+
: {},
99+
trustedCAs: additionalCAs
100+
? tls.rootCertificates.concat(additionalCAs.map(({ cert }) => cert))
101+
: undefined
102+
})
113103
});
114104

115105
options.abortSignal?.addEventListener('abort', () => {

0 commit comments

Comments
 (0)