diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..d24fc63a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Vendor/ed25519"] + path = Vendor/ed25519 + url = https://github.com/orlp/ed25519 diff --git a/Configurations/ConfigGenerateAppcastDebug.xcconfig b/Configurations/CommandLineTool-Debug.xcconfig similarity index 59% rename from Configurations/ConfigGenerateAppcastDebug.xcconfig rename to Configurations/CommandLineTool-Debug.xcconfig index 47efcb5c..9b4b2207 100644 --- a/Configurations/ConfigGenerateAppcastDebug.xcconfig +++ b/Configurations/CommandLineTool-Debug.xcconfig @@ -1,4 +1,4 @@ // Generate Appcast Debug -#include "ConfigGenerateAppcast.xcconfig" +#include "CommandLineTool-Shared.xcconfig" #include "ConfigSwiftDebug.xcconfig" diff --git a/Configurations/ConfigGenerateAppcastRelease.xcconfig b/Configurations/CommandLineTool-Release.xcconfig similarity index 61% rename from Configurations/ConfigGenerateAppcastRelease.xcconfig rename to Configurations/CommandLineTool-Release.xcconfig index c003f771..4b771a7b 100644 --- a/Configurations/ConfigGenerateAppcastRelease.xcconfig +++ b/Configurations/CommandLineTool-Release.xcconfig @@ -1,4 +1,4 @@ // Generate Appcast Release -#include "ConfigGenerateAppcast.xcconfig" +#include "CommandLineTool-Shared.xcconfig" #include "ConfigSwiftRelease.xcconfig" diff --git a/Configurations/CommandLineTool-Shared.xcconfig b/Configurations/CommandLineTool-Shared.xcconfig new file mode 100644 index 00000000..bff21f68 --- /dev/null +++ b/Configurations/CommandLineTool-Shared.xcconfig @@ -0,0 +1,6 @@ +// Generate Appcast only + +#include "ConfigSwift.xcconfig" + +SWIFT_OBJC_BRIDGING_HEADER = $(PRODUCT_NAME)/Bridging-Header.h +MACOSX_DEPLOYMENT_TARGET = 10.11 diff --git a/Configurations/ConfigGenerateAppcast.xcconfig b/Configurations/ConfigGenerateAppcast.xcconfig deleted file mode 100644 index cdfa9247..00000000 --- a/Configurations/ConfigGenerateAppcast.xcconfig +++ /dev/null @@ -1,7 +0,0 @@ -// Generate Appcast only - -#include "ConfigSwift.xcconfig" - -SWIFT_OBJC_BRIDGING_HEADER = generate_appcast/Appcast-Bridging-Header.h -MACOSX_DEPLOYMENT_TARGET = 10.11 -PRODUCT_NAME = generate_appcast diff --git a/Configurations/ed25519-Debug.xcconfig b/Configurations/ed25519-Debug.xcconfig new file mode 100644 index 00000000..79dda095 --- /dev/null +++ b/Configurations/ed25519-Debug.xcconfig @@ -0,0 +1,3 @@ +// Copyright © 2019 Sparkle Project. All rights reserved. + +#include "ed25519-Shared.xcconfig" diff --git a/Configurations/ed25519-Release.xcconfig b/Configurations/ed25519-Release.xcconfig new file mode 100644 index 00000000..79dda095 --- /dev/null +++ b/Configurations/ed25519-Release.xcconfig @@ -0,0 +1,3 @@ +// Copyright © 2019 Sparkle Project. All rights reserved. + +#include "ed25519-Shared.xcconfig" diff --git a/Configurations/ed25519-Shared.xcconfig b/Configurations/ed25519-Shared.xcconfig new file mode 100644 index 00000000..91faa52d --- /dev/null +++ b/Configurations/ed25519-Shared.xcconfig @@ -0,0 +1,14 @@ +// Copyright © 2019 Sparkle Project. All rights reserved. + +// Deployment +SKIP_INSTALL = YES + +// Packaging +EXECUTABLE_PREFIX = lib +PRODUCT_NAME = $(TARGET_NAME) + +// Search Paths +ALWAYS_SEARCH_USER_PATHS = NO + +// Disable Warnings - this is a third-party project, and we'll trust that the maintainers know what they're doing. +WARNING_CFLAGS = $(inherited) -Wno-cast-qual -Wno-conversion -Wno-sign-conversion diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 0f878dbf..8be9a384 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -96,7 +96,7 @@ 7205C4411E13049400E370AE /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7205C4401E13049400E370AE /* main.swift */; }; 7205C44C1E1304CE00E370AE /* Appcast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7205C4471E1304CE00E370AE /* Appcast.swift */; }; 7205C44D1E1304CE00E370AE /* ArchiveItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7205C4481E1304CE00E370AE /* ArchiveItem.swift */; }; - 7205C44E1E1304CE00E370AE /* DSASignature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7205C4491E1304CE00E370AE /* DSASignature.swift */; }; + 7205C44E1E1304CE00E370AE /* Signatures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7205C4491E1304CE00E370AE /* Signatures.swift */; }; 7205C44F1E1304CE00E370AE /* FeedXML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7205C44A1E1304CE00E370AE /* FeedXML.swift */; }; 7205C4501E1304CE00E370AE /* Unarchive.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7205C44B1E1304CE00E370AE /* Unarchive.swift */; }; 7205C4561E13060D00E370AE /* SUStandardVersionComparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */; }; @@ -431,6 +431,32 @@ EA1E282622B64693004AA304 /* bscommon.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 72B09CEA1CEA18900052EF9E /* bscommon.h */; }; EA1E282722B64694004AA304 /* bspatch.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 611142E810FB1BE5009810AA /* bspatch.h */; }; EA1E282822B64694004AA304 /* sais.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 7223E7621AD1AEFF008E3161 /* sais.h */; }; + EA1E284522B660ED004AA304 /* seed.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E283522B660ED004AA304 /* seed.c */; }; + EA1E284622B660ED004AA304 /* fe.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E283622B660ED004AA304 /* fe.c */; }; + EA1E284722B660ED004AA304 /* verify.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E283722B660ED004AA304 /* verify.c */; }; + EA1E284822B660ED004AA304 /* ge.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E283822B660ED004AA304 /* ge.c */; }; + EA1E284922B660ED004AA304 /* sc.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E283922B660ED004AA304 /* sc.c */; }; + EA1E284A22B660ED004AA304 /* sign.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E283A22B660ED004AA304 /* sign.c */; }; + EA1E284B22B660ED004AA304 /* key_exchange.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E283C22B660ED004AA304 /* key_exchange.c */; }; + EA1E284C22B660ED004AA304 /* add_scalar.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E283D22B660ED004AA304 /* add_scalar.c */; }; + EA1E284D22B660ED004AA304 /* keypair.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E284022B660ED004AA304 /* keypair.c */; }; + EA1E284E22B660ED004AA304 /* sha512.c in Sources */ = {isa = PBXBuildFile; fileRef = EA1E284222B660ED004AA304 /* sha512.c */; }; + EA1E284F22B66115004AA304 /* precomp_data.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = EA1E283422B660ED004AA304 /* precomp_data.h */; }; + EA1E285022B66115004AA304 /* sha512.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = EA1E283B22B660ED004AA304 /* sha512.h */; }; + EA1E285122B66115004AA304 /* ed25519.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = EA1E283E22B660ED004AA304 /* ed25519.h */; }; + EA1E285222B66115004AA304 /* fe.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = EA1E283F22B660ED004AA304 /* fe.h */; }; + EA1E285322B66115004AA304 /* fixedint.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = EA1E284122B660ED004AA304 /* fixedint.h */; }; + EA1E285422B66115004AA304 /* sc.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = EA1E284322B660ED004AA304 /* sc.h */; }; + EA1E285522B66115004AA304 /* ge.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = EA1E284422B660ED004AA304 /* ge.h */; }; + EA1E285622B6619B004AA304 /* libed25519.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EA1E282D22B660BE004AA304 /* libed25519.a */; }; + EA1E286122B66487004AA304 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1E286022B66487004AA304 /* main.swift */; }; + EA1E286A22B6653D004AA304 /* libed25519.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EA1E282D22B660BE004AA304 /* libed25519.a */; }; + EA1E286E22B665F0004AA304 /* SUSignatures.h in Headers */ = {isa = PBXBuildFile; fileRef = EA1E286C22B665E8004AA304 /* SUSignatures.h */; }; + EA1E286F22B6661D004AA304 /* SUSignatures.h in Headers */ = {isa = PBXBuildFile; fileRef = EA1E286C22B665E8004AA304 /* SUSignatures.h */; }; + EA1E287022B66621004AA304 /* SUSignatures.m in Sources */ = {isa = PBXBuildFile; fileRef = EA1E286D22B665E8004AA304 /* SUSignatures.m */; }; + EA1E287122B66622004AA304 /* SUSignatures.m in Sources */ = {isa = PBXBuildFile; fileRef = EA1E286D22B665E8004AA304 /* SUSignatures.m */; }; + EA1E287922B666EB004AA304 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1E287822B666EB004AA304 /* main.swift */; }; + EA1E287E22B66705004AA304 /* libed25519.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EA1E282D22B660BE004AA304 /* libed25519.a */; }; F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */; }; F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */ = {isa = PBXBuildFile; fileRef = F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */; }; /* End PBXBuildFile section */ @@ -769,6 +795,41 @@ name = "Copy Headers"; runOnlyForDeploymentPostprocessing = 0; }; + EA1E283222B660C6004AA304 /* Copy Headers */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + EA1E284F22B66115004AA304 /* precomp_data.h in Copy Headers */, + EA1E285022B66115004AA304 /* sha512.h in Copy Headers */, + EA1E285122B66115004AA304 /* ed25519.h in Copy Headers */, + EA1E285222B66115004AA304 /* fe.h in Copy Headers */, + EA1E285322B66115004AA304 /* fixedint.h in Copy Headers */, + EA1E285422B66115004AA304 /* sc.h in Copy Headers */, + EA1E285522B66115004AA304 /* ge.h in Copy Headers */, + ); + name = "Copy Headers"; + runOnlyForDeploymentPostprocessing = 0; + }; + EA1E285C22B66487004AA304 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; + EA1E287422B666EB004AA304 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ @@ -975,14 +1036,11 @@ 7205C4461E1304C300E370AE /* Appcast-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Appcast-Bridging-Header.h"; sourceTree = ""; }; 7205C4471E1304CE00E370AE /* Appcast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Appcast.swift; sourceTree = ""; }; 7205C4481E1304CE00E370AE /* ArchiveItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArchiveItem.swift; sourceTree = ""; }; - 7205C4491E1304CE00E370AE /* DSASignature.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DSASignature.swift; sourceTree = ""; }; + 7205C4491E1304CE00E370AE /* Signatures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Signatures.swift; sourceTree = ""; }; 7205C44A1E1304CE00E370AE /* FeedXML.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedXML.swift; sourceTree = ""; }; 7205C44B1E1304CE00E370AE /* Unarchive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Unarchive.swift; sourceTree = ""; }; 7205C4511E13053500E370AE /* ConfigSwiftDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSwiftDebug.xcconfig; sourceTree = ""; }; 7205C4521E13053500E370AE /* ConfigSwiftRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSwiftRelease.xcconfig; sourceTree = ""; }; - 7205C4531E13054900E370AE /* ConfigGenerateAppcast.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigGenerateAppcast.xcconfig; sourceTree = ""; }; - 7205C4541E13054900E370AE /* ConfigGenerateAppcastDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigGenerateAppcastDebug.xcconfig; sourceTree = ""; }; - 7205C4551E13054900E370AE /* ConfigGenerateAppcastRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigGenerateAppcastRelease.xcconfig; sourceTree = ""; }; 7205C46C1E13244800E370AE /* ConfigUnitTestDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUnitTestDebug.xcconfig; sourceTree = ""; }; 7205C46D1E13245600E370AE /* ConfigUnitTestRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUnitTestRelease.xcconfig; sourceTree = ""; }; 7205C46E1E13254500E370AE /* ConfigUITestDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestDebug.xcconfig; sourceTree = ""; }; @@ -1246,6 +1304,38 @@ EA1E281422B64548004AA304 /* bsdiff-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "bsdiff-Debug.xcconfig"; sourceTree = ""; }; EA1E281522B64549004AA304 /* bsdiff-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "bsdiff-Release.xcconfig"; sourceTree = ""; }; EA1E281622B64549004AA304 /* bsdiff-Shared.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "bsdiff-Shared.xcconfig"; sourceTree = ""; }; + EA1E282D22B660BE004AA304 /* libed25519.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libed25519.a; sourceTree = BUILT_PRODUCTS_DIR; }; + EA1E283422B660ED004AA304 /* precomp_data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = precomp_data.h; sourceTree = ""; }; + EA1E283522B660ED004AA304 /* seed.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = seed.c; sourceTree = ""; }; + EA1E283622B660ED004AA304 /* fe.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fe.c; sourceTree = ""; }; + EA1E283722B660ED004AA304 /* verify.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = verify.c; sourceTree = ""; }; + EA1E283822B660ED004AA304 /* ge.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ge.c; sourceTree = ""; }; + EA1E283922B660ED004AA304 /* sc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sc.c; sourceTree = ""; }; + EA1E283A22B660ED004AA304 /* sign.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sign.c; sourceTree = ""; }; + EA1E283B22B660ED004AA304 /* sha512.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sha512.h; sourceTree = ""; }; + EA1E283C22B660ED004AA304 /* key_exchange.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = key_exchange.c; sourceTree = ""; }; + EA1E283D22B660ED004AA304 /* add_scalar.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = add_scalar.c; sourceTree = ""; }; + EA1E283E22B660ED004AA304 /* ed25519.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ed25519.h; sourceTree = ""; }; + EA1E283F22B660ED004AA304 /* fe.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fe.h; sourceTree = ""; }; + EA1E284022B660ED004AA304 /* keypair.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = keypair.c; sourceTree = ""; }; + EA1E284122B660ED004AA304 /* fixedint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fixedint.h; sourceTree = ""; }; + EA1E284222B660ED004AA304 /* sha512.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sha512.c; sourceTree = ""; }; + EA1E284322B660ED004AA304 /* sc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sc.h; sourceTree = ""; }; + EA1E284422B660ED004AA304 /* ge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ge.h; sourceTree = ""; }; + EA1E285722B6622E004AA304 /* ed25519-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "ed25519-Release.xcconfig"; sourceTree = ""; }; + EA1E285822B6622E004AA304 /* ed25519-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "ed25519-Debug.xcconfig"; sourceTree = ""; }; + EA1E285922B6622E004AA304 /* ed25519-Shared.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "ed25519-Shared.xcconfig"; sourceTree = ""; }; + EA1E285E22B66487004AA304 /* generate_keys */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = generate_keys; sourceTree = BUILT_PRODUCTS_DIR; }; + EA1E286022B66487004AA304 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + EA1E286622B664A5004AA304 /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = ""; }; + EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "CommandLineTool-Release.xcconfig"; sourceTree = ""; }; + EA1E286822B664FD004AA304 /* CommandLineTool-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "CommandLineTool-Debug.xcconfig"; sourceTree = ""; }; + EA1E286922B664FD004AA304 /* CommandLineTool-Shared.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "CommandLineTool-Shared.xcconfig"; sourceTree = ""; }; + EA1E286C22B665E8004AA304 /* SUSignatures.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUSignatures.h; sourceTree = ""; }; + EA1E286D22B665E8004AA304 /* SUSignatures.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUSignatures.m; sourceTree = ""; }; + EA1E287622B666EB004AA304 /* sign_update */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = sign_update; sourceTree = BUILT_PRODUCTS_DIR; }; + EA1E287822B666EB004AA304 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + EA1E287F22B667D8004AA304 /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = ""; }; F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUCodeSigningVerifierTest.m; sourceTree = ""; }; F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = SparkleTestCodeSignApp.zip; sourceTree = ""; }; FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigFrameworkDebug.xcconfig; sourceTree = ""; }; @@ -1303,6 +1393,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + EA1E285622B6619B004AA304 /* libed25519.a in Frameworks */, EA1E281A22B645F4004AA304 /* libbsdiff.a in Frameworks */, 7205C4641E1306BE00E370AE /* libbz2.tbd in Frameworks */, 7205C4631E1306B500E370AE /* libxar.tbd in Frameworks */, @@ -1401,6 +1492,29 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + EA1E282B22B660BE004AA304 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + EA1E285B22B66487004AA304 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + EA1E286A22B6653D004AA304 /* libed25519.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + EA1E287322B666EB004AA304 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + EA1E287E22B66705004AA304 /* libed25519.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -1423,6 +1537,9 @@ 726B2B5D1C645FC900388755 /* UI Tests.xctest */, 721C24451CB753E6005440CB /* Updater.app */, EA1E280F22B64522004AA304 /* libbsdiff.a */, + EA1E282D22B660BE004AA304 /* libed25519.a */, + EA1E285E22B66487004AA304 /* generate_keys */, + EA1E287622B666EB004AA304 /* sign_update */, ); name = Products; sourceTree = ""; @@ -1430,8 +1547,8 @@ 0867D691FE84028FC02AAC07 /* Sparkle */ = { isa = PBXGroup; children = ( - 7205C43F1E13049400E370AE /* generate_appcast */, 1495006D195FBBBD00BC5B5B /* Sparkle */, + EA1E288122B6688A004AA304 /* Command Line Tools */, 14732BB81960EEB600593899 /* Resources */, 61227A100DB5484000AB99EA /* Tests */, 61B5F91D09C4CF7F00B25A18 /* Test Application */, @@ -1439,7 +1556,6 @@ 1420DE391962322200203BB0 /* Documentation */, FA1941C40D94A6EA00DD942E /* Configurations */, 726B2B5E1C645FC900388755 /* UI Tests */, - 72D9549F1CBB415C006F28BD /* sparkle-cli */, 0867D69AFE84028FC02AAC07 /* Frameworks */, 034768DFFF38A50411DB9C8B /* Products */, ); @@ -1499,6 +1615,7 @@ isa = PBXGroup; children = ( 14732BB61960ECE800593899 /* bsdiff */, + EA1E283322B660ED004AA304 /* ed25519 */, ); path = Vendor; sourceTree = ""; @@ -1555,6 +1672,7 @@ 721C24461CB753E6005440CB /* Installer Progress */, 729746481C91483B00FC134E /* IPC */, 61B5F8F309C4CE5900B25A18 /* Other Sources */, + EA1E286B22B665DB004AA304 /* Signatures */, 61F83F6E0DBFE07A006FDD30 /* Update Control */, 61299B3A09CB056100B7442F /* User Interface */, 72F94F551CC43D99002DEE68 /* XPC Services */, @@ -1841,9 +1959,9 @@ 7205C4461E1304C300E370AE /* Appcast-Bridging-Header.h */, 7205C4471E1304CE00E370AE /* Appcast.swift */, 7205C4481E1304CE00E370AE /* ArchiveItem.swift */, - 7205C4491E1304CE00E370AE /* DSASignature.swift */, 7205C44A1E1304CE00E370AE /* FeedXML.swift */, 7205C4401E13049400E370AE /* main.swift */, + 7205C4491E1304CE00E370AE /* Signatures.swift */, 7205C44B1E1304CE00E370AE /* Unarchive.swift */, ); path = generate_appcast; @@ -2046,6 +2164,69 @@ name = Deprecated; sourceTree = ""; }; + EA1E283322B660ED004AA304 /* ed25519 */ = { + isa = PBXGroup; + children = ( + EA1E283422B660ED004AA304 /* precomp_data.h */, + EA1E283522B660ED004AA304 /* seed.c */, + EA1E283622B660ED004AA304 /* fe.c */, + EA1E283722B660ED004AA304 /* verify.c */, + EA1E283822B660ED004AA304 /* ge.c */, + EA1E283922B660ED004AA304 /* sc.c */, + EA1E283A22B660ED004AA304 /* sign.c */, + EA1E283B22B660ED004AA304 /* sha512.h */, + EA1E283C22B660ED004AA304 /* key_exchange.c */, + EA1E283D22B660ED004AA304 /* add_scalar.c */, + EA1E283E22B660ED004AA304 /* ed25519.h */, + EA1E283F22B660ED004AA304 /* fe.h */, + EA1E284022B660ED004AA304 /* keypair.c */, + EA1E284122B660ED004AA304 /* fixedint.h */, + EA1E284222B660ED004AA304 /* sha512.c */, + EA1E284322B660ED004AA304 /* sc.h */, + EA1E284422B660ED004AA304 /* ge.h */, + ); + name = ed25519; + path = ed25519/src; + sourceTree = ""; + }; + EA1E285F22B66487004AA304 /* generate_keys */ = { + isa = PBXGroup; + children = ( + EA1E286622B664A5004AA304 /* Bridging-Header.h */, + EA1E286022B66487004AA304 /* main.swift */, + ); + path = generate_keys; + sourceTree = ""; + }; + EA1E286B22B665DB004AA304 /* Signatures */ = { + isa = PBXGroup; + children = ( + EA1E286C22B665E8004AA304 /* SUSignatures.h */, + EA1E286D22B665E8004AA304 /* SUSignatures.m */, + ); + name = Signatures; + sourceTree = ""; + }; + EA1E287722B666EB004AA304 /* sign_update */ = { + isa = PBXGroup; + children = ( + EA1E287F22B667D8004AA304 /* Bridging-Header.h */, + EA1E287822B666EB004AA304 /* main.swift */, + ); + path = sign_update; + sourceTree = ""; + }; + EA1E288122B6688A004AA304 /* Command Line Tools */ = { + isa = PBXGroup; + children = ( + 7205C43F1E13049400E370AE /* generate_appcast */, + EA1E285F22B66487004AA304 /* generate_keys */, + EA1E287722B666EB004AA304 /* sign_update */, + 72D9549F1CBB415C006F28BD /* sparkle-cli */, + ); + name = "Command Line Tools"; + sourceTree = ""; + }; FA1941C40D94A6EA00DD942E /* Configurations */ = { isa = PBXGroup; children = ( @@ -2053,6 +2234,9 @@ EA1E281422B64548004AA304 /* bsdiff-Debug.xcconfig */, EA1E281522B64549004AA304 /* bsdiff-Release.xcconfig */, EA1E281622B64549004AA304 /* bsdiff-Shared.xcconfig */, + EA1E286822B664FD004AA304 /* CommandLineTool-Debug.xcconfig */, + EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */, + EA1E286922B664FD004AA304 /* CommandLineTool-Shared.xcconfig */, 5D06E8F10FD68D21005AE3F6 /* ConfigBinaryDelta.xcconfig */, FA1941D00D94A70100DD942E /* ConfigCommon.xcconfig */, 149B78631B7D3A0C00D7D62C /* ConfigCommonCoverage.xcconfig */, @@ -2062,9 +2246,6 @@ 72F94ED61CC344A7002DEE68 /* ConfigDownloaderDebug.xcconfig */, FA1941D10D94A70100DD942E /* ConfigFramework.xcconfig */, FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */, - 7205C4531E13054900E370AE /* ConfigGenerateAppcast.xcconfig */, - 7205C4541E13054900E370AE /* ConfigGenerateAppcastDebug.xcconfig */, - 7205C4551E13054900E370AE /* ConfigGenerateAppcastRelease.xcconfig */, 724BB37E1D31D1EA005D534A /* ConfigInstallerConnection.xcconfig */, 724BB37F1D31D1EA005D534A /* ConfigInstallerConnectionDebug.xcconfig */, 726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */, @@ -2089,6 +2270,9 @@ 149B78641B7D3A4800D7D62C /* ConfigUnitTestCoverage.xcconfig */, 7205C46C1E13244800E370AE /* ConfigUnitTestDebug.xcconfig */, 7205C46D1E13245600E370AE /* ConfigUnitTestRelease.xcconfig */, + EA1E285822B6622E004AA304 /* ed25519-Debug.xcconfig */, + EA1E285722B6622E004AA304 /* ed25519-Release.xcconfig */, + EA1E285922B6622E004AA304 /* ed25519-Shared.xcconfig */, 14732BC91960F70A00593899 /* make-release-package.sh */, 721D8A831D498F1D0032E472 /* set-agent-signing.sh */, 729BB3CE1D50344A007C4276 /* set-ats-exceptions-downloader-service.sh */, @@ -2111,6 +2295,7 @@ 72A5D5EB1D692BD40009E5AC /* SPUDownloadData.h in Headers */, 72A5D5F91D692F4C0009E5AC /* SPUStatusCompletionResults.h in Headers */, 72A5D5E71D692BB00009E5AC /* SPUUpdatePermissionRequest.h in Headers */, + EA1E286F22B6661D004AA304 /* SUSignatures.h in Headers */, 72A5D5E21D692B770009E5AC /* SPUUpdater.h in Headers */, 72A5D5E41D692B770009E5AC /* SPUUpdaterDelegate.h in Headers */, 72A5D5E31D692B770009E5AC /* SPUUpdaterSettings.h in Headers */, @@ -2179,6 +2364,7 @@ 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */, 72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */, 55C14F06136EF6DB00649790 /* SULog.h in Headers */, + EA1E286E22B665F0004AA304 /* SUSignatures.h in Headers */, 72B3DECD1E23479000457642 /* SPUInformationalUpdate.h in Headers */, 726F2CE51BC9C33D001971A4 /* SUOperatingSystem.h in Headers */, 61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */, @@ -2546,6 +2732,57 @@ productReference = EA1E280F22B64522004AA304 /* libbsdiff.a */; productType = "com.apple.product-type.library.static"; }; + EA1E282C22B660BE004AA304 /* ed25519 */ = { + isa = PBXNativeTarget; + buildConfigurationList = EA1E282E22B660BE004AA304 /* Build configuration list for PBXNativeTarget "ed25519" */; + buildPhases = ( + EA1E282A22B660BE004AA304 /* Sources */, + EA1E282B22B660BE004AA304 /* Frameworks */, + EA1E283222B660C6004AA304 /* Copy Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ed25519; + productName = ed25519; + productReference = EA1E282D22B660BE004AA304 /* libed25519.a */; + productType = "com.apple.product-type.library.static"; + }; + EA1E285D22B66487004AA304 /* generate_keys */ = { + isa = PBXNativeTarget; + buildConfigurationList = EA1E286222B66487004AA304 /* Build configuration list for PBXNativeTarget "generate_keys" */; + buildPhases = ( + EA1E285A22B66487004AA304 /* Sources */, + EA1E285B22B66487004AA304 /* Frameworks */, + EA1E285C22B66487004AA304 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = generate_keys; + productName = generate_keys; + productReference = EA1E285E22B66487004AA304 /* generate_keys */; + productType = "com.apple.product-type.tool"; + }; + EA1E287522B666EB004AA304 /* sign_update */ = { + isa = PBXNativeTarget; + buildConfigurationList = EA1E287D22B666EB004AA304 /* Build configuration list for PBXNativeTarget "sign_update" */; + buildPhases = ( + EA1E287222B666EB004AA304 /* Sources */, + EA1E287322B666EB004AA304 /* Frameworks */, + EA1E287422B666EB004AA304 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = sign_update; + productName = sign_update; + productReference = EA1E287622B666EB004AA304 /* sign_update */; + productType = "com.apple.product-type.tool"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -2553,7 +2790,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = SU; - LastSwiftUpdateCheck = 0820; + LastSwiftUpdateCheck = 1020; LastUpgradeCheck = 0830; ORGANIZATIONNAME = "Sparkle Project"; TargetAttributes = { @@ -2617,6 +2854,15 @@ EA1E280E22B64522004AA304 = { CreatedOnToolsVersion = 10.2.1; }; + EA1E282C22B660BE004AA304 = { + CreatedOnToolsVersion = 10.2.1; + }; + EA1E285D22B66487004AA304 = { + CreatedOnToolsVersion = 10.2.1; + }; + EA1E287522B666EB004AA304 = { + CreatedOnToolsVersion = 10.2.1; + }; }; }; buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "Sparkle" */; @@ -2690,7 +2936,10 @@ 1495005F195FB89400BC5B5B /* All */, 726B2B5C1C645FC900388755 /* UI Tests */, 7205C43D1E13049400E370AE /* generate_appcast */, + EA1E285D22B66487004AA304 /* generate_keys */, + EA1E287522B666EB004AA304 /* sign_update */, EA1E280E22B64522004AA304 /* bsdiff */, + EA1E282C22B660BE004AA304 /* ed25519 */, ); }; /* End PBXProject section */ @@ -2975,7 +3224,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "ln -sfh \"pt_BR.lproj\" \"$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/pt.lproj\""; + shellScript = "ln -sfh \"pt_BR.lproj\" \"$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/pt.lproj\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -3050,7 +3299,7 @@ 72464F7C1E2097F600FB341C /* SUOperatingSystem.m in Sources */, 7205C44C1E1304CE00E370AE /* Appcast.swift in Sources */, 7205C44D1E1304CE00E370AE /* ArchiveItem.swift in Sources */, - 7205C44E1E1304CE00E370AE /* DSASignature.swift in Sources */, + 7205C44E1E1304CE00E370AE /* Signatures.swift in Sources */, 7205C44F1E1304CE00E370AE /* FeedXML.swift in Sources */, 7205C4411E13049400E370AE /* main.swift in Sources */, 7205C45F1E13066F00E370AE /* SUBinaryDeltaApply.m in Sources */, @@ -3174,6 +3423,7 @@ 72A5D5CD1D6929F80009E5AC /* SPUCoreBasedUpdateDriver.m in Sources */, 72A5D5BD1D6929F80009E5AC /* SPUDownloadData.m in Sources */, 72A5D5D01D6929F80009E5AC /* SPUDownloadDriver.m in Sources */, + EA1E287122B66622004AA304 /* SUSignatures.m in Sources */, 72A5D5AF1D6929F80009E5AC /* SPUDownloader.m in Sources */, 72A5D5B71D6929F80009E5AC /* SPUInstallationInfo.m in Sources */, 72A5D5B41D6929F80009E5AC /* SPUInstallationInputData.m in Sources */, @@ -3316,6 +3566,7 @@ 55C14F07136EF6DB00649790 /* SULog.m in Sources */, 726F2CE61BC9C33D001971A4 /* SUOperatingSystem.m in Sources */, 61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */, + EA1E287022B66621004AA304 /* SUSignatures.m in Sources */, 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */, 72B3DECA1E23472200457642 /* SPUDownloadedUpdate.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, @@ -3339,6 +3590,39 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + EA1E282A22B660BE004AA304 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EA1E284622B660ED004AA304 /* fe.c in Sources */, + EA1E284822B660ED004AA304 /* ge.c in Sources */, + EA1E284722B660ED004AA304 /* verify.c in Sources */, + EA1E284C22B660ED004AA304 /* add_scalar.c in Sources */, + EA1E284D22B660ED004AA304 /* keypair.c in Sources */, + EA1E284522B660ED004AA304 /* seed.c in Sources */, + EA1E284B22B660ED004AA304 /* key_exchange.c in Sources */, + EA1E284A22B660ED004AA304 /* sign.c in Sources */, + EA1E284922B660ED004AA304 /* sc.c in Sources */, + EA1E284E22B660ED004AA304 /* sha512.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + EA1E285A22B66487004AA304 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EA1E286122B66487004AA304 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + EA1E287222B666EB004AA304 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EA1E287922B666EB004AA304 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -3819,27 +4103,24 @@ }; 7205C4421E13049400E370AE /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7205C4541E13054900E370AE /* ConfigGenerateAppcastDebug.xcconfig */; + baseConfigurationReference = EA1E286822B664FD004AA304 /* CommandLineTool-Debug.xcconfig */; buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; CODE_SIGN_IDENTITY = "-"; }; name = Debug; }; 7205C4431E13049400E370AE /* Coverage */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7205C4541E13054900E370AE /* ConfigGenerateAppcastDebug.xcconfig */; + baseConfigurationReference = EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */; buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; CODE_SIGN_IDENTITY = "-"; }; name = Coverage; }; 7205C4441E13049400E370AE /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7205C4551E13054900E370AE /* ConfigGenerateAppcastRelease.xcconfig */; + baseConfigurationReference = EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */; buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; CODE_SIGN_IDENTITY = "-"; }; name = Release; @@ -4084,6 +4365,69 @@ }; name = Release; }; + EA1E282F22B660BE004AA304 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = EA1E285822B6622E004AA304 /* ed25519-Debug.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + EA1E283022B660BE004AA304 /* Coverage */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = EA1E285722B6622E004AA304 /* ed25519-Release.xcconfig */; + buildSettings = { + }; + name = Coverage; + }; + EA1E283122B660BE004AA304 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = EA1E285722B6622E004AA304 /* ed25519-Release.xcconfig */; + buildSettings = { + }; + name = Release; + }; + EA1E286322B66487004AA304 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = EA1E286822B664FD004AA304 /* CommandLineTool-Debug.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + EA1E286422B66487004AA304 /* Coverage */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */; + buildSettings = { + }; + name = Coverage; + }; + EA1E286522B66487004AA304 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */; + buildSettings = { + }; + name = Release; + }; + EA1E287A22B666EB004AA304 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = EA1E286822B664FD004AA304 /* CommandLineTool-Debug.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + EA1E287B22B666EB004AA304 /* Coverage */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */; + buildSettings = { + }; + name = Coverage; + }; + EA1E287C22B666EB004AA304 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = EA1E286722B664FD004AA304 /* CommandLineTool-Release.xcconfig */; + buildSettings = { + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -4287,6 +4631,36 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + EA1E282E22B660BE004AA304 /* Build configuration list for PBXNativeTarget "ed25519" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EA1E282F22B660BE004AA304 /* Debug */, + EA1E283022B660BE004AA304 /* Coverage */, + EA1E283122B660BE004AA304 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + EA1E286222B66487004AA304 /* Build configuration list for PBXNativeTarget "generate_keys" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EA1E286322B66487004AA304 /* Debug */, + EA1E286422B66487004AA304 /* Coverage */, + EA1E286522B66487004AA304 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + EA1E287D22B666EB004AA304 /* Build configuration list for PBXNativeTarget "sign_update" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EA1E287A22B666EB004AA304 /* Debug */, + EA1E287B22B666EB004AA304 /* Coverage */, + EA1E287C22B666EB004AA304 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 0867D690FE84028FC02AAC07 /* Project object */; diff --git a/Sparkle.xcodeproj/xcshareddata/xcschemes/generate_keys.xcscheme b/Sparkle.xcodeproj/xcshareddata/xcschemes/generate_keys.xcscheme new file mode 100644 index 00000000..e4f02895 --- /dev/null +++ b/Sparkle.xcodeproj/xcshareddata/xcschemes/generate_keys.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sparkle.xcodeproj/xcshareddata/xcschemes/sign_update.xcscheme b/Sparkle.xcodeproj/xcshareddata/xcschemes/sign_update.xcscheme new file mode 100644 index 00000000..839fc3da --- /dev/null +++ b/Sparkle.xcodeproj/xcshareddata/xcschemes/sign_update.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index 02725898..abf13893 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -43,8 +43,10 @@ extern NSString *const SUSkippedVersionKey; extern NSString *const SUScheduledCheckIntervalKey; extern NSString *const SULastCheckTimeKey; extern NSString *const SUExpectsDSASignatureKey; +extern NSString *const SUExpectsEDSignatureKey; extern NSString *const SUPublicDSAKeyKey; extern NSString *const SUPublicDSAKeyFileKey; +extern NSString *const SUPublicEDKeyKey; extern NSString *const SUAutomaticallyUpdateKey; extern NSString *const SUAllowsAutomaticUpdatesKey; extern NSString *const SUEnableAutomaticChecksKey; @@ -66,6 +68,7 @@ extern NSString *const SURelaunchToolNameKey __attribute__((deprecated("This key extern NSString *const SUAppcastAttributeDeltaFrom; extern NSString *const SUAppcastAttributeDSASignature; +extern NSString *const SUAppcastAttributeEDSignature; extern NSString *const SUAppcastAttributeShortVersionString; extern NSString *const SUAppcastAttributeVersion; extern NSString *const SUAppcastAttributeOsType; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index d6bf46b8..b74537ca 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -38,8 +38,10 @@ NSString *const SUSkippedVersionKey = @"SUSkippedVersion"; NSString *const SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval"; NSString *const SULastCheckTimeKey = @"SULastCheckTime"; NSString *const SUExpectsDSASignatureKey = @"SUExpectsDSASignature"; +NSString *const SUExpectsEDSignatureKey = @"SUExpectsEDSignatureKey"; NSString *const SUPublicDSAKeyKey = @"SUPublicDSAKey"; NSString *const SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile"; +NSString *const SUPublicEDKeyKey = @"SUPublicEDKey"; NSString *const SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate"; NSString *const SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates"; NSString *const SUEnableSystemProfilingKey = @"SUEnableSystemProfiling"; @@ -59,6 +61,7 @@ NSString *const SURelaunchToolNameKey = @"SURelaunchToolName"; NSString *const SUAppcastAttributeDeltaFrom = @"sparkle:deltaFrom"; NSString *const SUAppcastAttributeDSASignature = @"sparkle:dsaSignature"; +NSString *const SUAppcastAttributeEDSignature = @"sparkle:edSignature"; NSString *const SUAppcastAttributeShortVersionString = @"sparkle:shortVersionString"; NSString *const SUAppcastAttributeVersion = @"sparkle:version"; NSString *const SUAppcastAttributeOsType = @"sparkle:os"; diff --git a/Sparkle/SUSignatures.h b/Sparkle/SUSignatures.h new file mode 100644 index 00000000..5b3e40ca --- /dev/null +++ b/Sparkle/SUSignatures.h @@ -0,0 +1,40 @@ +// +// SUSignatures.h +// Sparkle +// +// Created by Kornel on 15/09/2018. +// Copyright © 2018 Sparkle Project. All rights reserved. +// + +#import + +#if __MAC_OS_X_VERSION_MAX_ALLOWED < 1090 +@interface NSData (SUDSAVerifier) +- (id)initWithBase64Encoding:(NSString *)base64String; +@end +#endif + +NS_ASSUME_NONNULL_BEGIN + +@interface SUSignatures : NSObject { + unsigned char ed25519_signature[64]; +} +@property (strong, readonly, nullable) NSData *dsaSignature; +@property (readonly, nullable, nonatomic) const unsigned char *ed25519Signature; + +- (instancetype)initWithDsa:(NSString * _Nullable)dsa ed:(NSString * _Nullable)ed; +@end + + +@interface SUPublicKeys : NSObject { + unsigned char ed25519_public_key[32]; +} +@property (strong, readonly, nullable) NSString *dsaPubKey; +@property (readonly, nullable, nonatomic) const unsigned char *ed25519PubKey; + +- (instancetype)initWithDsa:(NSString * _Nullable)dsa ed:(NSString * _Nullable)ed; +- (BOOL) isEqualToKey:(SUPublicKeys *)key; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUSignatures.m b/Sparkle/SUSignatures.m new file mode 100644 index 00000000..8e07d7e7 --- /dev/null +++ b/Sparkle/SUSignatures.m @@ -0,0 +1,96 @@ +// +// SUSignatures.m +// Sparkle +// +// Created by Kornel on 15/09/2018. +// Copyright © 2018 Sparkle Project. All rights reserved. +// + +#import "SUSignatures.h" +#import +#import "SULog.h" + +@implementation SUSignatures +@synthesize dsaSignature = _dsaSignature; + +static NSData *decode(NSString *str) { + if (str == nil) { + return nil; + } + + NSString *stripped = [str stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet]; + return [[NSData alloc] initWithBase64Encoding:stripped]; +} + +- (instancetype)initWithDsa:(NSString * _Nullable)maybeDsa ed:(NSString * _Nullable)maybeEd25519 +{ + self = [super init]; + if (self) { + if (maybeDsa != nil) { + _dsaSignature = decode(maybeDsa); + } + if (maybeEd25519 != nil) { + NSData *data = decode(maybeEd25519); + assert(64 == sizeof(self->ed25519_signature)); + [data getBytes:self->ed25519_signature length:sizeof(self->ed25519_signature)]; + } + } + return self; +} + +- (const unsigned char *)ed25519Signature { +// Xcode may enable this in pedantic mode +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdirect-ivar-access" + for(size_t i=0; i < sizeof(self->ed25519_signature); i++) { + if (self->ed25519_signature[i] != 0) { + return self->ed25519_signature; + } + } + return NULL; +#pragma clang diagnostic pop +} + +@end + +@implementation SUPublicKeys +@synthesize dsaPubKey = _dsaPubKey; + +- (instancetype)initWithDsa:(NSString * _Nullable)maybeDsa ed:(NSString * _Nullable)maybeEd25519 +{ + self = [super init]; + if (self) { + _dsaPubKey = maybeDsa; + if (maybeEd25519 != nil) { + NSData *ed = decode(maybeEd25519); + assert(32 == sizeof(self->ed25519_public_key)); + [ed getBytes:self->ed25519_public_key length:sizeof(self->ed25519_public_key)]; + } + } + return self; +} + +- (BOOL) isEqualToKey:(SUPublicKeys *)key { + NSString *thisKey = self.dsaPubKey; + NSString *thatKey = key.dsaPubKey; + if (thisKey == nil || thatKey == nil) { + return NO; + } + return NO; +} + + +- (const unsigned char *)ed25519PubKey { +// Xcode may enable this in pedantic mode +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdirect-ivar-access" + for(size_t i=0; i < sizeof(self->ed25519_public_key); i++) { + if (self->ed25519_public_key[i] != 0) { + return self->ed25519_public_key; + } + } + return NULL; +#pragma clang diagnostic pop +} + +@end diff --git a/Tests/SUCodeSigningVerifierTest.m b/Tests/SUCodeSigningVerifierTest.m index f52dae7b..e018ab33 100644 --- a/Tests/SUCodeSigningVerifierTest.m +++ b/Tests/SUCodeSigningVerifierTest.m @@ -9,11 +9,8 @@ #import #import #import "SUCodeSigningVerifier.h" -#import "SUAdHocCodeSigning.h" #import "SUFileManager.h" -#define CALCULATOR_PATH @"/Applications/Calculator.app" - @interface SUCodeSigningVerifierTest : XCTestCase @property (copy) NSURL *notSignedAppURL; @@ -30,6 +27,13 @@ @synthesize invalidSignedAppURL = _invalidSignedAppURL; @synthesize calculatorCopyURL = _calculatorCopyURL; ++ (NSString *)calculatorApplicationPath +{ + NSString *applicationsDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSSystemDomainMask, NO) objectAtIndex:0]; + NSString *calculatorPath = [applicationsDirectory stringByAppendingPathComponent:@"Calculator.app"]; + return calculatorPath; +} + - (void)setUp { [super setUp]; @@ -87,8 +91,9 @@ } self.validSignedAppURL = signedAndValid; - if (![SUAdHocCodeSigning codeSignApplicationAtPath:self.validSignedAppURL.path]) { - NSLog(@"Failed to codesign %@", self.validSignedAppURL); + + if (![self codesignAppURL:self.validSignedAppURL]) { + XCTFail(@"Failed to codesign %@", self.validSignedAppURL); } } @@ -99,14 +104,15 @@ [[NSFileManager defaultManager] removeItemAtURL:calculatorCopy error:NULL]; + NSString *calculatorPath = [SUCodeSigningVerifierTest calculatorApplicationPath]; // Make a copy of the signed calculator app so we can match signatures later // Matching signatures on ad-hoc signed apps does *not* work NSError *copyError = nil; // Don't check the return value of this operation - seems like on 10.11 the API can say it fails even though the operation really succeeds, // which sounds like some kind of (SIP / attribute?) bug - [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:CALCULATOR_PATH] toURL:calculatorCopy error:©Error]; + [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:calculatorPath] toURL:calculatorCopy error:©Error]; - if (![calculatorCopy checkResourceIsReachableAndReturnError:NULL]) { + if (![calculatorCopy checkResourceIsReachableAndReturnError:nil]) { XCTFail(@"Copied calculator application does not exist"); } @@ -131,7 +137,7 @@ [[NSFileManager defaultManager] removeItemAtURL:signedAndInvalid error:NULL]; if ([[NSFileManager defaultManager] copyItemAtURL:self.notSignedAppURL toURL:signedAndInvalid error:&error]) { self.invalidSignedAppURL = signedAndInvalid; - if ([SUAdHocCodeSigning codeSignApplicationAtPath:self.invalidSignedAppURL.path]) { + if ([self codesignAppURL:self.invalidSignedAppURL]) { NSURL *fileInAppBundleToRemove = [self.invalidSignedAppURL URLByAppendingPathComponent:@"Contents/Resources/test_app_only_dsa_pub.pem"]; if (![[NSFileManager defaultManager] removeItemAtURL:fileInAppBundleToRemove error:&error]) { NSLog(@"Failed to remove %@ with error %@", fileInAppBundleToRemove, error); @@ -167,6 +173,25 @@ return success; } +- (BOOL)codesignAppURL:(NSURL *)appURL +{ + BOOL success = NO; + @try + { + // ad-hoc signing with the dash + NSString *appPath = [appURL path]; + NSArray *arguments = @[ @"--force", @"--deep", @"--sign", @"-", appPath ]; + NSTask *task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/codesign" arguments:arguments]; + [task waitUntilExit]; + success = (task.terminationStatus == 0); + } + @catch (NSException *exception) + { + NSLog(@"exception: %@", exception); + } + return success; +} + - (void)testUnsignedApp { XCTAssertFalse([SUCodeSigningVerifier bundleAtURLIsCodeSigned:self.notSignedAppURL], @"App not expected to be code signed"); @@ -187,7 +212,8 @@ - (void)testValidSignedCalculatorApp { - NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH]; + NSString *calculatorPath = [SUCodeSigningVerifierTest calculatorApplicationPath]; + NSURL *appPath = [NSURL fileURLWithPath:calculatorPath]; XCTAssertTrue([SUCodeSigningVerifier bundleAtURLIsCodeSigned:appPath], @"App expected to be code signed"); NSError *error = nil; @@ -197,23 +223,26 @@ - (void)testValidMatchingSelf { + NSString *calculatorPath = [SUCodeSigningVerifierTest calculatorApplicationPath]; NSError *error = nil; - NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH]; + NSURL *appPath = [NSURL fileURLWithPath:calculatorPath]; XCTAssertTrue([SUCodeSigningVerifier codeSignatureAtBundleURL:appPath matchesSignatureAtBundleURL:appPath error:&error], @"Our valid signed app expected to having matching signature to itself"); } - (void)testValidMatching { + NSString *calculatorPath = [SUCodeSigningVerifierTest calculatorApplicationPath]; // We can't test our own app because matching with ad-hoc signed apps understandably does not succeed NSError *error = nil; - NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH]; + NSURL *appPath = [NSURL fileURLWithPath:calculatorPath]; XCTAssertTrue([SUCodeSigningVerifier codeSignatureAtBundleURL:appPath matchesSignatureAtBundleURL:self.calculatorCopyURL error:&error], @"The calculator app is expected to have matching identity signature to its altered copy"); } - (void)testInvalidMatching { - NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH]; + NSString *calculatorPath = [SUCodeSigningVerifierTest calculatorApplicationPath]; + NSURL *appPath = [NSURL fileURLWithPath:calculatorPath]; NSError *error = nil; XCTAssertFalse([SUCodeSigningVerifier codeSignatureAtBundleURL:appPath matchesSignatureAtBundleURL:self.validSignedAppURL error:&error], @"Calculator app bundle expected to have different signature than our valid signed app"); } diff --git a/Vendor/ed25519 b/Vendor/ed25519 new file mode 160000 index 00000000..7fa6712e --- /dev/null +++ b/Vendor/ed25519 @@ -0,0 +1 @@ +Subproject commit 7fa6712ef5d581a6981ec2b08ee623314cd1d1c4 diff --git a/generate_appcast/Appcast-Bridging-Header.h b/generate_appcast/Appcast-Bridging-Header.h index 916d1e79..4b8b160e 100644 --- a/generate_appcast/Appcast-Bridging-Header.h +++ b/generate_appcast/Appcast-Bridging-Header.h @@ -6,3 +6,4 @@ #import "SUUnarchiver.h" #import "SUBinaryDeltaUnarchiver.h" #import "SUBinaryDeltaCreate.h" +#import "ed25519.h" // Run `git submodule update --init` if you get an error here diff --git a/generate_appcast/Appcast.swift b/generate_appcast/Appcast.swift index 686e7372..0f4ff293 100644 --- a/generate_appcast/Appcast.swift +++ b/generate_appcast/Appcast.swift @@ -14,10 +14,11 @@ 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 cacheDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0].appendingPathComponent("Sparkle_generate_appcast"); let comparator = SUStandardVersionComparator(); - let allUpdates = (try unarchiveUpdates(archivesSourceDir: archivesSourceDir, verbose:verbose)) + let allUpdates = (try unarchiveUpdates(archivesSourceDir: archivesSourceDir, archivesDestDir: cacheDir, verbose:verbose)) .sorted(by: { .orderedDescending == comparator.compareVersion($0.version, toVersion:$1.version) }) @@ -33,11 +34,31 @@ 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 let privateDSAKey = keys.privateDSAKey { + do { + update.dsaSignature = try dsaSignature(path: update.archivePath, privateDSAKey: privateDSAKey); + } catch { + print(update, error); + } + } else if update.supportsDSA { + 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, 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"); + } + } + group.leave(); } @@ -63,16 +84,29 @@ func makeAppcast(archivesSourceDir: URL, privateKey: SecKey, verbose: Bool) thro var numDeltas = 0; let appBaseName = latestItem.appPath.deletingPathExtension().lastPathComponent; for item in updates { + if numDeltas > maxDeltas { + break; + } + // No downgrades if .orderedAscending != comparator.compareVersion(item.version, toVersion: latestItem.version) { continue; } + // Old version will not be able to verify the new version + if !item.supportsDSA && item.publicEdKey == nil { + continue; + } let deltaBaseName = appBaseName + latestItem.version + "-" + item.version; let deltaPath = archivesSourceDir.appendingPathComponent(deltaBaseName).appendingPathExtension("delta"); var delta:DeltaUpdate; - if !FileManager.default.fileExists(atPath: deltaPath.path) { + let ignoreMarkerPath = cacheDir.appendingPathComponent(deltaPath.lastPathComponent).appendingPathExtension(".ignore"); + let fm = FileManager.default; + if fm.fileExists(atPath: ignoreMarkerPath.path) { + continue; + } + if !fm.fileExists(atPath: deltaPath.path) { do { delta = try DeltaUpdate.create(from: item, to: latestItem, archivePath: deltaPath); } catch { @@ -83,23 +117,37 @@ func makeAppcast(archivesSourceDir: URL, privateKey: SecKey, verbose: Bool) thro delta = DeltaUpdate(fromVersion: item.version, archivePath: deltaPath); } - // Require delta to be a bit smaller - if delta.fileSize / 7 < latestItem.fileSize / 8 { - numDeltas += 1; - if numDeltas > maxDeltas { - break; - } + numDeltas += 1; - group.enter(); - DispatchQueue.global().async { + // Require delta to be a bit smaller + if delta.fileSize / 7 > latestItem.fileSize / 8 { + markDeltaAsIgnored(delta: delta, markerPath: ignoreMarkerPath) + continue; + } + + group.enter(); + DispatchQueue.global().async { + if item.supportsDSA, let privateDSAKey = keys.privateDSAKey { do { - delta.dsaSignature = try dsaSignature(path: deltaPath, privateKey: privateKey); - latestItem.deltas.append(delta); + delta.dsaSignature = try dsaSignature(path: deltaPath, privateDSAKey: privateDSAKey); } catch { print(delta.archivePath.lastPathComponent, error); } - group.leave(); } + 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 { + markDeltaAsIgnored(delta: delta, markerPath: ignoreMarkerPath) + print("Delta \(delta.archivePath.path) ignored, because it could not be signed"); + } + group.leave(); } } } @@ -109,3 +157,8 @@ func makeAppcast(archivesSourceDir: URL, privateKey: SecKey, verbose: Bool) thro return updatesByAppcast; } + +func markDeltaAsIgnored(delta: DeltaUpdate, markerPath: URL) { + let _ = try? FileManager.default.removeItem(at: delta.archivePath) + let _ = try? Data.init().write(to: markerPath); // 0-sized file +} diff --git a/generate_appcast/ArchiveItem.swift b/generate_appcast/ArchiveItem.swift index 4cee60bf..5fb4aa29 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,41 +39,57 @@ 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 = []; } convenience init(fromArchive archivePath: URL, unarchivedDir: URL) throws { - let items = try FileManager.default.contentsOfDirectory(atPath: unarchivedDir.path) - .filter({ !$0.hasPrefix(".") }) - .map({ unarchivedDir.appendingPathComponent($0) }) + let resourceKeys = [URLResourceKey.typeIdentifierKey] + let items = try FileManager.default.contentsOfDirectory(at: unarchivedDir, includingPropertiesForKeys: resourceKeys, options: .skipsHiddenFiles) - let apps = items.filter({ $0.pathExtension == "app" }); - if apps.count > 0 { - if apps.count > 1 { - throw makeError(code: .unarchivingError, "Too many apps in \(unarchivedDir.path) \(apps)"); + let bundles = items.filter({ + if let resourceValues = try? $0.resourceValues(forKeys: Set(resourceKeys)) { + return UTTypeConformsTo(resourceValues.typeIdentifier! as CFString, kUTTypeBundle) + } else { + return false + } + }); + if bundles.count > 0 { + if bundles.count > 1 { + throw makeError(code: .unarchivingError, "Too many bundles in \(unarchivedDir.path) \(bundles)"); } - let appPath = apps[0]; + let appPath = bundles[0]; guard let infoPlist = NSDictionary(contentsOf: appPath.appendingPathComponent("Contents/Info.plist")) else { 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[SUPublicEDKeyKey] as? String; + let supportsDSA = infoPlist[SUPublicDSAKeyKey] != nil || infoPlist[SUPublicDSAKeyFileKey] != nil; var feedURL:URL? = nil; if let feedURLStr = infoPlist["SUFeedURL"] as? String { @@ -80,11 +97,13 @@ class ArchiveItem: CustomStringConvertible { } try self.init(version: version, - shortVersion: shortVersion, - feedURL: feedURL, - minimumSystemVersion: infoPlist["LSMinimumSystemVersion"] as? String, - appPath: appPath, - archivePath: archivePath); + shortVersion: shortVersion, + feedURL: feedURL, + minimumSystemVersion: infoPlist["LSMinimumSystemVersion"] as? String, + publicEdKey: publicEdKey, + supportsDSA: supportsDSA, + appPath: appPath, + archivePath: archivePath); } else { throw makeError(code: .missingUpdateError, "No supported items in \(unarchivedDir) \(items) [note: only .app bundles are supported]"); } @@ -118,7 +137,7 @@ class ArchiveItem: CustomStringConvertible { var fileSize : Int64 { return (self.archiveFileAttributes[.size] as! NSNumber).int64Value; } - + private var releaseNotesPath : URL? { var basename = self.archivePath.deletingPathExtension(); if basename.pathExtension == "tar" { // tar.gz diff --git a/generate_appcast/FeedXML.swift b/generate_appcast/FeedXML.swift index 29e95266..84e3011f 100644 --- a/generate_appcast/FeedXML.swift +++ b/generate_appcast/FeedXML.swift @@ -23,7 +23,6 @@ func findOrCreateElement(name: String, parent: XMLElement) -> XMLElement { return element; } let element = XMLElement(name: name); - linebreak(parent); parent.addChild(element); return element; } @@ -32,10 +31,6 @@ func text(_ text: String) -> XMLNode { return XMLNode.text(withStringValue: text) as! XMLNode } -func linebreak(_ element: XMLElement) { - element.addChild(text("\n")); -} - func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { let appBaseName = updates[0].appPath.deletingPathExtension().lastPathComponent; @@ -70,9 +65,7 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { channel = channelNodes[0] as! XMLElement; } else { channel = XMLElement(name: "channel"); - linebreak(channel); channel.addChild(XMLElement.element(withName: "title", stringValue: appBaseName) as! XMLElement); - linebreak(root); root.addChild(channel); } @@ -90,18 +83,15 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { if createNewItem { item = XMLElement.element(withName: "item") as! XMLElement; - linebreak(channel); channel.addChild(item); } else { item = existingItems[0] as! XMLElement; } if nil == findElement(name: "title", parent: item) { - linebreak(item); item.addChild(XMLElement.element(withName: "title", stringValue: update.shortVersion) as! XMLElement); } if nil == findElement(name: "pubDate", parent: item) { - linebreak(item); item.addChild(XMLElement.element(withName: "pubDate", stringValue: update.pubDate) as! XMLElement); } @@ -112,28 +102,25 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { descElement.setChildren([cdata]); } - var minVer = findElement(name: "sparkle:minimumSystemVersion", parent: item); + var minVer = findElement(name: SUAppcastElementMinimumSystemVersion, parent: item); if nil == minVer { - minVer = XMLElement.element(withName: "sparkle:minimumSystemVersion", uri: sparkleNS) as? XMLElement; - linebreak(item); + minVer = XMLElement.element(withName: SUAppcastElementMinimumSystemVersion, uri: sparkleNS) as? XMLElement; item.addChild(minVer!); } minVer?.setChildren([text(update.minimumSystemVersion)]); - let relElement = findElement(name: "sparkle:releaseNotesLink", parent: item); + let relElement = findElement(name: SUAppcastElementReleaseNotesLink, parent: item); if let url = update.releaseNotesURL { if nil == relElement { - linebreak(item); - item.addChild(XMLElement.element(withName:"sparkle:releaseNotesLink", stringValue: url.absoluteString) as! XMLElement); + item.addChild(XMLElement.element(withName: SUAppcastElementReleaseNotesLink, stringValue: url.absoluteString) as! XMLElement); } } else if let childIndex = relElement?.index { item.removeChild(at: childIndex); } - + var enclosure = findElement(name: "enclosure", parent: item); if nil == enclosure { enclosure = XMLElement.element(withName: "enclosure") as? XMLElement; - linebreak(item); item.addChild(enclosure!); } @@ -142,21 +129,23 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { }; var attributes = [ XMLNode.attribute(withName: "url", stringValue: archiveURL) as! XMLNode, - XMLNode.attribute(withName: "sparkle:version", uri: sparkleNS, stringValue: update.version) as! XMLNode, - XMLNode.attribute(withName: "sparkle:shortVersionString", uri: sparkleNS, stringValue: update.shortVersion) as! XMLNode, + XMLNode.attribute(withName: SUAppcastAttributeVersion, uri: sparkleNS, stringValue: update.version) as! XMLNode, + XMLNode.attribute(withName: SUAppcastAttributeShortVersionString, uri: sparkleNS, stringValue: update.shortVersion) as! XMLNode, XMLNode.attribute(withName: "length", stringValue: String(update.fileSize)) as! XMLNode, XMLNode.attribute(withName: "type", stringValue: update.mimeType) as! XMLNode, ]; + if let sig = update.edSignature { + attributes.append(XMLNode.attribute(withName: SUAppcastAttributeEDSignature, uri: sparkleNS, stringValue: sig) as! XMLNode); + } if let sig = update.dsaSignature { - attributes.append(XMLNode.attribute(withName: "sparkle:dsaSignature", uri: sparkleNS, stringValue: sig) as! XMLNode); + attributes.append(XMLNode.attribute(withName: SUAppcastAttributeDSASignature, uri: sparkleNS, stringValue: sig) as! XMLNode); } enclosure!.attributes = attributes; if update.deltas.count > 0 { - var deltas = findElement(name: "sparkle:deltas", parent: item); + var deltas = findElement(name: SUAppcastElementDeltas, parent: item); if nil == deltas { - deltas = XMLElement.element(withName: "sparkle:deltas", uri: sparkleNS) as? XMLElement; - linebreak(item); + deltas = XMLElement.element(withName: SUAppcastElementDeltas, uri: sparkleNS) as? XMLElement; item.addChild(deltas!); } else { deltas!.setChildren([]); @@ -164,26 +153,24 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { for delta in update.deltas { var attributes = [ XMLNode.attribute(withName: "url", stringValue: URL(string: delta.archivePath.lastPathComponent.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlPathAllowed)!, relativeTo: update.archiveURL)!.absoluteString) as! XMLNode, - XMLNode.attribute(withName: "sparkle:version", uri: sparkleNS, stringValue: update.version) as! XMLNode, - XMLNode.attribute(withName: "sparkle:shortVersionString", uri: sparkleNS, stringValue: update.shortVersion) as! XMLNode, - XMLNode.attribute(withName: "sparkle:deltaFrom", uri: sparkleNS, stringValue: delta.fromVersion) as! XMLNode, + XMLNode.attribute(withName: SUAppcastAttributeVersion, uri: sparkleNS, stringValue: update.version) as! XMLNode, + XMLNode.attribute(withName: SUAppcastAttributeShortVersionString, uri: sparkleNS, stringValue: update.shortVersion) as! XMLNode, + XMLNode.attribute(withName: SUAppcastAttributeDeltaFrom, uri: sparkleNS, stringValue: delta.fromVersion) as! XMLNode, XMLNode.attribute(withName: "length", stringValue: String(delta.fileSize)) as! XMLNode, XMLNode.attribute(withName: "type", stringValue: "application/octet-stream") as! XMLNode, - ]; - if let sig = delta.dsaSignature { - attributes.append(XMLNode.attribute(withName: "sparkle:dsaSignature", uri: sparkleNS, stringValue: sig) as! XMLNode); + ]; + if let sig = delta.edSignature { + attributes.append(XMLNode.attribute(withName: SUAppcastAttributeEDSignature, uri: sparkleNS, stringValue: sig) as! XMLNode); + } + if let sig = delta.dsaSignature { + attributes.append(XMLNode.attribute(withName: SUAppcastAttributeDSASignature, uri: sparkleNS, stringValue: sig) as! XMLNode); } - linebreak(deltas!); deltas!.addChild(XMLNode.element(withName: "enclosure", children: nil, attributes: attributes) as! XMLElement); } } - if createNewItem { - linebreak(item); - linebreak(channel); - } } - let options = XMLNode.Options.nodeCompactEmptyElement; + let options: XMLNode.Options = [.nodeCompactEmptyElement, .nodePrettyPrint]; let docData = doc.xmlData(options:options); let _ = try XMLDocument(data: docData, options:XMLNode.Options()); // Verify that it was generated correctly, which does not always happen! try docData.write(to: appcastDestPath); diff --git a/generate_appcast/DSASignature.swift b/generate_appcast/Signatures.swift similarity index 69% rename from generate_appcast/DSASignature.swift rename to generate_appcast/Signatures.swift index 7040d54c..2a4b8594 100644 --- a/generate_appcast/DSASignature.swift +++ b/generate_appcast/Signatures.swift @@ -5,7 +5,19 @@ import Foundation -func loadPrivateKey(at privateKeyURL: URL) throws -> SecKey { +struct PrivateKeys { + var privateDSAKey: SecKey?; + var privateEdKey: Data?; + var publicEdKey: Data?; + + init(privateDSAKey: SecKey?, privateEdKey: Data?, publicEdKey: Data?) { + self.privateDSAKey = privateDSAKey; + self.privateEdKey = privateEdKey; + self.publicEdKey = publicEdKey; + } +} + +func loadPrivateDSAKey(at privateKeyURL: URL) throws -> SecKey { let data = try Data(contentsOf: privateKeyURL); var cfitems: CFArray? = nil; @@ -25,13 +37,13 @@ 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 { throw NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(SUError.signatureError.rawValue)), userInfo: nil) } - + let query: [CFString: CFTypeRef] = [ kSecClass: kSecClassKey, kSecAttrKeyClass: kSecAttrKeyClassPrivate, @@ -40,16 +52,16 @@ func loadPrivateKey(named keyName: String, fromKeychainAt keychainURL: URL) thro kSecUseKeychain: keychain!, kSecReturnRef: kCFBooleanTrue ] - + var item: CFTypeRef? = nil guard SecItemCopyMatching(query as CFDictionary, &item) == errSecSuccess, item != nil else { throw NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(SUError.signatureError.rawValue)), userInfo: nil) } - + 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 +69,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 +94,21 @@ func dsaSignature(path: URL, privateKey: SecKey) throws -> String { } return resultData.base64EncodedString(); } + +func edSignature(path: URL, publicEdKey: Data, privateEdKey: Data) throws -> String { + assert(publicEdKey.count == 32) + assert(privateEdKey.count == 64) + let data = try Data.init(contentsOf: path, options: .mappedIfSafe); + let len = data.count; + var output = Data(count: 64); + 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/Unarchive.swift b/generate_appcast/Unarchive.swift index 3cd01b67..aa1e9729 100644 --- a/generate_appcast/Unarchive.swift +++ b/generate_appcast/Unarchive.swift @@ -13,7 +13,11 @@ func unarchive(itemPath:URL, archiveDestDir: URL, callback: @escaping (Error?) - _ = try? fileManager.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: [:]); do { - try fileManager.linkItem(at: itemPath, to: itemCopy); + do { + try fileManager.linkItem(at: itemPath, to: itemCopy); + } catch { + try fileManager.copyItem(at: itemPath, to: itemCopy); + } if let unarchiver = SUUnarchiver.unarchiver(forPath: itemCopy.path, updatingHostBundlePath:nil, decryptionPassword:nil) { unarchiver.unarchive(completionBlock: { (error: Error?) in if error != nil { @@ -39,8 +43,7 @@ func unarchive(itemPath:URL, archiveDestDir: URL, callback: @escaping (Error?) - } } -func unarchiveUpdates(archivesSourceDir: URL, verbose: Bool) throws -> [ArchiveItem] { - let archivesDestDir = archivesSourceDir.appendingPathComponent(".tmp"); +func unarchiveUpdates(archivesSourceDir: URL, archivesDestDir: URL, verbose: Bool) throws -> [ArchiveItem] { if verbose { print("Unarchiving to temp directory", archivesDestDir.path); } diff --git a/generate_appcast/main.swift b/generate_appcast/main.swift index 57ae99f2..a97d7ea6 100644 --- a/generate_appcast/main.swift +++ b/generate_appcast/main.swift @@ -12,50 +12,72 @@ var verbose = false; func printUsage() { let command = URL(fileURLWithPath: CommandLine.arguments.first!).lastPathComponent; - print("Generate appcast from a directory of Sparkle updates\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", + print("Generate appcast from a directory of Sparkle update archives\n", + "Usage:\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 publicEdKey: 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]; + 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, publicEdKey: publicEdKey); +} + 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 let keychainURL: URL - + if args[1] == "-n" { if args[3] != "-k" { printUsage() exit(1) } - + keyName = args[2] keychainURL = URL(fileURLWithPath: args[4]) } @@ -64,28 +86,29 @@ func main() { printUsage() exit(1) } - + keyName = args[4] keychainURL = URL(fileURLWithPath: args[2]) } 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); try writeAppcast(appcastDestPath:appcastDestPath, updates:updates); diff --git a/generate_keys/Bridging-Header.h b/generate_keys/Bridging-Header.h new file mode 100644 index 00000000..5bf09466 --- /dev/null +++ b/generate_keys/Bridging-Header.h @@ -0,0 +1,6 @@ +#import + +#import "SUConstants.h" +#import "SUErrors.h" +#import "SUSignatures.h" +#import "ed25519.h" // Run `git submodule update --init` if you get an error here diff --git a/generate_keys/main.swift b/generate_keys/main.swift new file mode 100644 index 00000000..cdbb526f --- /dev/null +++ b/generate_keys/main.swift @@ -0,0 +1,94 @@ +// +// 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 if res == errSecInteractionNotAllowed { + print("\nERROR! The operating system has blocked access to the Keychain."); + } 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") diff --git a/sign_update/Bridging-Header.h b/sign_update/Bridging-Header.h new file mode 100644 index 00000000..5bf09466 --- /dev/null +++ b/sign_update/Bridging-Header.h @@ -0,0 +1,6 @@ +#import + +#import "SUConstants.h" +#import "SUErrors.h" +#import "SUSignatures.h" +#import "ed25519.h" // Run `git submodule update --init` if you get an error here diff --git a/sign_update/main.swift b/sign_update/main.swift new file mode 100644 index 00000000..da962823 --- /dev/null +++ b/sign_update/main.swift @@ -0,0 +1,72 @@ +// +// main.swift +// sign_update +// +// Created by Kornel on 16/09/2018. +// Copyright © 2018 Sparkle Project. All rights reserved. +// + +import Foundation +import Security + +func findKeys() -> (Data, 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) { + return (keys[0..<64], keys[64..<(64+32)]) + } + else if res == errSecItemNotFound { + print("ERROR! Signing key not found. Please run generate_keys tool first."); + } + else if res == errSecAuthFailed { + print("ERROR! Access denied. Can't get keys from the keychain."); + print("Go to Keychain Access.app, lock the login keychain, then unlock it again."); + } + else if res == errSecUserCanceled { + print("ABORTED! You've cancelled the request to read the key from the Keychain. Please run the tool again."); + } else if res == errSecInteractionNotAllowed { + print("ERROR! The operating system has blocked access to the Keychain."); + } else { + print("ERROR! Unable to access required key in the Keychain", res, "(you can look it up at osstatus.com)"); + } + exit(1) +} + +func edSignature(data: Data, publicEdKey: Data, privateEdKey: Data) -> String { + assert(publicEdKey.count == 32) + assert(privateEdKey.count == 64) + let len = data.count; + var output = Data(count: 64); + 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(); +} + +let args = CommandLine.arguments; +if args.count != 2 { + print("Usage: \(args[0]) \nPrivavte EdDSA (ed25519) key is automatically read from the Keychain.\n"); + exit(1) +} + +let(priv, pub) = findKeys(); + +do { + let data = try Data.init(contentsOf: URL.init(fileURLWithPath: args[1]), options: .mappedIfSafe); + let sig = edSignature(data:data , publicEdKey: pub, privateEdKey: priv); + print("sparkle:edSignature=\"\(sig)\" length=\"\(data.count)\""); +} catch { + print("ERROR: ", error) +}