From 013a2fc48e19144a53216557f065537371bb409f Mon Sep 17 00:00:00 2001 From: Declan Land Date: Tue, 3 Oct 2023 10:01:56 +0200 Subject: [PATCH 1/3] added a checkbox to the main view, and a function to check if the selected/dropped provisioning profile is a development certificate. if so, a warning will be displayed. --- AppSigner/AppDelegate.swift | 105 +++++++++---- AppSigner/Application.xib | 137 +++++++++-------- AppSigner/MainView.swift | 77 +++++++--- ProvisioningProfile.swift | 181 +++++++++++++++++------ iOS App Signer.xcodeproj/project.pbxproj | 14 +- 5 files changed, 357 insertions(+), 157 deletions(-) diff --git a/AppSigner/AppDelegate.swift b/AppSigner/AppDelegate.swift index cb4920a..c9cc50f 100644 --- a/AppSigner/AppDelegate.swift +++ b/AppSigner/AppDelegate.swift @@ -13,20 +13,31 @@ class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var mainView: MainView! @objc let fileManager = FileManager.default + - - func applicationDidFinishLaunching(_ aNotification: Notification) { - // Insert code here to initialize your application + func applicationDidFinishLaunching( + _ aNotification: Notification + ) { + } - func applicationWillTerminate(_ aNotification: Notification) { - // Insert code here to tear down your application + func applicationWillTerminate( + _ aNotification: Notification + ) { + try? fileManager.removeItem(atPath: Log.logName) } - func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + func applicationShouldTerminateAfterLastWindowClosed( + _ sender: NSApplication + ) -> Bool { + return true } + + + // MARK: - Actions: - + @IBAction func fixSigning(_ sender: NSMenuItem) { if let tempFolder = mainView.makeTempFolder() { iASShared.fixSigning(tempFolder) @@ -35,32 +46,72 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } - @IBAction func nsMenuLinkClick(_ sender: NSMenuLink) { - NSWorkspace.shared.open(URL(string: sender.url!)!) + @IBAction func nsMenuLinkClick( + _ sender: NSMenuLink + ) { + + NSWorkspace.shared.open( + URL(string: sender.url!)! + ) } - @IBAction func viewLog(_ sender: AnyObject) { + + @IBAction func viewLog( + _ sender: AnyObject + ) { + NSWorkspace.shared.openFile(Log.logName) } - @IBAction func checkForUpdates(_ sender: NSMenuItem) { - UpdatesController.checkForUpdate(forceShow: true) - func updateCheckStatus(_ status: Bool, data: Data?, response: URLResponse?, error: Error?){ + + @IBAction func checkForUpdates( + _ sender: NSMenuItem + ) { + + UpdatesController.checkForUpdate( + forceShow: true + ) + + func updateCheckStatus( + _ status: Bool, + data: Data?, + response: URLResponse?, + error: Error? + ){ + if status == false { - DispatchQueue.main.async { - let alert = NSAlert() - - - if error != nil { - alert.messageText = "There was a problem checking for a new version." - alert.informativeText = "More information is available in the application log." - Log.write(error!.localizedDescription) - } else { - alert.messageText = "You are currently running the latest version." - } - alert.runModal() - } + + showInvaldNewVersionAlert( + error: error + ) } } - UpdatesController.checkForUpdate(forceShow: true, callbackFunc: updateCheckStatus) + + UpdatesController.checkForUpdate( + forceShow: true, + callbackFunc: updateCheckStatus + ) } -} + private func showInvaldNewVersionAlert( + error: Error? + ) { + + DispatchQueue.main.async { + + let alert = NSAlert() + + if error != nil { + + alert.messageText = "There was a problem checking for a new version." + alert.informativeText = "More information is available in the application log." + Log.write(error!.localizedDescription) + } + + else { + + alert.messageText = "You are currently running the latest version." + } + + alert.runModal() + } + } +} diff --git a/AppSigner/Application.xib b/AppSigner/Application.xib index acca529..9eccd97 100644 --- a/AppSigner/Application.xib +++ b/AppSigner/Application.xib @@ -1,8 +1,8 @@ - + - + @@ -154,46 +154,46 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + @@ -211,7 +211,7 @@ - + @@ -238,7 +238,7 @@ - + @@ -254,39 +254,39 @@ - - + + - - + + - - + + - - + + - - - + @@ -392,15 +413,14 @@ - - + + - @@ -410,6 +430,7 @@ + @@ -417,7 +438,6 @@ - @@ -443,10 +463,11 @@ + - + diff --git a/AppSigner/MainView.swift b/AppSigner/MainView.swift index 0db96cd..0451d18 100644 --- a/AppSigner/MainView.swift +++ b/AppSigner/MainView.swift @@ -25,6 +25,7 @@ class MainView: NSView, URLSessionDataDelegate, URLSessionDelegate, URLSessionDo @IBOutlet var appVersion: NSTextField! @IBOutlet var ignorePluginsCheckbox: NSButton! @IBOutlet var noGetTaskAllowCheckbox: NSButton! + @IBOutlet var showDevWarningsCheckbox: NSButton! //MARK: Variables @@ -302,33 +303,65 @@ class MainView: NSView, URLSessionDataDelegate, URLSessionDelegate, URLSessionDo } - func checkProfileID(_ profile: ProvisioningProfile?){ - if let profile = profile { - self.profileFilename = profile.filename - setStatus("Selected provisioning profile \(profile.appID)") - if profile.expires.timeIntervalSince1970 < Date().timeIntervalSince1970 { - ProvisioningProfilesPopup.selectItem(at: 0) - setStatus("Provisioning profile expired") - chooseProvisioningProfile(ProvisioningProfilesPopup) - } - if profile.appID.firstIndex(of: "*") == nil { - // Not a wildcard profile - NewApplicationIDTextField.stringValue = profile.appID - NewApplicationIDTextField.isEnabled = false - } else { - // Wildcard profile - if NewApplicationIDTextField.isEnabled == false { - NewApplicationIDTextField.stringValue = "" - NewApplicationIDTextField.isEnabled = true - } - } - } else { + func checkProfileID( + _ profile: ProvisioningProfile? + ){ + + guard let profile = profile + else { + ProvisioningProfilesPopup.selectItem(at: 0) setStatus("Invalid provisioning profile") chooseProvisioningProfile(ProvisioningProfilesPopup) + return + } + + self.profileFilename = profile.filename + setStatus("Selected provisioning profile \(profile.appID)") + + if profile.expires.timeIntervalSince1970 < Date().timeIntervalSince1970 { + + ProvisioningProfilesPopup.selectItem(at: 0) + setStatus("Provisioning profile expired") + chooseProvisioningProfile(ProvisioningProfilesPopup) + } + + if profile.appID.firstIndex(of: "*") == nil { + + // Not a wildcard profile + NewApplicationIDTextField.stringValue = profile.appID + NewApplicationIDTextField.isEnabled = false + } + + else { + + // Wildcard profile + if NewApplicationIDTextField.isEnabled == false { + NewApplicationIDTextField.stringValue = "" + NewApplicationIDTextField.isEnabled = true + } + } + + // Check development profile: + if profile.isDevelopmentProfile() && showDevWarningsCheckbox.state != .off { + + DispatchQueue.main.async { + + self.showDevelopmentProfileAlert() + } } } - + + @objc + func showDevelopmentProfileAlert() { + + let alert = NSAlert() + alert.messageText = "Development Profile" + alert.informativeText = "Warning, this is a development profile. If you're re-signing an app meant for sideloading, you should use an Ad-Hoc profile." + alert.addButton(withTitle: "Okay") + alert.runModal() + } + @objc func controlsEnabled(_ enabled: Bool){ if (!Thread.isMainThread){ diff --git a/ProvisioningProfile.swift b/ProvisioningProfile.swift index 606cce6..90f77aa 100644 --- a/ProvisioningProfile.swift +++ b/ProvisioningProfile.swift @@ -8,7 +8,9 @@ import Foundation import AppKit + struct ProvisioningProfile { + var filename: String, name: String, created:Date, @@ -16,12 +18,14 @@ struct ProvisioningProfile { appID: String, teamID: String, entitlements: [String : AnyObject] + fileprivate let delegate = NSApplication.shared.delegate as! AppDelegate static func getProfiles() -> [ProvisioningProfile] { + var output: [ProvisioningProfile] = [] - let fileManager = FileManager() + if let libraryDirectory = fileManager.urls(for: .libraryDirectory, in: .userDomainMask).first { let provisioningProfilesPath = libraryDirectory.path.stringByAppendingPathComponent("MobileDevice/Provisioning Profiles") as NSString if let provisioningProfiles = try? fileManager.contentsOfDirectory(atPath: provisioningProfilesPath as String) { @@ -54,62 +58,88 @@ struct ProvisioningProfile { return newProfiles; } - init?(filename: String){ + init?( + filename: String + ) { + let securityArgs = ["cms","-D","-i", filename] - - let taskOutput = Process().execute("/usr/bin/security", workingDirectory: nil, arguments: securityArgs) - let rawXML: String - if taskOutput.status == 0 { - if let xmlIndex = taskOutput.output.range(of: " String? { - let data = PropertyListSerialization.dataFromPropertyList(entitlements, format: PropertyListSerialization.PropertyListFormat.xml, errorDescription: nil)! - return String(data: data, encoding: .utf8) + + let data = PropertyListSerialization.dataFromPropertyList( + entitlements, + format: PropertyListSerialization.PropertyListFormat.xml, + errorDescription: nil + )! + + return String( + data: data, + encoding: .utf8 + ) + } + + func isDevelopmentProfile() -> Bool { + + let profileString = try? NSString.init( + contentsOfFile: filename, + encoding: String.Encoding.isoLatin1.rawValue + ) + + let scanner = Scanner( + string: profileString as? String ?? "" + ) + + guard scanner.scanUpTo("", into: &extractedPlist + ) != false + else { + + return false + } + + guard let plistData = extractedPlist?.appending("").data(using: .isoLatin1) + else { + + return false + } + + do { + + let plist = try PropertyListSerialization.propertyList( + from: plistData, + options: [], + format: nil + ) + + if let plistDict = plist as? [String: Any], + let entitlements = plistDict["Entitlements"] as? [String: Any], + let getTaskAllow = entitlements["get-task-allow"] as? Bool { + + return getTaskAllow + } + + print("Could not find get-task-allow in entitlements") + return false + } + catch { + + print("Error decoding plist contents: \(error)") + return false + } } } diff --git a/iOS App Signer.xcodeproj/project.pbxproj b/iOS App Signer.xcodeproj/project.pbxproj index ff1957d..2801195 100644 --- a/iOS App Signer.xcodeproj/project.pbxproj +++ b/iOS App Signer.xcodeproj/project.pbxproj @@ -196,7 +196,7 @@ TargetAttributes = { 652408C71BE743D4006FA4C6 = { CreatedOnToolsVersion = 7.1; - DevelopmentTeam = 7PM929Z8M2; + DevelopmentTeam = 8734RMR67V; LastSwiftMigration = 1020; ProvisioningStyle = Automatic; SystemCapabilities = { @@ -357,12 +357,12 @@ CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 8734RMR67V; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = AppSigner/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.9; - PRODUCT_BUNDLE_IDENTIFIER = com.DanTheMan827.AppSigner; + MACOSX_DEPLOYMENT_TARGET = 10.13; + PRODUCT_BUNDLE_IDENTIFIER = com.declanland.AppSigner; PRODUCT_NAME = "iOS App Signer"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "iOS App Signer-Bridging-Header.h"; @@ -379,12 +379,12 @@ CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 8734RMR67V; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = AppSigner/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.9; - PRODUCT_BUNDLE_IDENTIFIER = com.DanTheMan827.AppSigner; + MACOSX_DEPLOYMENT_TARGET = 10.13; + PRODUCT_BUNDLE_IDENTIFIER = com.declanland.AppSigner; PRODUCT_NAME = "iOS App Signer"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "iOS App Signer-Bridging-Header.h"; From bf7f8e73cc8643e69a7b585d8ec0b8ca0e329d4a Mon Sep 17 00:00:00 2001 From: Declan Land Date: Tue, 3 Oct 2023 10:06:41 +0200 Subject: [PATCH 2/3] reverted to correct team --- AppSigner/Application.xib | 30 ++++++++++++------------ iOS App Signer.xcodeproj/project.pbxproj | 9 ++++--- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/AppSigner/Application.xib b/AppSigner/Application.xib index 9eccd97..9c6f86e 100644 --- a/AppSigner/Application.xib +++ b/AppSigner/Application.xib @@ -166,9 +166,9 @@ - + - + @@ -176,7 +176,7 @@ - + @@ -184,7 +184,7 @@ - + @@ -192,7 +192,7 @@ - + @@ -254,7 +254,7 @@ - + @@ -262,7 +262,7 @@ - + @@ -270,7 +270,7 @@ - + @@ -278,7 +278,7 @@ - + @@ -286,7 +286,7 @@ -