DNSProxyProvider not running

I've created a MacOS app project which contains System Network Extension (DNS proxy). With help of https://developer.apple.com/forums/thread/81103?answerId=246229022 and https://stackoverflow.com/questions/45508605/how-to-use-nednsproxyprovider-in-ios-11. I enabled DNSProxyProvider. When I built the app for the first time a prompt asked to allow the system extension. I allowed it and Under network in system preference, I can see DNS is not running (yellow dot).

I also changed my entitlements and info.plist as given in the https://stackoverflow.com/questions/45508605/how-to-use-nednsproxyprovider-in-ios-11

My APP delegate:


     
    private func enable() {
      NSLog("enabled already ",self.manager.isEnabled )
       
      self.update {
        self.manager.localizedDescription = "DNS"
        let proto = NEDNSProxyProviderProtocol()
        proto.providerBundleIdentifier = "com.procyon.ai.ProcyonDNS.SystemDNSProxyExtension"
        self.manager.providerProtocol = proto
        self.manager.isEnabled = true
      }
//      NEDNSProxyManager.conn
       
       
    }

    private func disable() {
      self.update {
        self.manager.isEnabled = false
      }
    }

    private func update(_ body: @escaping () -> Void) {
      self.manager.loadFromPreferences { (error) in
        guard error == nil else {
          NSLog("DNS Test App: load error")
          return
        }
        body()
        self.manager.saveToPreferences { (error) in
          guard error == nil else {
            NSLog("DNS Test App: save error")
            return
          }
          NSLog("DNS Test App: saved")
        }
      }
    }


  func applicationDidFinishLaunching(_ aNotification: Notification) {
    self.enable()
     
//    let DNSManager=NEDNSProxyManager.shared()
//    DNSManager.shared().start() {}
    // Insert code here to initialize your application
  }

Extension :

import OSLog

class DNSProxyProvider: NEDNSProxyProvider {
   
  static let log = OSLog(subsystem: "com.example.apple-samplecode.DNSTestBed.DNSExtension", category: "provider")
    private let log: OSLog
   
   override init() {
     NSLog("QNEDNSProxy.Provider: init")
     self.log = Self.log
     os_log(.debug, log: self.log, "init")
     super.init()
     
   }

  override func startProxy(options:[String: Any]? = nil, completionHandler: @escaping (Error?) -> Void) {
    NSLog("QNEDNSProxy.Provider: start")
    // Add code here to start the DNS proxy.
    completionHandler(nil)
  }

  override func stopProxy(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
    NSLog("QNEDNSProxy.Provider: stop")
    // Add code here to stop the DNS proxy.
    completionHandler()
  }

  override func sleep(completionHandler: @escaping () -> Void) {
    // Add code here to get ready to sleep.
    completionHandler()
  }

  override func wake() {
    // Add code here to wake up.
  }

  override func handleNewFlow(_ flow: NEAppProxyFlow) -> Bool {
    NSLog("QNEDNSProxy.Provider: new flow ")
    NSLog("DNSProxyProvider: handleFlow")
        if let tcpFlow = flow as? NEAppProxyTCPFlow {
          let remoteHost = (tcpFlow.remoteEndpoint as! NWHostEndpoint).hostname
          let remotePort = (tcpFlow.remoteEndpoint as! NWHostEndpoint).port
          NSLog("DNSProxyProvider: handleFlow",remotePort," ", remoteHost)
          // Do whatever I want with this data
        } else if let udpFlow = flow as? NEAppProxyUDPFlow {
          let localHost = (udpFlow.localEndpoint as! NWHostEndpoint).hostname
          let localPort = (udpFlow.localEndpoint as! NWHostEndpoint).port
          NSLog("DNSProxyProvider: handleFlow",localHost," ", localPort)
          // Do whatever I want with this data
        }
    // Add code here to handle the incoming flow.
    return false
  }

}

As you can see I added logs in the extension code. But I don't those logs when I launch the app. start proxy is not executed and the main in the extension is also not executed (added logs there as well). I want to start the system extension when the app is launched. Any help would be great.

Update: I added OsSystemExtensionRequest. But I'm getting this error The operation couldn’t be completed. (OSSystemExtensionErrorDomain error 1.)

  let log = OSLog(subsystem: "com.example.apple-samplecode.DNSTestBed", category: "app")
//  let manager = NEDNSProxyManager()
  var manager: NEDNSProxyManager?
  private func installSystemExtension() {
   os_log("DNSFProxy: installing system extension")
   let request = OSSystemExtensionRequest.activationRequest(
    forExtensionWithIdentifier: "bundle identifier",
    queue: .main
   )
   request.delegate = self
   OSSystemExtensionManager.shared.submitRequest(request)
  }

  private func configureProxy() {

      os_log(.info, log: self.log, "will load configurations")
    NSLog("QNEDNSProxy.Provider: controller")
    NEDNSProxyManager.shared().loadFromPreferences { [weak self] error in
        precondition(Thread.isMainThread)
      }
    os_log(.info, log: self.log, "logs indication the state of loading preferences")
  }
  override func viewDidLoad() {
    super.viewDidLoad()
    installSystemExtension()
//    configureProxy()
     

    // Do any additional setup after loading the view.
  }
//
//  override var representedObject: Any? {
//    didSet {
//    // Update the view, if already loaded.
//    }
//  }


}

extension ViewController: OSSystemExtensionRequestDelegate {
 func request(_ request: OSSystemExtensionRequest, actionForReplacingExtension existing: OSSystemExtensionProperties, withExtension ext: OSSystemExtensionProperties) -> OSSystemExtensionRequest.ReplacementAction {
  os_log("DNSProxy: Replacing extension %@ version %@ with version %@", request.identifier, existing.bundleShortVersion, ext.bundleShortVersion)
  return .replace
 }
  
 func requestNeedsUserApproval(_ request: OSSystemExtensionRequest) {
  os_log("DNSProxy: Extension %@ requires user approval", request.identifier)
 }
  
 func request(_ request: OSSystemExtensionRequest, didFailWithError error: Error) {
  os_log("DNSProxy: System extension request failed: %@", error.localizedDescription)
 }
  
 /* Other delegate methods here */
 func request(_ request: OSSystemExtensionRequest, didFinishWithResult result: OSSystemExtensionRequest.Result) {
  switch result {
  case .completed:
   manager = NEDNSProxyManager.shared()
  case .willCompleteAfterReboot:
    os_log("DNSProxy: willCompleteAfterReboot")
  @unknown default:
   os_log("DNSProxy: default")
  }
 }
}


The most common cause of problems like this is that your provider is crashing on launch (or, equivalently, being blocked from launch by the trusted execution system). Do you see any crash reports in Console?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

What does this error code mean  The operation couldn’t be completed. (OSSystemExtensionErrorDomain error 1.)?

Thanks for replying. No, I don't see any crash reports related to this in Console. FYI, I am running the app in debug mode, and SIP is enabled. When I run this command, systemextensionsctl list, I can see another app using the network extension ( network extension [activated enabled]). Is the another app causing this error?

The other app which activated network extension uses only content filtering.

Is the another app causing this error?

That’s unlikely given this…

What does this error code mean The operation couldn’t be completed. (OSSystemExtensionErrorDomain error 1.)?

That is OSSystemExtensionErrorUnknown. Regarding that, see my response here.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

DNSProxyProvider not running
 
 
Q