freerasp-react-native 5.3.0 → 6.1.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.
Files changed (153) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +2 -0
  3. package/android/build.gradle +3 -3
  4. package/android/proguard-rules.pro +3 -3
  5. package/android/src/main/AndroidManifest.xml +1 -1
  6. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/FreeraspReactNativeModule.kt +177 -17
  7. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/FreeraspReactNativePackage.kt +1 -1
  8. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/PluginThreatHandler.kt +20 -7
  9. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/ScreenProtector.kt +1 -1
  10. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/dispatchers/ExecutionStateDispatcher.kt +3 -3
  11. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/dispatchers/ThreatDispatcher.kt +23 -3
  12. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/events/BaseRaspEvent.kt +1 -1
  13. package/android/src/main/java/app/talsec/rasp/reactnative/events/RaspExecutionStateEvent.kt +22 -0
  14. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/events/ThreatEvent.kt +6 -3
  15. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/exceptions/TalsecException.kt +1 -1
  16. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/interfaces/PluginExecutionStateListener.kt +2 -2
  17. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/interfaces/PluginThreatListener.kt +4 -2
  18. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/models/RNSuspiciousAppInfo.kt +1 -1
  19. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/utils/Extensions.kt +4 -4
  20. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/utils/RandomGenerator.kt +1 -1
  21. package/android/src/main/java/{com/freeraspreactnative → app/talsec/rasp/reactnative}/utils/Utils.kt +1 -1
  22. package/ios/FreeraspReactNative.swift +17 -8
  23. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeDirectory +0 -0
  24. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeResources +88 -88
  25. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeSignature +0 -0
  26. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/CurlWrapper.h +1 -1
  27. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/TalsecRuntime-Swift.h +2 -2
  28. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/curl.h +292 -265
  29. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/curlver.h +10 -11
  30. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/easy.h +4 -6
  31. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/header.h +9 -9
  32. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/multi.h +147 -112
  33. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/options.h +1 -1
  34. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/system.h +14 -23
  35. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/typecheck-gcc.h +420 -403
  36. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/urlapi.h +29 -28
  37. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/websockets.h +10 -10
  38. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Info.plist +0 -0
  39. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.abi.json +563 -312
  40. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.private.swiftinterface +10 -3
  41. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  42. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.swiftinterface +10 -3
  43. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/TalsecRuntime +0 -0
  44. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/_CodeSignature/CodeResources +35 -35
  45. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/cacert.pem +483 -1088
  46. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/CurlWrapper.h +1 -1
  47. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/TalsecRuntime-Swift.h +4 -4
  48. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/curl.h +292 -265
  49. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/curlver.h +10 -11
  50. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/easy.h +4 -6
  51. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/header.h +9 -9
  52. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/multi.h +147 -112
  53. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/options.h +1 -1
  54. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/system.h +14 -23
  55. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/typecheck-gcc.h +420 -403
  56. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/urlapi.h +29 -28
  57. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/websockets.h +10 -10
  58. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Info.plist +0 -0
  59. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.abi.json +548 -297
  60. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +10 -3
  61. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  62. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.swiftinterface +10 -3
  63. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.abi.json +548 -297
  64. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +10 -3
  65. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  66. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +10 -3
  67. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/TalsecRuntime +0 -0
  68. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/_CodeSignature/CodeResources +43 -43
  69. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/cacert.pem +483 -1088
  70. package/ios/TalsecRuntimePackage/Package.swift +2 -2
  71. package/ios/dispatchers/ExecutionStateDispatcher.swift +4 -3
  72. package/ios/models/RaspExecutionStates.swift +10 -3
  73. package/ios/utils/EventIdentifiers.swift +2 -2
  74. package/lib/commonjs/api/listeners/raspExecutionState.js +13 -7
  75. package/lib/commonjs/api/listeners/raspExecutionState.js.map +1 -1
  76. package/lib/commonjs/api/listeners/threat.js +19 -8
  77. package/lib/commonjs/api/listeners/threat.js.map +1 -1
  78. package/lib/commonjs/api/methods/internal.js +20 -0
  79. package/lib/commonjs/api/methods/internal.js.map +1 -0
  80. package/lib/commonjs/api/methods/native.js +113 -21
  81. package/lib/commonjs/api/methods/native.js.map +1 -1
  82. package/lib/commonjs/api/methods/reactNative.js +38 -10
  83. package/lib/commonjs/api/methods/reactNative.js.map +1 -1
  84. package/lib/commonjs/channels/raspExecutionState.js +3 -3
  85. package/lib/commonjs/channels/raspExecutionState.js.map +1 -1
  86. package/lib/commonjs/channels/threat.js +4 -4
  87. package/lib/commonjs/channels/threat.js.map +1 -1
  88. package/lib/commonjs/index.js +23 -0
  89. package/lib/commonjs/index.js.map +1 -1
  90. package/lib/commonjs/models/raspExecutionState.js +4 -2
  91. package/lib/commonjs/models/raspExecutionState.js.map +1 -1
  92. package/lib/commonjs/models/threat.js +2 -1
  93. package/lib/commonjs/models/threat.js.map +1 -1
  94. package/lib/commonjs/types/errors.js +50 -0
  95. package/lib/commonjs/types/errors.js.map +1 -0
  96. package/lib/commonjs/types/types.js +4 -0
  97. package/lib/module/api/listeners/raspExecutionState.js +10 -4
  98. package/lib/module/api/listeners/raspExecutionState.js.map +1 -1
  99. package/lib/module/api/listeners/threat.js +16 -5
  100. package/lib/module/api/listeners/threat.js.map +1 -1
  101. package/lib/module/api/methods/internal.js +13 -0
  102. package/lib/module/api/methods/internal.js.map +1 -0
  103. package/lib/module/api/methods/native.js +106 -17
  104. package/lib/module/api/methods/native.js.map +1 -1
  105. package/lib/module/api/methods/reactNative.js +39 -12
  106. package/lib/module/api/methods/reactNative.js.map +1 -1
  107. package/lib/module/channels/raspExecutionState.js +1 -1
  108. package/lib/module/channels/raspExecutionState.js.map +1 -1
  109. package/lib/module/channels/threat.js +2 -2
  110. package/lib/module/channels/threat.js.map +1 -1
  111. package/lib/module/index.js +2 -0
  112. package/lib/module/index.js.map +1 -1
  113. package/lib/module/models/raspExecutionState.js +4 -2
  114. package/lib/module/models/raspExecutionState.js.map +1 -1
  115. package/lib/module/models/threat.js +2 -1
  116. package/lib/module/models/threat.js.map +1 -1
  117. package/lib/module/types/errors.js +41 -0
  118. package/lib/module/types/errors.js.map +1 -0
  119. package/lib/module/types/types.js +1 -1
  120. package/lib/typescript/src/api/listeners/raspExecutionState.d.ts.map +1 -1
  121. package/lib/typescript/src/api/listeners/threat.d.ts.map +1 -1
  122. package/lib/typescript/src/api/methods/internal.d.ts +7 -0
  123. package/lib/typescript/src/api/methods/internal.d.ts.map +1 -0
  124. package/lib/typescript/src/api/methods/native.d.ts +56 -7
  125. package/lib/typescript/src/api/methods/native.d.ts.map +1 -1
  126. package/lib/typescript/src/api/methods/reactNative.d.ts +11 -2
  127. package/lib/typescript/src/api/methods/reactNative.d.ts.map +1 -1
  128. package/lib/typescript/src/channels/threat.d.ts +1 -0
  129. package/lib/typescript/src/channels/threat.d.ts.map +1 -1
  130. package/lib/typescript/src/index.d.ts +2 -0
  131. package/lib/typescript/src/index.d.ts.map +1 -1
  132. package/lib/typescript/src/models/raspExecutionState.d.ts +3 -1
  133. package/lib/typescript/src/models/raspExecutionState.d.ts.map +1 -1
  134. package/lib/typescript/src/models/threat.d.ts +1 -0
  135. package/lib/typescript/src/models/threat.d.ts.map +1 -1
  136. package/lib/typescript/src/types/errors.d.ts +26 -0
  137. package/lib/typescript/src/types/errors.d.ts.map +1 -0
  138. package/lib/typescript/src/types/types.d.ts +61 -26
  139. package/lib/typescript/src/types/types.d.ts.map +1 -1
  140. package/package.json +1 -1
  141. package/src/api/listeners/raspExecutionState.ts +9 -3
  142. package/src/api/listeners/threat.ts +29 -5
  143. package/src/api/methods/internal.ts +13 -0
  144. package/src/api/methods/native.ts +125 -21
  145. package/src/api/methods/reactNative.ts +46 -16
  146. package/src/channels/raspExecutionState.ts +1 -1
  147. package/src/channels/threat.ts +3 -3
  148. package/src/index.tsx +2 -0
  149. package/src/models/raspExecutionState.ts +8 -2
  150. package/src/models/threat.ts +2 -0
  151. package/src/types/errors.ts +57 -0
  152. package/src/types/types.ts +66 -26
  153. package/android/src/main/java/com/freeraspreactnative/events/RaspExecutionStateEvent.kt +0 -18
@@ -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
- export const talsecStart = async (options: TalsecConfig): Promise<string> => {
7
- return FreeraspReactNative.talsecStart(withDefaults(options));
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
- export const addToWhitelist = async (packageName: string): Promise<boolean> => {
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 Promise.reject('Malware detection not available on iOS');
22
+ return androidOnly('Malware detection');
13
23
  }
14
- return FreeraspReactNative.addToWhitelist(packageName);
24
+ await wrapNative('malware-failure', () =>
25
+ FreeraspReactNative.addToWhitelist(packageName)
26
+ );
15
27
  };
16
28
 
17
- export const blockScreenCapture = (enable: boolean): Promise<string> => {
18
- return FreeraspReactNative.blockScreenCapture(enable);
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 FreeraspReactNative.isScreenCaptureBlocked();
42
+ return wrapNative('talsec-failure', () =>
43
+ FreeraspReactNative.isScreenCaptureBlocked()
44
+ );
23
45
  };
24
46
 
25
- export const storeExternalId = (data: string): Promise<string> => {
26
- return FreeraspReactNative.storeExternalId(data);
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
- export const removeExternalId = (): Promise<string> => {
30
- return FreeraspReactNative.removeExternalId();
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
- export const getAppIcon = (packageName: string): Promise<string> => {
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 Promise.reject(
36
- 'App icon retrieval for Malware detection not available on iOS'
37
- );
117
+ return androidOnly('Ongoing call detection');
38
118
  }
39
- return FreeraspReactNative.getAppIcon(packageName);
119
+ await wrapNative('talsec-failure', () =>
120
+ FreeraspReactNative.stopOngoingCallDetection()
121
+ );
40
122
  };
41
123
 
42
- export const onInvalidCallback = (): void => {
43
- FreeraspReactNative.onInvalidCallback();
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
- export const removeListenerForEvent = (channel: string): Promise<string> => {
47
- return FreeraspReactNative.removeListenerForEvent(channel);
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 { onInvalidCallback } from './native';
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
- await setThreatListeners(actions);
25
- raspExecutionStateActions &&
26
- (await setRaspExecutionStateListener(raspExecutionStateActions));
49
+ try {
50
+ await setThreatListeners(actions);
51
+ if (raspExecutionStateActions) {
52
+ await setRaspExecutionStateListener(raspExecutionStateActions);
53
+ }
27
54
 
28
- if (isRaspStarted) {
29
- return;
30
- }
55
+ if (!isRaspStarted) {
56
+ await talsecStart(config);
57
+ isRaspStarted = true;
58
+ }
31
59
 
32
- try {
33
- const response = await talsecStart(config);
34
- if (response !== 'freeRASP started') {
35
- onInvalidCallback();
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/native';
3
+ import { onInvalidCallback } from '../api/methods/internal';
4
4
  import { RaspExecutionState } from '../models/raspExecutionState';
5
5
 
6
6
  export const getRaspExecutionStateIdentifiers = async (): Promise<number[]> => {
@@ -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/native';
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 !== 3 || !itemsHaveType(data, 'string')) {
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,19 @@
1
1
  export class RaspExecutionState {
2
2
  value: number;
3
3
 
4
- static AllChecksFinished = new RaspExecutionState(0);
4
+ static FastChecksFinished = new RaspExecutionState(0);
5
+ static CriticalChecksFinished = new RaspExecutionState(0);
6
+ static PostponedChecksFinished = new RaspExecutionState(0);
5
7
 
6
8
  constructor(value: number) {
7
9
  this.value = value;
8
10
  }
9
11
 
10
12
  static getValues(): RaspExecutionState[] {
11
- return [this.AllChecksFinished];
13
+ return [
14
+ this.FastChecksFinished,
15
+ this.CriticalChecksFinished,
16
+ this.PostponedChecksFinished,
17
+ ];
12
18
  }
13
19
  }
@@ -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
+ );
@@ -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
- appBundleId: string;
42
+ appBundleIds: string[];
41
43
  appTeamId: string;
42
44
  };
43
45
 
@@ -55,34 +57,72 @@ 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?: () => any;
60
- debug?: () => any;
61
- simulator?: () => any;
62
- appIntegrity?: () => any;
63
- unofficialStore?: () => any;
64
- hooks?: () => any;
65
- deviceBinding?: () => any;
66
- deviceID?: () => any;
67
- passcode?: () => any;
68
- secureHardwareNotAvailable?: () => any;
69
- obfuscationIssues?: () => any;
70
- devMode?: () => any;
71
- systemVPN?: () => any;
72
- malware?: (suspiciousApps: SuspiciousAppInfo[]) => any;
73
- adbEnabled?: () => any;
74
- screenshot?: () => any;
75
- screenRecording?: () => any;
76
- multiInstance?: () => any;
77
- timeSpoofing?: () => any;
78
- locationSpoofing?: () => any;
79
- unsecureWifi?: () => any;
80
- automation?: () => any;
81
- bootloader?: () => any;
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 = { [key: string]: number | string[] | undefined };
99
+ export type NativeEvent = {
100
+ [key: string]: number | string | string[] | undefined;
101
+ };
85
102
 
86
103
  export type RaspExecutionStateEventActions = {
87
- allChecksFinished?: () => any;
104
+ /**
105
+ * The fast (standard) checks have been completed. The postponed checks may
106
+ * still run afterwards.
107
+ */
108
+ fastChecksFinished?: () => void;
109
+ /**
110
+ * The critical checks have been completed, before the non-critical checks.
111
+ */
112
+ criticalChecksFinished?: () => void;
113
+ /**
114
+ * The postponed checks have been completed, which ends the initial
115
+ * evaluation.
116
+ */
117
+ postponedChecksFinished?: () => void;
118
+ };
119
+
120
+ /**
121
+ * State returned by `useFreeRasp`.
122
+ */
123
+ export type FreeRaspStatus = {
124
+ /** `true` once freeRASP has been started. */
125
+ started: boolean;
126
+ /** Error that prevented the listeners from being registered or freeRASP from starting. */
127
+ error: TalsecError | null;
88
128
  };
@@ -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
- }