freerasp-react-native 3.8.1 → 3.9.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 (58) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/README.md +20 -556
  3. package/android/build.gradle +1 -1
  4. package/android/proguard-rules.pro +2 -1
  5. package/android/src/main/java/com/freeraspreactnative/FreeraspReactNativeModule.kt +19 -42
  6. package/android/src/main/java/com/freeraspreactnative/FreeraspThreatHandler.kt +3 -0
  7. package/android/src/main/java/com/freeraspreactnative/Utils.kt +40 -0
  8. package/android/src/main/java/com/freeraspreactnative/exceptions/TalsecException.kt +3 -0
  9. package/example/src/App.tsx +1 -1
  10. package/ios/FreeraspReactNative.swift +1 -1
  11. package/ios/TalsecRuntime.xcframework/Info.plist +9 -5
  12. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeDirectory +0 -0
  13. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeRequirements-1 +0 -0
  14. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeResources +105 -105
  15. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeSignature +0 -0
  16. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/CurlWrapper.h +1 -1
  17. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/TalsecRuntime-Swift.h +22 -5
  18. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/curl.h +57 -43
  19. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/curlver.h +4 -4
  20. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/mprintf.h +13 -5
  21. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/multi.h +18 -4
  22. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/options.h +1 -1
  23. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/system.h +1 -11
  24. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/urlapi.h +5 -1
  25. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Info.plist +0 -0
  26. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.abi.json +217 -2211
  27. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.private.swiftinterface +3 -3
  28. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  29. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.swiftinterface +3 -3
  30. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/TalsecRuntime +0 -0
  31. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/CurlWrapper.h +1 -1
  32. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/TalsecRuntime-Swift.h +44 -10
  33. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/curl.h +57 -43
  34. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/curlver.h +4 -4
  35. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/mprintf.h +13 -5
  36. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/multi.h +18 -4
  37. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/options.h +1 -1
  38. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/system.h +1 -11
  39. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/urlapi.h +5 -1
  40. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Info.plist +0 -0
  41. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.abi.json +220 -2193
  42. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +3 -3
  43. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  44. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.swiftinterface +3 -3
  45. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.abi.json +220 -2193
  46. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +3 -3
  47. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  48. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +3 -3
  49. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/TalsecRuntime +0 -0
  50. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/_CodeSignature/CodeResources +39 -39
  51. package/lib/commonjs/index.js +8 -4
  52. package/lib/commonjs/index.js.map +1 -1
  53. package/lib/module/index.js +8 -4
  54. package/lib/module/index.js.map +1 -1
  55. package/lib/typescript/src/index.d.ts.map +1 -1
  56. package/package.json +2 -2
  57. package/plugin/build/index.d.ts +1 -1
  58. package/src/index.tsx +8 -4
@@ -9,6 +9,7 @@ import com.facebook.react.bridge.ReactApplicationContext
9
9
  import com.facebook.react.bridge.ReactContextBaseJavaModule
10
10
  import com.facebook.react.bridge.ReactMethod
11
11
  import com.facebook.react.bridge.ReadableMap
12
+ import com.facebook.react.bridge.UiThreadUtil.runOnUiThread
12
13
  import com.facebook.react.bridge.WritableArray
13
14
  import com.facebook.react.modules.core.DeviceEventManagerModule
14
15
 
@@ -32,17 +33,18 @@ class FreeraspReactNativeModule(val reactContext: ReactApplicationContext) :
32
33
  ) {
33
34
 
34
35
  try {
35
- val config = parseTalsecConfig(options)
36
+ val config = buildTalsecConfig(options)
36
37
  FreeraspThreatHandler.listener = ThreatListener
37
38
  listener.registerListener(reactContext)
38
- Talsec.start(reactContext, config)
39
+ runOnUiThread {
40
+ Talsec.start(reactContext, config)
41
+ }
42
+
39
43
  promise.resolve("freeRASP started")
40
44
 
41
- } catch (e: Exception) {
42
- val params = Arguments.createMap().apply {
43
- putString("message", e.message)
44
- }
45
- promise.reject("initializationError", params)
45
+ }
46
+ catch (e: Exception) {
47
+ promise.reject("TalsecInitializationError", e.message, e)
46
48
  }
47
49
  }
48
50
 
@@ -85,42 +87,17 @@ class FreeraspReactNativeModule(val reactContext: ReactApplicationContext) :
85
87
  // Remove upstream listeners, stop unnecessary background tasks
86
88
  }
87
89
 
88
- private fun parseTalsecConfig(config: ReadableMap): TalsecConfig {
89
- val androidConfig = config.getMap("androidConfig")!!
90
- val packageName = androidConfig.getString("packageName")!!
91
- val certificateHashes = mutableListOf<String>()
92
- val hashes = androidConfig.getArray("certificateHashes")!!
93
- for (i in 0 until hashes.size()) {
94
- // in RN versions < 0.63, getString is nullable
95
- @Suppress("UNNECESSARY_SAFE_CALL")
96
- hashes.getString(i)?.let {
97
- certificateHashes.add(it)
98
- }
99
- }
100
- val watcherMail = config.getString("watcherMail")
101
- val alternativeStores = mutableListOf<String>()
102
- if (androidConfig.hasKey("supportedAlternativeStores")) {
103
- val stores = androidConfig.getArray("supportedAlternativeStores")!!
104
- for (i in 0 until stores.size()) {
105
- // in RN versions < 0.63, getString is nullable
106
- @Suppress("UNNECESSARY_SAFE_CALL")
107
- stores.getString(i)?.let {
108
- alternativeStores.add(it)
109
- }
110
- }
111
- }
112
- var isProd = true
113
- if (config.hasKey("isProd")) {
114
- isProd = config.getBoolean("isProd")
115
- }
90
+ private fun buildTalsecConfig(config: ReadableMap): TalsecConfig {
91
+ val androidConfig = config.getMapThrowing("androidConfig")
92
+ val packageName = androidConfig.getStringThrowing("packageName")
93
+ val certificateHashes = androidConfig.getArraySafe("certificateHashes")
94
+
95
+ val talsecBuilder = TalsecConfig.Builder(packageName, certificateHashes)
96
+ .watcherMail(config.getString("watcherMail"))
97
+ .supportedAlternativeStores(androidConfig.getArraySafe("supportedAlternativeStores"))
98
+ .prod(config.getBooleanSafe("isProd"))
116
99
 
117
- return TalsecConfig(
118
- packageName,
119
- certificateHashes.toTypedArray(),
120
- watcherMail,
121
- alternativeStores.toTypedArray(),
122
- isProd
123
- )
100
+ return talsecBuilder.build()
124
101
  }
125
102
 
126
103
  companion object {
@@ -1,5 +1,6 @@
1
1
  package com.freeraspreactnative
2
2
 
3
+ import com.aheaditec.talsec_security.security.api.SuspiciousAppInfo
3
4
  import com.aheaditec.talsec_security.security.api.ThreatListener
4
5
 
5
6
  internal object FreeraspThreatHandler : ThreatListener.ThreatDetected, ThreatListener.DeviceState {
@@ -38,6 +39,8 @@ internal object FreeraspThreatHandler : ThreatListener.ThreatDetected, ThreatLis
38
39
  listener?.threatDetected(Threat.ObfuscationIssues)
39
40
  }
40
41
 
42
+ override fun onMalwareDetected(p0: MutableList<SuspiciousAppInfo>?) {}
43
+
41
44
  override fun onUnlockedDeviceDetected() {
42
45
  listener?.threatDetected(Threat.Passcode)
43
46
  }
@@ -0,0 +1,40 @@
1
+ package com.freeraspreactnative
2
+
3
+ import com.facebook.react.bridge.ReadableArray
4
+ import com.facebook.react.bridge.ReadableMap
5
+ import com.freeraspreactnative.exceptions.TalsecException
6
+
7
+ internal fun ReadableMap.getMapThrowing(key: String): ReadableMap {
8
+ return this.getMap(key) ?: throw TalsecException("Key missing in configuration: $key")
9
+ }
10
+
11
+ internal fun ReadableMap.getStringThrowing(key: String): String {
12
+ return this.getString(key) ?: throw TalsecException("Key missing in configuration: $key")
13
+ }
14
+
15
+ internal fun ReadableMap.getBooleanSafe(key: String, defaultValue: Boolean = true): Boolean {
16
+ if (this.hasKey(key)) {
17
+ return this.getBoolean(key)
18
+ }
19
+ return defaultValue
20
+ }
21
+
22
+ internal fun ReadableArray.toArray(): Array<String> {
23
+ val output = mutableListOf<String>()
24
+ for (i in 0 until this.size()) {
25
+ // in RN versions < 0.63, getString is nullable
26
+ @Suppress("UNNECESSARY_SAFE_CALL")
27
+ this.getString(i)?.let {
28
+ output.add(it)
29
+ }
30
+ }
31
+ return output.toTypedArray()
32
+ }
33
+
34
+ internal fun ReadableMap.getArraySafe(key: String): Array<String> {
35
+ if (this.hasKey(key)) {
36
+ val inputArray = this.getArray(key)!!
37
+ return inputArray.toArray()
38
+ }
39
+ return arrayOf()
40
+ }
@@ -0,0 +1,3 @@
1
+ package com.freeraspreactnative.exceptions
2
+
3
+ class TalsecException(message: String, val code: String? = null, val ex: Exception? = null) : Exception(message)
@@ -14,7 +14,7 @@ const App = () => {
14
14
  const config = {
15
15
  androidConfig: {
16
16
  packageName: 'com.freeraspreactnativeexample',
17
- certificateHashes: ['your_signing_certificate_hash_base64'],
17
+ certificateHashes: ['AKoRuyLMM91E7lX/Zqp3u4jMmd0A7hH/Iqozu0TMVd0='],
18
18
  // supportedAlternativeStores: ['storeOne', 'storeTwo'],
19
19
  },
20
20
  iosConfig: {
@@ -20,7 +20,7 @@ class FreeraspReactNative: RCTEventEmitter {
20
20
  try initializeTalsec(talsecConfig: options)
21
21
  }
22
22
  catch let error as NSError {
23
- reject("initialization_error", "Could not initialize freeRASP", error)
23
+ reject("TalsecInitializationError", "Could not initialize freeRASP: \(error.domain)", error)
24
24
  return
25
25
  }
26
26
  resolve("freeRASP started")
@@ -5,31 +5,35 @@
5
5
  <key>AvailableLibraries</key>
6
6
  <array>
7
7
  <dict>
8
+ <key>BinaryPath</key>
9
+ <string>TalsecRuntime.framework/TalsecRuntime</string>
8
10
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64</string>
11
+ <string>ios-arm64_x86_64-simulator</string>
10
12
  <key>LibraryPath</key>
11
13
  <string>TalsecRuntime.framework</string>
12
14
  <key>SupportedArchitectures</key>
13
15
  <array>
14
16
  <string>arm64</string>
17
+ <string>x86_64</string>
15
18
  </array>
16
19
  <key>SupportedPlatform</key>
17
20
  <string>ios</string>
21
+ <key>SupportedPlatformVariant</key>
22
+ <string>simulator</string>
18
23
  </dict>
19
24
  <dict>
25
+ <key>BinaryPath</key>
26
+ <string>TalsecRuntime.framework/TalsecRuntime</string>
20
27
  <key>LibraryIdentifier</key>
21
- <string>ios-arm64_x86_64-simulator</string>
28
+ <string>ios-arm64</string>
22
29
  <key>LibraryPath</key>
23
30
  <string>TalsecRuntime.framework</string>
24
31
  <key>SupportedArchitectures</key>
25
32
  <array>
26
33
  <string>arm64</string>
27
- <string>x86_64</string>
28
34
  </array>
29
35
  <key>SupportedPlatform</key>
30
36
  <string>ios</string>
31
- <key>SupportedPlatformVariant</key>
32
- <string>simulator</string>
33
37
  </dict>
34
38
  </array>
35
39
  <key>CFBundlePackageType</key>