mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Merge branch '2.x' into alert-state
This commit is contained in:
commit
1d930b585e
17 files changed
+163
-56
No files matched your search
Vendored
+3
-3
@@ -77,12 +77,12 @@
|
||||
SULog(SULogLevelError, @"Error: resumeDownloadedUpdate:completion: called on SPUAutomaticUpdateDriver");
|
||||
}
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
|
||||
{
|
||||
self.updateItem = updateItem;
|
||||
|
||||
if (updateItem.isInformationOnlyUpdate) {
|
||||
[self.coreDriver deferInformationalUpdate:updateItem];
|
||||
if (updateItem.isInformationOnlyUpdate || preventsAutoupdate) {
|
||||
[self.coreDriver deferInformationalUpdate:updateItem preventsAutoupdate:preventsAutoupdate];
|
||||
[self abortUpdate];
|
||||
} else {
|
||||
[self.coreDriver downloadUpdateFromAppcastItem:updateItem inBackground:YES];
|
||||
|
||||
Vendored
+1
-1
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SPUBasicUpdateDriverDelegate <NSObject>
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem;
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem preventsAutoupdate:(BOOL)preventsAutoupdate;
|
||||
|
||||
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
|
||||
|
||||
|
||||
Vendored
+3
-3
@@ -87,7 +87,7 @@
|
||||
[self notifyFinishLoadingAppcast];
|
||||
|
||||
SUAppcastItem *nonNullUpdateItem = updateItem;
|
||||
[self didFindValidUpdateWithAppcastItem:nonNullUpdateItem];
|
||||
[self didFindValidUpdateWithAppcastItem:nonNullUpdateItem preventsAutoupdate:NO];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem
|
||||
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
|
||||
{
|
||||
if (!self.aborted) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
|
||||
@@ -152,7 +152,7 @@
|
||||
[self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem];
|
||||
}
|
||||
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SPUCoreBasedUpdateDriverDelegate <NSObject>
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem;
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate;
|
||||
|
||||
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently;
|
||||
|
||||
@@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem inBackground:(BOOL)background;
|
||||
|
||||
- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem;
|
||||
- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate;
|
||||
|
||||
- (void)extractDownloadedUpdate;
|
||||
|
||||
|
||||
Vendored
+6
-6
@@ -141,24 +141,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
|
||||
{
|
||||
self.updateItem = updateItem;
|
||||
|
||||
if (self.resumingInstallingUpdate) {
|
||||
[self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem];
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
|
||||
} else {
|
||||
if (!self.preventsInstallerInteraction) {
|
||||
// Simple case - delegate allows interaction, so we should continue along
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
|
||||
} else {
|
||||
// Package type installations will always require installer interaction as long as we don't support running as root
|
||||
// If it's not a package type installation, we should be okay since we did an auth check before checking for updates above
|
||||
if (![updateItem.installationType isEqualToString:SPUInstallationTypeApplication]) {
|
||||
[self.delegate coreDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNotAllowedInteractionError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"A new update is available but cannot be installed because interaction has been prevented.", nil)] }]];
|
||||
} else {
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,9 +204,9 @@
|
||||
[self extractUpdate:downloadedUpdate];
|
||||
}
|
||||
|
||||
- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem
|
||||
- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
|
||||
{
|
||||
self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem];
|
||||
self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
|
||||
}
|
||||
|
||||
- (void)extractDownloadedUpdate
|
||||
|
||||
Vendored
+1
-1
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SPUInformationalUpdate : NSObject <SPUResumableUpdate>
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem;
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Vendored
+3
-1
@@ -16,12 +16,14 @@
|
||||
// If we ever enable auto-synthesize in the future, we'll still need this synthesize
|
||||
// because the property is declared in a protocol
|
||||
@synthesize updateItem = _updateItem;
|
||||
@synthesize preventsAutoupdate = _preventsAutoupdate;
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_updateItem = updateItem;
|
||||
_preventsAutoupdate = preventsAutoupdate;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -54,7 +54,7 @@
|
||||
[self.basicDriver resumeUpdate:resumableUpdate completion:completionBlock];
|
||||
}
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem preventsAutoupdate:(BOOL)__unused preventsAutoupdate
|
||||
{
|
||||
// Stop as soon as we have an answer
|
||||
[self abortUpdate];
|
||||
|
||||
Vendored
+1
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@protocol SPUResumableUpdate <NSObject>
|
||||
|
||||
@property (nonatomic, readonly) SUAppcastItem *updateItem;
|
||||
@property (nonatomic, readonly) BOOL preventsAutoupdate;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Vendored
+3
-2
@@ -91,7 +91,8 @@
|
||||
- (void)resumeUpdate:(id<SPUResumableUpdate>)resumableUpdate completion:(SPUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
// Informational downloads shouldn't be presented as updates to be downloaded
|
||||
if (!resumableUpdate.updateItem.isInformationOnlyUpdate) {
|
||||
// Neither should items that prevent auto updating
|
||||
if (!resumableUpdate.updateItem.isInformationOnlyUpdate && !resumableUpdate.preventsAutoupdate) {
|
||||
self.resumingDownloadedUpdate = YES;
|
||||
}
|
||||
[self.coreDriver resumeUpdate:resumableUpdate completion:completionBlock];
|
||||
@@ -104,7 +105,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
|
||||
{
|
||||
if (updateItem.isInformationOnlyUpdate) {
|
||||
assert(!self.resumingDownloadedUpdate);
|
||||
|
||||
Vendored
+1
-1
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)didFailToFetchAppcastWithError:(NSError *)error;
|
||||
- (void)didFinishLoadingAppcast:(SUAppcast *)appcast;
|
||||
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem;
|
||||
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem preventsAutoupdate:(BOOL)preventsAutoupdate;
|
||||
- (void)didNotFindUpdate;
|
||||
|
||||
@end
|
||||
|
||||
Vendored
+6
-1
@@ -104,7 +104,7 @@
|
||||
|
||||
if ([self itemContainsValidUpdate:item includesSkippedUpdates:includesSkippedUpdates]) {
|
||||
self.nonDeltaUpdateItem = nonDeltaUpdateItem;
|
||||
[self.delegate didFindValidUpdateWithAppcastItem:item];
|
||||
[self.delegate didFindValidUpdateWithAppcastItem:item preventsAutoupdate:[self itemPreventsAutoupdate:item]];
|
||||
} else {
|
||||
[self.delegate didNotFindUpdate];
|
||||
}
|
||||
@@ -177,6 +177,11 @@
|
||||
return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending;
|
||||
}
|
||||
|
||||
- (BOOL)itemPreventsAutoupdate:(SUAppcastItem *)ui
|
||||
{
|
||||
return ([ui minimumAutoupdateVersion] && ! [[ui minimumAutoupdateVersion] isEqualToString:@""] && ([[self versionComparator] compareVersion:[self.host version] toVersion:[ui minimumAutoupdateVersion]] == NSOrderedAscending));
|
||||
}
|
||||
|
||||
- (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui
|
||||
{
|
||||
NSString *skippedVersion = [self.host objectForUserDefaultsKey:SUSkippedVersionKey];
|
||||
|
||||
Vendored
+1
@@ -36,6 +36,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject<NSSecureCoding>
|
||||
@property (copy, readonly) NSDictionary *deltaUpdates;
|
||||
@property (strong, readonly) NSURL *infoURL;
|
||||
@property (nonatomic, copy, readonly) NSString *installationType;
|
||||
@property (copy, readonly) NSString *minimumAutoupdateVersion;
|
||||
|
||||
// Initializes with data from a dictionary provided by the RSS class.
|
||||
- (instancetype)initWithDictionary:(NSDictionary *)dict;
|
||||
|
||||
Vendored
+7
@@ -49,6 +49,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
|
||||
@synthesize osString = _osString;
|
||||
@synthesize propertiesDictionary = _propertiesDictionary;
|
||||
@synthesize installationType = _installationType;
|
||||
@synthesize minimumAutoupdateVersion = _minimumAutoupdateVersion;
|
||||
|
||||
+ (BOOL)supportsSecureCoding
|
||||
{
|
||||
@@ -76,6 +77,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
|
||||
_itemDescription = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemDescriptionKey] copy];
|
||||
_maximumSystemVersion = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemMaximumSystemVersionKey] copy];
|
||||
_minimumSystemVersion = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemMinimumSystemVersionKey] copy];
|
||||
_minimumAutoupdateVersion = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastElementMinimumAutoupdateVersion] copy];
|
||||
_releaseNotesURL = [decoder decodeObjectOfClass:[NSURL class] forKey:SUAppcastItemReleaseNotesURLKey];
|
||||
_title = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemTitleKey] copy];
|
||||
_versionString = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemVersionStringKey] copy];
|
||||
@@ -122,6 +124,10 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
|
||||
[encoder encodeObject:self.minimumSystemVersion forKey:SUAppcastItemMinimumSystemVersionKey];
|
||||
}
|
||||
|
||||
if (self.minimumAutoupdateVersion != nil) {
|
||||
[encoder encodeObject:self.minimumAutoupdateVersion forKey:SUAppcastElementMinimumAutoupdateVersion];
|
||||
}
|
||||
|
||||
if (self.releaseNotesURL != nil) {
|
||||
[encoder encodeObject:self.releaseNotesURL forKey:SUAppcastItemReleaseNotesURLKey];
|
||||
}
|
||||
@@ -268,6 +274,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
|
||||
_versionString = [(NSString *)newVersion copy];
|
||||
_minimumSystemVersion = [(NSString *)[dict objectForKey:SUAppcastElementMinimumSystemVersion] copy];
|
||||
_maximumSystemVersion = [(NSString *)[dict objectForKey:SUAppcastElementMaximumSystemVersion] copy];
|
||||
_minimumAutoupdateVersion = [(NSString *)[dict objectForKey:SUAppcastElementMinimumAutoupdateVersion] copy];
|
||||
|
||||
NSString *shortVersionString = [enclosure objectForKey:SUAppcastAttributeShortVersionString];
|
||||
if (nil == shortVersionString) {
|
||||
|
||||
Vendored
+1
@@ -76,6 +76,7 @@ extern NSString *const SUAppcastAttributeInstallationType;
|
||||
|
||||
extern NSString *const SUAppcastElementCriticalUpdate;
|
||||
extern NSString *const SUAppcastElementDeltas;
|
||||
extern NSString *const SUAppcastElementMinimumAutoupdateVersion;
|
||||
extern NSString *const SUAppcastElementMinimumSystemVersion;
|
||||
extern NSString *const SUAppcastElementMaximumSystemVersion;
|
||||
extern NSString *const SUAppcastElementReleaseNotesLink;
|
||||
|
||||
Vendored
+1
@@ -69,6 +69,7 @@ NSString *const SUAppcastAttributeInstallationType = @"sparkle:installationType"
|
||||
|
||||
NSString *const SUAppcastElementCriticalUpdate = @"sparkle:criticalUpdate";
|
||||
NSString *const SUAppcastElementDeltas = @"sparkle:deltas";
|
||||
NSString *const SUAppcastElementMinimumAutoupdateVersion = @"sparkle:minimumAutoupdateVersion";
|
||||
NSString *const SUAppcastElementMinimumSystemVersion = @"sparkle:minimumSystemVersion";
|
||||
NSString *const SUAppcastElementMaximumSystemVersion = @"sparkle:maximumSystemVersion";
|
||||
NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink";
|
||||
|
||||
+122
-34
@@ -9,6 +9,8 @@
|
||||
import Foundation
|
||||
import Security
|
||||
|
||||
let PRIVATE_KEY_LABEL = "Private key for signing Sparkle updates"
|
||||
|
||||
private func commonKeychainItemAttributes() -> [String: Any] {
|
||||
/// Attributes used for both adding a new item and matching an existing one.
|
||||
return [
|
||||
@@ -37,7 +39,7 @@ private func failure(_ message: String) -> Never {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
func findPublicKey() -> Data? {
|
||||
func findKeyPair() -> Data? {
|
||||
var item: CFTypeRef?
|
||||
let res = SecItemCopyMatching(commonKeychainItemAttributes().merging([
|
||||
/// Return a matched item's value as a CFData object.
|
||||
@@ -47,7 +49,7 @@ func findPublicKey() -> Data? {
|
||||
switch res {
|
||||
case errSecSuccess:
|
||||
if let keys = (item as? Data).flatMap({ Data(base64Encoded: $0) }) {
|
||||
return keys[64...]
|
||||
return keys
|
||||
} else {
|
||||
failure("""
|
||||
Item found, but is corrupt or has been overwritten!
|
||||
@@ -86,7 +88,7 @@ func findPublicKey() -> Data? {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
func generateKeyPair() -> Data {
|
||||
func generateKeyPair() -> (publicEdKey: Data, privateEdKey: Data) {
|
||||
var seed = Array<UInt8>(repeating: 0, count: 32)
|
||||
var publicEdKey = Array<UInt8>(repeating: 0, count: 32)
|
||||
var privateEdKey = Array<UInt8>(repeating: 0, count: 64)
|
||||
@@ -95,7 +97,11 @@ func generateKeyPair() -> Data {
|
||||
failure("Unable to initialize random seed. Try restarting your computer.")
|
||||
}
|
||||
ed25519_create_keypair(&publicEdKey, &privateEdKey, seed)
|
||||
|
||||
return (Data(publicEdKey), Data(privateEdKey))
|
||||
}
|
||||
|
||||
func storeKeyPair(publicEdKey: Data, privateEdKey: Data) {
|
||||
let query = commonKeychainItemAttributes().merging([
|
||||
/// Mark the new item as sensitive (requires keychain password to export - e.g. a private key).
|
||||
kSecAttrIsSensitive as String: kCFBooleanTrue!,
|
||||
@@ -105,7 +111,7 @@ func generateKeyPair() -> Data {
|
||||
kSecAttrIsPermanent as String: kCFBooleanTrue!,
|
||||
|
||||
/// The label of the new item (shown as its name/title in Keychain Access).
|
||||
kSecAttrLabel as String: "Private key for signing Sparkle updates",
|
||||
kSecAttrLabel as String: PRIVATE_KEY_LABEL,
|
||||
|
||||
/// A comment regarding the item's content (can be viewed in Keychain Access; we give the public key here).
|
||||
kSecAttrComment as String: "Public key (SUPublicEDKey value) for this key is:\n\n\(Data(publicEdKey).base64EncodedString())",
|
||||
@@ -114,13 +120,13 @@ func generateKeyPair() -> Data {
|
||||
kSecAttrDescription as String: "private key",
|
||||
|
||||
/// The actual data content of the new item.
|
||||
kSecValueData as String: Data(privateEdKey + publicEdKey).base64EncodedData() as CFData
|
||||
kSecValueData as String: (privateEdKey + publicEdKey).base64EncodedData() as CFData
|
||||
|
||||
], uniquingKeysWith: { $1 }) as CFDictionary
|
||||
|
||||
switch SecItemAdd(query, nil) {
|
||||
case errSecSuccess:
|
||||
return Data(publicEdKey)
|
||||
break
|
||||
case errSecDuplicateItem:
|
||||
failure("You already have a conflicting key in your Keychain which was not found during lookup.")
|
||||
case errSecAuthFailed:
|
||||
@@ -135,36 +141,130 @@ func generateKeyPair() -> Data {
|
||||
You can look up this error at <https://osstatus.com/search/results?search=\(res)>
|
||||
""")
|
||||
}
|
||||
exit(1)
|
||||
}
|
||||
|
||||
func printNewPublicKeyUsage(_ publicKey: Data) {
|
||||
print("""
|
||||
A key has been generated and saved in your keychain. Add the `SUPublicEDKey` key to
|
||||
the Info.plist of each app for which you intend to use Sparkle for distributing
|
||||
updates. It should appear like this:
|
||||
|
||||
<key>SUPublicEDKey</key>
|
||||
<string>\(publicKey.base64EncodedString())</string>
|
||||
|
||||
""")
|
||||
}
|
||||
|
||||
/// Once it's safe to require Swift 5.3 and Xcode 12 for this code, rename this file to `generate_keys.swift` and
|
||||
/// replace this function with a class tagged with `@main`.
|
||||
func entryPoint() {
|
||||
let isLookupMode = (CommandLine.arguments.dropFirst().first.map({ $0 == "-p" }) ?? false)
|
||||
let arguments = CommandLine.arguments
|
||||
let programName = arguments.first ?? "generate_keys"
|
||||
|
||||
let mode = arguments.count > 1 ? arguments[1] : nil
|
||||
|
||||
/// If not in lookup-only mode, give an intro blurb.
|
||||
if !isLookupMode {
|
||||
/// If not in any mode, give an intro blurb.
|
||||
if mode == nil {
|
||||
print("""
|
||||
This tool uses the macOS Keychain to store a private key for signing app updates which
|
||||
will be distributed via Sparkle. The key will be associated with your user account.
|
||||
Usage: \(programName) [-p] [-x private-key-file] [-f private-key-file]
|
||||
|
||||
This tool generates a public & private keys and uses the macOS Keychain to store
|
||||
the private key for signing app updates which will be distributed via Sparkle.
|
||||
This key will be associated with your user account.
|
||||
|
||||
Note: You only need one signing key, no matter how many apps you embed Sparkle in.
|
||||
|
||||
The keychain may ask permission for this tool to access an existing key, if one
|
||||
exists, or for permission to save the new key. You must allow access in order to
|
||||
successfully proceed.
|
||||
|
||||
Additional Options:
|
||||
-p
|
||||
Looks up and just prints the existing public key stored in the Keychain.
|
||||
|
||||
-x private-key-file
|
||||
Exports your private key from your login keychain and writes it to private-key-file. Note the contents of
|
||||
this sensitive exported file are the same as the password to the \"\(PRIVATE_KEY_LABEL)\" item in
|
||||
your keychain.
|
||||
|
||||
-f private-key-file
|
||||
Imports the private key from private-key-file into your keychain instead of generating a new key.
|
||||
This file has likely been exported via -x option from another machine.
|
||||
Any existing \"\(PRIVATE_KEY_LABEL)\" items listed in Keychain Access may need to be removed manually first before proceeding.
|
||||
|
||||
----------------------------------------------------------------------------------------------------
|
||||
|
||||
""")
|
||||
}
|
||||
|
||||
switch (findPublicKey(), isLookupMode) {
|
||||
/// Existing key found, lookup mode - print just the pubkey and exit
|
||||
case (.some(let pubKey), true):
|
||||
switch mode {
|
||||
case .some("-p"):
|
||||
/// Lookup mode - print just the pubkey and exit
|
||||
if let keyPair = findKeyPair() {
|
||||
let pubKey = keyPair[64...]
|
||||
print(pubKey.base64EncodedString())
|
||||
} else {
|
||||
failure("No existing signing key found!")
|
||||
}
|
||||
case .some("-f"):
|
||||
/// Import mode - import the specifed key-pair file
|
||||
guard arguments.count > 2 else {
|
||||
failure("private-key-file was not specified")
|
||||
}
|
||||
|
||||
/// Existing key found, normal mode - print instructions blurb and pubkey
|
||||
case (.some(let pubKey), false):
|
||||
let privateAndPublicBase64KeyFile = arguments[2]
|
||||
let privateAndPublicBase64Key: String
|
||||
do {
|
||||
privateAndPublicBase64Key = try String(contentsOfFile: privateAndPublicBase64KeyFile)
|
||||
} catch {
|
||||
failure("Failed to read private-key-file: \(error)")
|
||||
}
|
||||
|
||||
guard let privateAndPublicKey = Data(base64Encoded: privateAndPublicBase64Key.trimmingCharacters(in: .whitespacesAndNewlines), options: .init()) else {
|
||||
failure("Failed to decode base64 encoded key data from: \(privateAndPublicBase64Key)")
|
||||
}
|
||||
|
||||
guard privateAndPublicKey.count == 64 + 32 else {
|
||||
failure("Imported key must be 96 bytes decoded. Instead it is \(privateAndPublicKey.count) bytes decoded.")
|
||||
}
|
||||
|
||||
print("Importing signing key..")
|
||||
|
||||
let publicKey = privateAndPublicKey[64...]
|
||||
let privateKey = privateAndPublicKey[0..<64]
|
||||
|
||||
storeKeyPair(publicEdKey: publicKey, privateEdKey: privateKey)
|
||||
|
||||
printNewPublicKeyUsage(publicKey)
|
||||
|
||||
case .some("-x"):
|
||||
/// Export mode - export the key-pair file from the user's keychain
|
||||
guard arguments.count > 2 else {
|
||||
failure("private-key-file was not specified")
|
||||
}
|
||||
|
||||
let exportURL = URL(fileURLWithPath: arguments[2])
|
||||
if let reachable = try? exportURL.checkResourceIsReachable(), reachable {
|
||||
failure("private-key-file already exists: \(exportURL.path)")
|
||||
}
|
||||
|
||||
guard let keyPair = findKeyPair() else {
|
||||
failure("No existing signing key found!")
|
||||
}
|
||||
|
||||
do {
|
||||
try keyPair.base64EncodedString().write(to: exportURL, atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
failure("Failed to write exported file: \(error)")
|
||||
}
|
||||
|
||||
case .some(let unknownOption):
|
||||
failure("Unknown option: \(unknownOption)")
|
||||
|
||||
case nil:
|
||||
/// Default mode - find an existing public key and print its usage, or generate new keys
|
||||
if let keyPair = findKeyPair() {
|
||||
let pubKey = keyPair[64...]
|
||||
print("""
|
||||
A pre-existing signing key was found. This is how it should appear in your Info.plist:
|
||||
|
||||
@@ -172,26 +272,14 @@ func entryPoint() {
|
||||
<string>\(pubKey.base64EncodedString())</string>
|
||||
|
||||
""")
|
||||
|
||||
/// No existing key, lookup mode - error out
|
||||
case (.none, true):
|
||||
failure("No existing signing key found!")
|
||||
|
||||
/// No existing key, normal mode - generate a new one
|
||||
case (.none, false):
|
||||
} else {
|
||||
print("Generating a new signing key. This may take a moment, depending on your machine.")
|
||||
|
||||
let pubKey = generateKeyPair()
|
||||
let (pubKey, privKey) = generateKeyPair()
|
||||
storeKeyPair(publicEdKey: pubKey, privateEdKey: privKey)
|
||||
|
||||
print("""
|
||||
A key has been generated and saved in your keychain. Add the `SUPublicEDKey` key to
|
||||
the Info.plist of each app for which you intend to use Sparkle for distributing
|
||||
updates. It should appear like this:
|
||||
|
||||
<key>SUPublicEDKey</key>
|
||||
<string>\(pubKey.base64EncodedString())</string>
|
||||
|
||||
""")
|
||||
printNewPublicKeyUsage(pubKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user