capacitor-freerasp 2.4.1 → 2.5.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 (61) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/aheaditec/freerasp/FreeraspPlugin.kt +60 -46
  4. package/android/src/main/java/com/aheaditec/freerasp/PluginThreatHandler.kt +9 -4
  5. package/android/src/main/java/com/aheaditec/freerasp/dispatchers/ExecutionStateDispatcher.kt +33 -16
  6. package/android/src/main/java/com/aheaditec/freerasp/dispatchers/ThreatDispatcher.kt +40 -24
  7. package/dist/esm/api/listeners/raspExecutionState.js +23 -11
  8. package/dist/esm/api/listeners/raspExecutionState.js.map +1 -1
  9. package/dist/esm/api/listeners/threat.js +25 -12
  10. package/dist/esm/api/listeners/threat.js.map +1 -1
  11. package/dist/esm/api/methods/capacitor.js +7 -1
  12. package/dist/esm/api/methods/capacitor.js.map +1 -1
  13. package/dist/esm/channels/threat.js +2 -5
  14. package/dist/esm/channels/threat.js.map +1 -1
  15. package/dist/esm/models/threat.js +1 -0
  16. package/dist/esm/models/threat.js.map +1 -1
  17. package/dist/esm/types/types.d.ts +6 -1
  18. package/dist/esm/types/types.js.map +1 -1
  19. package/dist/plugin.cjs.js +58 -28
  20. package/dist/plugin.cjs.js.map +1 -1
  21. package/dist/plugin.js +58 -28
  22. package/dist/plugin.js.map +1 -1
  23. package/ios/Plugin/FreeraspPlugin.m +1 -0
  24. package/ios/Plugin/FreeraspPlugin.swift +28 -8
  25. package/ios/Plugin/TalsecRuntime.xcframework/_CodeSignature/CodeDirectory +0 -0
  26. package/ios/Plugin/TalsecRuntime.xcframework/_CodeSignature/CodeResources +84 -62
  27. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/CurlWrapper.h +1 -1
  28. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/TalsecRuntime-Swift.h +1 -1
  29. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/curl.h +7 -7
  30. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/multi.h +4 -4
  31. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/options.h +1 -1
  32. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/urlapi.h +1 -1
  33. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Info.plist +0 -0
  34. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.abi.json +359 -102
  35. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.private.swiftinterface +2 -0
  36. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  37. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.swiftinterface +2 -0
  38. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/PrivacyInfo.xcprivacy +8 -0
  39. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/TalsecRuntime +0 -0
  40. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/CurlWrapper.h +1 -1
  41. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/TalsecRuntime-Swift.h +2 -2
  42. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/curl.h +7 -7
  43. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/multi.h +4 -4
  44. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/options.h +1 -1
  45. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/urlapi.h +1 -1
  46. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Info.plist +0 -0
  47. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.abi.json +366 -109
  48. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +2 -0
  49. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  50. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.swiftinterface +2 -0
  51. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.abi.json +366 -109
  52. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +2 -0
  53. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  54. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +2 -0
  55. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/PrivacyInfo.xcprivacy +8 -0
  56. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/TalsecRuntime +0 -0
  57. package/ios/Plugin/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/_CodeSignature/CodeResources +46 -35
  58. package/ios/Plugin/models/SecurityThreat.swift +2 -0
  59. package/ios/Plugin/utils/EventIdentifiers.swift +2 -2
  60. package/package.json +1 -1
  61. package/ios/Plugin/TalsecRuntime.xcframework/_CodeSignature/CodeSignature +0 -0
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
+ ## [2.5.0] - 2026-03-03
9
+
10
+ - Android SDK version: 18.0.4
11
+ - iOS SDK version: 6.14.1
12
+
13
+ ### Capacitor
14
+
15
+ #### Changed
16
+
17
+ - Refactor the Android plugin to separate the logic for managing listener states
18
+
19
+ ### Android
20
+
21
+ #### Added
22
+
23
+ - Added support for `KernelSU` to the existing root detection capabilities
24
+ - Added support for `HMA` to the existing root detection capabilities
25
+ - Added new malware detection capabilities
26
+ - Added `onAutomationDetected()` callback to `ThreatDetected` interface
27
+ - We are introducing a new capability, detecting whether the device is being automated using tools like Appium
28
+ - Added value restrictions to `externalId`
29
+ - Method `storeExternalId()` now returns `ExternalIdResult`, which indicates `Success` or `Error` when `externalId` violates restrictions
30
+
31
+ #### Fixed
32
+
33
+ - Fixed exception handling for the KeyStore `getEntry` operation
34
+ - Fixed issue in `ScreenProtector` concerning the `onScreenRecordingDetected` invocations
35
+ - Merged internal shared libraries into a single one, reducing the final APK size
36
+ - Fixed bug related to key storing in keystore type detection (hw-backed keystore check)
37
+ - Fixed manifest queries merge
38
+
39
+ #### Changed
40
+
41
+ - Removed unused library `tmlib`
42
+ - Refactoring of signature verification code
43
+ - Updated compile and target API to 36
44
+ - Improved root detection capabilities
45
+ - Detection of wireless ADB added to ADB detections
46
+
47
+ ### iOS
48
+
49
+ #### Added
50
+
51
+ - Added time spoofing detection, detecting an inaccurate device clock. It is a new threat `timeSpoofing`.
52
+
53
+ #### Changed
54
+
55
+ - Improved jailbreak detection methods.
56
+
8
57
  ## [2.4.1] - 2026-02-13
9
58
 
10
59
  - Android SDK version: 18.0.2
@@ -76,5 +76,5 @@ dependencies {
76
76
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
77
77
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
78
78
 
79
- implementation 'com.aheaditec.talsec.security:TalsecSecurity-Community-Capacitor:18.0.2'
79
+ implementation 'com.aheaditec.talsec.security:TalsecSecurity-Community-Capacitor:18.0.4'
80
80
  }
@@ -29,15 +29,22 @@ typealias CapacitorCallback = (String, JSObject) -> Unit
29
29
  @CapacitorPlugin(name = "Freerasp")
30
30
  class FreeraspPlugin : Plugin() {
31
31
 
32
- private var registered = true
33
-
34
32
  override fun load() {
35
33
  initializeEventKeys()
34
+ val pluginCallback: CapacitorCallback = { eventName, data ->
35
+ notifyListeners(eventName, data, true)
36
+ }
37
+ PluginThreatHandler.initializeDispatchers(PluginListener(context, pluginCallback))
36
38
  super.load()
37
39
  }
38
40
 
39
41
  @PluginMethod
40
42
  fun talsecStart(call: PluginCall) {
43
+ if (talsecStarted) {
44
+ call.resolve(JSObject().put("started", true))
45
+ return
46
+ }
47
+
41
48
  val config = call.getObject("config")
42
49
  if (config == null) {
43
50
  call.reject("Missing config parameter in freeRASP Native Plugin")
@@ -45,14 +52,7 @@ class FreeraspPlugin : Plugin() {
45
52
  }
46
53
  try {
47
54
  val talsecConfig = buildTalsecConfigThrowing(config)
48
-
49
- val pluginCallback: CapacitorCallback = { eventName, data ->
50
- notifyListeners(eventName, data, true)
51
- }
52
-
53
- PluginThreatHandler.threatDispatcher.listener = PluginListener(context, pluginCallback)
54
- PluginThreatHandler.executionStateDispatcher.listener = PluginListener(context, pluginCallback)
55
- PluginThreatHandler.registerListener(context)
55
+ PluginThreatHandler.registerSDKListener(context)
56
56
 
57
57
  bridge.activity.runOnUiThread {
58
58
  Talsec.start(context, talsecConfig)
@@ -75,35 +75,49 @@ class FreeraspPlugin : Plugin() {
75
75
  }
76
76
  }
77
77
 
78
- override fun handleOnStart() {
79
- super.handleOnStart()
80
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
81
- ScreenProtector.register(activity)
78
+ @PluginMethod(returnType = PluginMethod.RETURN_NONE)
79
+ override fun addListener(call: PluginCall) {
80
+ val eventName = call.getString("eventName")
81
+ if (eventName == ThreatEvent.CHANNEL_NAME) {
82
+ PluginThreatHandler.threatDispatcher.registerListener()
83
+ }
84
+ if (eventName == RaspExecutionStateEvent.CHANNEL_NAME) {
85
+ PluginThreatHandler.executionStateDispatcher.registerListener()
86
+ }
87
+ super.addListener(call)
88
+ }
89
+
90
+ @PluginMethod(returnType = PluginMethod.RETURN_NONE)
91
+ fun removeListenerForEvent(call: PluginCall) {
92
+ val eventName = call.getString("eventName")
93
+ if (eventName == ThreatEvent.CHANNEL_NAME) {
94
+ PluginThreatHandler.threatDispatcher.unregisterListener()
95
+ }
96
+ if (eventName == RaspExecutionStateEvent.CHANNEL_NAME) {
97
+ PluginThreatHandler.executionStateDispatcher.unregisterListener()
82
98
  }
83
99
  }
84
100
 
85
101
  override fun handleOnPause() {
86
102
  super.handleOnPause()
103
+ PluginThreatHandler.threatDispatcher.onPause()
104
+ PluginThreatHandler.executionStateDispatcher.onPause()
105
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
106
+ ScreenProtector.unregister(activity)
107
+ }
87
108
  if (activity.isFinishing) {
88
- PluginThreatHandler.unregisterListener(context)
89
- registered = false
90
- PluginThreatHandler.threatDispatcher.listener = null
91
- PluginThreatHandler.executionStateDispatcher.listener = null
109
+ PluginThreatHandler.threatDispatcher.unregisterListener()
110
+ PluginThreatHandler.executionStateDispatcher.unregisterListener()
111
+ PluginThreatHandler.unregisterSDKListener(context)
92
112
  }
93
113
  }
94
114
 
95
115
  override fun handleOnResume() {
96
116
  super.handleOnResume()
97
- if (!registered) {
98
- registered = true
99
- PluginThreatHandler.registerListener(context)
100
- }
101
- }
102
-
103
- override fun handleOnStop() {
104
- super.handleOnStop()
117
+ PluginThreatHandler.threatDispatcher.onResume()
118
+ PluginThreatHandler.executionStateDispatcher.onResume()
105
119
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
106
- ScreenProtector.unregister(activity)
120
+ ScreenProtector.register(activity)
107
121
  }
108
122
  }
109
123
 
@@ -317,8 +331,25 @@ class FreeraspPlugin : Plugin() {
317
331
  private val mainHandler = Handler(Looper.getMainLooper())
318
332
 
319
333
  internal var talsecStarted = false
334
+ }
320
335
 
321
- internal fun notifyEvent(
336
+ internal class PluginListener(
337
+ private val context: Context,
338
+ private val pluginCallback: CapacitorCallback
339
+ ) : PluginThreatListener, PluginExecutionStateListener {
340
+ override fun threatDetected(threatEventType: ThreatEvent) {
341
+ notifyEvent(threatEventType, pluginCallback)
342
+ }
343
+
344
+ override fun malwareDetected(suspiciousApps: MutableList<SuspiciousAppInfo>) {
345
+ notifyMalware(suspiciousApps, context, pluginCallback)
346
+ }
347
+
348
+ override fun raspExecutionStateChanged(event: RaspExecutionStateEvent) {
349
+ notifyEvent(event, pluginCallback)
350
+ }
351
+
352
+ private fun notifyEvent(
322
353
  event: BaseRaspEvent,
323
354
  notifyListenersCallback: CapacitorCallback
324
355
  ) {
@@ -326,7 +357,7 @@ class FreeraspPlugin : Plugin() {
326
357
  notifyListenersCallback(event.channelName, params)
327
358
  }
328
359
 
329
- internal fun notifyMalware(
360
+ private fun notifyMalware(
330
361
  suspiciousApps: MutableList<SuspiciousAppInfo>,
331
362
  context: Context,
332
363
  notifyListenersCallback: CapacitorCallback
@@ -345,21 +376,4 @@ class FreeraspPlugin : Plugin() {
345
376
  }
346
377
  }
347
378
  }
348
-
349
- internal class PluginListener(
350
- private val context: Context,
351
- private val pluginCallback: CapacitorCallback
352
- ) : PluginThreatListener, PluginExecutionStateListener {
353
- override fun threatDetected(threatEventType: ThreatEvent) {
354
- notifyEvent(threatEventType, pluginCallback)
355
- }
356
-
357
- override fun malwareDetected(suspiciousApps: MutableList<SuspiciousAppInfo>) {
358
- notifyMalware(suspiciousApps, context, pluginCallback)
359
- }
360
-
361
- override fun raspExecutionStateChanged(event: RaspExecutionStateEvent) {
362
- notifyEvent(event, pluginCallback)
363
- }
364
- }
365
379
  }
@@ -10,8 +10,13 @@ import com.aheaditec.freerasp.events.ThreatEvent
10
10
 
11
11
  internal object PluginThreatHandler {
12
12
 
13
- internal val threatDispatcher = ThreatDispatcher()
14
- internal val executionStateDispatcher = ExecutionStateDispatcher()
13
+ internal lateinit var threatDispatcher: ThreatDispatcher
14
+ internal lateinit var executionStateDispatcher: ExecutionStateDispatcher
15
+
16
+ fun initializeDispatchers(listener: FreeraspPlugin.PluginListener) {
17
+ threatDispatcher = ThreatDispatcher(listener)
18
+ executionStateDispatcher = ExecutionStateDispatcher(listener)
19
+ }
15
20
 
16
21
  private val threatDetected = object : ThreatListener.ThreatDetected() {
17
22
 
@@ -111,11 +116,11 @@ internal object PluginThreatHandler {
111
116
 
112
117
  private val internalListener = ThreatListener(threatDetected, deviceState, raspExecutionState)
113
118
 
114
- internal fun registerListener(context: Context) {
119
+ internal fun registerSDKListener(context: Context) {
115
120
  internalListener.registerListener(context)
116
121
  }
117
122
 
118
- internal fun unregisterListener(context: Context) {
123
+ internal fun unregisterSDKListener(context: Context) {
119
124
  internalListener.unregisterListener(context)
120
125
  }
121
126
  }
@@ -3,36 +3,53 @@ package com.aheaditec.freerasp.dispatchers
3
3
  import com.aheaditec.freerasp.events.RaspExecutionStateEvent
4
4
  import com.aheaditec.freerasp.interfaces.PluginExecutionStateListener
5
5
 
6
- internal class ExecutionStateDispatcher {
6
+ internal class ExecutionStateDispatcher(private val listener: PluginExecutionStateListener) {
7
7
  private val cache = mutableSetOf<RaspExecutionStateEvent>()
8
8
 
9
- var listener: PluginExecutionStateListener? = null
10
- set(value) {
11
- field = value
12
- if (value != null) {
13
- flushCache(value)
14
- }
9
+ private var isAppInForeground = false
10
+ private var isListenerRegistered = false
11
+
12
+ fun registerListener() {
13
+ isListenerRegistered = true
14
+ isAppInForeground = true
15
+ flushCache()
16
+ }
17
+
18
+ fun unregisterListener() {
19
+ isListenerRegistered = false
20
+ isAppInForeground = false
21
+ }
22
+
23
+ fun onResume() {
24
+ isAppInForeground = true
25
+ if (isListenerRegistered) {
26
+ flushCache()
15
27
  }
28
+ }
29
+
30
+ fun onPause() {
31
+ isAppInForeground = false
32
+ }
16
33
 
17
34
  fun dispatch(event: RaspExecutionStateEvent) {
18
- val checkedListener = synchronized(cache) {
19
- val currentListener = listener
20
- if (currentListener != null) {
21
- currentListener
22
- } else {
35
+ if (isAppInForeground && isListenerRegistered) {
36
+ listener.raspExecutionStateChanged(event)
37
+ } else {
38
+ synchronized(cache) {
23
39
  cache.add(event)
24
- null
25
40
  }
26
41
  }
27
- checkedListener?.raspExecutionStateChanged(event)
28
42
  }
29
43
 
30
- private fun flushCache(registeredListener: PluginExecutionStateListener) {
44
+ private fun flushCache() {
45
+ if (!isListenerRegistered || !isAppInForeground) {
46
+ return
47
+ }
31
48
  val events = synchronized(cache) {
32
49
  val snapshot = cache.toSet()
33
50
  cache.clear()
34
51
  snapshot
35
52
  }
36
- events.forEach { registeredListener.raspExecutionStateChanged(it) }
53
+ events.forEach { listener.raspExecutionStateChanged(it) }
37
54
  }
38
55
  }
@@ -4,51 +4,67 @@ import com.aheaditec.talsec_security.security.api.SuspiciousAppInfo
4
4
  import com.aheaditec.freerasp.events.ThreatEvent
5
5
  import com.aheaditec.freerasp.interfaces.PluginThreatListener
6
6
 
7
- internal class ThreatDispatcher {
7
+ internal class ThreatDispatcher(private val listener: PluginThreatListener) {
8
8
  private val threatCache = mutableSetOf<ThreatEvent>()
9
9
  private val malwareCache = mutableSetOf<SuspiciousAppInfo>()
10
10
 
11
- var listener: PluginThreatListener? = null
12
- set(value) {
13
- field = value
14
- if (value != null) {
15
- flushCache(value)
16
- }
11
+ private var isAppInForeground = false
12
+ private var isListenerRegistered = false
13
+
14
+ fun registerListener() {
15
+ isListenerRegistered = true
16
+ isAppInForeground = true
17
+ flushCache()
18
+ }
19
+
20
+ fun unregisterListener() {
21
+ isListenerRegistered = false
22
+ isAppInForeground = false
23
+ }
24
+
25
+ fun onResume() {
26
+ isAppInForeground = true
27
+ if (isListenerRegistered) {
28
+ flushCache()
17
29
  }
30
+ }
31
+
32
+ fun onPause() {
33
+ isAppInForeground = false
34
+ }
18
35
 
19
36
  fun dispatchThreat(event: ThreatEvent) {
20
- val checkedListener = synchronized(threatCache) {
21
- val currentListener = listener
22
- if (currentListener != null) {
23
- currentListener
24
- } else {
37
+ if (isAppInForeground && isListenerRegistered) {
38
+ listener.threatDetected(event)
39
+ } else {
40
+ synchronized(threatCache) {
25
41
  threatCache.add(event)
26
- null
27
42
  }
28
43
  }
29
- checkedListener?.threatDetected(event)
30
44
  }
31
45
 
32
46
  fun dispatchMalware(apps: MutableList<SuspiciousAppInfo>) {
33
- val checkedListener = synchronized(malwareCache) {
34
- val currentListener = listener
35
- if (currentListener != null) {
36
- currentListener
37
- } else {
47
+ if (isAppInForeground && isListenerRegistered) {
48
+ listener.malwareDetected(apps)
49
+ }
50
+ else {
51
+ synchronized(malwareCache) {
38
52
  malwareCache.addAll(apps)
39
- null
40
53
  }
41
54
  }
42
- checkedListener?.malwareDetected(apps)
43
55
  }
44
56
 
45
- private fun flushCache(registeredListener: PluginThreatListener) {
57
+ private fun flushCache() {
58
+ if (!isListenerRegistered || !isAppInForeground) {
59
+ return
60
+ }
61
+
46
62
  val threats = synchronized(threatCache) {
47
63
  val snapshot = threatCache.toSet()
48
64
  threatCache.clear()
49
65
  snapshot
50
66
  }
51
- threats.forEach { registeredListener.threatDetected(it) }
67
+ threats.forEach { listener.threatDetected(it) }
52
68
 
53
69
  val malware = synchronized(malwareCache) {
54
70
  val snapshot = malwareCache.toMutableList()
@@ -56,7 +72,7 @@ internal class ThreatDispatcher {
56
72
  snapshot
57
73
  }
58
74
  if (malware.isNotEmpty()) {
59
- registeredListener.malwareDetected(malware)
75
+ listener.malwareDetected(malware)
60
76
  }
61
77
  }
62
78
  }
@@ -3,24 +3,34 @@ import { RaspExecutionState } from '../../models/raspExecutionState';
3
3
  import { onInvalidCallback } from '../methods/native';
4
4
  import { Talsec } from '../nativeModules';
5
5
  let eventsListener = null;
6
+ let executionStateChannel = null;
7
+ let executionStateKey = null;
6
8
  let isInitializing = false;
9
+ let isMappingPrepared = false;
7
10
  export const registerRaspExecutionStateListener = async (config) => {
8
11
  if (isInitializing) {
9
12
  return;
10
13
  }
11
14
  isInitializing = true;
12
- if (eventsListener) {
13
- await eventsListener.remove();
14
- eventsListener = null;
15
+ await removeRaspExecutionStateListener();
16
+ if (!executionStateChannel || !executionStateKey) {
17
+ [executionStateChannel, executionStateKey] = await getRaspExecutionStateChannelData();
15
18
  }
16
- const [channel, key] = await getRaspExecutionStateChannelData();
17
- await prepareRaspExecutionStateMapping();
18
- eventsListener = await Talsec.addListener(channel, async (event) => {
19
+ if (!isMappingPrepared) {
20
+ await prepareRaspExecutionStateMapping();
21
+ isMappingPrepared = true;
22
+ }
23
+ if (!executionStateChannel) {
24
+ onInvalidCallback();
25
+ return;
26
+ }
27
+ eventsListener = await Talsec.addListener(executionStateChannel, async (event) => {
19
28
  var _a;
20
- if (event[key] == undefined) {
29
+ if (!executionStateKey) {
21
30
  onInvalidCallback();
31
+ return;
22
32
  }
23
- switch (event[key]) {
33
+ switch (event[executionStateKey]) {
24
34
  case RaspExecutionState.AllChecksFinished.value:
25
35
  (_a = config.allChecksFinished) === null || _a === void 0 ? void 0 : _a.call(config);
26
36
  break;
@@ -32,9 +42,11 @@ export const registerRaspExecutionStateListener = async (config) => {
32
42
  isInitializing = false;
33
43
  };
34
44
  export const removeRaspExecutionStateListener = async () => {
35
- if (eventsListener) {
36
- await eventsListener.remove();
37
- eventsListener = null;
45
+ if (!eventsListener || !executionStateChannel) {
46
+ return;
38
47
  }
48
+ await eventsListener.remove();
49
+ eventsListener = null;
50
+ await Talsec.removeListenerForEvent({ eventName: executionStateChannel });
39
51
  };
40
52
  //# sourceMappingURL=raspExecutionState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"raspExecutionState.js","sourceRoot":"","sources":["../../../../src/api/listeners/raspExecutionState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AACvH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,IAAI,cAAc,GAAgC,IAAI,CAAC;AACvD,IAAI,cAAc,GAAG,KAAK,CAAC;AAE3B,MAAM,CAAC,MAAM,kCAAkC,GAAG,KAAK,EAAE,MAAsC,EAAiB,EAAE;IAChH,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IACD,cAAc,GAAG,IAAI,CAAC;IAEtB,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,cAAc,CAAC,MAAM,EAAE,CAAC;QAC9B,cAAc,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,MAAM,gCAAgC,EAAE,CAAC;IAChE,MAAM,gCAAgC,EAAE,CAAC;IAEzC,cAAc,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,KAAU,EAAE,EAAE;;QACtE,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC;YAC5B,iBAAiB,EAAE,CAAC;QACtB,CAAC;QACD,QAAQ,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACnB,KAAK,kBAAkB,CAAC,iBAAiB,CAAC,KAAK;gBAC7C,MAAA,MAAM,CAAC,iBAAiB,sDAAI,CAAC;gBAC7B,MAAM;YACR;gBACE,iBAAiB,EAAE,CAAC;gBACpB,MAAM;QACV,CAAC;IACH,CAAC,CAAC,CAAC;IACH,cAAc,GAAG,KAAK,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAG,KAAK,IAAmB,EAAE;IACxE,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,cAAc,CAAC,MAAM,EAAE,CAAC;QAC9B,cAAc,GAAG,IAAI,CAAC;IACxB,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport { getRaspExecutionStateChannelData, prepareRaspExecutionStateMapping } from '../../channels/raspExecutionState';\nimport { RaspExecutionState } from '../../models/raspExecutionState';\nimport type { RaspExecutionStateEventActions } from '../../types/types';\nimport { onInvalidCallback } from '../methods/native';\nimport { Talsec } from '../nativeModules';\n\nlet eventsListener: PluginListenerHandle | null = null;\nlet isInitializing = false;\n\nexport const registerRaspExecutionStateListener = async (config: RaspExecutionStateEventActions): Promise<void> => {\n if (isInitializing) {\n return;\n }\n isInitializing = true;\n\n if (eventsListener) {\n await eventsListener.remove();\n eventsListener = null;\n }\n\n const [channel, key] = await getRaspExecutionStateChannelData();\n await prepareRaspExecutionStateMapping();\n\n eventsListener = await Talsec.addListener(channel, async (event: any) => {\n if (event[key] == undefined) {\n onInvalidCallback();\n }\n switch (event[key]) {\n case RaspExecutionState.AllChecksFinished.value:\n config.allChecksFinished?.();\n break;\n default:\n onInvalidCallback();\n break;\n }\n });\n isInitializing = false;\n};\n\nexport const removeRaspExecutionStateListener = async (): Promise<void> => {\n if (eventsListener) {\n await eventsListener.remove();\n eventsListener = null;\n }\n};\n"]}
1
+ {"version":3,"file":"raspExecutionState.js","sourceRoot":"","sources":["../../../../src/api/listeners/raspExecutionState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AACvH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,IAAI,cAAc,GAAgC,IAAI,CAAC;AACvD,IAAI,qBAAqB,GAAkB,IAAI,CAAC;AAChD,IAAI,iBAAiB,GAAkB,IAAI,CAAC;AAE5C,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,MAAM,CAAC,MAAM,kCAAkC,GAAG,KAAK,EAAE,MAAsC,EAAiB,EAAE;IAChH,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IACD,cAAc,GAAG,IAAI,CAAC;IAEtB,MAAM,gCAAgC,EAAE,CAAC;IAEzC,IAAI,CAAC,qBAAqB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACjD,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,GAAG,MAAM,gCAAgC,EAAE,CAAC;IACxF,CAAC;IAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,MAAM,gCAAgC,EAAE,CAAC;QACzC,iBAAiB,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,iBAAiB,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IAED,cAAc,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,qBAAqB,EAAE,KAAK,EAAE,KAAU,EAAE,EAAE;;QACpF,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACvB,iBAAiB,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,QAAQ,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACjC,KAAK,kBAAkB,CAAC,iBAAiB,CAAC,KAAK;gBAC7C,MAAA,MAAM,CAAC,iBAAiB,sDAAI,CAAC;gBAC7B,MAAM;YACR;gBACE,iBAAiB,EAAE,CAAC;gBACpB,MAAM;QACV,CAAC;IACH,CAAC,CAAC,CAAC;IACH,cAAc,GAAG,KAAK,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAG,KAAK,IAAmB,EAAE;IACxE,IAAI,CAAC,cAAc,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC9C,OAAO;IACT,CAAC;IACD,MAAM,cAAc,CAAC,MAAM,EAAE,CAAC;IAC9B,cAAc,GAAG,IAAI,CAAC;IACtB,MAAM,MAAM,CAAC,sBAAsB,CAAC,EAAE,SAAS,EAAE,qBAAqB,EAAE,CAAC,CAAC;AAC5E,CAAC,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport { getRaspExecutionStateChannelData, prepareRaspExecutionStateMapping } from '../../channels/raspExecutionState';\nimport { RaspExecutionState } from '../../models/raspExecutionState';\nimport type { RaspExecutionStateEventActions } from '../../types/types';\nimport { onInvalidCallback } from '../methods/native';\nimport { Talsec } from '../nativeModules';\n\nlet eventsListener: PluginListenerHandle | null = null;\nlet executionStateChannel: string | null = null;\nlet executionStateKey: string | null = null;\n\nlet isInitializing = false;\nlet isMappingPrepared = false;\n\nexport const registerRaspExecutionStateListener = async (config: RaspExecutionStateEventActions): Promise<void> => {\n if (isInitializing) {\n return;\n }\n isInitializing = true;\n\n await removeRaspExecutionStateListener();\n\n if (!executionStateChannel || !executionStateKey) {\n [executionStateChannel, executionStateKey] = await getRaspExecutionStateChannelData();\n }\n\n if (!isMappingPrepared) {\n await prepareRaspExecutionStateMapping();\n isMappingPrepared = true;\n }\n\n if (!executionStateChannel) {\n onInvalidCallback();\n return;\n }\n\n eventsListener = await Talsec.addListener(executionStateChannel, async (event: any) => {\n if (!executionStateKey) {\n onInvalidCallback();\n return;\n }\n\n switch (event[executionStateKey]) {\n case RaspExecutionState.AllChecksFinished.value:\n config.allChecksFinished?.();\n break;\n default:\n onInvalidCallback();\n break;\n }\n });\n isInitializing = false;\n};\n\nexport const removeRaspExecutionStateListener = async (): Promise<void> => {\n if (!eventsListener || !executionStateChannel) {\n return;\n }\n await eventsListener.remove();\n eventsListener = null;\n await Talsec.removeListenerForEvent({ eventName: executionStateChannel });\n};\n"]}
@@ -4,24 +4,35 @@ import { parseMalwareData } from '../../utils/malware';
4
4
  import { onInvalidCallback } from '../methods/native';
5
5
  import { Talsec } from '../nativeModules';
6
6
  let eventsListener = null;
7
+ let threatChannel = null;
8
+ let threatKey = null;
9
+ let threatMalwareKey = null;
7
10
  let isInitializing = false;
11
+ let isMappingPrepared = false;
8
12
  export const registerThreatListener = async (config) => {
9
13
  if (isInitializing) {
10
14
  return;
11
15
  }
12
16
  isInitializing = true;
13
- if (eventsListener) {
14
- await eventsListener.remove();
15
- eventsListener = null;
17
+ await removeThreatListener();
18
+ if (!threatChannel || !threatKey || !threatMalwareKey) {
19
+ [threatChannel, threatKey, threatMalwareKey] = await getThreatChannelData();
16
20
  }
17
- const [channel, key, malwareKey] = await getThreatChannelData();
18
- await prepareThreatMapping();
19
- eventsListener = await Talsec.addListener(channel, async (event) => {
21
+ if (!isMappingPrepared) {
22
+ await prepareThreatMapping();
23
+ isMappingPrepared = true;
24
+ }
25
+ if (!threatChannel) {
26
+ onInvalidCallback();
27
+ return;
28
+ }
29
+ eventsListener = await Talsec.addListener(threatChannel, async (event) => {
20
30
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
21
- if (event[key] == undefined) {
31
+ if (!threatKey || !threatMalwareKey) {
22
32
  onInvalidCallback();
33
+ return;
23
34
  }
24
- switch (event[key]) {
35
+ switch (event[threatKey]) {
25
36
  case Threat.PrivilegedAccess.value:
26
37
  (_a = config.privilegedAccess) === null || _a === void 0 ? void 0 : _a.call(config);
27
38
  break;
@@ -62,7 +73,7 @@ export const registerThreatListener = async (config) => {
62
73
  (_o = config.systemVPN) === null || _o === void 0 ? void 0 : _o.call(config);
63
74
  break;
64
75
  case Threat.Malware.value:
65
- (_p = config.malware) === null || _p === void 0 ? void 0 : _p.call(config, await parseMalwareData(event[malwareKey]));
76
+ (_p = config.malware) === null || _p === void 0 ? void 0 : _p.call(config, await parseMalwareData(event[threatMalwareKey]));
66
77
  break;
67
78
  case Threat.ADBEnabled.value:
68
79
  (_q = config.adbEnabled) === null || _q === void 0 ? void 0 : _q.call(config);
@@ -96,9 +107,11 @@ export const registerThreatListener = async (config) => {
96
107
  isInitializing = false;
97
108
  };
98
109
  export const removeThreatListener = async () => {
99
- if (eventsListener) {
100
- await eventsListener.remove();
101
- eventsListener = null;
110
+ if (!eventsListener || !threatChannel) {
111
+ return;
102
112
  }
113
+ await eventsListener.remove();
114
+ eventsListener = null;
115
+ await Talsec.removeListenerForEvent({ eventName: threatChannel });
103
116
  };
104
117
  //# sourceMappingURL=threat.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"threat.js","sourceRoot":"","sources":["../../../../src/api/listeners/threat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,IAAI,cAAc,GAAgC,IAAI,CAAC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CAAC,KAAK;gBAC7B,MAAA,MAAM,CAAC,aAAa,sDAAI,CAAC;gBACzB,MAAM;YACR,KAAK,MAAM,CAAC,YAAY,CAAC,KAAK;gBAC5B,MAAA,MAAM,CAAC,YAAY,sDAAI,CAAC;gBACxB,MAAM;YACR,KAAK,MAAM,CAAC,gBAAgB,CAAC,KAAK;gBAChC,MAAA,MAAM,CAAC,gBAAgB,sDAAI,CAAC;gBAC5B,MAAM;YACR,KAAK,MAAM,CAAC,YAAY,CAAC,KAAK;gBAC5B,MAAA,MAAM,CAAC,YAAY,sDAAI,CAAC;gBACxB,MAAM;YACR,KAAK,MAAM,CAAC,UAAU,CAAC,KAAK;gBAC1B,MAAA,MAAM,CAAC,UAAU,sDAAI,CAAC;gBACtB,MAAM;YACR;gBACE,iBAAiB,EAAE,CAAC;gBACpB,MAAM;QACV,CAAC;IACH,CAAC,CAAC,CAAC;IACH,cAAc,GAAG,KAAK,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,IAAmB,EAAE;IAC5D,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,cAAc,CAAC,MAAM,EAAE,CAAC;QAC9B,cAAc,GAAG,IAAI,CAAC;IACxB,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport { getThreatChannelData, prepareThreatMapping } from '../../channels/threat';\nimport { Threat } from '../../models/threat';\nimport type { ThreatEventActions } from '../../types/types';\nimport { parseMalwareData } from '../../utils/malware';\nimport { onInvalidCallback } from '../methods/native';\nimport { Talsec } from '../nativeModules';\n\nlet eventsListener: PluginListenerHandle | null = null;\nlet isInitializing = false;\n\nexport const registerThreatListener = async (config: ThreatEventActions): Promise<void> => {\n if (isInitializing) {\n return;\n }\n isInitializing = true;\n\n if (eventsListener) {\n await eventsListener.remove();\n eventsListener = null;\n }\n\n const [channel, key, malwareKey] = await getThreatChannelData();\n await prepareThreatMapping();\n\n eventsListener = await Talsec.addListener(channel, async (event: any) => {\n if (event[key] == undefined) {\n onInvalidCallback();\n }\n switch (event[key]) {\n case Threat.PrivilegedAccess.value:\n config.privilegedAccess?.();\n break;\n case Threat.Debug.value:\n config.debug?.();\n break;\n case Threat.Simulator.value:\n config.simulator?.();\n break;\n case Threat.AppIntegrity.value:\n config.appIntegrity?.();\n break;\n case Threat.UnofficialStore.value:\n config.unofficialStore?.();\n break;\n case Threat.Hooks.value:\n config.hooks?.();\n break;\n case Threat.DeviceBinding.value:\n config.deviceBinding?.();\n break;\n case Threat.Passcode.value:\n config.passcode?.();\n break;\n case Threat.SecureHardwareNotAvailable.value:\n config.secureHardwareNotAvailable?.();\n break;\n case Threat.ObfuscationIssues.value:\n config.obfuscationIssues?.();\n break;\n case Threat.DeviceID.value:\n config.deviceID?.();\n break;\n case Threat.DevMode.value:\n config.devMode?.();\n break;\n case Threat.SystemVPN.value:\n config.systemVPN?.();\n break;\n case Threat.Malware.value:\n config.malware?.(await parseMalwareData(event[malwareKey]));\n break;\n case Threat.ADBEnabled.value:\n config.adbEnabled?.();\n break;\n case Threat.Screenshot.value:\n config.screenshot?.();\n break;\n case Threat.ScreenRecording.value:\n config.screenRecording?.();\n break;\n case Threat.MultiInstance.value:\n config.multiInstance?.();\n break;\n case Threat.TimeSpoofing.value:\n config.timeSpoofing?.();\n break;\n case Threat.LocationSpoofing.value:\n config.locationSpoofing?.();\n break;\n case Threat.UnsecureWifi.value:\n config.unsecureWifi?.();\n break;\n case Threat.Automation.value:\n config.automation?.();\n break;\n default:\n onInvalidCallback();\n break;\n }\n });\n isInitializing = false;\n};\n\nexport const removeThreatListener = async (): Promise<void> => {\n if (eventsListener) {\n await eventsListener.remove();\n eventsListener = null;\n }\n};\n"]}
1
+ {"version":3,"file":"threat.js","sourceRoot":"","sources":["../../../../src/api/listeners/threat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,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,IAAI,CAAC,cAAc,IAAI,CAAC,aAAa,EAAE,CAAC;QACtC,OAAO;IACT,CAAC;IACD,MAAM,cAAc,CAAC,MAAM,EAAE,CAAC;IAC9B,cAAc,GAAG,IAAI,CAAC;IACtB,MAAM,MAAM,CAAC,sBAAsB,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;AACpE,CAAC,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport { getThreatChannelData, prepareThreatMapping } from '../../channels/threat';\nimport { Threat } from '../../models/threat';\nimport type { ThreatEventActions } from '../../types/types';\nimport { parseMalwareData } from '../../utils/malware';\nimport { onInvalidCallback } from '../methods/native';\nimport { Talsec } from '../nativeModules';\n\nlet eventsListener: PluginListenerHandle | null = null;\n\nlet threatChannel: string | null = null;\nlet threatKey: string | null = null;\nlet threatMalwareKey: string | null = null;\n\nlet isInitializing = false;\nlet isMappingPrepared = false;\n\nexport const registerThreatListener = async (config: ThreatEventActions): Promise<void> => {\n if (isInitializing) {\n return;\n }\n isInitializing = true;\n\n await removeThreatListener();\n\n if (!threatChannel || !threatKey || !threatMalwareKey) {\n [threatChannel, threatKey, threatMalwareKey] = await getThreatChannelData();\n }\n\n if (!isMappingPrepared) {\n await prepareThreatMapping();\n isMappingPrepared = true;\n }\n\n if (!threatChannel) {\n onInvalidCallback();\n return;\n }\n\n eventsListener = await Talsec.addListener(threatChannel, async (event: any) => {\n if (!threatKey || !threatMalwareKey) {\n onInvalidCallback();\n return;\n }\n switch (event[threatKey]) {\n case Threat.PrivilegedAccess.value:\n config.privilegedAccess?.();\n break;\n case Threat.Debug.value:\n config.debug?.();\n break;\n case Threat.Simulator.value:\n config.simulator?.();\n break;\n case Threat.AppIntegrity.value:\n config.appIntegrity?.();\n break;\n case Threat.UnofficialStore.value:\n config.unofficialStore?.();\n break;\n case Threat.Hooks.value:\n config.hooks?.();\n break;\n case Threat.DeviceBinding.value:\n config.deviceBinding?.();\n break;\n case Threat.Passcode.value:\n config.passcode?.();\n break;\n case Threat.SecureHardwareNotAvailable.value:\n config.secureHardwareNotAvailable?.();\n break;\n case Threat.ObfuscationIssues.value:\n config.obfuscationIssues?.();\n break;\n case Threat.DeviceID.value:\n config.deviceID?.();\n break;\n case Threat.DevMode.value:\n config.devMode?.();\n break;\n case Threat.SystemVPN.value:\n config.systemVPN?.();\n break;\n case Threat.Malware.value:\n config.malware?.(await parseMalwareData(event[threatMalwareKey]));\n break;\n case Threat.ADBEnabled.value:\n config.adbEnabled?.();\n break;\n case Threat.Screenshot.value:\n config.screenshot?.();\n break;\n case Threat.ScreenRecording.value:\n config.screenRecording?.();\n break;\n case Threat.MultiInstance.value:\n config.multiInstance?.();\n break;\n case Threat.TimeSpoofing.value:\n config.timeSpoofing?.();\n break;\n case Threat.LocationSpoofing.value:\n config.locationSpoofing?.();\n break;\n case Threat.UnsecureWifi.value:\n config.unsecureWifi?.();\n break;\n case Threat.Automation.value:\n config.automation?.();\n break;\n default:\n onInvalidCallback();\n break;\n }\n });\n isInitializing = false;\n};\n\nexport const removeThreatListener = async (): Promise<void> => {\n if (!eventsListener || !threatChannel) {\n return;\n }\n await eventsListener.remove();\n eventsListener = null;\n await Talsec.removeListenerForEvent({ eventName: threatChannel });\n};\n"]}
@@ -1,11 +1,17 @@
1
1
  import { registerRaspExecutionStateListener } from '../listeners/raspExecutionState';
2
2
  import { registerThreatListener } from '../listeners/threat';
3
3
  import { Talsec } from '../nativeModules';
4
+ let isRaspStarted = false;
4
5
  export const startFreeRASP = async (config, actions, raspExecutionStateActions) => {
5
6
  await registerThreatListener(actions);
6
7
  if (raspExecutionStateActions) {
7
8
  await registerRaspExecutionStateListener(raspExecutionStateActions);
8
9
  }
9
- return Talsec.talsecStart({ config });
10
+ if (isRaspStarted) {
11
+ return { started: true };
12
+ }
13
+ const response = await Talsec.talsecStart({ config });
14
+ isRaspStarted = true;
15
+ return response;
10
16
  };
11
17
  //# sourceMappingURL=capacitor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"capacitor.js","sourceRoot":"","sources":["../../../../src/api/methods/capacitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kCAAkC,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,MAAoB,EACpB,OAA2B,EAC3B,yBAA0D,EAC3B,EAAE;IACjC,MAAM,sBAAsB,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,yBAAyB,EAAE,CAAC;QAC9B,MAAM,kCAAkC,CAAC,yBAAyB,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import type { TalsecConfig, ThreatEventActions, RaspExecutionStateEventActions } from '../../types/types';\nimport { registerRaspExecutionStateListener } from '../listeners/raspExecutionState';\nimport { registerThreatListener } from '../listeners/threat';\nimport { Talsec } from '../nativeModules';\n\nexport const startFreeRASP = async (\n config: TalsecConfig,\n actions: ThreatEventActions,\n raspExecutionStateActions?: RaspExecutionStateEventActions,\n): Promise<{ started: boolean }> => {\n await registerThreatListener(actions);\n if (raspExecutionStateActions) {\n await registerRaspExecutionStateListener(raspExecutionStateActions);\n }\n return Talsec.talsecStart({ config });\n};\n"]}
1
+ {"version":3,"file":"capacitor.js","sourceRoot":"","sources":["../../../../src/api/methods/capacitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kCAAkC,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,MAAoB,EACpB,OAA2B,EAC3B,yBAA0D,EAC3B,EAAE;IACjC,MAAM,sBAAsB,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,yBAAyB,EAAE,CAAC;QAC9B,MAAM,kCAAkC,CAAC,yBAAyB,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACtD,aAAa,GAAG,IAAI,CAAC;IAErB,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import type { TalsecConfig, ThreatEventActions, RaspExecutionStateEventActions } from '../../types/types';\nimport { registerRaspExecutionStateListener } from '../listeners/raspExecutionState';\nimport { registerThreatListener } from '../listeners/threat';\nimport { Talsec } from '../nativeModules';\n\nlet isRaspStarted = false;\n\nexport const startFreeRASP = async (\n config: TalsecConfig,\n actions: ThreatEventActions,\n raspExecutionStateActions?: RaspExecutionStateEventActions,\n): Promise<{ started: boolean }> => {\n await registerThreatListener(actions);\n if (raspExecutionStateActions) {\n await registerRaspExecutionStateListener(raspExecutionStateActions);\n }\n if (isRaspStarted) {\n return { started: true };\n }\n\n const response = await Talsec.talsecStart({ config });\n isRaspStarted = true;\n\n return response;\n};\n"]}