From f80907fa2cf3a66ecb05cbbbe81e9b2aa2c75c80 Mon Sep 17 00:00:00 2001 From: Kornel Date: Sun, 25 Nov 2018 15:53:17 +0000 Subject: [PATCH] Check if public key is configured correctly --- generate_appcast/Appcast.swift | 14 +++++++++----- generate_appcast/Signatures.swift | 4 +++- generate_appcast/main.swift | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/generate_appcast/Appcast.swift b/generate_appcast/Appcast.swift index 069dd0aa..0f4ff293 100644 --- a/generate_appcast/Appcast.swift +++ b/generate_appcast/Appcast.swift @@ -44,11 +44,15 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw print("Note: did not sign with legacy DSA \(update.archivePath.path) because private DSA key file was not specified"); } if let publicEdKey = update.publicEdKey { - if let privateEdKey = keys.privateEdKey { - do { - update.edSignature = try edSignature(path: update.archivePath, publicEdKey: publicEdKey, privateEdKey: privateEdKey); - } catch { - print(update, error); + if let privateEdKey = keys.privateEdKey, let expectedPublicKey = keys.publicEdKey { + if publicEdKey == expectedPublicKey { + do { + update.edSignature = try edSignature(path: update.archivePath, publicEdKey: publicEdKey, privateEdKey: privateEdKey); + } catch { + print(update, error); + } + } else { + print("Warning: SUPublicEDKey in the app \(update.archivePath.path) does not match key EdDSA in the Keychain. Run generate_keys and update Info.plist to match"); } } else { print("Warning: could not sign \(update.archivePath.path) due to lack of private EdDSA key"); diff --git a/generate_appcast/Signatures.swift b/generate_appcast/Signatures.swift index 9e7902b9..e7f3adab 100644 --- a/generate_appcast/Signatures.swift +++ b/generate_appcast/Signatures.swift @@ -8,10 +8,12 @@ import Foundation struct PrivateKeys { var privateDSAKey: SecKey?; var privateEdKey: Data?; + var publicEdKey: Data?; - init(privateDSAKey: SecKey?, privateEdKey: Data?) { + init(privateDSAKey: SecKey?, privateEdKey: Data?, publicEdKey: Data?) { self.privateDSAKey = privateDSAKey; self.privateEdKey = privateEdKey; + self.publicEdKey = publicEdKey; } } diff --git a/generate_appcast/main.swift b/generate_appcast/main.swift index 20bbfc0f..ac7a1309 100644 --- a/generate_appcast/main.swift +++ b/generate_appcast/main.swift @@ -27,6 +27,7 @@ func printUsage() { func loadPrivateKeys(_ privateDSAKey: SecKey?) -> PrivateKeys { var privateEdKey: Data?; + var publicEdKey: Data?; var item: CFTypeRef?; let res = SecItemCopyMatching([ kSecClass as String: kSecClassGenericPassword, @@ -37,10 +38,11 @@ func loadPrivateKeys(_ privateDSAKey: SecKey?) -> PrivateKeys { ] as CFDictionary, &item); if res == errSecSuccess, let encoded = item as? Data, let keys = Data(base64Encoded: encoded) { privateEdKey = keys[0..<64]; + publicEdKey = keys[64...]; } else { print("Warning: Private key not found in the Keychain (\(res)). Please run the generate_keys tool"); } - return PrivateKeys(privateDSAKey: privateDSAKey, privateEdKey: privateEdKey); + return PrivateKeys(privateDSAKey: privateDSAKey, privateEdKey: privateEdKey, publicEdKey: publicEdKey); } func main() {