freerasp-react-native 5.3.0 → 6.0.0
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/CHANGELOG.md +49 -0
- package/README.md +2 -0
- package/android/build.gradle +3 -3
- package/android/proguard-rules.pro +3 -3
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/FreeraspReactNativeModule.kt +177 -17
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/FreeraspReactNativePackage.kt +1 -1
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/PluginThreatHandler.kt +20 -7
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/ScreenProtector.kt +1 -1
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/dispatchers/ExecutionStateDispatcher.kt +3 -3
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/dispatchers/ThreatDispatcher.kt +23 -3
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/events/BaseRaspEvent.kt +1 -1
- package/android/src/main/java/app/talsec/rasp/reactnative/events/RaspExecutionStateEvent.kt +22 -0
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/events/ThreatEvent.kt +6 -3
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/exceptions/TalsecException.kt +1 -1
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/interfaces/PluginExecutionStateListener.kt +2 -2
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/interfaces/PluginThreatListener.kt +4 -2
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/models/RNSuspiciousAppInfo.kt +1 -1
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/utils/Extensions.kt +4 -4
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/utils/RandomGenerator.kt +1 -1
- package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/utils/Utils.kt +1 -1
- package/ios/FreeraspReactNative.swift +7 -5
- package/ios/models/RaspExecutionStates.swift +3 -3
- package/lib/commonjs/api/listeners/raspExecutionState.js +13 -7
- package/lib/commonjs/api/listeners/raspExecutionState.js.map +1 -1
- package/lib/commonjs/api/listeners/threat.js +19 -8
- package/lib/commonjs/api/listeners/threat.js.map +1 -1
- package/lib/commonjs/api/methods/internal.js +20 -0
- package/lib/commonjs/api/methods/internal.js.map +1 -0
- package/lib/commonjs/api/methods/native.js +113 -21
- package/lib/commonjs/api/methods/native.js.map +1 -1
- package/lib/commonjs/api/methods/reactNative.js +38 -10
- package/lib/commonjs/api/methods/reactNative.js.map +1 -1
- package/lib/commonjs/channels/raspExecutionState.js +3 -3
- package/lib/commonjs/channels/raspExecutionState.js.map +1 -1
- package/lib/commonjs/channels/threat.js +4 -4
- package/lib/commonjs/channels/threat.js.map +1 -1
- package/lib/commonjs/index.js +23 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/raspExecutionState.js +5 -2
- package/lib/commonjs/models/raspExecutionState.js.map +1 -1
- package/lib/commonjs/models/threat.js +2 -1
- package/lib/commonjs/models/threat.js.map +1 -1
- package/lib/commonjs/types/errors.js +50 -0
- package/lib/commonjs/types/errors.js.map +1 -0
- package/lib/commonjs/types/types.js +4 -0
- package/lib/module/api/listeners/raspExecutionState.js +10 -4
- package/lib/module/api/listeners/raspExecutionState.js.map +1 -1
- package/lib/module/api/listeners/threat.js +16 -5
- package/lib/module/api/listeners/threat.js.map +1 -1
- package/lib/module/api/methods/internal.js +13 -0
- package/lib/module/api/methods/internal.js.map +1 -0
- package/lib/module/api/methods/native.js +106 -17
- package/lib/module/api/methods/native.js.map +1 -1
- package/lib/module/api/methods/reactNative.js +39 -12
- package/lib/module/api/methods/reactNative.js.map +1 -1
- package/lib/module/channels/raspExecutionState.js +1 -1
- package/lib/module/channels/raspExecutionState.js.map +1 -1
- package/lib/module/channels/threat.js +2 -2
- package/lib/module/channels/threat.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/raspExecutionState.js +5 -2
- package/lib/module/models/raspExecutionState.js.map +1 -1
- package/lib/module/models/threat.js +2 -1
- package/lib/module/models/threat.js.map +1 -1
- package/lib/module/types/errors.js +41 -0
- package/lib/module/types/errors.js.map +1 -0
- package/lib/module/types/types.js +1 -1
- package/lib/typescript/src/api/listeners/raspExecutionState.d.ts.map +1 -1
- package/lib/typescript/src/api/listeners/threat.d.ts.map +1 -1
- package/lib/typescript/src/api/methods/internal.d.ts +7 -0
- package/lib/typescript/src/api/methods/internal.d.ts.map +1 -0
- package/lib/typescript/src/api/methods/native.d.ts +56 -7
- package/lib/typescript/src/api/methods/native.d.ts.map +1 -1
- package/lib/typescript/src/api/methods/reactNative.d.ts +11 -2
- package/lib/typescript/src/api/methods/reactNative.d.ts.map +1 -1
- package/lib/typescript/src/channels/threat.d.ts +1 -0
- package/lib/typescript/src/channels/threat.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/models/raspExecutionState.d.ts +3 -1
- package/lib/typescript/src/models/raspExecutionState.d.ts.map +1 -1
- package/lib/typescript/src/models/threat.d.ts +1 -0
- package/lib/typescript/src/models/threat.d.ts.map +1 -1
- package/lib/typescript/src/types/errors.d.ts +26 -0
- package/lib/typescript/src/types/errors.d.ts.map +1 -0
- package/lib/typescript/src/types/types.d.ts +63 -26
- package/lib/typescript/src/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/listeners/raspExecutionState.ts +9 -3
- package/src/api/listeners/threat.ts +29 -5
- package/src/api/methods/internal.ts +13 -0
- package/src/api/methods/native.ts +125 -21
- package/src/api/methods/reactNative.ts +46 -16
- package/src/channels/raspExecutionState.ts +1 -1
- package/src/channels/threat.ts +3 -3
- package/src/index.tsx +2 -0
- package/src/models/raspExecutionState.ts +12 -2
- package/src/models/threat.ts +2 -0
- package/src/types/errors.ts +57 -0
- package/src/types/types.ts +68 -26
- package/android/src/main/java/com/freeraspreactnative/events/RaspExecutionStateEvent.kt +0 -18
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FreeraspReactNative } from '../nativeModules';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Terminates the app. Called when the native side sends data that freeRASP
|
|
5
|
+
* never sends, which indicates tampering. Exported publicly as `abortApp`.
|
|
6
|
+
*/
|
|
7
|
+
export const onInvalidCallback = (): void => {
|
|
8
|
+
FreeraspReactNative.onInvalidCallback();
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const removeListenerForEvent = (channel: string): Promise<string> => {
|
|
12
|
+
return FreeraspReactNative.removeListenerForEvent(channel);
|
|
13
|
+
};
|
|
@@ -1,48 +1,152 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
2
|
import { FreeraspReactNative } from '../nativeModules';
|
|
3
3
|
import type { TalsecConfig } from '../../types/types';
|
|
4
|
+
import { androidOnly, wrapNative } from '../../types/errors';
|
|
4
5
|
import { withDefaults } from '../../utils/config';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Starts freeRASP. Prefer the `useFreeRasp` hook, which also registers the
|
|
9
|
+
* listeners.
|
|
10
|
+
*/
|
|
11
|
+
export const talsecStart = async (options: TalsecConfig): Promise<void> => {
|
|
12
|
+
await wrapNative('talsec-failure', () =>
|
|
13
|
+
FreeraspReactNative.talsecStart(withDefaults(options))
|
|
14
|
+
);
|
|
8
15
|
};
|
|
9
16
|
|
|
10
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Android only. Adds an app to the malware whitelist so it is not reported.
|
|
19
|
+
*/
|
|
20
|
+
export const addToWhitelist = async (packageName: string): Promise<void> => {
|
|
11
21
|
if (Platform.OS === 'ios') {
|
|
12
|
-
return
|
|
22
|
+
return androidOnly('Malware detection');
|
|
13
23
|
}
|
|
14
|
-
|
|
24
|
+
await wrapNative('malware-failure', () =>
|
|
25
|
+
FreeraspReactNative.addToWhitelist(packageName)
|
|
26
|
+
);
|
|
15
27
|
};
|
|
16
28
|
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Blocks or unblocks screenshots and screen recording of the app screen.
|
|
31
|
+
*/
|
|
32
|
+
export const blockScreenCapture = async (enable: boolean): Promise<void> => {
|
|
33
|
+
await wrapNative('talsec-failure', () =>
|
|
34
|
+
FreeraspReactNative.blockScreenCapture(enable)
|
|
35
|
+
);
|
|
19
36
|
};
|
|
20
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Returns whether screen capture is blocked for the current screen.
|
|
40
|
+
*/
|
|
21
41
|
export const isScreenCaptureBlocked = (): Promise<boolean> => {
|
|
22
|
-
return
|
|
42
|
+
return wrapNative('talsec-failure', () =>
|
|
43
|
+
FreeraspReactNative.isScreenCaptureBlocked()
|
|
44
|
+
);
|
|
23
45
|
};
|
|
24
46
|
|
|
25
|
-
|
|
26
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Android only. Prevents accessibility services from reading or controlling
|
|
49
|
+
* the app screen.
|
|
50
|
+
*/
|
|
51
|
+
export const blockScreenControl = async (enable: boolean): Promise<void> => {
|
|
52
|
+
if (Platform.OS === 'ios') {
|
|
53
|
+
return androidOnly('Screen control blocking');
|
|
54
|
+
}
|
|
55
|
+
await wrapNative('talsec-failure', () =>
|
|
56
|
+
FreeraspReactNative.blockScreenControl(enable)
|
|
57
|
+
);
|
|
27
58
|
};
|
|
28
59
|
|
|
29
|
-
|
|
30
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Android only. Returns whether screen control is blocked.
|
|
62
|
+
*/
|
|
63
|
+
export const isScreenControlBlocked = (): Promise<boolean> => {
|
|
64
|
+
if (Platform.OS === 'ios') {
|
|
65
|
+
return androidOnly('Screen control blocking');
|
|
66
|
+
}
|
|
67
|
+
return wrapNative('talsec-failure', () =>
|
|
68
|
+
FreeraspReactNative.isScreenControlBlocked()
|
|
69
|
+
);
|
|
31
70
|
};
|
|
32
71
|
|
|
33
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Android only. Hides overlay windows of other apps over the app screen.
|
|
74
|
+
* Requires Android 12+ and the `HIDE_OVERLAY_WINDOWS` permission.
|
|
75
|
+
*
|
|
76
|
+
* @returns whether the request was applied
|
|
77
|
+
*/
|
|
78
|
+
export const blockOverlayWindows = (enable: boolean): Promise<boolean> => {
|
|
79
|
+
if (Platform.OS === 'ios') {
|
|
80
|
+
return androidOnly('Overlay windows blocking');
|
|
81
|
+
}
|
|
82
|
+
return wrapNative('talsec-failure', () =>
|
|
83
|
+
FreeraspReactNative.blockOverlayWindows(enable)
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Android only. Returns whether overlay windows of other apps are hidden.
|
|
89
|
+
*/
|
|
90
|
+
export const isOverlayWindowsBlocked = (): Promise<boolean> => {
|
|
91
|
+
if (Platform.OS === 'ios') {
|
|
92
|
+
return androidOnly('Overlay windows blocking');
|
|
93
|
+
}
|
|
94
|
+
return wrapNative('talsec-failure', () =>
|
|
95
|
+
FreeraspReactNative.isOverlayWindowsBlocked()
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Android only. Starts the ongoing call (cellular and VoIP) detection.
|
|
101
|
+
* Call states are reported through the `ongoingCall` threat action.
|
|
102
|
+
*/
|
|
103
|
+
export const startOngoingCallDetection = async (): Promise<void> => {
|
|
104
|
+
if (Platform.OS === 'ios') {
|
|
105
|
+
return androidOnly('Ongoing call detection');
|
|
106
|
+
}
|
|
107
|
+
await wrapNative('talsec-failure', () =>
|
|
108
|
+
FreeraspReactNative.startOngoingCallDetection()
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Android only. Stops the ongoing call detection.
|
|
114
|
+
*/
|
|
115
|
+
export const stopOngoingCallDetection = async (): Promise<void> => {
|
|
34
116
|
if (Platform.OS === 'ios') {
|
|
35
|
-
return
|
|
36
|
-
'App icon retrieval for Malware detection not available on iOS'
|
|
37
|
-
);
|
|
117
|
+
return androidOnly('Ongoing call detection');
|
|
38
118
|
}
|
|
39
|
-
|
|
119
|
+
await wrapNative('talsec-failure', () =>
|
|
120
|
+
FreeraspReactNative.stopOngoingCallDetection()
|
|
121
|
+
);
|
|
40
122
|
};
|
|
41
123
|
|
|
42
|
-
|
|
43
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Stores an external ID sent with freeRASP logs.
|
|
126
|
+
*/
|
|
127
|
+
export const storeExternalId = async (data: string): Promise<void> => {
|
|
128
|
+
await wrapNative('external-id-failure', () =>
|
|
129
|
+
FreeraspReactNative.storeExternalId(data)
|
|
130
|
+
);
|
|
44
131
|
};
|
|
45
132
|
|
|
46
|
-
|
|
47
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Removes the stored external ID.
|
|
135
|
+
*/
|
|
136
|
+
export const removeExternalId = async (): Promise<void> => {
|
|
137
|
+
await wrapNative('external-id-failure', () =>
|
|
138
|
+
FreeraspReactNative.removeExternalId()
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Android only. Returns the icon of the given app as a base64-encoded PNG.
|
|
144
|
+
*/
|
|
145
|
+
export const getAppIcon = (packageName: string): Promise<string> => {
|
|
146
|
+
if (Platform.OS === 'ios') {
|
|
147
|
+
return androidOnly('App icon retrieval for malware detection');
|
|
148
|
+
}
|
|
149
|
+
return wrapNative('malware-failure', () =>
|
|
150
|
+
FreeraspReactNative.getAppIcon(packageName)
|
|
151
|
+
);
|
|
48
152
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { talsecStart } from './native';
|
|
2
|
-
import { useEffect } from 'react';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
3
|
import {
|
|
4
4
|
setRaspExecutionStateListener,
|
|
5
5
|
removeRaspExecutionStateEventListener,
|
|
@@ -9,38 +9,66 @@ import type {
|
|
|
9
9
|
ThreatEventActions,
|
|
10
10
|
TalsecConfig,
|
|
11
11
|
RaspExecutionStateEventActions,
|
|
12
|
+
FreeRaspStatus,
|
|
12
13
|
} from '../../types/types';
|
|
13
|
-
import {
|
|
14
|
+
import { TalsecError } from '../../types/errors';
|
|
14
15
|
|
|
15
16
|
let isRaspStarted = false;
|
|
16
17
|
|
|
18
|
+
const toTalsecError = (e: unknown): TalsecError =>
|
|
19
|
+
e instanceof TalsecError
|
|
20
|
+
? e
|
|
21
|
+
: new TalsecError(
|
|
22
|
+
'talsec-failure',
|
|
23
|
+
e instanceof Error ? e.message : String(e)
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Registers the threat and RASP execution state listeners and starts freeRASP.
|
|
28
|
+
*
|
|
29
|
+
* freeRASP is started only once per app run; later mounts only re-register
|
|
30
|
+
* the listeners.
|
|
31
|
+
*
|
|
32
|
+
* @returns `started` once freeRASP runs, or the `TalsecError` that prevented
|
|
33
|
+
* the listeners from being registered or freeRASP from starting.
|
|
34
|
+
*/
|
|
17
35
|
export const useFreeRasp = (
|
|
18
36
|
config: TalsecConfig,
|
|
19
37
|
actions: ThreatEventActions,
|
|
20
38
|
raspExecutionStateActions?: RaspExecutionStateEventActions
|
|
21
|
-
) => {
|
|
39
|
+
): FreeRaspStatus => {
|
|
40
|
+
const [status, setStatus] = useState<FreeRaspStatus>({
|
|
41
|
+
started: isRaspStarted,
|
|
42
|
+
error: null,
|
|
43
|
+
});
|
|
44
|
+
|
|
22
45
|
useEffect(() => {
|
|
46
|
+
let isMounted = true;
|
|
47
|
+
|
|
23
48
|
(async () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
49
|
+
try {
|
|
50
|
+
await setThreatListeners(actions);
|
|
51
|
+
if (raspExecutionStateActions) {
|
|
52
|
+
await setRaspExecutionStateListener(raspExecutionStateActions);
|
|
53
|
+
}
|
|
27
54
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
55
|
+
if (!isRaspStarted) {
|
|
56
|
+
await talsecStart(config);
|
|
57
|
+
isRaspStarted = true;
|
|
58
|
+
}
|
|
31
59
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
60
|
+
if (isMounted) {
|
|
61
|
+
setStatus({ started: true, error: null });
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
if (isMounted) {
|
|
65
|
+
setStatus({ started: isRaspStarted, error: toTalsecError(e) });
|
|
36
66
|
}
|
|
37
|
-
isRaspStarted = true;
|
|
38
|
-
} catch (e: any) {
|
|
39
|
-
console.error(`${e.code}: ${e.message}`);
|
|
40
67
|
}
|
|
41
68
|
})();
|
|
42
69
|
|
|
43
70
|
return () => {
|
|
71
|
+
isMounted = false;
|
|
44
72
|
(async () => {
|
|
45
73
|
await removeThreatListener();
|
|
46
74
|
await removeRaspExecutionStateEventListener();
|
|
@@ -48,4 +76,6 @@ export const useFreeRasp = (
|
|
|
48
76
|
};
|
|
49
77
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
78
|
}, []);
|
|
79
|
+
|
|
80
|
+
return status;
|
|
51
81
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getRaspExecutionStateCount, itemsHaveType } from '../utils/utils';
|
|
2
2
|
import { FreeraspReactNative } from '../api/nativeModules';
|
|
3
|
-
import { onInvalidCallback } from '../api/methods/
|
|
3
|
+
import { onInvalidCallback } from '../api/methods/internal';
|
|
4
4
|
import { RaspExecutionState } from '../models/raspExecutionState';
|
|
5
5
|
|
|
6
6
|
export const getRaspExecutionStateIdentifiers = async (): Promise<number[]> => {
|
package/src/channels/threat.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getThreatCount, itemsHaveType } from '../utils/utils';
|
|
2
2
|
import { FreeraspReactNative } from '../api/nativeModules';
|
|
3
3
|
import { Threat } from '../models/threat';
|
|
4
|
-
import { onInvalidCallback } from '../api/methods/
|
|
4
|
+
import { onInvalidCallback } from '../api/methods/internal';
|
|
5
5
|
|
|
6
6
|
export const getThreatIdentifiers = async (): Promise<number[]> => {
|
|
7
7
|
const identifiers = await FreeraspReactNative.getThreatIdentifiers();
|
|
@@ -15,10 +15,10 @@ export const getThreatIdentifiers = async (): Promise<number[]> => {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export const getThreatChannelData = async (): Promise<
|
|
18
|
-
[string, string, string]
|
|
18
|
+
[string, string, string, string]
|
|
19
19
|
> => {
|
|
20
20
|
const data = await FreeraspReactNative.getThreatChannelData();
|
|
21
|
-
if (data.length !==
|
|
21
|
+
if (data.length !== 4 || !itemsHaveType(data, 'string')) {
|
|
22
22
|
onInvalidCallback();
|
|
23
23
|
}
|
|
24
24
|
return data;
|
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './types/types';
|
|
2
|
+
export { TalsecError, type TalsecErrorCode } from './types/errors';
|
|
2
3
|
export * from './api/methods/native';
|
|
3
4
|
export * from './api/methods/reactNative';
|
|
4
5
|
export * from './api/listeners/threat';
|
|
5
6
|
export * from './api/listeners/raspExecutionState';
|
|
7
|
+
export { onInvalidCallback as abortApp } from './api/methods/internal';
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
1
3
|
export class RaspExecutionState {
|
|
2
4
|
value: number;
|
|
3
5
|
|
|
4
|
-
static
|
|
6
|
+
static FastChecksFinished = new RaspExecutionState(0);
|
|
7
|
+
static CriticalChecksFinished = new RaspExecutionState(0);
|
|
8
|
+
static PostponedChecksFinished = new RaspExecutionState(0);
|
|
5
9
|
|
|
6
10
|
constructor(value: number) {
|
|
7
11
|
this.value = value;
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
static getValues(): RaspExecutionState[] {
|
|
11
|
-
return
|
|
15
|
+
return Platform.OS === 'android'
|
|
16
|
+
? [
|
|
17
|
+
this.FastChecksFinished,
|
|
18
|
+
this.CriticalChecksFinished,
|
|
19
|
+
this.PostponedChecksFinished,
|
|
20
|
+
]
|
|
21
|
+
: [this.FastChecksFinished];
|
|
12
22
|
}
|
|
13
23
|
}
|
package/src/models/threat.ts
CHANGED
|
@@ -26,6 +26,7 @@ export class Threat {
|
|
|
26
26
|
static UnsecureWifi = new Threat(0);
|
|
27
27
|
static Automation = new Threat(0);
|
|
28
28
|
static Bootloader = new Threat(0);
|
|
29
|
+
static OngoingCall = new Threat(0);
|
|
29
30
|
|
|
30
31
|
constructor(value: number) {
|
|
31
32
|
this.value = value;
|
|
@@ -56,6 +57,7 @@ export class Threat {
|
|
|
56
57
|
this.UnsecureWifi,
|
|
57
58
|
this.Automation,
|
|
58
59
|
this.Bootloader,
|
|
60
|
+
this.OngoingCall,
|
|
59
61
|
]
|
|
60
62
|
: [
|
|
61
63
|
this.AppIntegrity,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable error codes shared with the other freeRASP plugins.
|
|
3
|
+
*
|
|
4
|
+
* - `talsec-failure` - a native call failed
|
|
5
|
+
* - `unsupported-platform` - the feature is not available on this platform
|
|
6
|
+
* - `configuration-exception` - the configuration is invalid
|
|
7
|
+
* - `external-id-failure` - storing or removing the external ID failed
|
|
8
|
+
* - `malware-failure` - a malware-detection call failed
|
|
9
|
+
*/
|
|
10
|
+
export type TalsecErrorCode =
|
|
11
|
+
| 'talsec-failure'
|
|
12
|
+
| 'unsupported-platform'
|
|
13
|
+
| 'configuration-exception'
|
|
14
|
+
| 'external-id-failure'
|
|
15
|
+
| 'malware-failure';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The only error freeRASP methods reject with.
|
|
19
|
+
*/
|
|
20
|
+
export class TalsecError extends Error {
|
|
21
|
+
readonly code: TalsecErrorCode;
|
|
22
|
+
|
|
23
|
+
constructor(code: TalsecErrorCode, message?: string) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'TalsecError';
|
|
26
|
+
this.code = code;
|
|
27
|
+
Object.setPrototypeOf(this, TalsecError.prototype);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Runs a native call and rethrows any failure as a {@link TalsecError}.
|
|
33
|
+
*/
|
|
34
|
+
export const wrapNative = async <T>(
|
|
35
|
+
code: TalsecErrorCode,
|
|
36
|
+
fn: () => Promise<T>
|
|
37
|
+
): Promise<T> => {
|
|
38
|
+
try {
|
|
39
|
+
return await fn();
|
|
40
|
+
} catch (e: any) {
|
|
41
|
+
if (e instanceof TalsecError) {
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
44
|
+
throw new TalsecError(code, e?.message ?? String(e));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Rejects with an `unsupported-platform` error for Android-only features.
|
|
50
|
+
*/
|
|
51
|
+
export const androidOnly = (feature: string): Promise<never> =>
|
|
52
|
+
Promise.reject(
|
|
53
|
+
new TalsecError(
|
|
54
|
+
'unsupported-platform',
|
|
55
|
+
`${feature} is not available on iOS`
|
|
56
|
+
)
|
|
57
|
+
);
|
package/src/types/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TalsecError } from './errors';
|
|
2
|
+
|
|
1
3
|
export type TalsecConfig = {
|
|
2
4
|
androidConfig?: TalsecAndroidConfig;
|
|
3
5
|
iosConfig?: TalsecIosConfig;
|
|
@@ -37,7 +39,7 @@ export type TalsecAndroidConfig = {
|
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
export type TalsecIosConfig = {
|
|
40
|
-
|
|
42
|
+
appBundleIds: string[];
|
|
41
43
|
appTeamId: string;
|
|
42
44
|
};
|
|
43
45
|
|
|
@@ -55,34 +57,74 @@ export type PackageInfo = {
|
|
|
55
57
|
installerStore?: string;
|
|
56
58
|
};
|
|
57
59
|
|
|
60
|
+
/**
|
|
61
|
+
* State of an ongoing call reported by the ongoing call detection.
|
|
62
|
+
*
|
|
63
|
+
* - `STARTED` - a call started while the detection was running
|
|
64
|
+
* - `ONGOING` - a call was already in progress when the detection started
|
|
65
|
+
* - `STOPPED` - a previously reported call has ended
|
|
66
|
+
*/
|
|
67
|
+
export type CallState = 'STARTED' | 'ONGOING' | 'STOPPED';
|
|
68
|
+
|
|
58
69
|
export type ThreatEventActions = {
|
|
59
|
-
privilegedAccess?: () =>
|
|
60
|
-
debug?: () =>
|
|
61
|
-
simulator?: () =>
|
|
62
|
-
appIntegrity?: () =>
|
|
63
|
-
unofficialStore?: () =>
|
|
64
|
-
hooks?: () =>
|
|
65
|
-
deviceBinding?: () =>
|
|
66
|
-
deviceID?: () =>
|
|
67
|
-
passcode?: () =>
|
|
68
|
-
secureHardwareNotAvailable?: () =>
|
|
69
|
-
obfuscationIssues?: () =>
|
|
70
|
-
devMode?: () =>
|
|
71
|
-
systemVPN?: () =>
|
|
72
|
-
malware?: (suspiciousApps: SuspiciousAppInfo[]) =>
|
|
73
|
-
adbEnabled?: () =>
|
|
74
|
-
screenshot?: () =>
|
|
75
|
-
screenRecording?: () =>
|
|
76
|
-
multiInstance?: () =>
|
|
77
|
-
timeSpoofing?: () =>
|
|
78
|
-
locationSpoofing?: () =>
|
|
79
|
-
unsecureWifi?: () =>
|
|
80
|
-
automation?: () =>
|
|
81
|
-
bootloader?: () =>
|
|
70
|
+
privilegedAccess?: () => void;
|
|
71
|
+
debug?: () => void;
|
|
72
|
+
simulator?: () => void;
|
|
73
|
+
appIntegrity?: () => void;
|
|
74
|
+
unofficialStore?: () => void;
|
|
75
|
+
hooks?: () => void;
|
|
76
|
+
deviceBinding?: () => void;
|
|
77
|
+
deviceID?: () => void;
|
|
78
|
+
passcode?: () => void;
|
|
79
|
+
secureHardwareNotAvailable?: () => void;
|
|
80
|
+
obfuscationIssues?: () => void;
|
|
81
|
+
devMode?: () => void;
|
|
82
|
+
systemVPN?: () => void;
|
|
83
|
+
malware?: (suspiciousApps: SuspiciousAppInfo[]) => void;
|
|
84
|
+
adbEnabled?: () => void;
|
|
85
|
+
screenshot?: () => void;
|
|
86
|
+
screenRecording?: () => void;
|
|
87
|
+
multiInstance?: () => void;
|
|
88
|
+
timeSpoofing?: () => void;
|
|
89
|
+
locationSpoofing?: () => void;
|
|
90
|
+
unsecureWifi?: () => void;
|
|
91
|
+
automation?: () => void;
|
|
92
|
+
bootloader?: () => void;
|
|
93
|
+
/**
|
|
94
|
+
* Android only. Requires `startOngoingCallDetection()`.
|
|
95
|
+
*/
|
|
96
|
+
ongoingCall?: (state: CallState) => void;
|
|
82
97
|
};
|
|
83
98
|
|
|
84
|
-
export type NativeEvent = {
|
|
99
|
+
export type NativeEvent = {
|
|
100
|
+
[key: string]: number | string | string[] | undefined;
|
|
101
|
+
};
|
|
85
102
|
|
|
86
103
|
export type RaspExecutionStateEventActions = {
|
|
87
|
-
|
|
104
|
+
/**
|
|
105
|
+
* The fast (standard) checks have been completed. On Android, the postponed
|
|
106
|
+
* checks may still run afterwards. On iOS, triggered when all checks have
|
|
107
|
+
* been completed.
|
|
108
|
+
*/
|
|
109
|
+
fastChecksFinished?: () => void;
|
|
110
|
+
/**
|
|
111
|
+
* Android only. The critical checks have been completed, before the
|
|
112
|
+
* non-critical checks.
|
|
113
|
+
*/
|
|
114
|
+
criticalChecksFinished?: () => void;
|
|
115
|
+
/**
|
|
116
|
+
* Android only. The postponed checks have been completed, which ends the
|
|
117
|
+
* initial evaluation.
|
|
118
|
+
*/
|
|
119
|
+
postponedChecksFinished?: () => void;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* State returned by `useFreeRasp`.
|
|
124
|
+
*/
|
|
125
|
+
export type FreeRaspStatus = {
|
|
126
|
+
/** `true` once freeRASP has been started. */
|
|
127
|
+
started: boolean;
|
|
128
|
+
/** Error that prevented the listeners from being registered or freeRASP from starting. */
|
|
129
|
+
error: TalsecError | null;
|
|
88
130
|
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
package com.freeraspreactnative.events
|
|
2
|
-
|
|
3
|
-
import com.freeraspreactnative.utils.RandomGenerator
|
|
4
|
-
|
|
5
|
-
internal sealed class RaspExecutionStateEvent(override val value: Int) : BaseRaspEvent {
|
|
6
|
-
override val channelName: String get() = CHANNEL_NAME
|
|
7
|
-
override val channelKey: String get() = CHANNEL_KEY
|
|
8
|
-
|
|
9
|
-
data object AllChecksFinished : RaspExecutionStateEvent(RandomGenerator.next())
|
|
10
|
-
|
|
11
|
-
companion object Companion {
|
|
12
|
-
internal val CHANNEL_NAME = RandomGenerator.next().toString()
|
|
13
|
-
internal val CHANNEL_KEY = RandomGenerator.next().toString()
|
|
14
|
-
internal val ALL_EVENT_IDENTIFIERS = listOf(
|
|
15
|
-
AllChecksFinished
|
|
16
|
-
).map { it.value }
|
|
17
|
-
}
|
|
18
|
-
}
|