Skip to content

Commit

Permalink
On iOS, use custom resolver with system DNS servers only in VPN mode
Browse files Browse the repository at this point in the history
- Partially reverts ecd1195, adding back self->tunnelWholeDevice
  • Loading branch information
rod-hynes committed Nov 2, 2022
1 parent 2c2e4fb commit ca5adc9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ @implementation PsiphonTunnel {
id<ReachabilityProtocol> reachability;
_Atomic NetworkReachability currentNetworkStatus;

BOOL tunnelWholeDevice;

_Atomic BOOL usingNoticeFiles;

// DNS
Expand Down Expand Up @@ -166,6 +168,7 @@ - (void)initializeWithAppDelegate:(id<TunneledAppDelegate> _Nullable)appDelegate
self->reachability = [Reachability reachabilityForInternetConnection];
}
atomic_init(&self->currentNetworkStatus, NetworkReachabilityNotReachable);
self->tunnelWholeDevice = FALSE;
atomic_init(&self->usingNoticeFiles, FALSE);

// Use the workaround, comma-delimited format required for gobind.
Expand Down Expand Up @@ -536,6 +539,7 @@ - (NSString * _Nullable)getConfig:(BOOL * _Nonnull)usingNoticeFiles

NSError *err;
NSString *psiphonConfig = [PsiphonTunnel buildPsiphonConfig:configObject
tunnelWholeDevice:&self->tunnelWholeDevice
usingNoticeFiles:usingNoticeFiles
sessionID:self.sessionID
logMessage:logMessage
Expand All @@ -549,6 +553,7 @@ - (NSString * _Nullable)getConfig:(BOOL * _Nonnull)usingNoticeFiles
}

+ (NSString * _Nullable)buildPsiphonConfig:(id _Nonnull)configObject
tunnelWholeDevice:(BOOL * _Nonnull)tunnelWholeDevice
usingNoticeFiles:(BOOL * _Nonnull)usingNoticeFiles
sessionID:(NSString * _Nonnull)sessionID
logMessage:(void (^)(NSString * _Nonnull))logMessage
Expand Down Expand Up @@ -790,7 +795,7 @@ + (NSString * _Nullable)buildPsiphonConfig:(id _Nonnull)configObject
//

// We'll record our state about what mode we're in.
BOOL tunnelWholeDevice = (config[@"PacketTunnelTunFileDescriptor"] != nil);
*tunnelWholeDevice = (config[@"PacketTunnelTunFileDescriptor"] != nil);

// Optional fields not being altered. If not set, their defaults will be used:
// * LocalSocksProxyPort
Expand Down Expand Up @@ -820,7 +825,7 @@ + (NSString * _Nullable)buildPsiphonConfig:(id _Nonnull)configObject
*usingNoticeFiles = (config[@"UseNoticeFiles"] != nil);

// For iOS VPN, set VPN client feature while preserving any present feature names
if (tunnelWholeDevice == TRUE) {
if (*tunnelWholeDevice == TRUE) {
id oldClientFeatures = config[@"ClientFeatures"];
NSString *vpnClientFeature = @"VPN";
NSMutableArray<NSString*> *clientFeatures;
Expand All @@ -840,6 +845,7 @@ + (NSString * _Nullable)buildPsiphonConfig:(id _Nonnull)configObject
clientFeatures = [NSMutableArray arrayWithObject:vpnClientFeature];
}
config[@"ClientFeatures"] = clientFeatures;

}

NSString *finalConfigStr = [[[SBJson4Writer alloc] init] stringWithObject:config];
Expand Down Expand Up @@ -1228,7 +1234,11 @@ - (NSString *)bindToDevice:(long)fileDescriptor error:(NSError **)error {

- (NSString *)getDNSServersAsString {

if (atomic_load(&self->useInitialDNS)) {
// In non-VPN mode, don't use the tunnel-core custom DNS resolver with
// any system DNS servers, as these are commonly LAN addresses and
// sending UDP packets to the LAN will trigger Local Network Privacy
// permissions requirements.
if (self->tunnelWholeDevice == TRUE && atomic_load(&self->useInitialDNS)) {
return self->initialDNSCache;
} else {
// Alternate DNS servers may be provided by psiphon-tunnel-core config
Expand Down Expand Up @@ -1635,9 +1645,11 @@ - (void)startSendFeedback:(NSString * _Nonnull)feedbackJson
return;
}

BOOL tunnelWholeDevice = FALSE;
BOOL usingNoticeFiles = FALSE;

NSString *psiphonConfig = [PsiphonTunnel buildPsiphonConfig:feedbackConfigJson
tunnelWholeDevice:&tunnelWholeDevice
usingNoticeFiles:&usingNoticeFiles
sessionID:sessionID
logMessage:logMessage
Expand Down

0 comments on commit ca5adc9

Please sign in to comment.