Skip notifications without a bundle identifier

Would raise fatalError in notification getter.
This commit is contained in:
Davide De Rosa 2023-12-22 22:06:16 +01:00
parent 6101e92c3b
commit 92bc00e1fd
No known key found for this signature in database
GPG Key ID: A48836171C759F5E
1 changed files with 9 additions and 4 deletions

View File

@ -228,8 +228,10 @@ public class NetworkExtensionVPN: VPN {
}
private func notifyReinstall(_ manager: NETunnelProviderManager) {
let bundleId = manager.tunnelBundleIdentifier
log.debug("VPN did reinstall (\(bundleId ?? "?")): isEnabled=\(manager.isEnabled)")
guard let bundleId = manager.tunnelBundleIdentifier else {
return
}
log.debug("VPN did reinstall (\(bundleId)): isEnabled=\(manager.isEnabled)")
var notification = Notification(name: VPNNotification.didReinstall)
notification.vpnBundleIdentifier = bundleId
@ -242,8 +244,10 @@ public class NetworkExtensionVPN: VPN {
log.verbose("Ignoring VPN notification from bogus manager")
return
}
let bundleId = connection.manager.tunnelBundleIdentifier
log.debug("VPN status did change (\(bundleId ?? "?")): isEnabled=\(connection.manager.isEnabled), status=\(connection.status.rawValue)")
guard let bundleId = connection.manager.tunnelBundleIdentifier else {
return
}
log.debug("VPN status did change (\(bundleId)): isEnabled=\(connection.manager.isEnabled), status=\(connection.status.rawValue)")
var notification = Notification(name: VPNNotification.didChangeStatus)
notification.vpnBundleIdentifier = bundleId
notification.vpnIsEnabled = connection.manager.isEnabled
@ -265,6 +269,7 @@ public class NetworkExtensionVPN: VPN {
private extension NEVPNManager {
var tunnelBundleIdentifier: String? {
guard let proto = protocolConfiguration as? NETunnelProviderProtocol else {
log.warning("No bundle identifier found because protocolConfiguration is not NETunnelProviderProtocol (\(type(of: protocolConfiguration))")
return nil
}
return proto.providerBundleIdentifier