I'm trying to get a DNS Proxy working in iOS 11.0 beta 2. I have the entitlements, and I have enabled the DNS proxy through the manager but it isn't calling startProxy in my Proxy Provider. I'm able to loadFromPreferences() so I think the entitlements are correct and isEnabled shows true when I move the app to the background and back to the foreground. Any help would be great.
In my main app:
func applicationDidBecomeActive(_ application: UIApplication) {
let manager = NEDNSProxyManager.shared()
if manager.isEnabled == true {
NSLog("enabled")
} else {
manager.localizedDescription = "DNS Proxy"
manager.loadFromPreferences { error in
if (error != nil) {
NSLog("Load error: \(String(describing: error?.localizedDescription))");
} else {
NSLog("loaded preferences");
let dict = ["foo": "bar"]
let proto = NEDNSProxyProviderProtocol()
proto.providerConfiguration = dict
proto.providerBundleIdentifier = "com.bangj.DNS.DNS-Proxy"
manager.providerProtocol = proto
manager.isEnabled = true
}
}
}
}
My Proxy Provider:
class DNSProxyProvider: NEDNSProxyProvider {
override func startProxy(options:[String: Any]? = nil, completionHandler: @escaping (Error?) -> Void) {
NSLog("startproxy")
/
completionHandler(nil)
}
override func stopProxy(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
NSLog("stopproxy")
/
completionHandler()
}
override func sleep(completionHandler: @escaping () -> Void) {
NSLog("sleep")
/
completionHandler()
}
override func wake() {
NSLog("wake")
/
}
override func handleNewFlow(_ flow: NEAppProxyFlow) -> Bool {
NSLog("handleNewFlow")
/
return false
}
}
I think my entitlements look good:
butte% codesign -d --entitlements :- DNS-Proxy.appex
Executable=/Users/pusateri/Library/Developer/Xcode/DerivedData/DNS-grgoqerfsmhphqfyrpxzgzxiqdkd/Build/Products/Debug-iphoneos/DNS-Proxy.appex/DNS-Proxy
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-/
<plist version="1.0">
<dict>
<key>application-identifier</key>
<string>XXXXXXXXXX.com.bangj.DNS.DNS-Proxy</string>
<key>com.apple.developer.networking.networkextension</key>
<array>
<string>dns-proxy</string>
</array>
<key>com.apple.developer.team-identifier</key>
<string>XXXXXXXXXX</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.bangj.DNS</string>
</array>
<key>get-task-allow</key>
<true/>
</dict>
</plist>
% codesign -d --entitlements :- DNS.app
Executable=/Users/pusateri/Library/Developer/Xcode/DerivedData/DNS-grgoqerfsmhphqfyrpxzgzxiqdkd/Build/Products/Debug-iphoneos/DNS.app/DNS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-/
<plist version="1.0">
<dict>
<key>application-identifier</key>
<string>XXXXXXXXXX.com.bangj.DNS</string>
<key>com.apple.developer.networking.networkextension</key>
<array>
<string>dns-proxy</string>
</array>
<key>com.apple.developer.team-identifier</key>
<string>XXXXXXXXXX</string>
<key>get-task-allow</key>
<true/>
</dict>
</plist>
One thing that is confusing is that in NEDNSProxyManager.h, enabled is the property but I can't set enabled in Xcode. I have to use isEnabled even though it's just the getter (and not the setter). I'm new to Swift so maybe I don't understand how setters work in Swift. setEnabled doesn't work either.
/!
* @property enabled
* @discussion Toggles the enabled status of the DNS proxy. Setting this property will disable DNS proxy configurations of other apps. This property will be set to NO when other DNS proxy configurations are enabled.
*/
@property (getter=isEnabled) BOOL enabled NS_AVAILABLE(NA, 11_0);
One more thing, this is probably a beta thing but NEDNS Proxy doesn't seem to be available for macos, just iOS.
I'm running this on a real phone. No configuration profile. And, yes, wifi debugging is AWESOME!