From 623b7b6bda8043e28bd8c5f793c2c8f228f0f993 Mon Sep 17 00:00:00 2001 From: Kornel Date: Sun, 16 Sep 2018 00:02:37 +0100 Subject: [PATCH] ed25519 keys in generate_* tools --- Configurations/ConfigGenerateKeys.xcconfig | 7 + .../ConfigGenerateKeysDebug.xcconfig | 4 + .../ConfigGenerateKeysRelease.xcconfig | 4 + Sparkle.xcodeproj/project.pbxproj | 151 +++++++++++++++++- generate_appcast/Appcast-Bridging-Header.h | 2 + generate_appcast/Appcast.swift | 55 +++++-- generate_appcast/ArchiveItem.swift | 18 ++- .../{DSASignature.swift => Signatures.swift} | 34 +++- generate_appcast/main.swift | 49 ++++-- generate_keys/Bridging-Header.h | 6 + generate_keys/main.swift | 92 +++++++++++ 11 files changed, 388 insertions(+), 34 deletions(-) create mode 100644 Configurations/ConfigGenerateKeys.xcconfig create mode 100644 Configurations/ConfigGenerateKeysDebug.xcconfig create mode 100644 Configurations/ConfigGenerateKeysRelease.xcconfig rename generate_appcast/{DSASignature.swift => Signatures.swift} (72%) create mode 100644 generate_keys/Bridging-Header.h create mode 100644 generate_keys/main.swift diff --git a/Configurations/ConfigGenerateKeys.xcconfig b/Configurations/ConfigGenerateKeys.xcconfig new file mode 100644 index 00000000..d62c5b95 --- /dev/null +++ b/Configurations/ConfigGenerateKeys.xcconfig @@ -0,0 +1,7 @@ +// Generate Appcast only + +#include "ConfigSwift.xcconfig" + +SWIFT_OBJC_BRIDGING_HEADER = generate_keys/Bridging-Header.h +MACOSX_DEPLOYMENT_TARGET = 10.11 +PRODUCT_NAME = generate_keys diff --git a/Configurations/ConfigGenerateKeysDebug.xcconfig b/Configurations/ConfigGenerateKeysDebug.xcconfig new file mode 100644 index 00000000..bc4e111b --- /dev/null +++ b/Configurations/ConfigGenerateKeysDebug.xcconfig @@ -0,0 +1,4 @@ +// Generate Appcast Debug + +#include "ConfigGenerateKeys.xcconfig" +#include "ConfigSwiftDebug.xcconfig" diff --git a/Configurations/ConfigGenerateKeysRelease.xcconfig b/Configurations/ConfigGenerateKeysRelease.xcconfig new file mode 100644 index 00000000..b69bf619 --- /dev/null +++ b/Configurations/ConfigGenerateKeysRelease.xcconfig @@ -0,0 +1,4 @@ +// Generate Appcast Release + +#include "ConfigGenerateKeys.xcconfig" +#include "ConfigSwiftRelease.xcconfig" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 39974b5f..4d714fab 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -117,8 +117,29 @@ 5AB8F18E214D564C00A1187F /* sign.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17D214D564B00A1187F /* sign.c */; }; 5AB8F18F214D564C00A1187F /* sc.h in Headers */ = {isa = PBXBuildFile; fileRef = 5AB8F17E214D564B00A1187F /* sc.h */; }; 5AB8F190214D564C00A1187F /* keypair.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17F214D564C00A1187F /* keypair.c */; }; + 5AB8F191214DA5FD00A1187F /* add_scalar.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F171214D564A00A1187F /* add_scalar.c */; }; + 5AB8F192214DA5FD00A1187F /* fe.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17C214D564B00A1187F /* fe.c */; }; + 5AB8F193214DA5FD00A1187F /* ge.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F175214D564B00A1187F /* ge.c */; }; + 5AB8F194214DA5FD00A1187F /* key_exchange.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F178214D564B00A1187F /* key_exchange.c */; }; + 5AB8F195214DA5FD00A1187F /* keypair.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17F214D564C00A1187F /* keypair.c */; }; + 5AB8F196214DA5FD00A1187F /* sc.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F16F214D564A00A1187F /* sc.c */; }; + 5AB8F197214DA5FD00A1187F /* seed.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17B214D564B00A1187F /* seed.c */; }; + 5AB8F198214DA5FD00A1187F /* sha512.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F172214D564B00A1187F /* sha512.c */; }; + 5AB8F199214DA5FD00A1187F /* sign.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17D214D564B00A1187F /* sign.c */; }; + 5AB8F19A214DA5FD00A1187F /* verify.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F177214D564B00A1187F /* verify.c */; }; + 5AB8F1A2214DA72000A1187F /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F1A1214DA72000A1187F /* main.swift */; }; + 5AB8F1AC214DAB9D00A1187F /* add_scalar.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F171214D564A00A1187F /* add_scalar.c */; }; + 5AB8F1AD214DAB9D00A1187F /* fe.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17C214D564B00A1187F /* fe.c */; }; + 5AB8F1AE214DAB9D00A1187F /* ge.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F175214D564B00A1187F /* ge.c */; }; + 5AB8F1AF214DAB9D00A1187F /* key_exchange.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F178214D564B00A1187F /* key_exchange.c */; }; + 5AB8F1B0214DAB9D00A1187F /* keypair.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17F214D564C00A1187F /* keypair.c */; }; + 5AB8F1B1214DAB9D00A1187F /* sc.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F16F214D564A00A1187F /* sc.c */; }; + 5AB8F1B2214DAB9D00A1187F /* seed.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17B214D564B00A1187F /* seed.c */; }; + 5AB8F1B3214DAB9D00A1187F /* sha512.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F172214D564B00A1187F /* sha512.c */; }; + 5AB8F1B4214DAB9D00A1187F /* sign.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F17D214D564B00A1187F /* sign.c */; }; + 5AB8F1B5214DAB9D00A1187F /* verify.c in Sources */ = {isa = PBXBuildFile; fileRef = 5AB8F177214D564B00A1187F /* verify.c */; }; 5AD0FA7F1C73F2E2004BCEFF /* testappcast.xml in Resources */ = {isa = PBXBuildFile; fileRef = 5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */; }; - 5AE13F781E0C9B12000D2C2C /* DSASignature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE13F771E0C9B12000D2C2C /* DSASignature.swift */; }; + 5AE13F781E0C9B12000D2C2C /* Signatures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE13F771E0C9B12000D2C2C /* Signatures.swift */; }; 5AE13FA01E0D4F65000D2C2C /* Appcast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE13F9F1E0D4F65000D2C2C /* Appcast.swift */; }; 5AE13FA11E0D7168000D2C2C /* SUUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A8C09CA790200B7442F /* SUUnarchiver.m */; }; 5AE13FA21E0D716F000D2C2C /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; }; @@ -451,6 +472,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 5AB8F19D214DA72000A1187F /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; 61B5FB4D09C4E9FA00B25A18 /* Copy Frameworks */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -674,8 +704,14 @@ 5AB8F17D214D564B00A1187F /* sign.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = sign.c; path = ed25519/src/sign.c; sourceTree = SOURCE_ROOT; }; 5AB8F17E214D564B00A1187F /* sc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sc.h; path = ed25519/src/sc.h; sourceTree = SOURCE_ROOT; }; 5AB8F17F214D564C00A1187F /* keypair.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = keypair.c; path = ed25519/src/keypair.c; sourceTree = SOURCE_ROOT; }; + 5AB8F19F214DA72000A1187F /* generate_keys */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = generate_keys; sourceTree = BUILT_PRODUCTS_DIR; }; + 5AB8F1A1214DA72000A1187F /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + 5AB8F1A8214DA85900A1187F /* ConfigGenerateKeys.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigGenerateKeys.xcconfig; sourceTree = ""; }; + 5AB8F1A9214DA85900A1187F /* ConfigGenerateKeysRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigGenerateKeysRelease.xcconfig; sourceTree = ""; }; + 5AB8F1AA214DA85900A1187F /* ConfigGenerateKeysDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigGenerateKeysDebug.xcconfig; sourceTree = ""; }; + 5AB8F1AB214DA8F200A1187F /* Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = ""; }; 5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast.xml; sourceTree = ""; }; - 5AE13F771E0C9B12000D2C2C /* DSASignature.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DSASignature.swift; sourceTree = ""; }; + 5AE13F771E0C9B12000D2C2C /* Signatures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Signatures.swift; sourceTree = ""; }; 5AE13F9F1E0D4F65000D2C2C /* Appcast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Appcast.swift; sourceTree = ""; }; 5AE13FB31E0D9E07000D2C2C /* generate_appcast */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = generate_appcast; sourceTree = BUILT_PRODUCTS_DIR; }; 5AE13FBC1E0DA39B000D2C2C /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; }; @@ -923,6 +959,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 5AB8F19C214DA72000A1187F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 5D06E8CE0FD68C7C005AE3F6 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1001,6 +1044,7 @@ 5D06E8D00FD68C7C005AE3F6 /* BinaryDelta */, 722954B41D04ADAF00ECF9CA /* fileop */, 5AE13FB31E0D9E07000D2C2C /* generate_appcast */, + 5AB8F19F214DA72000A1187F /* generate_keys */, 55C14BB7136EEF1500649790 /* Autoupdate.app */, 61B5F90209C4CEE200B25A18 /* Sparkle Test App.app */, 612279D90DB5470200AB99EA /* Sparkle Unit Tests.xctest */, @@ -1022,6 +1066,7 @@ 1420DE391962322200203BB0 /* Documentation */, FA1941C40D94A6EA00DD942E /* Configurations */, 726B2B5E1C645FC900388755 /* UI Tests */, + 5AB8F1A0214DA72000A1187F /* generate_keys */, 0867D69AFE84028FC02AAC07 /* Frameworks */, 034768DFFF38A50411DB9C8B /* Products */, ); @@ -1198,9 +1243,9 @@ 5AA96C5D1E0AE0F900CA4346 /* Appcast-Bridging-Header.h */, 5AE13F9F1E0D4F65000D2C2C /* Appcast.swift */, 5AAD00511E0BE6BE00AF411E /* ArchiveItem.swift */, - 5AE13F771E0C9B12000D2C2C /* DSASignature.swift */, 5A5AC5371E0C6D3000998119 /* FeedXML.swift */, 5AA96C571E0AE0DB00CA4346 /* main.swift */, + 5AE13F771E0C9B12000D2C2C /* Signatures.swift */, 5A5AC5351E0C6CA300998119 /* Unarchive.swift */, ); path = generate_appcast; @@ -1230,6 +1275,15 @@ path = ed25519; sourceTree = ""; }; + 5AB8F1A0214DA72000A1187F /* generate_keys */ = { + isa = PBXGroup; + children = ( + 5AB8F1AB214DA8F200A1187F /* Bridging-Header.h */, + 5AB8F1A1214DA72000A1187F /* main.swift */, + ); + path = generate_keys; + sourceTree = ""; + }; 5AF04874214D2E2800B5789F /* Signatures */ = { isa = PBXGroup; children = ( @@ -1483,6 +1537,9 @@ 7205C4331E12C23C00E370AE /* ConfigGenerateAppcast.xcconfig */, 7205C4351E12CA7000E370AE /* ConfigGenerateAppcastDebug.xcconfig */, 7205C4341E12C66D00E370AE /* ConfigGenerateAppcastRelease.xcconfig */, + 5AB8F1A8214DA85900A1187F /* ConfigGenerateKeys.xcconfig */, + 5AB8F1AA214DA85900A1187F /* ConfigGenerateKeysDebug.xcconfig */, + 5AB8F1A9214DA85900A1187F /* ConfigGenerateKeysRelease.xcconfig */, FA1941CE0D94A70100DD942E /* ConfigRelaunch.xcconfig */, FA1941D30D94A70100DD942E /* ConfigRelaunchDebug.xcconfig */, FA1941D40D94A70100DD942E /* ConfigRelaunchRelease.xcconfig */, @@ -1658,6 +1715,23 @@ productReference = 5AE13FB31E0D9E07000D2C2C /* generate_appcast */; productType = "com.apple.product-type.tool"; }; + 5AB8F19E214DA72000A1187F /* generate_keys */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5AB8F1A3214DA72000A1187F /* Build configuration list for PBXNativeTarget "generate_keys" */; + buildPhases = ( + 5AB8F19B214DA72000A1187F /* Sources */, + 5AB8F19C214DA72000A1187F /* Frameworks */, + 5AB8F19D214DA72000A1187F /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = generate_keys; + productName = generate_keys; + productReference = 5AB8F19F214DA72000A1187F /* generate_keys */; + productType = "com.apple.product-type.tool"; + }; 5D06E8CF0FD68C7C005AE3F6 /* BinaryDelta */ = { isa = PBXNativeTarget; buildConfigurationList = 5D06E8DA0FD68C95005AE3F6 /* Build configuration list for PBXNativeTarget "BinaryDelta" */; @@ -1873,6 +1947,7 @@ 726B2B5C1C645FC900388755 /* UI Tests */, 722954B31D04ADAF00ECF9CA /* fileop */, 5AA96C541E0AE0DB00CA4346 /* generate_appcast */, + 5AB8F19E214DA72000A1187F /* generate_keys */, ); }; /* End PBXProject section */ @@ -2046,15 +2121,24 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5AB8F191214DA5FD00A1187F /* add_scalar.c in Sources */, 5AE13FA01E0D4F65000D2C2C /* Appcast.swift in Sources */, 5AAD00521E0BE6BE00AF411E /* ArchiveItem.swift in Sources */, 5AAD00681E0C2DAB00AF411E /* bscommon.c in Sources */, 5AAD00691E0C2DAB00AF411E /* bsdiff.c in Sources */, 5AE13FBB1E0DA391000D2C2C /* bspatch.c in Sources */, - 5AE13F781E0C9B12000D2C2C /* DSASignature.swift in Sources */, + 5AB8F192214DA5FD00A1187F /* fe.c in Sources */, 5A5AC5381E0C6D3000998119 /* FeedXML.swift in Sources */, + 5AB8F193214DA5FD00A1187F /* ge.c in Sources */, + 5AB8F194214DA5FD00A1187F /* key_exchange.c in Sources */, + 5AB8F195214DA5FD00A1187F /* keypair.c in Sources */, 5AA96C581E0AE0DB00CA4346 /* main.swift in Sources */, 5AAD006A1E0C2DB500AF411E /* sais.c in Sources */, + 5AB8F196214DA5FD00A1187F /* sc.c in Sources */, + 5AB8F197214DA5FD00A1187F /* seed.c in Sources */, + 5AB8F198214DA5FD00A1187F /* sha512.c in Sources */, + 5AB8F199214DA5FD00A1187F /* sign.c in Sources */, + 5AE13F781E0C9B12000D2C2C /* Signatures.swift in Sources */, 5AE13FBA1E0DA389000D2C2C /* SUBinaryDeltaApply.m in Sources */, 5AAD00661E0C2D9B00AF411E /* SUBinaryDeltaCommon.m in Sources */, 5AAD00671E0C2D9B00AF411E /* SUBinaryDeltaCreate.m in Sources */, @@ -2070,6 +2154,25 @@ 5AE13FA11E0D7168000D2C2C /* SUUnarchiver.m in Sources */, 5AE13FB71E0D9F42000D2C2C /* SUUnarchiverNotifier.m in Sources */, 5A5AC5361E0C6CA300998119 /* Unarchive.swift in Sources */, + 5AB8F19A214DA5FD00A1187F /* verify.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 5AB8F19B214DA72000A1187F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5AB8F1AC214DAB9D00A1187F /* add_scalar.c in Sources */, + 5AB8F1AD214DAB9D00A1187F /* fe.c in Sources */, + 5AB8F1AE214DAB9D00A1187F /* ge.c in Sources */, + 5AB8F1AF214DAB9D00A1187F /* key_exchange.c in Sources */, + 5AB8F1B0214DAB9D00A1187F /* keypair.c in Sources */, + 5AB8F1A2214DA72000A1187F /* main.swift in Sources */, + 5AB8F1B1214DAB9D00A1187F /* sc.c in Sources */, + 5AB8F1B2214DAB9D00A1187F /* seed.c in Sources */, + 5AB8F1B3214DAB9D00A1187F /* sha512.c in Sources */, + 5AB8F1B4214DAB9D00A1187F /* sign.c in Sources */, + 5AB8F1B5214DAB9D00A1187F /* verify.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2682,6 +2785,36 @@ }; name = Release; }; + 5AB8F1A4214DA72000A1187F /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5AB8F1AA214DA85900A1187F /* ConfigGenerateKeysDebug.xcconfig */; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_VERSION = 4.2; + }; + name = Debug; + }; + 5AB8F1A5214DA72000A1187F /* Coverage */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5AB8F1AA214DA85900A1187F /* ConfigGenerateKeysDebug.xcconfig */; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_VERSION = 4.2; + }; + name = Coverage; + }; + 5AB8F1A6214DA72000A1187F /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5AB8F1A9214DA85900A1187F /* ConfigGenerateKeysRelease.xcconfig */; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_VERSION = 4.2; + }; + name = Release; + }; 5D06E8D20FD68C7D005AE3F6 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 5D06E8F20FD68D21005AE3F6 /* ConfigBinaryDeltaDebug.xcconfig */; @@ -2845,6 +2978,16 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 5AB8F1A3214DA72000A1187F /* Build configuration list for PBXNativeTarget "generate_keys" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5AB8F1A4214DA72000A1187F /* Debug */, + 5AB8F1A5214DA72000A1187F /* Coverage */, + 5AB8F1A6214DA72000A1187F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 5D06E8DA0FD68C95005AE3F6 /* Build configuration list for PBXNativeTarget "BinaryDelta" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/generate_appcast/Appcast-Bridging-Header.h b/generate_appcast/Appcast-Bridging-Header.h index c7d7bf74..340552f5 100644 --- a/generate_appcast/Appcast-Bridging-Header.h +++ b/generate_appcast/Appcast-Bridging-Header.h @@ -6,3 +6,5 @@ #import "SUUnarchiver.h" #import "SUBinaryDeltaUnarchiver.h" #import "SUBinaryDeltaCreate.h" +#import "SUSignatures.h" +#import "../ed25519/src/ed25519.h" // run `git submodule update --init` if you get an erorr here diff --git a/generate_appcast/Appcast.swift b/generate_appcast/Appcast.swift index 686e7372..09087f02 100644 --- a/generate_appcast/Appcast.swift +++ b/generate_appcast/Appcast.swift @@ -14,7 +14,7 @@ func makeError(code: SUError, _ description: String) -> NSError { ]); } -func makeAppcast(archivesSourceDir: URL, privateKey: SecKey, verbose: Bool) throws -> [String:[ArchiveItem]] { +func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throws -> [String:[ArchiveItem]] { let comparator = SUStandardVersionComparator(); let allUpdates = (try unarchiveUpdates(archivesSourceDir: archivesSourceDir, verbose:verbose)) @@ -33,11 +33,29 @@ func makeAppcast(archivesSourceDir: URL, privateKey: SecKey, verbose: Bool) thro for update in allUpdates { group.enter(); DispatchQueue.global().async { - do { - update.dsaSignature = try dsaSignature(path: update.archivePath, privateKey: privateKey); - } catch { - print(update, error); + if update.supportsDSA { + if let privateDSAKey = keys.privateDSAKey { + do { + update.dsaSignature = try dsaSignature(path: update.archivePath, privateDSAKey: privateDSAKey); + } catch { + print(update, error); + } + } else { + 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); + } + } else { + print("Warning: could not sign \(update.archivePath.path) due to lack of private ed25519 key"); + } + } + group.leave(); } @@ -52,6 +70,9 @@ func makeAppcast(archivesSourceDir: URL, privateKey: SecKey, verbose: Bool) thro var latestUpdatePerOS:[String:ArchiveItem] = [:]; for update in updates { + if !update.supportsDSA && update.publicEdKey == nil { + continue; + } // items are ordered starting latest first let os = update.minimumSystemVersion; if latestUpdatePerOS[os] == nil { @@ -92,12 +113,26 @@ func makeAppcast(archivesSourceDir: URL, privateKey: SecKey, verbose: Bool) thro group.enter(); DispatchQueue.global().async { - do { - delta.dsaSignature = try dsaSignature(path: deltaPath, privateKey: privateKey); - latestItem.deltas.append(delta); - } catch { - print(delta.archivePath.lastPathComponent, error); + if latestItem.supportsDSA, let privateDSAKey = keys.privateDSAKey { + do { + delta.dsaSignature = try dsaSignature(path: deltaPath, privateDSAKey: privateDSAKey); + } catch { + print(delta.archivePath.lastPathComponent, error); + } } + if let publicEdKey = item.publicEdKey, let privateEdKey = keys.privateEdKey { + do { + delta.edSignature = try edSignature(path: deltaPath, publicEdKey: publicEdKey, privateEdKey: privateEdKey); + } catch { + print(delta.archivePath.lastPathComponent, error); + } + } + if delta.dsaSignature != nil || delta.edSignature != nil { + latestItem.deltas.append(delta); + } else { + print("Delta \(delta.archivePath.path) ignored, because it could not be signed"); + } + group.leave(); } } diff --git a/generate_appcast/ArchiveItem.swift b/generate_appcast/ArchiveItem.swift index 4cee60bf..9ddc2e91 100644 --- a/generate_appcast/ArchiveItem.swift +++ b/generate_appcast/ArchiveItem.swift @@ -9,6 +9,7 @@ class DeltaUpdate { let fromVersion: String; let archivePath: URL; var dsaSignature: String?; + var edSignature: String?; init(fromVersion: String, archivePath: URL) { self.archivePath = archivePath; @@ -38,18 +39,27 @@ class ArchiveItem: CustomStringConvertible { let archivePath: URL; let appPath: URL; let feedURL: URL?; + let publicEdKey: Data?; + let supportsDSA: Bool; let archiveFileAttributes: [FileAttributeKey:Any]; var deltas: [DeltaUpdate]; var dsaSignature: String?; + var edSignature: String?; - init(version: String, shortVersion: String?, feedURL: URL?, minimumSystemVersion: String?, appPath: URL, archivePath: URL) throws { + init(version: String, shortVersion: String?, feedURL: URL?, minimumSystemVersion: String?, publicEdKey: String?, supportsDSA: Bool, appPath: URL, archivePath: URL) throws { self.version = version; self._shortVersion = shortVersion; self.feedURL = feedURL; self.minimumSystemVersion = minimumSystemVersion ?? "10.7"; self.archivePath = archivePath; self.appPath = appPath; + self.supportsDSA = supportsDSA; + if let publicEdKey = publicEdKey { + self.publicEdKey = Data(base64Encoded: publicEdKey); + } else { + self.publicEdKey = nil; + } self.archiveFileAttributes = try FileManager.default.attributesOfItem(atPath: self.archivePath.path); self.deltas = []; } @@ -70,9 +80,11 @@ class ArchiveItem: CustomStringConvertible { throw makeError(code: .unarchivingError, "No plist \(appPath.path)"); } guard let version = infoPlist[kCFBundleVersionKey] as? String else { - throw makeError(code: .unarchivingError, "No Version \(kCFBundleVersionKey) \(appPath)"); + throw makeError(code: .unarchivingError, "No Version \(kCFBundleVersionKey as String? ?? "missing kCFBundleVersionKey") \(appPath)"); } let shortVersion = infoPlist["CFBundleShortVersionString"] as? String; + let publicEdKey = infoPlist["SUPublicEDKey"] as? String; + let supportsDSA = infoPlist["SUPublicDSAKey"] != nil || infoPlist["SUPublicDSAKeyFile"] != nil; var feedURL:URL? = nil; if let feedURLStr = infoPlist["SUFeedURL"] as? String { @@ -83,6 +95,8 @@ class ArchiveItem: CustomStringConvertible { shortVersion: shortVersion, feedURL: feedURL, minimumSystemVersion: infoPlist["LSMinimumSystemVersion"] as? String, + publicEdKey: publicEdKey, + supportsDSA: supportsDSA, appPath: appPath, archivePath: archivePath); } else { diff --git a/generate_appcast/DSASignature.swift b/generate_appcast/Signatures.swift similarity index 72% rename from generate_appcast/DSASignature.swift rename to generate_appcast/Signatures.swift index 7040d54c..f41fa1c5 100644 --- a/generate_appcast/DSASignature.swift +++ b/generate_appcast/Signatures.swift @@ -5,7 +5,17 @@ import Foundation -func loadPrivateKey(at privateKeyURL: URL) throws -> SecKey { +struct PrivateKeys { + var privateDSAKey: SecKey?; + var privateEdKey: Data?; + + init(privateDSAKey: SecKey?, privateEdKey: Data?) { + self.privateDSAKey = privateDSAKey; + self.privateEdKey = privateEdKey; + } +} + +func loadPrivateDSAKey(at privateKeyURL: URL) throws -> SecKey { let data = try Data(contentsOf: privateKeyURL); var cfitems: CFArray? = nil; @@ -25,7 +35,7 @@ func loadPrivateKey(at privateKeyURL: URL) throws -> SecKey { return (cfitems! as NSArray)[0] as! SecKey; } -func loadPrivateKey(named keyName: String, fromKeychainAt keychainURL: URL) throws -> SecKey { +func loadPrivateDSAKey(named keyName: String, fromKeychainAt keychainURL: URL) throws -> SecKey { var keychain: SecKeychain? = nil guard SecKeychainOpen(keychainURL.path, &keychain) == errSecSuccess, keychain != nil else { @@ -49,7 +59,7 @@ func loadPrivateKey(named keyName: String, fromKeychainAt keychainURL: URL) thro return item! as! SecKey } -func dsaSignature(path: URL, privateKey: SecKey) throws -> String { +func dsaSignature(path: URL, privateDSAKey: SecKey) throws -> String { var error: Unmanaged?; @@ -57,7 +67,7 @@ func dsaSignature(path: URL, privateKey: SecKey) throws -> String { let dataReadTransform = SecTransformCreateReadTransformWithReadStream(stream); let dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA1, 20, nil); - guard let dataSignTransform = SecSignTransformCreate(privateKey, &error) else { + guard let dataSignTransform = SecSignTransformCreate(privateDSAKey, &error) else { print("can't use the key"); throw error!.takeRetainedValue(); } @@ -82,3 +92,19 @@ func dsaSignature(path: URL, privateKey: SecKey) throws -> String { } return resultData.base64EncodedString(); } + +func edSignature(path: URL, publicEdKey: Data, privateEdKey: Data) throws -> String { + let data = try Data.init(contentsOf: path, options: .mappedIfSafe); + var output = Data(count: 64); + let len = data.count; + output.withUnsafeMutableBytes({ (output: UnsafeMutablePointer) in + data.withUnsafeBytes({ (data: UnsafePointer) in + publicEdKey.withUnsafeBytes({ (publicEdKey: UnsafePointer) in + privateEdKey.withUnsafeBytes({ (privateEdKey: UnsafePointer) in + ed25519_sign(output, data, len, publicEdKey, privateEdKey) + }); + }); + }) + }); + return output.base64EncodedString(); +} diff --git a/generate_appcast/main.swift b/generate_appcast/main.swift index 57ae99f2..20bbfc0f 100644 --- a/generate_appcast/main.swift +++ b/generate_appcast/main.swift @@ -12,39 +12,59 @@ var verbose = false; func printUsage() { let command = URL(fileURLWithPath: CommandLine.arguments.first!).lastPathComponent; - print("Generate appcast from a directory of Sparkle updates\n", + print("Generate appcast from a directory of Sparkle update archives\n", "Usage:\n", - " \(command) < -f private key path | -k keychain_path -n key_name > \n", - " e.g. \(command) -k ~/Library/Keychains/login.keychain -n 'My Private Key' archives/\n", - "\nOR (legacy)\n\n", - " \(command) \n", + " \(command) \n", + " e.g. \(command) ./my-app-release-zipfiles/\n", + "\nOR for old apps that have a DSA keys (deprecated):\n", + " \(command) \n", " e.g. \(command) dsa_priv.pem archives/\n", "\n", - " Appcast files and deltas will be written to the archives directory.\n", - " Note that pkg-based updates are not supported.\n" + "Appcast files and deltas will be written to the archives directory.\n", + "Note that pkg-based updates are not supported.\n" ) } +func loadPrivateKeys(_ privateDSAKey: SecKey?) -> PrivateKeys { + var privateEdKey: Data?; + var item: CFTypeRef?; + let res = SecItemCopyMatching([ + kSecClass as String: kSecClassGenericPassword, + kSecAttrService as String: "https://sparkle-project.org", + kSecAttrAccount as String: "ed25519", + kSecAttrProtocol as String: kSecAttrProtocolSSH, + kSecReturnData as String: kCFBooleanTrue, + ] as CFDictionary, &item); + if res == errSecSuccess, let encoded = item as? Data, let keys = Data(base64Encoded: encoded) { + privateEdKey = keys[0..<64]; + } else { + print("Warning: Private key not found in the Keychain (\(res)). Please run the generate_keys tool"); + } + return PrivateKeys(privateDSAKey: privateDSAKey, privateEdKey: privateEdKey); +} + func main() { let args = CommandLine.arguments; - if args.count < 3 { + if args.count < 2 { printUsage() exit(1) } - let privateKey: SecKey - + var privateDSAKey: SecKey? = nil; + + // this was typical usage for DSA keys if args.count == 3 || (args.count == 4 && args[1] == "-f") { // private key specified by filename let privateKeyURL = URL(fileURLWithPath: args.count == 3 ? args[1] : args[2]) do { - privateKey = try loadPrivateKey(at: privateKeyURL) + privateDSAKey = try loadPrivateDSAKey(at: privateKeyURL) } catch { print("Unable to load DSA private key from", privateKeyURL.path, "\n", error) exit(1) } } + // this is legacy for DSA keychain; probably very rarely used else if args.count == 6 && (args[1] == "-n" || args[1] == "-k") { // private key specified by keychain + key name let keyName: String @@ -70,21 +90,22 @@ func main() { } do { - privateKey = try loadPrivateKey(named: keyName, fromKeychainAt: keychainURL) + privateDSAKey = try loadPrivateDSAKey(named: keyName, fromKeychainAt: keychainURL) } catch { print("Unable to load DSA private key '\(keyName)' from keychain at", keychainURL.path, "\n", error) exit(1) } } - else { + else if args.count != 2 { printUsage() exit(1) } let archivesSourceDir = URL(fileURLWithPath: args.last!, isDirectory: true) + let keys = loadPrivateKeys(privateDSAKey) do { - let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, privateKey: privateKey, verbose:verbose); + let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, keys: keys, verbose:verbose); for (appcastFile, updates) in allUpdates { let appcastDestPath = URL(fileURLWithPath: appcastFile, relativeTo: archivesSourceDir); diff --git a/generate_keys/Bridging-Header.h b/generate_keys/Bridging-Header.h new file mode 100644 index 00000000..3fd1d596 --- /dev/null +++ b/generate_keys/Bridging-Header.h @@ -0,0 +1,6 @@ +#import + +#import "SUConstants.h" +#import "SUErrors.h" +#import "SUSignatures.h" +#import "../ed25519/src/ed25519.h" // run `git submodule update --init` if you get an erorr here diff --git a/generate_keys/main.swift b/generate_keys/main.swift new file mode 100644 index 00000000..f0cae114 --- /dev/null +++ b/generate_keys/main.swift @@ -0,0 +1,92 @@ +// +// main.swift +// generate_keys +// +// Created by Kornel on 15/09/2018. +// Copyright © 2018 Sparkle Project. All rights reserved. +// + +import Foundation +import Security + +func findPublicKey() -> Data? { + var item: CFTypeRef?; + let res = SecItemCopyMatching([ + kSecClass as String: kSecClassGenericPassword, + kSecAttrService as String: "https://sparkle-project.org", + kSecAttrAccount as String: "ed25519", + kSecAttrProtocol as String: kSecAttrProtocolSSH, + kSecReturnData as String: kCFBooleanTrue, + ] as CFDictionary, &item); + if res == errSecSuccess, let encoded = item as? Data, let keys = Data(base64Encoded: encoded) { + print("OK! Read the existing key saved in the Keychain."); + return keys[64...] + } + else if res == errSecItemNotFound { + return nil; + } + else if res == errSecAuthFailed { + print("\nERROR! Access denied. Can't check existing keys in the keychain."); + print("Go to Keychain Access.app, lock the login keychain, then unlock it again."); + } + else if res == errSecUserCanceled { + print("\nABORTED! You've cancelled the request to read the key from the Keychain. Please run the tool again."); + } else { + print("\nERROR! Unable to access existing item in the Keychain", res, "(you can look it up at osstatus.com)"); + } + exit(1) +} + +func generateKeyPair() -> Data { + var seed = Data(count: 32); + var publicEdKey = Data(count: 32); + var privateEdKey = Data(count: 64); + + if !seed.withUnsafeMutableBytes { (seed: UnsafeMutablePointer) in 0 == ed25519_create_seed(seed)} { + print("\nERROR: Unable to initialize random seed"); + exit(1) + } + + seed.withUnsafeBytes({(seed: UnsafePointer) in + publicEdKey.withUnsafeMutableBytes({(publicEdKey: UnsafeMutablePointer) in + privateEdKey.withUnsafeMutableBytes({(privateEdKey: UnsafeMutablePointer) in + ed25519_create_keypair(publicEdKey, privateEdKey, seed); + }); + }); + }); + + let bothKeys = privateEdKey + publicEdKey; // public key can't be derived from the private one + let query = [ + // macOS doesn't support ed25519 keys, so we're forced to save the key as a "password" + // and add some made-up service data for it to prevent it clashing with other passwords. + kSecClass as String: kSecClassGenericPassword, + kSecAttrService as String: "https://sparkle-project.org", + kSecAttrAccount as String: "ed25519", + + kSecValueData as String: bothKeys.base64EncodedData() as CFData, // it's base64-encoded, because user may request to show it + kSecAttrIsSensitive as String: kCFBooleanTrue, + kSecAttrIsPermanent as String: kCFBooleanTrue, + kSecAttrLabel as String: "Private key for signing Sparkle updates", + kSecAttrComment as String: "Public key (SUPublicEDKey value) for this key is:\n\n\(publicEdKey.base64EncodedString())", + kSecAttrDescription as String: "private key", + ] as CFDictionary; + let res = SecItemAdd(query, nil); + + if res == errSecSuccess { + print("OK! A new key has been generated and saved in the Keychain."); + } + else if res == errSecDuplicateItem { + print("\nERROR: You already have a previously generated key in the Keychain"); + } else if res == errSecAuthFailed { + print("\nERROR: System denied access to the Keychain. Unable to save the new key"); + print("Go to Keychain Access.app, lock the login keychain, then unlock it again."); + } else { + print("\nERROR: The key could not be saved to the Keychain. error: \(res) (you can look it up at osstatus.com)"); + } + exit(1); +} + +print("This tool uses macOS Keychain to store the Sparkle private key.") +print("If the Keychain prompts you for permission, please allow it.") +let pubKey = findPublicKey() ?? generateKeyPair(); +print("\nIn your app's Info.plist set SUPublicEDKey to:\n\(pubKey.base64EncodedString())\n")