Skip to content

Commit 0e72886

Browse files
committed
Update to Mockttp v4 for SOCKS, non-HTTP, delays & URL transforms
Lots and lots of exciting changes here - internally there's also some notable CA & cert generation changes that might cause downstream effects to watch out for. Mostly nothing immediately impactful though (hopefully) and this is primarily a question of enabling shiny new features that'll be powered by the UI shortly.
1 parent 8d00adb commit 0e72886

File tree

8 files changed

+330
-57
lines changed

8 files changed

+330
-57
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
"lookpath": "^1.2.1",
8484
"mime-types": "^2.1.27",
8585
"mobx": "^6.3.5",
86-
"mockrtc": "^0.4.0",
87-
"mockttp": "^3.17.1",
86+
"mockrtc": "^0.5.0",
87+
"mockttp": "^4.0.0",
8888
"node-fetch": "^2.6.1",
8989
"node-forge": "^1.3.0",
9090
"node-gsettings-wrapper": "^0.5.0",

src/api/api-model.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export class ApiModel {
5151
// Wait for each async part in parallel:
5252
const [
5353
systemProxy,
54-
dnsServers
54+
dnsServers,
55+
spkiFingerprint
5556
] = await Promise.all([
5657
withFallback(
5758
() => getSystemProxy(),
@@ -61,7 +62,9 @@ export class ApiModel {
6162

6263
proxyPort
6364
? await this.getDnsServers(proxyPort)
64-
: []
65+
: [],
66+
67+
generateSPKIFingerprint(this.config.https.certContent)
6568
])
6669

6770
return {
@@ -74,7 +77,7 @@ export class ApiModel {
7477
// We could calculate this client side, but it requires node-forge or some
7578
// other heavyweight crypto lib, and we already have that here, so it's
7679
// convenient to do it up front.
77-
certificateFingerprint: generateSPKIFingerprint(this.config.https.certContent),
80+
certificateFingerprint: spkiFingerprint,
7881

7982
networkInterfaces: this.getNetworkInterfaces(),
8083
systemProxy,

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import {
3434
import { clearWebExtensionConfig, updateWebExtensionConfig } from './webextension';
3535
import { HttpClient } from './client/http-client';
3636

37-
const APP_NAME = "HTTP Toolkit";
38-
3937
async function generateHTTPSConfig(configPath: string) {
4038
const keyPath = path.join(configPath, 'ca.key');
4139
const certPath = path.join(configPath, 'ca.pem');
@@ -50,8 +48,10 @@ async function generateHTTPSConfig(configPath: string) {
5048
// Cert doesn't exist, or is too close/past expiry. Generate a new one:
5149

5250
const newCertPair = await generateCACertificate({
53-
commonName: APP_NAME + ' CA',
54-
organizationName: APP_NAME + ' CA'
51+
subject: {
52+
commonName: 'HTTP Toolkit CA',
53+
organizationName: 'HTTP Toolkit CA'
54+
}
5555
});
5656

5757
return Promise.all([

src/interceptors/android/android-adb-interceptor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class AndroidAdbInterceptor implements Interceptor {
106106
),
107107
port: proxyPort,
108108
localTunnelPort: proxyPort,
109-
certFingerprint: generateSPKIFingerprint(this.config.https.certContent)
109+
certFingerprint: await generateSPKIFingerprint(this.config.https.certContent)
110110
};
111111
const intentData = urlSafeBase64(JSON.stringify(setupParams));
112112

@@ -189,7 +189,7 @@ export class AndroidAdbInterceptor implements Interceptor {
189189
console.log("Cert already installed, nothing to do");
190190
}
191191

192-
const spkiFingerprint = generateSPKIFingerprint(certContent);
192+
const spkiFingerprint = await generateSPKIFingerprint(certContent);
193193

194194
// Chrome requires system certificates to use certificate transparency, which we can't do. To work
195195
// around this, we need to explicitly trust our certificate in Chrome:

src/interceptors/chromium-based-interceptors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const getChromiumLaunchOptions = async (
2929
webExtensionEnabled: boolean
3030
): Promise<LaunchOptions & { options: Required<LaunchOptions>['options'] }> => {
3131
const certificatePem = await readFile(config.https.certPath, 'utf8');
32-
const spkiFingerprint = generateSPKIFingerprint(certificatePem);
32+
const spkiFingerprint = await generateSPKIFingerprint(certificatePem);
3333

3434
return {
3535
profile: profilePath,

src/interceptors/electron.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class ElectronInterceptor implements Interceptor {
148148
JSON.stringify(path.join(OVERRIDES_DIR, 'js', 'prepend-electron.js'))
149149
})({
150150
newlineEncodedCertData: "${(await this.certData).replace(/\r\n|\r|\n/g, '\\n')}",
151-
spkiFingerprint: "${generateSPKIFingerprint(await this.certData)}"
151+
spkiFingerprint: "${await generateSPKIFingerprint(await this.certData)}"
152152
})`,
153153
callFrameId
154154
});

src/interceptors/terminal/existing-terminal-interceptor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class ExistingTerminalInterceptor implements Interceptor {
108108
// A success endpoint, so we can mark this as active (which provides some helpful UX on the frontend)
109109
await server.forPost('/success').thenCallback(() => {
110110
serverState.isActive = true;
111-
return { status: 200 };
111+
return { statusCode: 200 };
112112
});
113113

114114
this.servers[proxyPort] = serverState;

0 commit comments

Comments
 (0)