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