-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathindex.ts
120 lines (97 loc) · 3.87 KB
/
index.ts
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
import _ from 'lodash';
import { ErrorLike } from '@httptoolkit/util';
import { HtkConfig } from '../config';
import { addShutdownHandler } from '../shutdown';
import { FreshFirefox, FreshFirefoxDeveloper, FreshFirefoxNightly } from './fresh-firefox';
import {
FreshChrome,
ExistingChrome,
FreshChromeBeta,
FreshChromeCanary,
FreshChromeDev,
FreshChromium,
ExistingChromium,
FreshChromiumDev,
FreshEdge,
FreshEdgeBeta,
FreshEdgeDev,
FreshEdgeCanary,
FreshBrave,
FreshOpera
} from './chromium-based-interceptors';
import { FreshTerminalInterceptor } from './terminal/fresh-terminal-interceptor';
import { ExistingTerminalInterceptor } from './terminal/existing-terminal-interceptor';
import { AndroidAdbInterceptor } from './android/android-adb-interceptor';
import { DockerContainerInterceptor } from './docker/docker-interceptor';
import { ElectronInterceptor } from './electron';
import { JvmInterceptor } from './jvm';
import { FridaAndroidInterceptor } from './frida/frida-android-interceptor';
import { FridaIosInterceptor } from './frida/frida-ios-interceptor';
export interface Interceptor {
id: string;
version: string;
getMetadata?(type: 'summary' | 'detailed'): Promise<any>;
getSubMetadata?(subId: string): Promise<any>;
isActivable(): Promise<boolean>;
activableTimeout?: number;
isActive(proxyPort: number): Promise<boolean> | boolean;
activate(proxyPort: number, options?: any): Promise<void | {}>;
deactivate(proxyPort: number, options?: any): Promise<void | {}>;
deactivateAll(): Promise<void | {}>;
}
export interface ActivationError extends ErrorLike {
/**
* Activation errors can have an extra `metadata` field, to share data with the
* client which attempted the activation, e.g. whether it can be retried.
*/
metadata?: any;
/**
* Errors should be thrown with reportable set to `false` if they're a 'normal'
* event that shouldn't be logged or exposed to the user. For example, if it's a
* temporary failure that will lead to a confirmation flow or similar.
*
* This disables error logging and reporting of failure details from the API
* (it assumes that the metadata will expose any info required, since this is a
* recognized failure case).
*/
reportable?: boolean;
}
export function buildInterceptors(config: HtkConfig): _.Dictionary<Interceptor> {
const interceptors = [
new FreshChrome(config),
new ExistingChrome(config),
new FreshChromeBeta(config),
new FreshChromeDev(config),
new FreshChromeCanary(config),
new FreshChromium(config),
new ExistingChromium(config),
new FreshChromiumDev(config),
new FreshEdge(config),
new FreshEdgeBeta(config),
new FreshEdgeDev(config),
new FreshEdgeCanary(config),
new FreshOpera(config),
new FreshBrave(config),
new FreshFirefox(config),
new FreshFirefoxDeveloper(config),
new FreshFirefoxNightly(config),
new FreshTerminalInterceptor(config),
new ExistingTerminalInterceptor(config),
new ElectronInterceptor(config),
new AndroidAdbInterceptor(config),
new FridaAndroidInterceptor(config),
new FridaIosInterceptor(config),
new JvmInterceptor(config),
new DockerContainerInterceptor(config)
];
// When the server exits, try to shut down the interceptors too
addShutdownHandler(() => shutdownInterceptors(interceptors));
const interceptorIndex = _.keyBy(interceptors, (interceptor) => interceptor.id);
if (Object.keys(interceptorIndex).length !== interceptors.length) {
throw new Error('Duplicate interceptor id');
}
return interceptorIndex;
}
function shutdownInterceptors(interceptors: Interceptor[]) {
return Promise.all(interceptors.map(i => i.deactivateAll()));
}