freerasp-react-native 5.2.3 → 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 +76 -0
- package/README.md +2 -0
- package/android/build.gradle +10 -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/plugin/src/index.d.ts +1 -1
- package/lib/typescript/plugin/src/index.d.ts.map +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 +2 -2
- package/plugin/build/index.d.ts +1 -1
- package/plugin/build/index.js +1 -1
- package/plugin/tests/pluginProps.test.js +15 -0
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,SAAS,GACjB,iBAAiB,GACjB,mCAAmC,GACnC,oBAAoB,GACpB,+BAA+B,GAC/B,KAAK,CAAC;AAEV,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,oBAAoB,CAAC;AAEtD,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,oBAAoB,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IAClC,kBAAkB,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IAChC,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,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
"version": "6.0.0",
|
|
4
4
|
"description": "React Native plugin for improving app security and threat monitoring on Android and iOS mobile devices.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"prettier": "prettier \"**/*.{ts,js}\"",
|
|
15
15
|
"prepack": "bob build && yarn build:plugin",
|
|
16
16
|
"build": "bob build",
|
|
17
|
-
"test:plugin": "yarn build:plugin && node plugin/tests/iosSpm.test.js",
|
|
17
|
+
"test:plugin": "yarn build:plugin && node plugin/tests/iosSpm.test.js && node plugin/tests/pluginProps.test.js",
|
|
18
18
|
"example": "yarn --cwd example",
|
|
19
19
|
"bootstrap": "yarn example && yarn install && yarn example pods",
|
|
20
20
|
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build",
|
package/plugin/build/index.d.ts
CHANGED
package/plugin/build/index.js
CHANGED
|
@@ -108,7 +108,7 @@ const withRnTalsecIos = (config, props) => {
|
|
|
108
108
|
config = withFreeraspIosPodfile(config, { spmEnabled });
|
|
109
109
|
return config;
|
|
110
110
|
};
|
|
111
|
-
const withRnTalsecApp = (config, props) => {
|
|
111
|
+
const withRnTalsecApp = (config, props = {}) => {
|
|
112
112
|
config = withBuildscriptDependency(config);
|
|
113
113
|
config = withAndroidMinSdkVersion(config, props);
|
|
114
114
|
config = withAndroidR8Version(config, props);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-env node */
|
|
2
|
+
|
|
3
|
+
const assert = require('assert').strict;
|
|
4
|
+
const withRnTalsecApp = require('../build').default;
|
|
5
|
+
|
|
6
|
+
const expoConfig = () => ({ name: 'example', slug: 'example' });
|
|
7
|
+
|
|
8
|
+
assert.doesNotThrow(() => withRnTalsecApp(expoConfig()));
|
|
9
|
+
assert.doesNotThrow(() => withRnTalsecApp(expoConfig(), undefined));
|
|
10
|
+
assert.doesNotThrow(() => withRnTalsecApp(expoConfig(), {}));
|
|
11
|
+
assert.doesNotThrow(() =>
|
|
12
|
+
withRnTalsecApp(expoConfig(), { android: { minSdkVersion: 26 } })
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
console.log('pluginProps tests passed');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NativeEventEmitter, type EmitterSubscription } from 'react-native';
|
|
2
2
|
import { FreeraspReactNative } from '../nativeModules';
|
|
3
|
-
import { onInvalidCallback, removeListenerForEvent } from '../methods/
|
|
3
|
+
import { onInvalidCallback, removeListenerForEvent } from '../methods/internal';
|
|
4
4
|
import type {
|
|
5
5
|
NativeEvent,
|
|
6
6
|
RaspExecutionStateEventActions,
|
|
@@ -47,8 +47,14 @@ export const setRaspExecutionStateListener = async (
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
switch (event[executionStateKey]) {
|
|
50
|
-
case RaspExecutionState.
|
|
51
|
-
config.
|
|
50
|
+
case RaspExecutionState.FastChecksFinished.value:
|
|
51
|
+
config.fastChecksFinished?.();
|
|
52
|
+
break;
|
|
53
|
+
case RaspExecutionState.CriticalChecksFinished.value:
|
|
54
|
+
config.criticalChecksFinished?.();
|
|
55
|
+
break;
|
|
56
|
+
case RaspExecutionState.PostponedChecksFinished.value:
|
|
57
|
+
config.postponedChecksFinished?.();
|
|
52
58
|
break;
|
|
53
59
|
default:
|
|
54
60
|
onInvalidCallback();
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { NativeEventEmitter, type EmitterSubscription } from 'react-native';
|
|
2
2
|
import { FreeraspReactNative } from '../nativeModules';
|
|
3
|
-
import { onInvalidCallback, removeListenerForEvent } from '../methods/
|
|
3
|
+
import { onInvalidCallback, removeListenerForEvent } from '../methods/internal';
|
|
4
4
|
import { Threat } from '../../models/threat';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
CallState,
|
|
7
|
+
NativeEvent,
|
|
8
|
+
ThreatEventActions,
|
|
9
|
+
} from '../../types/types';
|
|
6
10
|
import { parseMalwareData } from '../../utils/malware';
|
|
7
11
|
import {
|
|
8
12
|
getThreatChannelData,
|
|
@@ -15,6 +19,12 @@ let eventsListener: EmitterSubscription | null = null;
|
|
|
15
19
|
let threatChannel: string | null = null;
|
|
16
20
|
let threatKey: string | null = null;
|
|
17
21
|
let threatMalwareKey: string | null = null;
|
|
22
|
+
let threatCallStateKey: string | null = null;
|
|
23
|
+
|
|
24
|
+
const callStates: readonly string[] = ['STARTED', 'ONGOING', 'STOPPED'];
|
|
25
|
+
|
|
26
|
+
const isCallState = (value: unknown): value is CallState =>
|
|
27
|
+
typeof value === 'string' && callStates.includes(value);
|
|
18
28
|
|
|
19
29
|
let isMappingPrepared = false;
|
|
20
30
|
let isInitializing = false;
|
|
@@ -28,8 +38,14 @@ export const setThreatListeners = async (config: ThreatEventActions) => {
|
|
|
28
38
|
|
|
29
39
|
await removeThreatListener();
|
|
30
40
|
|
|
31
|
-
if (
|
|
32
|
-
|
|
41
|
+
if (
|
|
42
|
+
!threatChannel ||
|
|
43
|
+
!threatKey ||
|
|
44
|
+
!threatMalwareKey ||
|
|
45
|
+
!threatCallStateKey
|
|
46
|
+
) {
|
|
47
|
+
[threatChannel, threatKey, threatMalwareKey, threatCallStateKey] =
|
|
48
|
+
await getThreatChannelData();
|
|
33
49
|
}
|
|
34
50
|
|
|
35
51
|
if (!isMappingPrepared) {
|
|
@@ -38,7 +54,7 @@ export const setThreatListeners = async (config: ThreatEventActions) => {
|
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
const listener = async (event: NativeEvent) => {
|
|
41
|
-
if (!threatKey || !threatMalwareKey) {
|
|
57
|
+
if (!threatKey || !threatMalwareKey || !threatCallStateKey) {
|
|
42
58
|
onInvalidCallback();
|
|
43
59
|
return;
|
|
44
60
|
}
|
|
@@ -116,6 +132,14 @@ export const setThreatListeners = async (config: ThreatEventActions) => {
|
|
|
116
132
|
case Threat.Bootloader.value:
|
|
117
133
|
config.bootloader?.();
|
|
118
134
|
break;
|
|
135
|
+
case Threat.OngoingCall.value:
|
|
136
|
+
const callState = event[threatCallStateKey];
|
|
137
|
+
if (!isCallState(callState)) {
|
|
138
|
+
onInvalidCallback();
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
config.ongoingCall?.(callState);
|
|
142
|
+
break;
|
|
119
143
|
default:
|
|
120
144
|
onInvalidCallback();
|
|
121
145
|
break;
|
|
@@ -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
|
+
);
|