Skip to content

Commit

Permalink
Deal with some xcode warnings (#216)
Browse files Browse the repository at this point in the history
This performs the recommended setting updates from xcode, though I needed to turn off `ENABLE_USER_SCRIPT_SANDBOXING` as it does not seem to be fully compatible with flutter.

I also dealt with a warning of: "Extension declares a conformance of imported type 'String' to imported protocol 'Error'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future", by creating and using some custom error types.

Lastly, I fixed our podfile to ensure that the `IPHONEOS_DEPLOYMENT_TARGET` is at least 12, which is our project setting.
  • Loading branch information
IanVS authored Jan 13, 2025
1 parent c781ac4 commit 46f029a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 23 deletions.
16 changes: 15 additions & 1 deletion ios/NebulaNetworkExtension/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ enum VPNStartError: Error {
case noProviderConfig
}

enum AppMessageError: Error {
case unknownIPCType(command: String)
}

extension AppMessageError: LocalizedError {
public var description: String? {
switch self {
case .unknownIPCType(let command):
return NSLocalizedString("Unknown IPC message type \(String(command))", comment: "")
}
}
}


class PacketTunnelProvider: NEPacketTunnelProvider {
private var networkMonitor: NWPathMonitor?

Expand Down Expand Up @@ -221,7 +235,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
case "closeTunnel": (data, error) = closeTunnel(args: call.arguments!)

default:
error = "Unknown IPC message type \(call.command)"
error = AppMessageError.unknownIPCType(command: call.command)
}

if (error != nil) {
Expand Down
54 changes: 44 additions & 10 deletions ios/NebulaNetworkExtension/Site.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,41 @@ import os.log

let log = Logger(subsystem: "net.defined.mobileNebula", category: "Site")

extension String: Error {}
enum SiteError: Error {
case nonConforming(site: [String : Any]?)
case noCertificate
case keyLoad
case keySave
case unmanagedGetCredentials
case dnCredentialLoad
case dnCredentialSave

// Throw in all other cases
case unexpected(code: Int)
}

extension SiteError: CustomStringConvertible {
public var description: String {
switch self {
case .nonConforming(let site):
return String("Non-conforming site \(String(describing: site))")
case .noCertificate:
return "No certificate found"
case .keyLoad:
return "failed to get key from keychain"
case .keySave:
return "failed to store key material in keychain"
case .unmanagedGetCredentials:
return "Cannot get dn credentials for unmanaged site"
case .dnCredentialLoad:
return "failed to find dn credentials in keychain"
case .dnCredentialSave:
return "failed to store dn credentials in keychain"
case .unexpected(_):
return "An unexpected error occurred."
}
}
}

enum IPCResponseType: String, Codable {
case error = "error"
Expand Down Expand Up @@ -174,7 +208,7 @@ class Site: Codable {

let id = dict?["id"] as? String ?? nil
if id == nil {
throw("Non-conforming site \(String(describing: dict))")
throw SiteError.nonConforming(site: dict)
}

try self.init(path: SiteList.getSiteConfigFile(id: id!, createDir: false))
Expand Down Expand Up @@ -218,7 +252,7 @@ class Site: Codable {

certs = try JSONDecoder().decode([CertificateInfo].self, from: rawDetails.data(using: .utf8)!)
if (certs.count == 0) {
throw "No certificate found"
throw SiteError.noCertificate
}
cert = certs[0]
if (!cert!.validity.valid) {
Expand Down Expand Up @@ -285,7 +319,7 @@ class Site: Codable {
// Gets the private key from the keystore, we don't always need it in memory
func getKey() throws -> String {
guard let keyData = KeyChain.load(key: "\(id).key") else {
throw "failed to get key from keychain"
throw SiteError.keyLoad
}

//TODO: make sure this is valid on return!
Expand All @@ -294,12 +328,12 @@ class Site: Codable {

func getDNCredentials() throws -> DNCredentials {
if (!managed) {
throw "unmanaged site has no dn credentials"
throw SiteError.unmanagedGetCredentials
}

let rawDNCredentials = KeyChain.load(key: "\(id).dnCredentials")
if rawDNCredentials == nil {
throw "failed to find dn credentials in keychain"
throw SiteError.dnCredentialLoad
}

let decoder = JSONDecoder()
Expand All @@ -311,7 +345,7 @@ class Site: Codable {
creds.invalid = true

if (!(try creds.save(siteID: self.id))) {
throw "failed to store dn credentials in keychain"
throw SiteError.dnCredentialLoad
}
}

Expand All @@ -320,7 +354,7 @@ class Site: Codable {
creds.invalid = false

if (!(try creds.save(siteID: self.id))) {
throw "failed to store dn credentials in keychain"
throw SiteError.dnCredentialSave
}
}

Expand Down Expand Up @@ -438,13 +472,13 @@ struct IncomingSite: Codable {
if (self.key != nil) {
let data = self.key!.data(using: .utf8)
if (!KeyChain.save(key: "\(self.id).key", data: data!, managed: self.managed ?? false)) {
return callback("failed to store key material in keychain")
return callback(SiteError.keySave)
}
}

do {
if ((try self.dnCredentials?.save(siteID: self.id)) == false) {
return callback("failed to store dn credentials in keychain")
return callback(SiteError.dnCredentialSave)
}
} catch {
return callback(error)
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ post_install do |installer|
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
if Gem::Version.new('11.0') > Gem::Version.new(config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
if Gem::Version.new('12.0') > Gem::Version.new(config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
end
end
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ SPEC CHECKSUMS:
SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe

PODFILE CHECKSUM: 6c27958b72564ad432c3d7024daffcc9edb8534a
PODFILE CHECKSUM: b44d9de9944d89118a4ff4bfffe1c2dab91de156

COCOAPODS: 1.15.2
23 changes: 14 additions & 9 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
43871C9D2444E2EC004F9075 /* Sites.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43871C9C2444E2EC004F9075 /* Sites.swift */; };
43AA894F2444D8BC00EDC39C /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43AA894E2444D8BC00EDC39C /* NetworkExtension.framework */; };
43AA89572444DA6500EDC39C /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43AA89562444DA6500EDC39C /* PacketTunnelProvider.swift */; };
43AA895C2444DA6500EDC39C /* NebulaNetworkExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 43AA89542444DA6500EDC39C /* NebulaNetworkExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
43AA895C2444DA6500EDC39C /* NebulaNetworkExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 43AA89542444DA6500EDC39C /* NebulaNetworkExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
43AA89622444DAA500EDC39C /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43AA894E2444D8BC00EDC39C /* NetworkExtension.framework */; };
43ED87842912D0DD004DAFC5 /* DNUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43ED87832912D0DD004DAFC5 /* DNUpdate.swift */; };
43ED87852912D0DD004DAFC5 /* DNUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43ED87832912D0DD004DAFC5 /* DNUpdate.swift */; };
Expand All @@ -47,15 +47,15 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
43AA89612444DA6500EDC39C /* Embed App Extensions */ = {
43AA89612444DA6500EDC39C /* Embed Foundation Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
43AA895C2444DA6500EDC39C /* NebulaNetworkExtension.appex in Embed App Extensions */,
43AA895C2444DA6500EDC39C /* NebulaNetworkExtension.appex in Embed Foundation Extensions */,
);
name = "Embed App Extensions";
name = "Embed Foundation Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
9705A1C41CF9048500538489 /* Embed Frameworks */ = {
Expand Down Expand Up @@ -266,7 +266,7 @@
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
43AA89612444DA6500EDC39C /* Embed App Extensions */,
43AA89612444DA6500EDC39C /* Embed Foundation Extensions */,
00C7A79AE88792090BDAC68B /* [CP] Embed Pods Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
);
Expand All @@ -286,8 +286,9 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1140;
LastUpgradeCheck = 1510;
LastUpgradeCheck = 1600;
ORGANIZATIONNAME = "The Chromium Authors";
TargetAttributes = {
43AA89532444DA6500EDC39C = {
Expand Down Expand Up @@ -538,6 +539,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -548,6 +550,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -569,7 +572,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
Expand Down Expand Up @@ -740,6 +742,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -750,6 +753,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -795,6 +799,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -805,6 +810,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -817,6 +823,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
Expand All @@ -827,7 +834,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
Expand Down Expand Up @@ -863,7 +869,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

0 comments on commit 46f029a

Please sign in to comment.