Add safety around missing providerConfiguration
This commit is contained in:
parent
d25834d69d
commit
b0331ed111
|
@ -7,6 +7,7 @@ enum VPNStartError: Error {
|
|||
case noManagers
|
||||
case couldNotFindManager
|
||||
case noTunFileDescriptor
|
||||
case noProviderConfig
|
||||
}
|
||||
|
||||
class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
|
@ -115,15 +116,20 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
|||
// }
|
||||
|
||||
private func findManager() async throws -> NETunnelProviderManager {
|
||||
let targetProtoConfig = self.protocolConfiguration as? NETunnelProviderProtocol;
|
||||
let targetID = targetProtoConfig?.providerConfiguration!["id"] as? String;
|
||||
let targetProtoConfig = self.protocolConfiguration as? NETunnelProviderProtocol
|
||||
guard let targetProviderConfig = targetProtoConfig?.providerConfiguration else {
|
||||
throw VPNStartError.noProviderConfig
|
||||
}
|
||||
let targetID = targetProviderConfig["id"] as? String
|
||||
|
||||
// Load vpn configs from system, and find the manager matching the one being started
|
||||
let managers = try await NETunnelProviderManager.loadAllFromPreferences()
|
||||
for manager in managers {
|
||||
let mgrProtoConfig = manager.protocolConfiguration as? NETunnelProviderProtocol;
|
||||
let id = mgrProtoConfig?.providerConfiguration!["id"] as? String;
|
||||
|
||||
let mgrProtoConfig = manager.protocolConfiguration as? NETunnelProviderProtocol
|
||||
guard let mgrProviderConfig = mgrProtoConfig?.providerConfiguration else {
|
||||
throw VPNStartError.noProviderConfig
|
||||
}
|
||||
let id = mgrProviderConfig["id"] as? String
|
||||
if (id == targetID) {
|
||||
return manager
|
||||
}
|
||||
|
|
|
@ -489,6 +489,8 @@ struct IncomingSite: Codable {
|
|||
// Stuff our details in the protocol
|
||||
let proto = manager.protocolConfiguration as? NETunnelProviderProtocol ?? NETunnelProviderProtocol()
|
||||
proto.providerBundleIdentifier = "net.defined.mobileNebula.NebulaNetworkExtension";
|
||||
// WARN: If we stop setting providerConfiguration["id"] here, we'll need to use something else to match
|
||||
// managers in PacketTunnelProvider.findManager
|
||||
proto.providerConfiguration = ["id": self.id]
|
||||
proto.serverAddress = "Nebula"
|
||||
|
||||
|
|
Loading…
Reference in New Issue