Skip to content

Commit 8f8dfc3

Browse files
committed
feat(iOS): add vpn detection
1 parent 4eb646d commit 8f8dfc3

37 files changed

+2653
-1341
lines changed

ios/FreeraspReactNative.swift

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import TalsecRuntime
55
class FreeraspReactNative: RCTEventEmitter {
66

77
public static var shared:FreeraspReactNative?
8-
8+
99
let threatChannelKey = String(Int.random(in: 100_000..<999_999_999)) // key of the argument map under which threats are expected
1010
let threatChannelName = String(Int.random(in: 100_000..<999_999_999)) // name of the channel over which threat callbacks are sent
11-
let threatIdentifierList = (1...12).map { _ in Int.random(in: 100_000..<999_999_999) }
1211

1312
override init() {
1413
super.init()
@@ -45,27 +44,27 @@ class FreeraspReactNative: RCTEventEmitter {
4544
let config = TalsecConfig(appBundleIds: [appBundleIds], appTeamId: appTeamId, watcherMailAddress: watcherMailAddress, isProd: isProd)
4645
Talsec.start(config: config)
4746
}
48-
47+
4948
/**
5049
* Method to setup the message passing between native and React Native
5150
*/
5251
@objc(getThreatChannelData:withRejecter:)
5352
private func getThreatChannelData(resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
5453
resolve([threatChannelName, threatChannelKey])
5554
}
56-
55+
5756
func dispatchEvent(securityThreat: SecurityThreat) -> Void {
5857
FreeraspReactNative.shared!.sendEvent(withName: threatChannelName, body: [threatChannelKey: securityThreat.callbackIdentifier])
5958
}
60-
59+
6160
/**
6261
* Method to get the random identifiers of callbacks
6362
*/
6463
@objc(getThreatIdentifiers:withRejecter:)
6564
private func getThreatIdentifiers(resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
6665
resolve(getThreatIdentifiers())
6766
}
68-
67+
6968
/**
7069
* We never send an invalid callback over our channel.
7170
* Therefore, if this happens, we want to kill the app.
@@ -74,7 +73,7 @@ class FreeraspReactNative: RCTEventEmitter {
7473
private func onInvalidCallback() -> Void {
7574
abort()
7675
}
77-
76+
7877
private func getThreatIdentifiers() -> [Int] {
7978
return SecurityThreat.allCases
8079
.filter {
@@ -90,33 +89,39 @@ class FreeraspReactNative: RCTEventEmitter {
9089
}
9190
}
9291

92+
struct ThreatIdentifiers {
93+
static let threatIdentifierList: [Int] = (1...12).map { _ in Int.random(in: 100_000..<999_999_999) }
94+
}
95+
9396
/// An extension to unify callback names with RN ones.
9497
extension SecurityThreat {
9598

9699
var callbackIdentifier: Int {
97100
switch self {
98101
case .signature:
99-
return FreeraspReactNative.shared!.threatIdentifierList[0]
102+
return ThreatIdentifiers.threatIdentifierList[0]
100103
case .jailbreak:
101-
return FreeraspReactNative.shared!.threatIdentifierList[1]
104+
return ThreatIdentifiers.threatIdentifierList[1]
102105
case .debugger:
103-
return FreeraspReactNative.shared!.threatIdentifierList[2]
106+
return ThreatIdentifiers.threatIdentifierList[2]
104107
case .runtimeManipulation:
105-
return FreeraspReactNative.shared!.threatIdentifierList[3]
108+
return ThreatIdentifiers.threatIdentifierList[3]
106109
case .passcode:
107-
return FreeraspReactNative.shared!.threatIdentifierList[4]
110+
return ThreatIdentifiers.threatIdentifierList[4]
108111
case .passcodeChange:
109-
return FreeraspReactNative.shared!.threatIdentifierList[5]
112+
return ThreatIdentifiers.threatIdentifierList[5]
110113
case .simulator:
111-
return FreeraspReactNative.shared!.threatIdentifierList[6]
114+
return ThreatIdentifiers.threatIdentifierList[6]
112115
case .missingSecureEnclave:
113-
return FreeraspReactNative.shared!.threatIdentifierList[7]
116+
return ThreatIdentifiers.threatIdentifierList[7]
117+
case .systemVPN:
118+
return ThreatIdentifiers.threatIdentifierList[8]
114119
case .deviceChange:
115-
return FreeraspReactNative.shared!.threatIdentifierList[8]
120+
return ThreatIdentifiers.threatIdentifierList[9]
116121
case .deviceID:
117-
return FreeraspReactNative.shared!.threatIdentifierList[9]
122+
return ThreatIdentifiers.threatIdentifierList[10]
118123
case .unofficialStore:
119-
return FreeraspReactNative.shared!.threatIdentifierList[10]
124+
return ThreatIdentifiers.threatIdentifierList[11]
120125
@unknown default:
121126
abort()
122127
}

ios/TalsecRuntime.xcframework/Info.plist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@
66
<array>
77
<dict>
88
<key>LibraryIdentifier</key>
9-
<string>ios-arm64_x86_64-simulator</string>
9+
<string>ios-arm64</string>
1010
<key>LibraryPath</key>
1111
<string>TalsecRuntime.framework</string>
1212
<key>SupportedArchitectures</key>
1313
<array>
1414
<string>arm64</string>
15-
<string>x86_64</string>
1615
</array>
1716
<key>SupportedPlatform</key>
1817
<string>ios</string>
19-
<key>SupportedPlatformVariant</key>
20-
<string>simulator</string>
2118
</dict>
2219
<dict>
2320
<key>LibraryIdentifier</key>
24-
<string>ios-arm64</string>
21+
<string>ios-arm64_x86_64-simulator</string>
2522
<key>LibraryPath</key>
2623
<string>TalsecRuntime.framework</string>
2724
<key>SupportedArchitectures</key>
2825
<array>
2926
<string>arm64</string>
27+
<string>x86_64</string>
3028
</array>
3129
<key>SupportedPlatform</key>
3230
<string>ios</string>
31+
<key>SupportedPlatformVariant</key>
32+
<string>simulator</string>
3333
</dict>
3434
</array>
3535
<key>CFBundlePackageType</key>
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)