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.
Files changed (103) hide show
  1. package/CHANGELOG.md +49 -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 +7 -5
  23. package/ios/models/RaspExecutionStates.swift +3 -3
  24. package/lib/commonjs/api/listeners/raspExecutionState.js +13 -7
  25. package/lib/commonjs/api/listeners/raspExecutionState.js.map +1 -1
  26. package/lib/commonjs/api/listeners/threat.js +19 -8
  27. package/lib/commonjs/api/listeners/threat.js.map +1 -1
  28. package/lib/commonjs/api/methods/internal.js +20 -0
  29. package/lib/commonjs/api/methods/internal.js.map +1 -0
  30. package/lib/commonjs/api/methods/native.js +113 -21
  31. package/lib/commonjs/api/methods/native.js.map +1 -1
  32. package/lib/commonjs/api/methods/reactNative.js +38 -10
  33. package/lib/commonjs/api/methods/reactNative.js.map +1 -1
  34. package/lib/commonjs/channels/raspExecutionState.js +3 -3
  35. package/lib/commonjs/channels/raspExecutionState.js.map +1 -1
  36. package/lib/commonjs/channels/threat.js +4 -4
  37. package/lib/commonjs/channels/threat.js.map +1 -1
  38. package/lib/commonjs/index.js +23 -0
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/commonjs/models/raspExecutionState.js +5 -2
  41. package/lib/commonjs/models/raspExecutionState.js.map +1 -1
  42. package/lib/commonjs/models/threat.js +2 -1
  43. package/lib/commonjs/models/threat.js.map +1 -1
  44. package/lib/commonjs/types/errors.js +50 -0
  45. package/lib/commonjs/types/errors.js.map +1 -0
  46. package/lib/commonjs/types/types.js +4 -0
  47. package/lib/module/api/listeners/raspExecutionState.js +10 -4
  48. package/lib/module/api/listeners/raspExecutionState.js.map +1 -1
  49. package/lib/module/api/listeners/threat.js +16 -5
  50. package/lib/module/api/listeners/threat.js.map +1 -1
  51. package/lib/module/api/methods/internal.js +13 -0
  52. package/lib/module/api/methods/internal.js.map +1 -0
  53. package/lib/module/api/methods/native.js +106 -17
  54. package/lib/module/api/methods/native.js.map +1 -1
  55. package/lib/module/api/methods/reactNative.js +39 -12
  56. package/lib/module/api/methods/reactNative.js.map +1 -1
  57. package/lib/module/channels/raspExecutionState.js +1 -1
  58. package/lib/module/channels/raspExecutionState.js.map +1 -1
  59. package/lib/module/channels/threat.js +2 -2
  60. package/lib/module/channels/threat.js.map +1 -1
  61. package/lib/module/index.js +2 -0
  62. package/lib/module/index.js.map +1 -1
  63. package/lib/module/models/raspExecutionState.js +5 -2
  64. package/lib/module/models/raspExecutionState.js.map +1 -1
  65. package/lib/module/models/threat.js +2 -1
  66. package/lib/module/models/threat.js.map +1 -1
  67. package/lib/module/types/errors.js +41 -0
  68. package/lib/module/types/errors.js.map +1 -0
  69. package/lib/module/types/types.js +1 -1
  70. package/lib/typescript/src/api/listeners/raspExecutionState.d.ts.map +1 -1
  71. package/lib/typescript/src/api/listeners/threat.d.ts.map +1 -1
  72. package/lib/typescript/src/api/methods/internal.d.ts +7 -0
  73. package/lib/typescript/src/api/methods/internal.d.ts.map +1 -0
  74. package/lib/typescript/src/api/methods/native.d.ts +56 -7
  75. package/lib/typescript/src/api/methods/native.d.ts.map +1 -1
  76. package/lib/typescript/src/api/methods/reactNative.d.ts +11 -2
  77. package/lib/typescript/src/api/methods/reactNative.d.ts.map +1 -1
  78. package/lib/typescript/src/channels/threat.d.ts +1 -0
  79. package/lib/typescript/src/channels/threat.d.ts.map +1 -1
  80. package/lib/typescript/src/index.d.ts +2 -0
  81. package/lib/typescript/src/index.d.ts.map +1 -1
  82. package/lib/typescript/src/models/raspExecutionState.d.ts +3 -1
  83. package/lib/typescript/src/models/raspExecutionState.d.ts.map +1 -1
  84. package/lib/typescript/src/models/threat.d.ts +1 -0
  85. package/lib/typescript/src/models/threat.d.ts.map +1 -1
  86. package/lib/typescript/src/types/errors.d.ts +26 -0
  87. package/lib/typescript/src/types/errors.d.ts.map +1 -0
  88. package/lib/typescript/src/types/types.d.ts +63 -26
  89. package/lib/typescript/src/types/types.d.ts.map +1 -1
  90. package/package.json +1 -1
  91. package/src/api/listeners/raspExecutionState.ts +9 -3
  92. package/src/api/listeners/threat.ts +29 -5
  93. package/src/api/methods/internal.ts +13 -0
  94. package/src/api/methods/native.ts +125 -21
  95. package/src/api/methods/reactNative.ts +46 -16
  96. package/src/channels/raspExecutionState.ts +1 -1
  97. package/src/channels/threat.ts +3 -3
  98. package/src/index.tsx +2 -0
  99. package/src/models/raspExecutionState.ts +12 -2
  100. package/src/models/threat.ts +2 -0
  101. package/src/types/errors.ts +57 -0
  102. package/src/types/types.ts +68 -26
  103. package/android/src/main/java/com/freeraspreactnative/events/RaspExecutionStateEvent.kt +0 -18
package/CHANGELOG.md CHANGED
@@ -5,6 +5,55 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [6.0.0] - 2026-11-11
9
+
10
+ - Android SDK version: 20.0.1
11
+ - iOS SDK version: 8.0.1
12
+
13
+ ### Breaking
14
+
15
+ - `allChecksFinished` RASP execution state action renamed to `fastChecksFinished`. On Android, it is triggered when the fast checks are completed, while the postponed checks may still run; on iOS, when all checks are completed
16
+ - `TalsecIosConfig.appBundleId` (string) replaced by `appBundleIds` (string[]), matching the iOS SDK
17
+ - Methods that resolved with a status string or a constant now resolve to `void`: `talsecStart`, `addToWhitelist`, `blockScreenCapture`, `blockScreenControl`, `startOngoingCallDetection`, `stopOngoingCallDetection`, `storeExternalId`, `removeExternalId`
18
+ - All methods now reject with `TalsecError` (`code`: `talsec-failure`, `unsupported-platform`, `configuration-exception`, `external-id-failure`, `malware-failure`) instead of native errors or plain strings
19
+ - `onInvalidCallback` and `removeListenerForEvent` are no longer exported; use `abortApp` to terminate the app
20
+
21
+ ### React Native
22
+
23
+ #### Added
24
+
25
+ - `useFreeRasp` returns `{ started, error }`; `error` is the `TalsecError` that prevented the listeners from being registered or freeRASP from starting, which was previously only logged to the console
26
+ - `ongoingCall` threat action with the new `CallState` type (`'STARTED' | 'ONGOING' | 'STOPPED'`), driven by `startOngoingCallDetection()` and `stopOngoingCallDetection()` (Android only)
27
+ - `blockScreenControl()` and `isScreenControlBlocked()` to prevent accessibility services from reading or controlling the app screen (Android only)
28
+ - `blockOverlayWindows()` and `isOverlayWindowsBlocked()` to hide overlay windows of other apps (Android 12+ only, requires the `HIDE_OVERLAY_WINDOWS` permission)
29
+ - `criticalChecksFinished` and `postponedChecksFinished` RASP execution state actions (Android only)
30
+
31
+ #### Changed
32
+
33
+ - Android package (namespace) of the plugin renamed from `com.freeraspreactnative` to `app.talsec.rasp.reactnative`, following the Android SDK's `app.talsec.rasp` (update the import if you register `FreeraspReactNativePackage` manually)
34
+ - On Android, `isScreenCaptureBlocked()` reports the protection state of the current activity
35
+ - Threat and RASP execution state actions are typed as returning `void` instead of `any`
36
+
37
+ ### Android
38
+
39
+ #### Fixed
40
+
41
+ - Improved hook detection to prevent collisions with running VPN services and to better work with the device resources (threads/RAM)
42
+ - Fixed a release crash during root detection when a checked package is not installed
43
+ - Fixed a crash in `ScreenProtector.unregisterScreenCallbacks` on Android 15+ when several activities registered screen callbacks
44
+ - Fixed intermittent build failures of apps using the SDK (`NullPointerException: Cannot read field "d"`, shown by Gradle as `[CIRCULAR REFERENCE]`) caused by invalid bytecode in some SDK builds
45
+ - Fixed `killOnBypass` closing the app when the same threat was reported twice in quick succession
46
+
47
+ #### Changed
48
+
49
+ - Deprecated the freeRASP Maven coordinates (`com.aheaditec.talsec.security:TalsecSecurity-{flavor}`)
50
+ - Improved Bootloader detection
51
+ - Extended emulator detection with additional device-property and ABI checks
52
+ - Improved logging structure and data enrichment for better Portal insights/reports
53
+ - Refactoring of the time spoofing detection which improves the performance of the freeRASP check execution
54
+ - Improved the performance of the App integrity check
55
+ - Updated CA bundle
56
+
8
57
  ## [5.3.0] - 2026-11-09
9
58
 
10
59
  - Android SDK version: 19.3.1
package/README.md CHANGED
@@ -27,6 +27,8 @@ Key features are the detection and prevention of
27
27
  - Unlocked or compromised bootloader
28
28
  - Hooking framework (e.g., Frida, LSPosed, Shadow)
29
29
  - UI automation and driven-input attacks (e.g., Appium)
30
+ - Ongoing cellular and VoIP calls during sensitive flows (Android)
31
+ - Screen control by accessibility services and overlay windows of other apps (Android)
30
32
  - Untrusted installation method
31
33
  - App Data Migration protection
32
34
 
@@ -57,7 +57,7 @@ android {
57
57
  compileSdk getMaxVersion("compileSdk")
58
58
 
59
59
  talsec {
60
- sdkVersion = "19.3.1"
60
+ sdkVersion = "20.0.1"
61
61
  platform = "ReactNative"
62
62
  }
63
63
 
@@ -87,7 +87,7 @@ android {
87
87
  }
88
88
 
89
89
  if (project.android.hasProperty("namespace")) {
90
- namespace("com.freeraspreactnative")
90
+ namespace("app.talsec.rasp.reactnative")
91
91
  }
92
92
  }
93
93
 
@@ -119,6 +119,6 @@ if (isNewArchitectureEnabled()) {
119
119
  react {
120
120
  jsRootDir = file("../src/")
121
121
  libraryName = "FreeraspReactNative"
122
- codegenJavaPackageName = "com.freeraspreactnative"
122
+ codegenJavaPackageName = "app.talsec.rasp.reactnative"
123
123
  }
124
124
  }
@@ -1,12 +1,12 @@
1
1
  -dontwarn java.lang.invoke.StringConcatFactory
2
- -keep class com.freeraspreactnative.FreeraspReactNativePackage { public *; }
2
+ -keep class app.talsec.rasp.reactnative.FreeraspReactNativePackage { public *; }
3
3
 
4
4
  -if @kotlinx.serialization.Serializable class **
5
5
  -keep class <1> {
6
6
  *;
7
7
  }
8
8
 
9
- -keep class com.freeraspreactnative.models.RNSuspiciousAppInfo$Companion
10
- -keep class com.freeraspreactnative.models.RNPackageInfo$Companion
9
+ -keep class app.talsec.rasp.reactnative.models.RNSuspiciousAppInfo$Companion
10
+ -keep class app.talsec.rasp.reactnative.models.RNPackageInfo$Companion
11
11
 
12
12
  -repackageclasses 'ts'
@@ -1,4 +1,4 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="com.freeraspreactnative">
2
+ package="app.talsec.rasp.reactnative">
3
3
 
4
4
  </manifest>
@@ -1,5 +1,7 @@
1
- package com.freeraspreactnative
1
+ package app.talsec.rasp.reactnative
2
2
 
3
+ import android.annotation.SuppressLint
4
+ import android.app.Activity
3
5
  import android.os.Build
4
6
  import android.os.Handler
5
7
  import android.os.HandlerThread
@@ -9,6 +11,7 @@ import app.talsec.rasp.security.api.SuspiciousAppInfo
9
11
  import app.talsec.rasp.security.api.Talsec
10
12
  import app.talsec.rasp.security.api.TalsecConfig
11
13
  import app.talsec.rasp.security.api.TalsecMode
14
+ import app.talsec.rasp.security.api.ThreatListener.CallState
12
15
  import com.facebook.react.bridge.Arguments
13
16
  import com.facebook.react.bridge.LifecycleEventListener
14
17
  import com.facebook.react.bridge.Promise
@@ -20,20 +23,21 @@ import com.facebook.react.bridge.UiThreadUtil.runOnUiThread
20
23
  import com.facebook.react.bridge.WritableArray
21
24
  import com.facebook.react.bridge.WritableMap
22
25
  import com.facebook.react.modules.core.DeviceEventManagerModule
23
- import com.freeraspreactnative.dispatchers.ExecutionStateDispatcher
24
- import com.freeraspreactnative.dispatchers.ThreatDispatcher
25
- import com.freeraspreactnative.events.RaspExecutionStateEvent
26
- import com.freeraspreactnative.events.ThreatEvent
27
- import com.freeraspreactnative.interfaces.PluginExecutionStateListener
28
- import com.freeraspreactnative.interfaces.PluginThreatListener
29
- import com.freeraspreactnative.utils.Utils
30
- import com.freeraspreactnative.utils.getArraySafe
31
- import com.freeraspreactnative.utils.getBooleanSafe
32
- import com.freeraspreactnative.utils.getMapThrowing
33
- import com.freeraspreactnative.utils.getNestedArraySafe
34
- import com.freeraspreactnative.utils.getStringThrowing
35
- import com.freeraspreactnative.utils.toEncodedWritableArray
36
- import com.freeraspreactnative.utils.toSuspiciousAppDetectionConfig
26
+ import app.talsec.rasp.reactnative.dispatchers.ExecutionStateDispatcher
27
+ import app.talsec.rasp.reactnative.dispatchers.ThreatDispatcher
28
+ import app.talsec.rasp.reactnative.events.RaspExecutionStateEvent
29
+ import app.talsec.rasp.reactnative.events.ThreatEvent
30
+ import app.talsec.rasp.reactnative.interfaces.PluginExecutionStateListener
31
+ import app.talsec.rasp.reactnative.interfaces.PluginThreatListener
32
+ import app.talsec.rasp.reactnative.utils.Utils
33
+ import app.talsec.rasp.reactnative.utils.getArraySafe
34
+ import app.talsec.rasp.reactnative.utils.getBooleanSafe
35
+ import app.talsec.rasp.reactnative.utils.getMapThrowing
36
+ import app.talsec.rasp.reactnative.utils.getNestedArraySafe
37
+ import app.talsec.rasp.reactnative.utils.getStringThrowing
38
+ import app.talsec.rasp.reactnative.utils.toEncodedWritableArray
39
+ import app.talsec.rasp.reactnative.utils.toSuspiciousAppDetectionConfig
40
+ import java.lang.ref.WeakReference
37
41
 
38
42
  class FreeraspReactNativeModule(private val reactContext: ReactApplicationContext) :
39
43
  ReactContextBaseJavaModule(reactContext) {
@@ -54,6 +58,7 @@ class FreeraspReactNativeModule(private val reactContext: ReactApplicationContex
54
58
  reactContext.currentActivity?.let { ScreenProtector.unregister(it) }
55
59
  }
56
60
  if (reactContext.currentActivity?.isFinishing == true) {
61
+ stopOngoingCallDetectionInternal()
57
62
  ThreatDispatcher.unregisterListener()
58
63
  ExecutionStateDispatcher.unregisterListener()
59
64
  PluginThreatHandler.unregisterSDKListener(reactContext)
@@ -134,7 +139,7 @@ class FreeraspReactNativeModule(private val reactContext: ReactApplicationContex
134
139
 
135
140
  /**
136
141
  * Method to setup the threat message passing between native and React Native
137
- * @return list of [THREAT_CHANNEL_NAME, THREAT_CHANNEL_KEY]
142
+ * @return list of [THREAT_CHANNEL_NAME, THREAT_CHANNEL_KEY, MALWARE_CHANNEL_KEY, CALL_STATE_CHANNEL_KEY]
138
143
  */
139
144
  @ReactMethod
140
145
  fun getThreatChannelData(promise: Promise) {
@@ -142,6 +147,7 @@ class FreeraspReactNativeModule(private val reactContext: ReactApplicationContex
142
147
  channelData.pushString(ThreatEvent.CHANNEL_NAME)
143
148
  channelData.pushString(ThreatEvent.CHANNEL_KEY)
144
149
  channelData.pushString(ThreatEvent.MALWARE_CHANNEL_KEY)
150
+ channelData.pushString(ThreatEvent.CALL_STATE_CHANNEL_KEY)
145
151
  promise.resolve(channelData)
146
152
  }
147
153
 
@@ -245,14 +251,158 @@ class FreeraspReactNativeModule(private val reactContext: ReactApplicationContex
245
251
  */
246
252
  @ReactMethod
247
253
  fun isScreenCaptureBlocked(promise: Promise) {
254
+ val activity = reactContext.currentActivity ?: run {
255
+ promise.reject(
256
+ "NativePluginError", "Cannot check screen capture state, activity is null."
257
+ )
258
+ return
259
+ }
260
+
248
261
  try {
249
- val isBlocked = Talsec.isScreenCaptureBlocked()
262
+ val isBlocked = Talsec.isScreenCaptureBlocked(activity)
250
263
  promise.resolve(isBlocked)
251
264
  } catch (e: Exception) {
252
265
  promise.reject("NativePluginError", "Error in isScreenCaptureBlocked: ${e.message}")
253
266
  }
254
267
  }
255
268
 
269
+ /**
270
+ * Method Block/Unblock accessibility services from reading or controlling the screen
271
+ * @param enable boolean for whether want to block or unblock the screen control
272
+ */
273
+ @ReactMethod
274
+ fun blockScreenControl(enable: Boolean, promise: Promise) {
275
+ val activity = reactContext.currentActivity ?: run {
276
+ promise.reject(
277
+ "NativePluginError", "Cannot block screen control, activity is null."
278
+ )
279
+ return
280
+ }
281
+
282
+ runOnUiThread {
283
+ try {
284
+ Talsec.blockScreenControl(activity, enable)
285
+ promise.resolve("Screen control is now ${if (enable) "Blocked" else "Enabled"}.")
286
+ } catch (e: Exception) {
287
+ promise.reject("NativePluginError", "Error in blockScreenControl: ${e.message}")
288
+ }
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Method Returns whether screen control is blocked or not
294
+ * @return boolean for is screen control blocked or not
295
+ */
296
+ @ReactMethod
297
+ fun isScreenControlBlocked(promise: Promise) {
298
+ val activity = reactContext.currentActivity ?: run {
299
+ promise.reject(
300
+ "NativePluginError", "Cannot check screen control state, activity is null."
301
+ )
302
+ return
303
+ }
304
+
305
+ try {
306
+ promise.resolve(Talsec.isScreenControlBlocked(activity))
307
+ } catch (e: Exception) {
308
+ promise.reject("NativePluginError", "Error in isScreenControlBlocked: ${e.message}")
309
+ }
310
+ }
311
+
312
+ /**
313
+ * Method Hide/Show overlay windows of other apps over the activity.
314
+ * Requires Android 12+ and the HIDE_OVERLAY_WINDOWS permission.
315
+ * @param enable boolean for whether want to hide or show overlay windows
316
+ * @return boolean whether the request was applied
317
+ */
318
+ // Missing permission is suppressed because the decision to use the overlay API is made
319
+ // by developer, and not enforced by the library.
320
+ @SuppressLint("MissingPermission")
321
+ @ReactMethod
322
+ fun blockOverlayWindows(enable: Boolean, promise: Promise) {
323
+ val activity = reactContext.currentActivity ?: run {
324
+ promise.reject(
325
+ "NativePluginError", "Cannot block overlay windows, activity is null."
326
+ )
327
+ return
328
+ }
329
+
330
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
331
+ promise.resolve(false)
332
+ return
333
+ }
334
+
335
+ runOnUiThread {
336
+ try {
337
+ promise.resolve(Talsec.blockOverlayWindows(activity, enable))
338
+ } catch (e: Exception) {
339
+ promise.reject("NativePluginError", "Error in blockOverlayWindows: ${e.message}")
340
+ }
341
+ }
342
+ }
343
+
344
+ /**
345
+ * Method Returns whether overlay windows of other apps are hidden or not
346
+ * @return boolean for are overlay windows hidden or not
347
+ */
348
+ @ReactMethod
349
+ fun isOverlayWindowsBlocked(promise: Promise) {
350
+ val activity = reactContext.currentActivity ?: run {
351
+ promise.reject(
352
+ "NativePluginError", "Cannot check overlay windows state, activity is null."
353
+ )
354
+ return
355
+ }
356
+
357
+ try {
358
+ promise.resolve(Talsec.isOverlayWindowsBlocked(activity))
359
+ } catch (e: Exception) {
360
+ promise.reject("NativePluginError", "Error in isOverlayWindowsBlocked: ${e.message}")
361
+ }
362
+ }
363
+
364
+ /**
365
+ * Method starts the ongoing call (cellular and VoIP) detection for the current activity
366
+ */
367
+ @ReactMethod
368
+ fun startOngoingCallDetection(promise: Promise) {
369
+ val activity = reactContext.currentActivity ?: run {
370
+ promise.reject(
371
+ "NativePluginError", "Cannot start ongoing call detection, activity is null."
372
+ )
373
+ return
374
+ }
375
+
376
+ try {
377
+ if (ongoingCallActivity?.get() !== activity) {
378
+ stopOngoingCallDetectionInternal()
379
+ Talsec.startOngoingCallDetection(activity)
380
+ ongoingCallActivity = WeakReference(activity)
381
+ }
382
+ promise.resolve("Ongoing call detection started.")
383
+ } catch (e: Exception) {
384
+ promise.reject("NativePluginError", "Error in startOngoingCallDetection: ${e.message}")
385
+ }
386
+ }
387
+
388
+ /**
389
+ * Method stops the ongoing call detection
390
+ */
391
+ @ReactMethod
392
+ fun stopOngoingCallDetection(promise: Promise) {
393
+ try {
394
+ stopOngoingCallDetectionInternal()
395
+ promise.resolve("Ongoing call detection stopped.")
396
+ } catch (e: Exception) {
397
+ promise.reject("NativePluginError", "Error in stopOngoingCallDetection: ${e.message}")
398
+ }
399
+ }
400
+
401
+ private fun stopOngoingCallDetectionInternal() {
402
+ ongoingCallActivity?.get()?.let { Talsec.stopOngoingCallDetection(it) }
403
+ ongoingCallActivity = null
404
+ }
405
+
256
406
  @ReactMethod
257
407
  fun storeExternalId(
258
408
  externalId: String, promise: Promise
@@ -319,6 +469,9 @@ class FreeraspReactNativeModule(private val reactContext: ReactApplicationContex
319
469
  private val mainHandler = Handler(Looper.getMainLooper())
320
470
 
321
471
  internal var talsecStarted = false
472
+
473
+ // Ongoing call detection is registered per activity
474
+ private var ongoingCallActivity: WeakReference<Activity>? = null
322
475
  }
323
476
 
324
477
  internal class PluginListener(private val reactContext: ReactApplicationContext) :
@@ -344,6 +497,13 @@ class FreeraspReactNativeModule(private val reactContext: ReactApplicationContex
344
497
  }
345
498
  }
346
499
 
500
+ override fun ongoingCallDetected(state: CallState) {
501
+ val params = Arguments.createMap()
502
+ params.putInt(ThreatEvent.CHANNEL_KEY, ThreatEvent.OngoingCall.value)
503
+ params.putString(ThreatEvent.CALL_STATE_CHANNEL_KEY, state.name)
504
+ notifyEvent(ThreatEvent.CHANNEL_NAME, params)
505
+ }
506
+
347
507
  override fun raspExecutionStateChanged(event: RaspExecutionStateEvent) {
348
508
  val params = Arguments.createMap()
349
509
  params.putInt(event.channelKey, event.value)
@@ -1,4 +1,4 @@
1
- package com.freeraspreactnative
1
+ package app.talsec.rasp.reactnative
2
2
 
3
3
  import com.facebook.react.ReactPackage
4
4
  import com.facebook.react.bridge.NativeModule
@@ -1,12 +1,13 @@
1
- package com.freeraspreactnative
1
+ package app.talsec.rasp.reactnative
2
2
 
3
3
  import android.content.Context
4
4
  import app.talsec.rasp.security.api.SuspiciousAppInfo
5
5
  import app.talsec.rasp.security.api.ThreatListener
6
- import com.freeraspreactnative.dispatchers.ExecutionStateDispatcher
7
- import com.freeraspreactnative.dispatchers.ThreatDispatcher
8
- import com.freeraspreactnative.events.RaspExecutionStateEvent
9
- import com.freeraspreactnative.events.ThreatEvent
6
+ import app.talsec.rasp.security.api.ThreatListener.CallState
7
+ import app.talsec.rasp.reactnative.dispatchers.ExecutionStateDispatcher
8
+ import app.talsec.rasp.reactnative.dispatchers.ThreatDispatcher
9
+ import app.talsec.rasp.reactnative.events.RaspExecutionStateEvent
10
+ import app.talsec.rasp.reactnative.events.ThreatEvent
10
11
 
11
12
  internal object PluginThreatHandler {
12
13
 
@@ -79,6 +80,10 @@ internal object PluginThreatHandler {
79
80
  override fun onBootloader() {
80
81
  ThreatDispatcher.dispatchThreat(ThreatEvent.Bootloader)
81
82
  }
83
+
84
+ override fun onOngoingCall(state: CallState) {
85
+ ThreatDispatcher.dispatchOngoingCall(state)
86
+ }
82
87
  }
83
88
 
84
89
  private val deviceState = object : ThreatListener.DeviceState() {
@@ -105,8 +110,16 @@ internal object PluginThreatHandler {
105
110
  }
106
111
 
107
112
  private val raspExecutionState = object : ThreatListener.RaspExecutionState() {
108
- override fun onAllChecksFinished() {
109
- ExecutionStateDispatcher.dispatch(RaspExecutionStateEvent.AllChecksFinished)
113
+ override fun onCriticalChecksFinished() {
114
+ ExecutionStateDispatcher.dispatch(RaspExecutionStateEvent.CriticalChecksFinished)
115
+ }
116
+
117
+ override fun onFastChecksFinished() {
118
+ ExecutionStateDispatcher.dispatch(RaspExecutionStateEvent.FastChecksFinished)
119
+ }
120
+
121
+ override fun onPostponedChecksFinished() {
122
+ ExecutionStateDispatcher.dispatch(RaspExecutionStateEvent.PostponedChecksFinished)
110
123
  }
111
124
  }
112
125
 
@@ -1,4 +1,4 @@
1
- package com.freeraspreactnative
1
+ package app.talsec.rasp.reactnative
2
2
 
3
3
  import android.annotation.SuppressLint
4
4
  import android.annotation.TargetApi
@@ -1,7 +1,7 @@
1
- package com.freeraspreactnative.dispatchers
1
+ package app.talsec.rasp.reactnative.dispatchers
2
2
 
3
- import com.freeraspreactnative.events.RaspExecutionStateEvent
4
- import com.freeraspreactnative.interfaces.PluginExecutionStateListener
3
+ import app.talsec.rasp.reactnative.events.RaspExecutionStateEvent
4
+ import app.talsec.rasp.reactnative.interfaces.PluginExecutionStateListener
5
5
 
6
6
  internal object ExecutionStateDispatcher {
7
7
  private lateinit var listener: PluginExecutionStateListener
@@ -1,13 +1,15 @@
1
- package com.freeraspreactnative.dispatchers
1
+ package app.talsec.rasp.reactnative.dispatchers
2
2
 
3
3
  import app.talsec.rasp.security.api.SuspiciousAppInfo
4
- import com.freeraspreactnative.events.ThreatEvent
5
- import com.freeraspreactnative.interfaces.PluginThreatListener
4
+ import app.talsec.rasp.security.api.ThreatListener.CallState
5
+ import app.talsec.rasp.reactnative.events.ThreatEvent
6
+ import app.talsec.rasp.reactnative.interfaces.PluginThreatListener
6
7
 
7
8
  internal object ThreatDispatcher {
8
9
  private lateinit var listener: PluginThreatListener
9
10
  private val threatCache = mutableSetOf<ThreatEvent>()
10
11
  private val malwareCache = mutableSetOf<SuspiciousAppInfo>()
12
+ private val callStateCache = mutableListOf<CallState>()
11
13
 
12
14
  private var isAppInForeground = false
13
15
  private var isListenerRegistered = false
@@ -56,6 +58,17 @@ internal object ThreatDispatcher {
56
58
  }
57
59
  }
58
60
 
61
+ fun dispatchOngoingCall(state: CallState) {
62
+ if (isAppInForeground && isListenerRegistered) {
63
+ listener.ongoingCallDetected(state)
64
+ } else {
65
+ // Keep the order: a call that started and stopped in background is reported as both.
66
+ synchronized(callStateCache) {
67
+ callStateCache.add(state)
68
+ }
69
+ }
70
+ }
71
+
59
72
  private fun flushCache() {
60
73
  val threats = synchronized(threatCache) {
61
74
  val snapshot = threatCache.toSet()
@@ -72,6 +85,13 @@ internal object ThreatDispatcher {
72
85
  if (malware.isNotEmpty()) {
73
86
  listener.malwareDetected(malware)
74
87
  }
88
+
89
+ val callStates = synchronized(callStateCache) {
90
+ val snapshot = callStateCache.toList()
91
+ callStateCache.clear()
92
+ snapshot
93
+ }
94
+ callStates.forEach { listener.ongoingCallDetected(it) }
75
95
  }
76
96
  }
77
97
 
@@ -1,4 +1,4 @@
1
- package com.freeraspreactnative.events
1
+ package app.talsec.rasp.reactnative.events
2
2
 
3
3
  internal interface BaseRaspEvent {
4
4
  val value: Int
@@ -0,0 +1,22 @@
1
+ package app.talsec.rasp.reactnative.events
2
+
3
+ import app.talsec.rasp.reactnative.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 FastChecksFinished : RaspExecutionStateEvent(RandomGenerator.next())
10
+ data object CriticalChecksFinished : RaspExecutionStateEvent(RandomGenerator.next())
11
+ data object PostponedChecksFinished : RaspExecutionStateEvent(RandomGenerator.next())
12
+
13
+ companion object Companion {
14
+ internal val CHANNEL_NAME = RandomGenerator.next().toString()
15
+ internal val CHANNEL_KEY = RandomGenerator.next().toString()
16
+ internal val ALL_EVENT_IDENTIFIERS = listOf(
17
+ FastChecksFinished,
18
+ CriticalChecksFinished,
19
+ PostponedChecksFinished
20
+ ).map { it.value }
21
+ }
22
+ }
@@ -1,6 +1,6 @@
1
- package com.freeraspreactnative.events
1
+ package app.talsec.rasp.reactnative.events
2
2
 
3
- import com.freeraspreactnative.utils.RandomGenerator
3
+ import app.talsec.rasp.reactnative.utils.RandomGenerator
4
4
 
5
5
  /**
6
6
  * Sealed class to represent the error codes.
@@ -35,11 +35,13 @@ internal sealed class ThreatEvent(override val value: Int) : BaseRaspEvent {
35
35
  data object UnsecureWifi : ThreatEvent(RandomGenerator.next())
36
36
  data object Automation : ThreatEvent(RandomGenerator.next())
37
37
  data object Bootloader : ThreatEvent(RandomGenerator.next())
38
+ data object OngoingCall : ThreatEvent(RandomGenerator.next())
38
39
 
39
40
  companion object {
40
41
  internal val CHANNEL_NAME = RandomGenerator.next().toString()
41
42
  internal val CHANNEL_KEY = RandomGenerator.next().toString()
42
43
  internal val MALWARE_CHANNEL_KEY = RandomGenerator.next().toString()
44
+ internal val CALL_STATE_CHANNEL_KEY = RandomGenerator.next().toString()
43
45
 
44
46
  internal val ALL_EVENT_IDENTIFIERS = listOf(
45
47
  AppIntegrity,
@@ -63,7 +65,8 @@ internal sealed class ThreatEvent(override val value: Int) : BaseRaspEvent {
63
65
  LocationSpoofing,
64
66
  UnsecureWifi,
65
67
  Automation,
66
- Bootloader
68
+ Bootloader,
69
+ OngoingCall
67
70
  ).map { it.value }
68
71
  }
69
72
  }
@@ -1,3 +1,3 @@
1
- package com.freeraspreactnative.exceptions
1
+ package app.talsec.rasp.reactnative.exceptions
2
2
 
3
3
  class TalsecException(message: String, val code: String? = null, val ex: Exception? = null) : Exception(message)
@@ -1,6 +1,6 @@
1
- package com.freeraspreactnative.interfaces
1
+ package app.talsec.rasp.reactnative.interfaces
2
2
 
3
- import com.freeraspreactnative.events.RaspExecutionStateEvent
3
+ import app.talsec.rasp.reactnative.events.RaspExecutionStateEvent
4
4
 
5
5
  internal interface PluginExecutionStateListener {
6
6
  fun raspExecutionStateChanged(event: RaspExecutionStateEvent)
@@ -1,9 +1,11 @@
1
- package com.freeraspreactnative.interfaces
1
+ package app.talsec.rasp.reactnative.interfaces
2
2
 
3
3
  import app.talsec.rasp.security.api.SuspiciousAppInfo
4
- import com.freeraspreactnative.events.ThreatEvent
4
+ import app.talsec.rasp.security.api.ThreatListener.CallState
5
+ import app.talsec.rasp.reactnative.events.ThreatEvent
5
6
 
6
7
  internal interface PluginThreatListener {
7
8
  fun threatDetected(threatEventType: ThreatEvent)
8
9
  fun malwareDetected(suspiciousApps: MutableList<SuspiciousAppInfo>)
10
+ fun ongoingCallDetected(state: CallState)
9
11
  }
@@ -1,4 +1,4 @@
1
- package com.freeraspreactnative.models
1
+ package app.talsec.rasp.reactnative.models
2
2
 
3
3
  import kotlinx.serialization.Serializable
4
4
 
@@ -1,4 +1,4 @@
1
- package com.freeraspreactnative.utils
1
+ package app.talsec.rasp.reactnative.utils
2
2
 
3
3
  import android.content.pm.PackageInfo
4
4
  import android.util.Base64
@@ -13,9 +13,9 @@ import com.facebook.react.bridge.ReactContext
13
13
  import com.facebook.react.bridge.ReadableArray
14
14
  import com.facebook.react.bridge.ReadableMap
15
15
  import com.facebook.react.bridge.WritableArray
16
- import com.freeraspreactnative.exceptions.TalsecException
17
- import com.freeraspreactnative.models.RNPackageInfo
18
- import com.freeraspreactnative.models.RNSuspiciousAppInfo
16
+ import app.talsec.rasp.reactnative.exceptions.TalsecException
17
+ import app.talsec.rasp.reactnative.models.RNPackageInfo
18
+ import app.talsec.rasp.reactnative.models.RNSuspiciousAppInfo
19
19
  import kotlinx.serialization.encodeToString
20
20
  import kotlinx.serialization.json.Json
21
21
  import org.json.JSONException
@@ -1,4 +1,4 @@
1
- package com.freeraspreactnative.utils
1
+ package app.talsec.rasp.reactnative.utils
2
2
 
3
3
  import java.security.SecureRandom
4
4
 
@@ -1,4 +1,4 @@
1
- package com.freeraspreactnative.utils
1
+ package app.talsec.rasp.reactnative.utils
2
2
 
3
3
  import android.content.pm.ApplicationInfo
4
4
  import android.graphics.Bitmap