@@ -6,12 +6,6 @@ class FreeraspReactNative: RCTEventEmitter {
66
77 public static var shared : FreeraspReactNative ?
88
9- let threatChannelKey = String ( Int . random ( in: 100_000 ..< 999_999_999 ) ) // key of the argument map under which threats are expected
10- let threatChannelName = String ( Int . random ( in: 100_000 ..< 999_999_999 ) ) // name of the channel over which threat callbacks are sent
11-
12- let raspExecutionStateChannelKey = String ( Int . random ( in: 100_000 ..< 999_999_999 ) ) // key of the argument map under which threats are expected
13- let raspExecutionStateChannelName = String ( Int . random ( in: 100_000 ..< 999_999_999 ) ) // name of the channel over which threat callbacks are sent
14-
159 override init ( ) {
1610 super. init ( )
1711 FreeraspReactNative . shared = self
@@ -77,48 +71,32 @@ class FreeraspReactNative: RCTEventEmitter {
7771 UserDefaults . standard. set ( externalId, forKey: " app.talsec.externalid " )
7872 resolve ( " OK - Store external ID " )
7973 }
80-
81- private func getProtectedWindow( completion: @escaping ( UIWindow ? ) -> Void ) {
82- DispatchQueue . main. async {
83- if #available( iOS 13 . 0 , * ) {
84- if let windowScene = UIApplication . shared. connectedScenes. first as? UIWindowScene {
85- if let window = windowScene. windows. first {
86- completion ( window)
87- } else {
88- completion ( nil )
89- }
90- } else {
91- completion ( nil )
92- }
93- }
94- }
95- }
9674
9775 /**
9876 * Method to setup the message passing between native and React Native
9977 */
10078 @objc ( getThreatChannelData: withRejecter: )
10179 private func getThreatChannelData( resolve: RCTPromiseResolveBlock , rejecter reject: RCTPromiseRejectBlock ) -> Void {
102- resolve ( [ threatChannelName, threatChannelKey] )
80+ resolve ( [ EventIdentifiers . threatChannelName, EventIdentifiers . threatChannelKey] )
10381 }
10482
10583 /**
10684 * Method to setup the message passing between native and React Native
10785 */
10886 @objc ( getRaspExecutionStateChannelData: withRejecter: )
10987 private func getRaspExecutionStateChannelData( resolve: RCTPromiseResolveBlock , rejecter reject: RCTPromiseRejectBlock ) -> Void {
110- resolve ( [ raspExecutionStateChannelName, raspExecutionStateChannelKey] )
88+ resolve ( [ EventIdentifiers . raspExecutionStateChannelName, EventIdentifiers . raspExecutionStateChannelKey] )
11189 }
11290
11391 func dispatchEvent( securityThreat: SecurityThreat ) -> Void {
114- FreeraspReactNative . shared!. sendEvent ( withName: threatChannelName, body: [
115- threatChannelKey: securityThreat. callbackIdentifier,
92+ FreeraspReactNative . shared!. sendEvent ( withName: EventIdentifiers . threatChannelName, body: [
93+ EventIdentifiers . threatChannelKey: securityThreat. callbackIdentifier,
11694 ] )
11795 }
11896
11997 func dispatchRaspExecutionStateEvent( event: RaspExecutionStates ) -> Void {
120- FreeraspReactNative . shared!. sendEvent ( withName: raspExecutionStateChannelName, body: [
121- raspExecutionStateChannelKey: event. callbackIdentifier,
98+ FreeraspReactNative . shared!. sendEvent ( withName: EventIdentifiers . raspExecutionStateChannelName, body: [
99+ EventIdentifiers . raspExecutionStateChannelKey: event. callbackIdentifier,
122100 ] )
123101 }
124102
@@ -127,15 +105,15 @@ class FreeraspReactNative: RCTEventEmitter {
127105 */
128106 @objc ( getThreatIdentifiers: withRejecter: )
129107 private func getThreatIdentifiers( resolve: RCTPromiseResolveBlock , rejecter reject: RCTPromiseRejectBlock ) -> Void {
130- resolve ( getThreatIdentifiers ( ) )
108+ resolve ( freerasp_react_native . getThreatIdentifiers ( ) )
131109 }
132110
133111 /**
134112 * Method to get the random identifiers of callbacks
135113 */
136114 @objc ( getRaspExecutionStateIdentifiers: withRejecter: )
137115 private func getRaspExecutionStateIdentifiers( resolve: RCTPromiseResolveBlock , rejecter reject: RCTPromiseRejectBlock ) -> Void {
138- resolve ( getRaspExecutionStateIdentifiers ( ) )
116+ resolve ( freerasp_react_native . getRaspExecutionStateIdentifiers ( ) )
139117 }
140118
141119 /**
@@ -147,71 +125,13 @@ class FreeraspReactNative: RCTEventEmitter {
147125 abort ( )
148126 }
149127
150- private func getThreatIdentifiers( ) -> [ Int ] {
151- return SecurityThreat . allCases
152- . filter {
153- threat in threat. rawValue != " passcodeChange "
154- }
155- . map {
156- threat in threat. callbackIdentifier
157- }
158- }
159-
160- private func getRaspExecutionStateIdentifiers( ) -> [ Int ] {
161- return RaspExecutionStates . allCases
162- . map {
163- event in event. callbackIdentifier
164- }
165- }
166-
167128 override func supportedEvents( ) -> [ String ] ! {
168- return [ threatChannelName, raspExecutionStateChannelName]
129+ return [ EventIdentifiers . threatChannelName, EventIdentifiers . raspExecutionStateChannelName]
169130 }
170131}
171132
172- struct ThreatIdentifiers {
173- static let threatIdentifierList : [ Int ] = ( 1 ... 14 ) . map { _ in Int . random ( in: 100_000 ..< 999_999_999 ) }
174- static let raspExecutionStateIdentifierList : [ Int ] = ( 1 ... 1 ) . map { _ in Int . random ( in: 100_000 ..< 999_999_999 ) }
175- }
176133
177- /// An extension to unify callback names with RN ones.
178- extension SecurityThreat {
179-
180- var callbackIdentifier : Int {
181- switch self {
182- case . signature:
183- return ThreatIdentifiers . threatIdentifierList [ 0 ]
184- case . jailbreak:
185- return ThreatIdentifiers . threatIdentifierList [ 1 ]
186- case . debugger:
187- return ThreatIdentifiers . threatIdentifierList [ 2 ]
188- case . runtimeManipulation:
189- return ThreatIdentifiers . threatIdentifierList [ 3 ]
190- case . passcode:
191- return ThreatIdentifiers . threatIdentifierList [ 4 ]
192- case . passcodeChange:
193- return ThreatIdentifiers . threatIdentifierList [ 5 ]
194- case . simulator:
195- return ThreatIdentifiers . threatIdentifierList [ 6 ]
196- case . missingSecureEnclave:
197- return ThreatIdentifiers . threatIdentifierList [ 7 ]
198- case . systemVPN:
199- return ThreatIdentifiers . threatIdentifierList [ 8 ]
200- case . deviceChange:
201- return ThreatIdentifiers . threatIdentifierList [ 9 ]
202- case . deviceID:
203- return ThreatIdentifiers . threatIdentifierList [ 10 ]
204- case . unofficialStore:
205- return ThreatIdentifiers . threatIdentifierList [ 11 ]
206- case . screenshot:
207- return ThreatIdentifiers . threatIdentifierList [ 12 ]
208- case . screenRecording:
209- return ThreatIdentifiers . threatIdentifierList [ 13 ]
210- @unknown default :
211- abort ( )
212- }
213- }
214- }
134+
215135
216136extension SecurityThreatCenter : @retroactive SecurityThreatHandler , @retroactive RaspExecutionState {
217137
@@ -228,18 +148,4 @@ extension SecurityThreatCenter: @retroactive SecurityThreatHandler, @retroactive
228148 }
229149}
230150
231- enum RaspExecutionStates : String , Codable , CaseIterable , Equatable {
232-
233- case allChecksFinished
234-
235- public static var allCases : [ RaspExecutionStates ] {
236- return [ . allChecksFinished]
237- }
238-
239- var callbackIdentifier : Int {
240- switch self {
241- case . allChecksFinished:
242- return ThreatIdentifiers . raspExecutionStateIdentifierList [ 0 ]
243- }
244- }
245- }
151+
0 commit comments