Skip to content

Commit eaa40bd

Browse files
committed
feat: ios side done
1 parent e818b4d commit eaa40bd

File tree

4 files changed

+79
-18
lines changed

4 files changed

+79
-18
lines changed

example/ios/OpenvpnExample.xcodeproj/project.pbxproj

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,10 @@
309309
inputFileListPaths = (
310310
"${PODS_ROOT}/Target Support Files/Pods-OpenvpnExample/Pods-OpenvpnExample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
311311
);
312-
inputPaths = (
313-
);
314312
name = "[CP] Embed Pods Frameworks";
315313
outputFileListPaths = (
316314
"${PODS_ROOT}/Target Support Files/Pods-OpenvpnExample/Pods-OpenvpnExample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
317315
);
318-
outputPaths = (
319-
);
320316
runOnlyForDeploymentPostprocessing = 0;
321317
shellPath = /bin/sh;
322318
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-OpenvpnExample/Pods-OpenvpnExample-frameworks.sh\"\n";
@@ -352,14 +348,10 @@
352348
inputFileListPaths = (
353349
"${PODS_ROOT}/Target Support Files/Pods-OpenvpnExample/Pods-OpenvpnExample-resources-${CONFIGURATION}-input-files.xcfilelist",
354350
);
355-
inputPaths = (
356-
);
357351
name = "[CP] Copy Pods Resources";
358352
outputFileListPaths = (
359353
"${PODS_ROOT}/Target Support Files/Pods-OpenvpnExample/Pods-OpenvpnExample-resources-${CONFIGURATION}-output-files.xcfilelist",
360354
);
361-
outputPaths = (
362-
);
363355
runOnlyForDeploymentPostprocessing = 0;
364356
shellPath = /bin/sh;
365357
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-OpenvpnExample/Pods-OpenvpnExample-resources.sh\"\n";
@@ -632,7 +624,10 @@
632624
"-DFOLLY_CFG_NO_COROUTINES=1",
633625
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
634626
);
635-
OTHER_LDFLAGS = "$(inherited) ";
627+
OTHER_LDFLAGS = (
628+
"$(inherited)",
629+
" ",
630+
);
636631
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
637632
SDKROOT = iphoneos;
638633
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
@@ -701,7 +696,10 @@
701696
"-DFOLLY_CFG_NO_COROUTINES=1",
702697
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
703698
);
704-
OTHER_LDFLAGS = "$(inherited) ";
699+
OTHER_LDFLAGS = (
700+
"$(inherited)",
701+
" ",
702+
);
705703
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
706704
SDKROOT = iphoneos;
707705
USE_HERMES = true;

example/ios/openvpnx/PacketTunnelProvider.swift

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,42 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
5353
* OVPN CONFIG OPTIONS
5454
*
5555
*/
56-
57-
58-
59-
// Uncomment this line if you want to keep TUN interface active during pauses or reconnections
60-
// configuration.tunPersist = true
56+
guard let ovpnOptions: NSDictionary = providerConfiguration["options"] as? NSDictionary else {
57+
fatalError()
58+
}
59+
guard let optionsDict = ovpnOptions as? [AnyHashable: Any] else { // Or [String: Any]
60+
print("ovpnOptions is not a compatible dictionary type or is nil.")
61+
return // Or handle error appropriately
62+
}
6163

62-
configuration.compressionMode = OpenVPNCompressionMode.asym
64+
if let persistTunValue = optionsDict["persistTun"] as? Bool {
65+
configuration.tunPersist = persistTunValue
66+
}
67+
68+
if let connectionTimeout = optionsDict["connectionTimeout"] as? Int {
69+
configuration.connectionTimeout = connectionTimeout
70+
}
71+
72+
if let googleDNSFallback = optionsDict["googleDNSFallback"] as? Bool {
73+
configuration.googleDNSFallback = googleDNSFallback
74+
}
75+
76+
if let autologinSessions = optionsDict["autologinSessions"] as? Bool {
77+
configuration.autologinSessions = autologinSessions
78+
}
79+
80+
if let retryOnAuthFailed = optionsDict["retryOnAuthFailed"] as? Bool {
81+
configuration.retryOnAuthFailed = retryOnAuthFailed
82+
}
83+
84+
if let disableClientCert = optionsDict["disableClientCert"] as? Bool {
85+
configuration.disableClientCert = disableClientCert
86+
}
87+
88+
if let forceCiphersuitesAESCBC = optionsDict["forceCiphersuitesAESCBC"] as? Bool {
89+
configuration.forceCiphersuitesAESCBC = forceCiphersuitesAESCBC
90+
}
91+
6392

6493
// Apply OpenVPN configuration
6594
let evaluation: OpenVPNConfigurationEvaluation

example/src/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ export default function App() {
121121
networkExtensionBundleIdentifier: 'openvpn.example.aplus.openvpnx',
122122
disconnectOnSleep: false,
123123
onDemandEnabled: false,
124+
125+
persistTun: false,
126+
forceCiphersuitesAESCBC: true,
127+
connectionTimeout: 100,
128+
disableClientCert: false,
129+
autologinSessions: false,
124130
},
125131
})
126132
.then((_) => {})

ios/Openvpn.mm

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ - (void)connect:(JS::NativeOpenvpn::ConnectionParams &)params resolve:(nonnull R
3939
bool disconnectOnSleep = params.iOSOptions().disconnectOnSleep();
4040

4141

42+
/**
43+
iOS Options
44+
*/
45+
NSMutableDictionary<NSString *, id> *options = [NSMutableDictionary dictionary];
46+
47+
if(params.iOSOptions().persistTun().has_value()){
48+
options[@"persistTun"] = @(params.iOSOptions().persistTun().value());
49+
}
50+
if(params.iOSOptions().connectionTimeout().has_value()){
51+
options[@"connectionTimeout"] = @(params.iOSOptions().connectionTimeout().value());
52+
}
53+
if(params.iOSOptions().googleDNSFallback().has_value()){
54+
options[@"googleDNSFallback"] = @(params.iOSOptions().googleDNSFallback().value());
55+
}
56+
if(params.iOSOptions().autologinSessions().has_value()){
57+
options[@"autologinSessions"] = @(params.iOSOptions().autologinSessions().value());
58+
}
59+
if(params.iOSOptions().retryOnAuthFailed().has_value()){
60+
options[@"retryOnAuthFailed"] = @(params.iOSOptions().retryOnAuthFailed().value());
61+
}
62+
if(params.iOSOptions().disableClientCert().has_value()){
63+
options[@"disableClientCert"] = @(params.iOSOptions().disableClientCert().value());
64+
}
65+
if(params.iOSOptions().forceCiphersuitesAESCBC().has_value()){
66+
options[@"forceCiphersuitesAESCBC"] = @(params.iOSOptions().forceCiphersuitesAESCBC().value());
67+
}
4268

4369

4470
if((configFile==nil || [configFile isEqual: @""]) && (configString==nil || [configString isEqual: @""])){
@@ -63,7 +89,8 @@ - (void)connect:(JS::NativeOpenvpn::ConnectionParams &)params resolve:(nonnull R
6389
@"ovpnConfig": ovpnConfig,
6490
@"address": address,
6591
@"username" : username,
66-
@"password": password
92+
@"password": password,
93+
@"options": options
6794
};
6895
tunnel.providerBundleIdentifier = networkExtensionBundleIdentifier;
6996
tunnel.serverAddress = @"127.0.0.1";
@@ -122,7 +149,8 @@ - (void)connect:(JS::NativeOpenvpn::ConnectionParams &)params resolve:(nonnull R
122149
@"ovpnConfig": ovpnConfig,
123150
@"address": address,
124151
@"username" : username,
125-
@"password": password}
152+
@"password": password,
153+
@"options": options}
126154
andReturnError:&error];
127155

128156
if (error) {

0 commit comments

Comments
 (0)