react-native-security-pack 1.0.1 → 2.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 (73) hide show
  1. package/README.md +181 -13
  2. package/android/CMakeLists.txt +24 -0
  3. package/android/build.gradle +55 -60
  4. package/android/fix-prefab.gradle +44 -0
  5. package/android/gradle.properties +5 -5
  6. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  7. package/android/src/main/java/com/leerman/rnsecuritypack/RNSecurityPackPackage.kt +23 -0
  8. package/android/src/main/java/com/margelo/nitro/rnsecuritypack/HybridSecurityPack.kt +85 -0
  9. package/ios/HybridSecurityPack.swift +17 -0
  10. package/jest/mock.js +7 -0
  11. package/lib/commonjs/index.js +24 -17
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/specs/SecurityPack.nitro.js +6 -0
  14. package/lib/commonjs/specs/SecurityPack.nitro.js.map +1 -0
  15. package/lib/module/index.js +25 -18
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/module/specs/SecurityPack.nitro.js +4 -0
  18. package/lib/module/specs/SecurityPack.nitro.js.map +1 -0
  19. package/lib/typescript/commonjs/src/index.d.ts +7 -0
  20. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  21. package/lib/typescript/commonjs/src/specs/SecurityPack.nitro.d.ts +9 -0
  22. package/lib/typescript/commonjs/src/specs/SecurityPack.nitro.d.ts.map +1 -0
  23. package/lib/typescript/module/src/index.d.ts +7 -0
  24. package/lib/typescript/module/src/index.d.ts.map +1 -1
  25. package/lib/typescript/module/src/specs/SecurityPack.nitro.d.ts +9 -0
  26. package/lib/typescript/module/src/specs/SecurityPack.nitro.d.ts.map +1 -0
  27. package/nitro.json +24 -0
  28. package/nitrogen/generated/.gitattributes +1 -0
  29. package/nitrogen/generated/android/RNSecurityPack+autolinking.cmake +81 -0
  30. package/nitrogen/generated/android/RNSecurityPack+autolinking.gradle +27 -0
  31. package/nitrogen/generated/android/RNSecurityPackOnLoad.cpp +54 -0
  32. package/nitrogen/generated/android/RNSecurityPackOnLoad.hpp +34 -0
  33. package/nitrogen/generated/android/c++/JHybridSecurityPackSpec.cpp +92 -0
  34. package/nitrogen/generated/android/c++/JHybridSecurityPackSpec.hpp +64 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnsecuritypack/HybridSecurityPackSpec.kt +59 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnsecuritypack/RNSecurityPackOnLoad.kt +35 -0
  37. package/nitrogen/generated/ios/RNSecurityPack+autolinking.rb +62 -0
  38. package/nitrogen/generated/ios/RNSecurityPack-Swift-Cxx-Bridge.cpp +57 -0
  39. package/nitrogen/generated/ios/RNSecurityPack-Swift-Cxx-Bridge.hpp +166 -0
  40. package/nitrogen/generated/ios/RNSecurityPack-Swift-Cxx-Umbrella.hpp +46 -0
  41. package/nitrogen/generated/ios/RNSecurityPackAutolinking.mm +33 -0
  42. package/nitrogen/generated/ios/RNSecurityPackAutolinking.swift +26 -0
  43. package/nitrogen/generated/ios/c++/HybridSecurityPackSpecSwift.cpp +11 -0
  44. package/nitrogen/generated/ios/c++/HybridSecurityPackSpecSwift.hpp +92 -0
  45. package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  46. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  47. package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +46 -0
  48. package/nitrogen/generated/ios/swift/HybridSecurityPackSpec.swift +56 -0
  49. package/nitrogen/generated/ios/swift/HybridSecurityPackSpec_cxx.swift +170 -0
  50. package/nitrogen/generated/shared/c++/HybridSecurityPackSpec.cpp +22 -0
  51. package/nitrogen/generated/shared/c++/HybridSecurityPackSpec.hpp +65 -0
  52. package/package.json +36 -42
  53. package/react-native-security-pack.podspec +18 -27
  54. package/react-native.config.js +1 -0
  55. package/src/index.ts +39 -0
  56. package/src/specs/SecurityPack.nitro.ts +7 -0
  57. package/android/src/main/AndroidManifestNew.xml +0 -2
  58. package/android/src/main/java/com/leerman/rnsecuritypack/SecurityPackModule.kt +0 -85
  59. package/android/src/main/java/com/leerman/rnsecuritypack/SecurityPackPackage.kt +0 -35
  60. package/android/src/newarch/SecurityPackSpec.kt +0 -7
  61. package/android/src/oldarch/SecurityPackSpec.kt +0 -12
  62. package/ios/SecurityPack.h +0 -12
  63. package/ios/SecurityPack.mm +0 -25
  64. package/lib/commonjs/NativeSecurityPack.js +0 -9
  65. package/lib/commonjs/NativeSecurityPack.js.map +0 -1
  66. package/lib/module/NativeSecurityPack.js +0 -5
  67. package/lib/module/NativeSecurityPack.js.map +0 -1
  68. package/lib/typescript/commonjs/src/NativeSecurityPack.d.ts +0 -8
  69. package/lib/typescript/commonjs/src/NativeSecurityPack.d.ts.map +0 -1
  70. package/lib/typescript/module/src/NativeSecurityPack.d.ts +0 -8
  71. package/lib/typescript/module/src/NativeSecurityPack.d.ts.map +0 -1
  72. package/src/NativeSecurityPack.ts +0 -9
  73. package/src/index.tsx +0 -43
@@ -0,0 +1,56 @@
1
+ ///
2
+ /// HybridSecurityPackSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /// See ``HybridSecurityPackSpec``
11
+ public protocol HybridSecurityPackSpec_protocol: HybridObject {
12
+ // Properties
13
+
14
+
15
+ // Methods
16
+ func getSignatures() throws -> Promise<[String]>
17
+ func isRooted() throws -> Promise<Bool>
18
+ }
19
+
20
+ public extension HybridSecurityPackSpec_protocol {
21
+ /// Default implementation of ``HybridObject.toString``
22
+ func toString() -> String {
23
+ return "[HybridObject SecurityPack]"
24
+ }
25
+ }
26
+
27
+ /// See ``HybridSecurityPackSpec``
28
+ open class HybridSecurityPackSpec_base {
29
+ private weak var cxxWrapper: HybridSecurityPackSpec_cxx? = nil
30
+ public init() { }
31
+ public func getCxxWrapper() -> HybridSecurityPackSpec_cxx {
32
+ #if DEBUG
33
+ guard self is any HybridSecurityPackSpec else {
34
+ fatalError("`self` is not a `HybridSecurityPackSpec`! Did you accidentally inherit from `HybridSecurityPackSpec_base` instead of `HybridSecurityPackSpec`?")
35
+ }
36
+ #endif
37
+ if let cxxWrapper = self.cxxWrapper {
38
+ return cxxWrapper
39
+ } else {
40
+ let cxxWrapper = HybridSecurityPackSpec_cxx(self as! any HybridSecurityPackSpec)
41
+ self.cxxWrapper = cxxWrapper
42
+ return cxxWrapper
43
+ }
44
+ }
45
+ }
46
+
47
+ /**
48
+ * A Swift base-protocol representing the SecurityPack HybridObject.
49
+ * Implement this protocol to create Swift-based instances of SecurityPack.
50
+ * ```swift
51
+ * class HybridSecurityPack : HybridSecurityPackSpec {
52
+ * // ...
53
+ * }
54
+ * ```
55
+ */
56
+ public typealias HybridSecurityPackSpec = HybridSecurityPackSpec_protocol & HybridSecurityPackSpec_base
@@ -0,0 +1,170 @@
1
+ ///
2
+ /// HybridSecurityPackSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * A class implementation that bridges HybridSecurityPackSpec over to C++.
12
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
13
+ *
14
+ * Also, some Swift types need to be bridged with special handling:
15
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
16
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
17
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
18
+ */
19
+ open class HybridSecurityPackSpec_cxx {
20
+ /**
21
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::rnsecuritypack::bridge::swift`)
22
+ * from `RNSecurityPack-Swift-Cxx-Bridge.hpp`.
23
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
24
+ */
25
+ public typealias bridge = margelo.nitro.rnsecuritypack.bridge.swift
26
+
27
+ /**
28
+ * Holds an instance of the `HybridSecurityPackSpec` Swift protocol.
29
+ */
30
+ private var __implementation: any HybridSecurityPackSpec
31
+
32
+ /**
33
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
34
+ */
35
+ private var __cxxPart: bridge.std__weak_ptr_HybridSecurityPackSpec_
36
+
37
+ /**
38
+ * Create a new `HybridSecurityPackSpec_cxx` that wraps the given `HybridSecurityPackSpec`.
39
+ * All properties and methods bridge to C++ types.
40
+ */
41
+ public init(_ implementation: any HybridSecurityPackSpec) {
42
+ self.__implementation = implementation
43
+ self.__cxxPart = .init()
44
+ /* no base class */
45
+ }
46
+
47
+ /**
48
+ * Get the actual `HybridSecurityPackSpec` instance this class wraps.
49
+ */
50
+ @inline(__always)
51
+ public func getHybridSecurityPackSpec() -> any HybridSecurityPackSpec {
52
+ return __implementation
53
+ }
54
+
55
+ /**
56
+ * Casts this instance to a retained unsafe raw pointer.
57
+ * This acquires one additional strong reference on the object!
58
+ */
59
+ public func toUnsafe() -> UnsafeMutableRawPointer {
60
+ return Unmanaged.passRetained(self).toOpaque()
61
+ }
62
+
63
+ /**
64
+ * Casts an unsafe pointer to a `HybridSecurityPackSpec_cxx`.
65
+ * The pointer has to be a retained opaque `Unmanaged<HybridSecurityPackSpec_cxx>`.
66
+ * This removes one strong reference from the object!
67
+ */
68
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridSecurityPackSpec_cxx {
69
+ return Unmanaged<HybridSecurityPackSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
70
+ }
71
+
72
+ /**
73
+ * Gets (or creates) the C++ part of this Hybrid Object.
74
+ * The C++ part is a `std::shared_ptr<HybridSecurityPackSpec>`.
75
+ */
76
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridSecurityPackSpec_ {
77
+ let cachedCxxPart = self.__cxxPart.lock()
78
+ if Bool(fromCxx: cachedCxxPart) {
79
+ return cachedCxxPart
80
+ } else {
81
+ let newCxxPart = bridge.create_std__shared_ptr_HybridSecurityPackSpec_(self.toUnsafe())
82
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridSecurityPackSpec_(newCxxPart)
83
+ return newCxxPart
84
+ }
85
+ }
86
+
87
+
88
+
89
+ /**
90
+ * Get the memory size of the Swift class (plus size of any other allocations)
91
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
92
+ */
93
+ @inline(__always)
94
+ public var memorySize: Int {
95
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
96
+ }
97
+
98
+ /**
99
+ * Compares this object with the given [other] object for reference equality.
100
+ */
101
+ @inline(__always)
102
+ public func equals(other: HybridSecurityPackSpec_cxx) -> Bool {
103
+ return self.__implementation === other.__implementation
104
+ }
105
+
106
+ /**
107
+ * Call dispose() on the Swift class.
108
+ * This _may_ be called manually from JS.
109
+ */
110
+ @inline(__always)
111
+ public func dispose() {
112
+ self.__implementation.dispose()
113
+ }
114
+
115
+ /**
116
+ * Call toString() on the Swift class.
117
+ */
118
+ @inline(__always)
119
+ public func toString() -> String {
120
+ return self.__implementation.toString()
121
+ }
122
+
123
+ // Properties
124
+
125
+
126
+ // Methods
127
+ @inline(__always)
128
+ public final func getSignatures() -> bridge.Result_std__shared_ptr_Promise_std__vector_std__string____ {
129
+ do {
130
+ let __result = try self.__implementation.getSignatures()
131
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__vector_std__string___ in
132
+ let __promise = bridge.create_std__shared_ptr_Promise_std__vector_std__string___()
133
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__vector_std__string___(__promise)
134
+ __result
135
+ .then({ __result in __promiseHolder.resolve({ () -> bridge.std__vector_std__string_ in
136
+ var __vector = bridge.create_std__vector_std__string_(__result.count)
137
+ for __item in __result {
138
+ __vector.push_back(std.string(__item))
139
+ }
140
+ return __vector
141
+ }()) })
142
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
143
+ return __promise
144
+ }()
145
+ return bridge.create_Result_std__shared_ptr_Promise_std__vector_std__string____(__resultCpp)
146
+ } catch (let __error) {
147
+ let __exceptionPtr = __error.toCpp()
148
+ return bridge.create_Result_std__shared_ptr_Promise_std__vector_std__string____(__exceptionPtr)
149
+ }
150
+ }
151
+
152
+ @inline(__always)
153
+ public final func isRooted() -> bridge.Result_std__shared_ptr_Promise_bool___ {
154
+ do {
155
+ let __result = try self.__implementation.isRooted()
156
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_bool__ in
157
+ let __promise = bridge.create_std__shared_ptr_Promise_bool__()
158
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
159
+ __result
160
+ .then({ __result in __promiseHolder.resolve(__result) })
161
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
162
+ return __promise
163
+ }()
164
+ return bridge.create_Result_std__shared_ptr_Promise_bool___(__resultCpp)
165
+ } catch (let __error) {
166
+ let __exceptionPtr = __error.toCpp()
167
+ return bridge.create_Result_std__shared_ptr_Promise_bool___(__exceptionPtr)
168
+ }
169
+ }
170
+ }
@@ -0,0 +1,22 @@
1
+ ///
2
+ /// HybridSecurityPackSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridSecurityPackSpec.hpp"
9
+
10
+ namespace margelo::nitro::rnsecuritypack {
11
+
12
+ void HybridSecurityPackSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("getSignatures", &HybridSecurityPackSpec::getSignatures);
18
+ prototype.registerHybridMethod("isRooted", &HybridSecurityPackSpec::isRooted);
19
+ });
20
+ }
21
+
22
+ } // namespace margelo::nitro::rnsecuritypack
@@ -0,0 +1,65 @@
1
+ ///
2
+ /// HybridSecurityPackSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+
17
+
18
+ #include <string>
19
+ #include <vector>
20
+ #include <NitroModules/Promise.hpp>
21
+
22
+ namespace margelo::nitro::rnsecuritypack {
23
+
24
+ using namespace margelo::nitro;
25
+
26
+ /**
27
+ * An abstract base class for `SecurityPack`
28
+ * Inherit this class to create instances of `HybridSecurityPackSpec` in C++.
29
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
30
+ * @example
31
+ * ```cpp
32
+ * class HybridSecurityPack: public HybridSecurityPackSpec {
33
+ * public:
34
+ * HybridSecurityPack(...): HybridObject(TAG) { ... }
35
+ * // ...
36
+ * };
37
+ * ```
38
+ */
39
+ class HybridSecurityPackSpec: public virtual HybridObject {
40
+ public:
41
+ // Constructor
42
+ explicit HybridSecurityPackSpec(): HybridObject(TAG) { }
43
+
44
+ // Destructor
45
+ ~HybridSecurityPackSpec() override = default;
46
+
47
+ public:
48
+ // Properties
49
+
50
+
51
+ public:
52
+ // Methods
53
+ virtual std::shared_ptr<Promise<std::vector<std::string>>> getSignatures() = 0;
54
+ virtual std::shared_ptr<Promise<bool>> isRooted() = 0;
55
+
56
+ protected:
57
+ // Hybrid Setup
58
+ void loadHybridMethods() override;
59
+
60
+ protected:
61
+ // Tag for logging
62
+ static constexpr auto TAG = "SecurityPack";
63
+ };
64
+
65
+ } // namespace margelo::nitro::rnsecuritypack
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "react-native-security-pack",
3
- "version": "1.0.1",
4
- "description": "security",
5
- "source": "./src/index.tsx",
3
+ "version": "2.0.0",
4
+ "description": "Root/jailbreak detection and APK signature verification for React Native (Nitro Modules, New Architecture)",
5
+ "source": "./src/index.ts",
6
6
  "main": "./lib/commonjs/index.js",
7
7
  "module": "./lib/module/index.js",
8
+ "types": "./lib/typescript/module/src/index.d.ts",
9
+ "react-native": "src/index",
8
10
  "exports": {
9
11
  ".": {
10
12
  "import": {
@@ -20,22 +22,21 @@
20
22
  "files": [
21
23
  "src",
22
24
  "lib",
23
- "android",
25
+ "jest",
26
+ "nitrogen",
27
+ "android/build.gradle",
28
+ "android/gradle.properties",
29
+ "android/fix-prefab.gradle",
30
+ "android/CMakeLists.txt",
31
+ "android/src",
24
32
  "ios",
25
- "cpp",
33
+ "nitro.json",
34
+ "react-native.config.js",
26
35
  "*.podspec",
27
- "!ios/build",
28
- "!ios/generated",
29
36
  "!android/build",
30
- "!android/gradle",
31
- "!android/gradlew",
32
- "!android/gradlew.bat",
33
- "!android/local.properties",
34
- "!android/generated",
35
37
  "!**/__tests__",
36
38
  "!**/__fixtures__",
37
- "!**/__mocks__",
38
- "!**/.*"
39
+ "!**/__mocks__"
39
40
  ],
40
41
  "scripts": {
41
42
  "example": "yarn workspace react-native-security-pack-example",
@@ -43,13 +44,18 @@
43
44
  "typecheck": "tsc",
44
45
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
45
46
  "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
46
- "prepare": "bob build",
47
+ "specs": "nitrogen",
48
+ "prepare": "yarn specs && bob build",
47
49
  "release": "release-it"
48
50
  },
49
51
  "keywords": [
50
52
  "react-native",
51
- "ios",
52
- "android"
53
+ "security",
54
+ "jailbreak",
55
+ "root",
56
+ "signature",
57
+ "nitro",
58
+ "new-architecture"
53
59
  ],
54
60
  "repository": {
55
61
  "type": "git",
@@ -67,30 +73,33 @@
67
73
  "devDependencies": {
68
74
  "@commitlint/config-conventional": "^17.0.2",
69
75
  "@evilmartians/lefthook": "^1.5.0",
70
- "@react-native/eslint-config": "^0.73.1",
76
+ "@react-native/eslint-config": "^0.76.0",
71
77
  "@release-it/conventional-changelog": "^5.0.0",
72
78
  "@types/jest": "^29.5.5",
73
- "@types/react": "^18.2.44",
79
+ "@types/react": "^18.3.0",
74
80
  "commitlint": "^17.0.2",
75
81
  "del-cli": "^5.1.0",
76
82
  "eslint": "^8.51.0",
77
83
  "eslint-config-prettier": "^9.0.0",
78
84
  "eslint-plugin-prettier": "^5.0.1",
79
85
  "jest": "^29.7.0",
86
+ "nitrogen": "^0.35.9",
80
87
  "prettier": "^3.0.3",
81
88
  "react": "18.3.1",
82
- "react-native": "0.75.2",
89
+ "react-native": "0.76.9",
83
90
  "react-native-builder-bob": "^0.30.0",
91
+ "react-native-nitro-modules": "^0.35.9",
84
92
  "release-it": "^15.0.0",
85
93
  "turbo": "^1.10.7",
86
94
  "typescript": "^5.2.2"
87
95
  },
88
96
  "resolutions": {
89
- "@types/react": "^18.2.44"
97
+ "@types/react": "^18.3.0"
90
98
  },
91
99
  "peerDependencies": {
92
100
  "react": "*",
93
- "react-native": "*"
101
+ "react-native": ">=0.75.0",
102
+ "react-native-nitro-modules": ">=0.35.0"
94
103
  },
95
104
  "workspaces": [
96
105
  "example"
@@ -131,6 +140,9 @@
131
140
  "@react-native",
132
141
  "prettier"
133
142
  ],
143
+ "plugins": [
144
+ "prettier"
145
+ ],
134
146
  "rules": {
135
147
  "react/react-in-jsx-scope": "off",
136
148
  "prettier/prettier": [
@@ -147,7 +159,8 @@
147
159
  },
148
160
  "eslintIgnore": [
149
161
  "node_modules/",
150
- "lib/"
162
+ "lib/",
163
+ "nitrogen/"
151
164
  ],
152
165
  "prettier": {
153
166
  "quoteProps": "consistent",
@@ -160,7 +173,6 @@
160
173
  "source": "src",
161
174
  "output": "lib",
162
175
  "targets": [
163
- "codegen",
164
176
  [
165
177
  "commonjs",
166
178
  {
@@ -181,23 +193,5 @@
181
193
  }
182
194
  ]
183
195
  ]
184
- },
185
- "codegenConfig": {
186
- "name": "RNSecurityPackSpec",
187
- "type": "all",
188
- "jsSrcsDir": "src",
189
- "outputDir": {
190
- "ios": "ios/generated",
191
- "android": "android/generated"
192
- },
193
- "android": {
194
- "javaPackageName": "com.leerman.rnsecuritypack"
195
- },
196
- "includesGeneratedCode": true
197
- },
198
- "create-react-native-library": {
199
- "type": "module-mixed",
200
- "languages": "kotlin-objc",
201
- "version": "0.41.0"
202
196
  }
203
197
  }
@@ -1,7 +1,6 @@
1
1
  require "json"
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
- folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
4
 
6
5
  Pod::Spec.new do |s|
7
6
  s.name = "react-native-security-pack"
@@ -12,32 +11,24 @@ Pod::Spec.new do |s|
12
11
  s.authors = package["author"]
13
12
 
14
13
  s.platforms = { :ios => min_ios_version_supported }
15
- s.source = { :git => "https://github.com/leerman/react-native-security-pack.git", :tag => "#{s.version}" }
16
-
17
- s.source_files = "ios/**/*.{h,m,mm,cpp}"
18
-
19
- # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
20
- # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
21
- if respond_to?(:install_modules_dependencies, true)
22
- install_modules_dependencies(s)
23
- else
24
- s.dependency "React-Core"
25
-
26
- # Don't install the dependencies when we run `pod install` in the old architecture.
27
- if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
28
- s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
29
- s.pod_target_xcconfig = {
30
- "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
31
- "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
32
- "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
33
- }
34
- s.dependency "React-Codegen"
35
- s.dependency "RCT-Folly"
36
- s.dependency "RCTRequired"
37
- s.dependency "RCTTypeSafety"
38
- s.dependency "ReactCommon/turbomodule/core"
39
- end
40
- end
14
+ s.source = { :git => package["repository"]["url"] + ".git", :tag => "#{s.version}" }
15
+ s.module_name = "RNSecurityPack"
41
16
 
17
+ s.source_files = [
18
+ "ios/**/*.{swift}",
19
+ "ios/**/*.{m,mm}",
20
+ ]
21
+
22
+ s.pod_target_xcconfig = {
23
+ "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES",
24
+ }
25
+
26
+ load "nitrogen/generated/ios/RNSecurityPack+autolinking.rb"
27
+ add_nitrogen_files(s)
28
+
29
+ s.dependency "React-jsi"
30
+ s.dependency "React-callinvoker"
42
31
  s.dependency "DTTJailbreakDetection"
32
+
33
+ install_modules_dependencies(s)
43
34
  end
@@ -0,0 +1 @@
1
+ module.exports = {};
package/src/index.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { Platform } from 'react-native';
2
+ import { NitroModules } from 'react-native-nitro-modules';
3
+ import type { SecurityPack as SecurityPackSpec } from './specs/SecurityPack.nitro';
4
+
5
+ let securityPack: SecurityPackSpec | null = null;
6
+
7
+ function getSecurityPack(): SecurityPackSpec {
8
+ if (securityPack == null) {
9
+ securityPack =
10
+ NitroModules.createHybridObject<SecurityPackSpec>('SecurityPack');
11
+ }
12
+ return securityPack;
13
+ }
14
+
15
+ async function getSignatures(): Promise<string[]> {
16
+ const signatures = await getSecurityPack().getSignatures();
17
+ return signatures.map((item) => item.toUpperCase());
18
+ }
19
+
20
+ /**
21
+ * Checks whether the app's signing certificate matches any of the given SHA-1
22
+ * fingerprints (hex, case-insensitive).
23
+ *
24
+ * On iOS this always returns `true` because APK signatures are Android-only.
25
+ */
26
+ export async function containsSignatures(sigs: string[]): Promise<boolean> {
27
+ if (Platform.OS === 'ios') {
28
+ return true;
29
+ }
30
+
31
+ const signatures = await getSignatures();
32
+ const expected = sigs.map((item) => item.toUpperCase());
33
+ return signatures.some((item) => expected.includes(item));
34
+ }
35
+
36
+ /** Returns `true` when the device appears to be rooted (Android) or jailbroken (iOS). */
37
+ export async function isRooted(): Promise<boolean> {
38
+ return await getSecurityPack().isRooted();
39
+ }
@@ -0,0 +1,7 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface SecurityPack
4
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
5
+ getSignatures(): Promise<string[]>;
6
+ isRooted(): Promise<boolean>;
7
+ }
@@ -1,2 +0,0 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
- </manifest>
@@ -1,85 +0,0 @@
1
- package com.leerman.rnsecuritypack
2
-
3
- import com.facebook.react.bridge.Arguments
4
- import com.facebook.react.bridge.ReactApplicationContext
5
- import com.facebook.react.bridge.ReactMethod
6
- import com.facebook.react.bridge.Promise
7
-
8
- import android.os.Build
9
- import android.content.pm.PackageManager
10
- import com.kimchangyoun.rootbeerFresh.RootBeer
11
-
12
- import java.security.MessageDigest
13
-
14
- class SecurityPackModule internal constructor(context: ReactApplicationContext) :
15
- SecurityPackSpec(context) {
16
-
17
- override fun getName(): String {
18
- return NAME
19
- }
20
-
21
- companion object {
22
- const val NAME = "SecurityPack"
23
- }
24
-
25
- private val mContext: ReactApplicationContext = context
26
-
27
- @ReactMethod
28
- override fun isRooted(promise: Promise) {
29
- val rootBeer = RootBeer(mContext)
30
- promise.resolve(rootBeer.isRooted)
31
- }
32
-
33
- @ReactMethod
34
- override fun getSignatures(promise: Promise) {
35
- val signatureList: List<String>
36
- try {
37
- val packageName = mContext.getPackageName()
38
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
39
- // New signature
40
- val sig = mContext.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES).signingInfo
41
- signatureList = if (sig.hasMultipleSigners()) {
42
- // Send all with apkContentsSigners
43
- sig.apkContentsSigners.map {
44
- val digest = MessageDigest.getInstance("SHA")
45
- digest.update(it.toByteArray())
46
- bytesToHex(digest.digest())
47
- }
48
- } else {
49
- // Send one with signingCertificateHistory
50
- sig.signingCertificateHistory.map {
51
- val digest = MessageDigest.getInstance("SHA")
52
- digest.update(it.toByteArray())
53
- bytesToHex(digest.digest())
54
- }
55
- }
56
- } else {
57
- val sig = mContext.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures
58
- signatureList = sig.map {
59
- val digest = MessageDigest.getInstance("SHA")
60
- digest.update(it.toByteArray())
61
- bytesToHex(digest.digest())
62
- }
63
- }
64
- val array = Arguments.fromList(signatureList)
65
- promise.resolve(array)
66
- } catch (e: Exception) {
67
- // Handle error
68
- }
69
-
70
- val empty = Arguments.fromList(emptyList<String>())
71
- promise.resolve(empty)
72
- }
73
-
74
- fun bytesToHex(bytes: ByteArray): String {
75
- val hexArray = charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')
76
- val hexChars = CharArray(bytes.size * 2)
77
- var v: Int
78
- for (j in bytes.indices) {
79
- v = bytes[j].toInt() and 0xFF
80
- hexChars[j * 2] = hexArray[v.ushr(4)]
81
- hexChars[j * 2 + 1] = hexArray[v and 0x0F]
82
- }
83
- return String(hexChars)
84
- }
85
- }