mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Run swiftlint
This commit is contained in:
1 parent
1755a3da05
commit
0900d09ab3
8 files changed
+186
-195
No files matched your search
@@ -14,11 +14,11 @@ func makeError(code: SUError, _ description: String) -> NSError {
|
||||
])
|
||||
}
|
||||
|
||||
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();
|
||||
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, archivesDestDir: cacheDir, verbose:verbose))
|
||||
let allUpdates = (try unarchiveUpdates(archivesSourceDir: archivesSourceDir, archivesDestDir: cacheDir, verbose: verbose))
|
||||
.sorted(by: {
|
||||
.orderedDescending == comparator.compareVersion($0.version, toVersion: $1.version)
|
||||
})
|
||||
@@ -36,30 +36,30 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
DispatchQueue.global().async {
|
||||
if let privateDSAKey = keys.privateDSAKey {
|
||||
do {
|
||||
update.dsaSignature = try dsaSignature(path: update.archivePath, privateDSAKey: privateDSAKey);
|
||||
update.dsaSignature = try dsaSignature(path: update.archivePath, privateDSAKey: privateDSAKey)
|
||||
} catch {
|
||||
print(update, error);
|
||||
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");
|
||||
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);
|
||||
update.edSignature = try edSignature(path: update.archivePath, publicEdKey: publicEdKey, privateEdKey: privateEdKey)
|
||||
} catch {
|
||||
print(update, error);
|
||||
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");
|
||||
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");
|
||||
print("Warning: could not sign \(update.archivePath.path) due to lack of private EdDSA key")
|
||||
}
|
||||
}
|
||||
|
||||
group.leave();
|
||||
group.leave()
|
||||
}
|
||||
|
||||
let appcastFile = update.feedURL?.lastPathComponent ?? "appcast.xml"
|
||||
@@ -85,7 +85,7 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
let appBaseName = latestItem.appPath.deletingPathExtension().lastPathComponent
|
||||
for item in updates {
|
||||
if numDeltas > maxDeltas {
|
||||
break;
|
||||
break
|
||||
}
|
||||
|
||||
// No downgrades
|
||||
@@ -94,17 +94,17 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
}
|
||||
// Old version will not be able to verify the new version
|
||||
if !item.supportsDSA && item.publicEdKey == nil {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
|
||||
let deltaBaseName = appBaseName + latestItem.version + "-" + item.version
|
||||
let deltaPath = archivesSourceDir.appendingPathComponent(deltaBaseName).appendingPathExtension("delta")
|
||||
|
||||
var delta:DeltaUpdate;
|
||||
let ignoreMarkerPath = cacheDir.appendingPathComponent(deltaPath.lastPathComponent).appendingPathExtension(".ignore");
|
||||
let fm = FileManager.default;
|
||||
var delta: DeltaUpdate
|
||||
let ignoreMarkerPath = cacheDir.appendingPathComponent(deltaPath.lastPathComponent).appendingPathExtension(".ignore")
|
||||
let fm = FileManager.default
|
||||
if fm.fileExists(atPath: ignoreMarkerPath.path) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
if !fm.fileExists(atPath: deltaPath.path) {
|
||||
do {
|
||||
@@ -117,37 +117,37 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
delta = DeltaUpdate(fromVersion: item.version, archivePath: deltaPath)
|
||||
}
|
||||
|
||||
numDeltas += 1;
|
||||
numDeltas += 1
|
||||
|
||||
// Require delta to be a bit smaller
|
||||
if delta.fileSize / 7 > latestItem.fileSize / 8 {
|
||||
markDeltaAsIgnored(delta: delta, markerPath: ignoreMarkerPath)
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
|
||||
group.enter();
|
||||
group.enter()
|
||||
DispatchQueue.global().async {
|
||||
if item.supportsDSA, let privateDSAKey = keys.privateDSAKey {
|
||||
do {
|
||||
delta.dsaSignature = try dsaSignature(path: deltaPath, privateDSAKey: privateDSAKey);
|
||||
delta.dsaSignature = try dsaSignature(path: deltaPath, privateDSAKey: privateDSAKey)
|
||||
} catch {
|
||||
print(delta.archivePath.lastPathComponent, error)
|
||||
}
|
||||
}
|
||||
if let publicEdKey = item.publicEdKey, let privateEdKey = keys.privateEdKey {
|
||||
do {
|
||||
delta.edSignature = try edSignature(path: deltaPath, publicEdKey: publicEdKey, privateEdKey: privateEdKey);
|
||||
delta.edSignature = try edSignature(path: deltaPath, publicEdKey: publicEdKey, privateEdKey: privateEdKey)
|
||||
} catch {
|
||||
print(delta.archivePath.lastPathComponent, error);
|
||||
print(delta.archivePath.lastPathComponent, error)
|
||||
}
|
||||
}
|
||||
if delta.dsaSignature != nil || delta.edSignature != nil {
|
||||
latestItem.deltas.append(delta);
|
||||
latestItem.deltas.append(delta)
|
||||
} else {
|
||||
markDeltaAsIgnored(delta: delta, markerPath: ignoreMarkerPath)
|
||||
print("Delta \(delta.archivePath.path) ignored, because it could not be signed");
|
||||
print("Delta \(delta.archivePath.path) ignored, because it could not be signed")
|
||||
}
|
||||
group.leave();
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,6 +159,6 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
}
|
||||
|
||||
func markDeltaAsIgnored(delta: DeltaUpdate, markerPath: URL) {
|
||||
let _ = try? FileManager.default.removeItem(at: delta.archivePath)
|
||||
let _ = try? Data.init().write(to: markerPath); // 0-sized file
|
||||
_ = try? FileManager.default.removeItem(at: delta.archivePath)
|
||||
_ = try? Data.init().write(to: markerPath); // 0-sized file
|
||||
}
|
||||
@@ -6,10 +6,10 @@
|
||||
import Foundation
|
||||
|
||||
class DeltaUpdate {
|
||||
let fromVersion: String;
|
||||
let archivePath: URL;
|
||||
var dsaSignature: String?;
|
||||
var edSignature: String?;
|
||||
let fromVersion: String
|
||||
let archivePath: URL
|
||||
var dsaSignature: String?
|
||||
var edSignature: String?
|
||||
|
||||
init(fromVersion: String, archivePath: URL) {
|
||||
self.archivePath = archivePath
|
||||
@@ -33,36 +33,36 @@ class DeltaUpdate {
|
||||
}
|
||||
|
||||
class ArchiveItem: CustomStringConvertible {
|
||||
let version: String;
|
||||
let version: String
|
||||
// swiftlint:disable identifier_name
|
||||
let _shortVersion: String?;
|
||||
let minimumSystemVersion: String;
|
||||
let archivePath: URL;
|
||||
let appPath: URL;
|
||||
let feedURL: URL?;
|
||||
let publicEdKey: Data?;
|
||||
let supportsDSA: Bool;
|
||||
let archiveFileAttributes: [FileAttributeKey:Any];
|
||||
var deltas: [DeltaUpdate];
|
||||
let _shortVersion: String?
|
||||
let minimumSystemVersion: String
|
||||
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?;
|
||||
var dsaSignature: String?
|
||||
var edSignature: String?
|
||||
|
||||
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;
|
||||
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);
|
||||
self.publicEdKey = Data(base64Encoded: publicEdKey)
|
||||
} else {
|
||||
self.publicEdKey = nil;
|
||||
self.publicEdKey = nil
|
||||
}
|
||||
self.archiveFileAttributes = try FileManager.default.attributesOfItem(atPath: self.archivePath.path);
|
||||
self.deltas = [];
|
||||
self.archiveFileAttributes = try FileManager.default.attributesOfItem(atPath: self.archivePath.path)
|
||||
self.deltas = []
|
||||
}
|
||||
|
||||
convenience init(fromArchive archivePath: URL, unarchivedDir: URL) throws {
|
||||
@@ -75,22 +75,22 @@ class ArchiveItem: CustomStringConvertible {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
});
|
||||
})
|
||||
if bundles.count > 0 {
|
||||
if bundles.count > 1 {
|
||||
throw makeError(code: .unarchivingError, "Too many bundles in \(unarchivedDir.path) \(bundles)");
|
||||
throw makeError(code: .unarchivingError, "Too many bundles in \(unarchivedDir.path) \(bundles)")
|
||||
}
|
||||
|
||||
let appPath = bundles[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 as String? ?? "missing 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;
|
||||
let shortVersion = infoPlist["CFBundleShortVersionString"] as? String
|
||||
let publicEdKey = infoPlist[SUPublicEDKeyKey] as? String
|
||||
let supportsDSA = infoPlist[SUPublicDSAKeyKey] != nil || infoPlist[SUPublicDSAKeyFileKey] != nil
|
||||
|
||||
var feedURL: URL?
|
||||
if let feedURLStr = infoPlist["SUFeedURL"] as? String {
|
||||
@@ -104,7 +104,7 @@ class ArchiveItem: CustomStringConvertible {
|
||||
publicEdKey: publicEdKey,
|
||||
supportsDSA: supportsDSA,
|
||||
appPath: appPath,
|
||||
archivePath: archivePath);
|
||||
archivePath: archivePath)
|
||||
} else {
|
||||
throw makeError(code: .missingUpdateError, "No supported items in \(unarchivedDir) \(items) [note: only .app bundles are supported]")
|
||||
}
|
||||
@@ -139,8 +139,8 @@ class ArchiveItem: CustomStringConvertible {
|
||||
return (self.archiveFileAttributes[.size] as! NSNumber).int64Value
|
||||
}
|
||||
|
||||
private var releaseNotesPath : URL? {
|
||||
var basename = self.archivePath.deletingPathExtension();
|
||||
private var releaseNotesPath: URL? {
|
||||
var basename = self.archivePath.deletingPathExtension()
|
||||
if basename.pathExtension == "tar" { // tar.gz
|
||||
basename = basename.deletingPathExtension()
|
||||
}
|
||||
|
||||
@@ -22,16 +22,15 @@ func findOrCreateElement(name: String, parent: XMLElement) -> XMLElement {
|
||||
if let element = findElement(name: name, parent: parent) {
|
||||
return element
|
||||
}
|
||||
let element = XMLElement(name: name);
|
||||
parent.addChild(element);
|
||||
return element;
|
||||
let element = XMLElement(name: name)
|
||||
parent.addChild(element)
|
||||
return element
|
||||
}
|
||||
|
||||
func text(_ text: String) -> XMLNode {
|
||||
return XMLNode.text(withStringValue: text) as! XMLNode
|
||||
}
|
||||
|
||||
|
||||
func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
let appBaseName = updates[0].appPath.deletingPathExtension().lastPathComponent
|
||||
|
||||
@@ -64,9 +63,9 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
if channelNodes.count > 0 {
|
||||
channel = channelNodes[0] as! XMLElement
|
||||
} else {
|
||||
channel = XMLElement(name: "channel");
|
||||
channel.addChild(XMLElement.element(withName: "title", stringValue: appBaseName) as! XMLElement);
|
||||
root.addChild(channel);
|
||||
channel = XMLElement(name: "channel")
|
||||
channel.addChild(XMLElement.element(withName: "title", stringValue: appBaseName) as! XMLElement)
|
||||
root.addChild(channel)
|
||||
}
|
||||
|
||||
var numItems = 0
|
||||
@@ -82,17 +81,17 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
numItems += 1
|
||||
|
||||
if createNewItem {
|
||||
item = XMLElement.element(withName: "item") as! XMLElement;
|
||||
channel.addChild(item);
|
||||
item = XMLElement.element(withName: "item") as! XMLElement
|
||||
channel.addChild(item)
|
||||
} else {
|
||||
item = existingItems[0] as! XMLElement
|
||||
}
|
||||
|
||||
if nil == findElement(name: "title", parent: item) {
|
||||
item.addChild(XMLElement.element(withName: "title", stringValue: update.shortVersion) as! XMLElement);
|
||||
item.addChild(XMLElement.element(withName: "title", stringValue: update.shortVersion) as! XMLElement)
|
||||
}
|
||||
if nil == findElement(name: "pubDate", parent: item) {
|
||||
item.addChild(XMLElement.element(withName: "pubDate", stringValue: update.pubDate) as! XMLElement);
|
||||
item.addChild(XMLElement.element(withName: "pubDate", stringValue: update.pubDate) as! XMLElement)
|
||||
}
|
||||
|
||||
if let html = update.releaseNotesHTML {
|
||||
@@ -102,26 +101,26 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
descElement.setChildren([cdata])
|
||||
}
|
||||
|
||||
var minVer = findElement(name: SUAppcastElementMinimumSystemVersion, parent: item);
|
||||
var minVer = findElement(name: SUAppcastElementMinimumSystemVersion, parent: item)
|
||||
if nil == minVer {
|
||||
minVer = XMLElement.element(withName: SUAppcastElementMinimumSystemVersion, uri: sparkleNS) as? XMLElement;
|
||||
item.addChild(minVer!);
|
||||
minVer = XMLElement.element(withName: SUAppcastElementMinimumSystemVersion, uri: sparkleNS) as? XMLElement
|
||||
item.addChild(minVer!)
|
||||
}
|
||||
minVer?.setChildren([text(update.minimumSystemVersion)])
|
||||
|
||||
let relElement = findElement(name: SUAppcastElementReleaseNotesLink, parent: item);
|
||||
let relElement = findElement(name: SUAppcastElementReleaseNotesLink, parent: item)
|
||||
if let url = update.releaseNotesURL {
|
||||
if nil == relElement {
|
||||
item.addChild(XMLElement.element(withName: SUAppcastElementReleaseNotesLink, 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);
|
||||
var enclosure = findElement(name: "enclosure", parent: item)
|
||||
if nil == enclosure {
|
||||
enclosure = XMLElement.element(withName: "enclosure") as? XMLElement;
|
||||
item.addChild(enclosure!);
|
||||
enclosure = XMLElement.element(withName: "enclosure") as? XMLElement
|
||||
item.addChild(enclosure!)
|
||||
}
|
||||
|
||||
guard let archiveURL = update.archiveURL?.absoluteString else {
|
||||
@@ -133,20 +132,20 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
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);
|
||||
attributes.append(XMLNode.attribute(withName: SUAppcastAttributeEDSignature, uri: sparkleNS, stringValue: sig) as! XMLNode)
|
||||
}
|
||||
if let sig = update.dsaSignature {
|
||||
attributes.append(XMLNode.attribute(withName: SUAppcastAttributeDSASignature, 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: SUAppcastElementDeltas, parent: item);
|
||||
var deltas = findElement(name: SUAppcastElementDeltas, parent: item)
|
||||
if nil == deltas {
|
||||
deltas = XMLElement.element(withName: SUAppcastElementDeltas, uri: sparkleNS) as? XMLElement;
|
||||
item.addChild(deltas!);
|
||||
deltas = XMLElement.element(withName: SUAppcastElementDeltas, uri: sparkleNS) as? XMLElement
|
||||
item.addChild(deltas!)
|
||||
} else {
|
||||
deltas!.setChildren([])
|
||||
}
|
||||
@@ -158,20 +157,20 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
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.edSignature {
|
||||
attributes.append(XMLNode.attribute(withName: SUAppcastAttributeEDSignature, uri: sparkleNS, stringValue: sig) as! XMLNode);
|
||||
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);
|
||||
attributes.append(XMLNode.attribute(withName: SUAppcastAttributeDSASignature, uri: sparkleNS, stringValue: sig) as! XMLNode)
|
||||
}
|
||||
deltas!.addChild(XMLNode.element(withName: "enclosure", children: nil, attributes: attributes) as! XMLElement);
|
||||
deltas!.addChild(XMLNode.element(withName: "enclosure", children: nil, attributes: attributes) as! XMLElement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
let options: XMLNode.Options = [.nodeCompactEmptyElement, .nodePrettyPrint]
|
||||
let docData = doc.xmlData(options: options)
|
||||
_ = try XMLDocument(data: docData, options: XMLNode.Options()); // Verify that it was generated correctly, which does not always happen!
|
||||
try docData.write(to: appcastDestPath)
|
||||
}
|
||||
@@ -6,19 +6,19 @@
|
||||
import Foundation
|
||||
|
||||
struct PrivateKeys {
|
||||
var privateDSAKey: SecKey?;
|
||||
var privateEdKey: Data?;
|
||||
var publicEdKey: Data?;
|
||||
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;
|
||||
self.privateDSAKey = privateDSAKey
|
||||
self.privateEdKey = privateEdKey
|
||||
self.publicEdKey = publicEdKey
|
||||
}
|
||||
}
|
||||
|
||||
func loadPrivateDSAKey(at privateKeyURL: URL) throws -> SecKey {
|
||||
let data = try Data(contentsOf: privateKeyURL);
|
||||
let data = try Data(contentsOf: privateKeyURL)
|
||||
|
||||
var cfitems: CFArray?
|
||||
var format = SecExternalFormat.formatOpenSSL
|
||||
@@ -38,7 +38,7 @@ func loadPrivateDSAKey(at privateKeyURL: URL) throws -> SecKey {
|
||||
}
|
||||
|
||||
func loadPrivateDSAKey(named keyName: String, fromKeychainAt keychainURL: URL) throws -> SecKey {
|
||||
var keychain: SecKeychain? = nil
|
||||
var keychain: SecKeychain?
|
||||
|
||||
guard SecKeychainOpen(keychainURL.path, &keychain) == errSecSuccess, keychain != nil else {
|
||||
throw NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(SUError.signatureError.rawValue)), userInfo: nil)
|
||||
@@ -53,7 +53,7 @@ func loadPrivateDSAKey(named keyName: String, fromKeychainAt keychainURL: URL) t
|
||||
kSecReturnRef: kCFBooleanTrue,
|
||||
]
|
||||
|
||||
var item: CFTypeRef? = nil
|
||||
var item: CFTypeRef?
|
||||
guard SecItemCopyMatching(query as CFDictionary, &item) == errSecSuccess, item != nil else {
|
||||
throw NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(SUError.signatureError.rawValue)), userInfo: nil)
|
||||
}
|
||||
@@ -68,10 +68,10 @@ func dsaSignature(path: URL, privateDSAKey: SecKey) throws -> String {
|
||||
let stream = InputStream(fileAtPath: path.path)!
|
||||
let dataReadTransform = SecTransformCreateReadTransformWithReadStream(stream)
|
||||
|
||||
let dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA1, 20, nil);
|
||||
let dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA1, 20, nil)
|
||||
guard let dataSignTransform = SecSignTransformCreate(privateDSAKey, &error) else {
|
||||
print("can't use the key");
|
||||
throw error!.takeRetainedValue();
|
||||
print("can't use the key")
|
||||
throw error!.takeRetainedValue()
|
||||
}
|
||||
|
||||
let group = SecTransformCreateGroupTransform()
|
||||
@@ -98,17 +98,17 @@ func dsaSignature(path: URL, privateDSAKey: SecKey) throws -> String {
|
||||
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);
|
||||
let data = try Data.init(contentsOf: path, options: .mappedIfSafe)
|
||||
let len = data.count
|
||||
var output = Data(count: 64)
|
||||
output.withUnsafeMutableBytes({ (output: UnsafeMutablePointer<UInt8>) in
|
||||
data.withUnsafeBytes({ (data: UnsafePointer<UInt8>) in
|
||||
publicEdKey.withUnsafeBytes({ (publicEdKey: UnsafePointer<UInt8>) in
|
||||
privateEdKey.withUnsafeBytes({ (privateEdKey: UnsafePointer<UInt8>) in
|
||||
ed25519_sign(output, data, len, publicEdKey, privateEdKey)
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
return output.base64EncodedString();
|
||||
})
|
||||
return output.base64EncodedString()
|
||||
}
|
||||
@@ -14,11 +14,11 @@ func unarchive(itemPath: URL, archiveDestDir: URL, callback: @escaping (Error?)
|
||||
|
||||
do {
|
||||
do {
|
||||
try fileManager.linkItem(at: itemPath, to: itemCopy);
|
||||
try fileManager.linkItem(at: itemPath, to: itemCopy)
|
||||
} catch {
|
||||
try fileManager.copyItem(at: itemPath, to: itemCopy);
|
||||
try fileManager.copyItem(at: itemPath, to: itemCopy)
|
||||
}
|
||||
if let unarchiver = SUUnarchiver.unarchiver(forPath: itemCopy.path, updatingHostBundlePath:nil, decryptionPassword:nil) {
|
||||
if let unarchiver = SUUnarchiver.unarchiver(forPath: itemCopy.path, updatingHostBundlePath: nil, decryptionPassword: nil) {
|
||||
unarchiver.unarchive(completionBlock: { (error: Error?) in
|
||||
if error != nil {
|
||||
callback(error)
|
||||
|
||||
+13
-14
@@ -11,7 +11,7 @@ import Foundation
|
||||
var verbose = false
|
||||
|
||||
func printUsage() {
|
||||
let command = URL(fileURLWithPath: CommandLine.arguments.first!).lastPathComponent;
|
||||
let command = URL(fileURLWithPath: CommandLine.arguments.first!).lastPathComponent
|
||||
print("Generate appcast from a directory of Sparkle update archives\n",
|
||||
"Usage:\n",
|
||||
" \(command) <directory with update files>\n",
|
||||
@@ -26,33 +26,33 @@ func printUsage() {
|
||||
}
|
||||
|
||||
func loadPrivateKeys(_ privateDSAKey: SecKey?) -> PrivateKeys {
|
||||
var privateEdKey: Data?;
|
||||
var publicEdKey: Data?;
|
||||
var item: CFTypeRef?;
|
||||
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);
|
||||
] as CFDictionary, &item)
|
||||
if res == errSecSuccess, let encoded = item as? Data, let keys = Data(base64Encoded: encoded) {
|
||||
privateEdKey = keys[0..<64];
|
||||
publicEdKey = keys[64...];
|
||||
privateEdKey = keys[0..<64]
|
||||
publicEdKey = keys[64...]
|
||||
} else {
|
||||
print("Warning: Private key not found in the Keychain (\(res)). Please run the generate_keys tool");
|
||||
print("Warning: Private key not found in the Keychain (\(res)). Please run the generate_keys tool")
|
||||
}
|
||||
return PrivateKeys(privateDSAKey: privateDSAKey, privateEdKey: privateEdKey, publicEdKey: publicEdKey);
|
||||
return PrivateKeys(privateDSAKey: privateDSAKey, privateEdKey: privateEdKey, publicEdKey: publicEdKey)
|
||||
}
|
||||
|
||||
func main() {
|
||||
let args = CommandLine.arguments;
|
||||
let args = CommandLine.arguments
|
||||
if args.count < 2 {
|
||||
printUsage()
|
||||
exit(1)
|
||||
}
|
||||
|
||||
var privateDSAKey: SecKey? = nil;
|
||||
var privateDSAKey: SecKey?
|
||||
|
||||
// this was typical usage for DSA keys
|
||||
if args.count == 3 || (args.count == 4 && args[1] == "-f") {
|
||||
@@ -96,8 +96,7 @@ func main() {
|
||||
print("Unable to load DSA private key '\(keyName)' from keychain at", keychainURL.path, "\n", error)
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
else if args.count != 2 {
|
||||
} else if args.count != 2 {
|
||||
printUsage()
|
||||
exit(1)
|
||||
}
|
||||
@@ -106,7 +105,7 @@ func main() {
|
||||
let keys = loadPrivateKeys(privateDSAKey)
|
||||
|
||||
do {
|
||||
let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, keys: keys, verbose:verbose);
|
||||
let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, keys: keys, verbose: verbose)
|
||||
|
||||
for (appcastFile, updates) in allUpdates {
|
||||
let appcastDestPath = URL(fileURLWithPath: appcastFile, relativeTo: archivesSourceDir)
|
||||
|
||||
+30
-34
@@ -10,52 +10,49 @@ import Foundation
|
||||
import Security
|
||||
|
||||
func findPublicKey() -> Data? {
|
||||
var item: CFTypeRef?;
|
||||
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);
|
||||
] 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.");
|
||||
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 == 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.");
|
||||
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)");
|
||||
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);
|
||||
var seed = Data(count: 32)
|
||||
var publicEdKey = Data(count: 32)
|
||||
var privateEdKey = Data(count: 64)
|
||||
|
||||
if !seed.withUnsafeMutableBytes { (seed: UnsafeMutablePointer<UInt8>) in 0 == ed25519_create_seed(seed)} {
|
||||
print("\nERROR: Unable to initialize random seed");
|
||||
print("\nERROR: Unable to initialize random seed")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
seed.withUnsafeBytes({(seed: UnsafePointer<UInt8>) in
|
||||
publicEdKey.withUnsafeMutableBytes({(publicEdKey: UnsafeMutablePointer<UInt8>) in
|
||||
privateEdKey.withUnsafeMutableBytes({(privateEdKey: UnsafeMutablePointer<UInt8>) in
|
||||
ed25519_create_keypair(publicEdKey, privateEdKey, seed);
|
||||
});
|
||||
});
|
||||
});
|
||||
ed25519_create_keypair(publicEdKey, privateEdKey, seed)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
let bothKeys = privateEdKey + publicEdKey; // public key can't be derived from the private one
|
||||
let query = [
|
||||
@@ -71,24 +68,23 @@ func generateKeyPair() -> Data {
|
||||
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);
|
||||
] 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");
|
||||
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.");
|
||||
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)");
|
||||
print("\nERROR: The key could not be saved to the Keychain. error: \(res) (you can look it up at osstatus.com)")
|
||||
}
|
||||
exit(1);
|
||||
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();
|
||||
let pubKey = findPublicKey() ?? generateKeyPair()
|
||||
print("\nIn your app's Info.plist set SUPublicEDKey to:\n\(pubKey.base64EncodedString())\n")
|
||||
+23
-26
@@ -10,30 +10,27 @@ import Foundation
|
||||
import Security
|
||||
|
||||
func findKeys() -> (Data, Data) {
|
||||
var item: CFTypeRef?;
|
||||
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);
|
||||
] 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 == 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.");
|
||||
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)");
|
||||
print("ERROR! Unable to access required key in the Keychain", res, "(you can look it up at osstatus.com)")
|
||||
}
|
||||
exit(1)
|
||||
}
|
||||
@@ -41,32 +38,32 @@ func findKeys() -> (Data, Data) {
|
||||
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);
|
||||
let len = data.count
|
||||
var output = Data(count: 64)
|
||||
output.withUnsafeMutableBytes({ (output: UnsafeMutablePointer<UInt8>) in
|
||||
data.withUnsafeBytes({ (data: UnsafePointer<UInt8>) in
|
||||
publicEdKey.withUnsafeBytes({ (publicEdKey: UnsafePointer<UInt8>) in
|
||||
privateEdKey.withUnsafeBytes({ (privateEdKey: UnsafePointer<UInt8>) in
|
||||
ed25519_sign(output, data, len, publicEdKey, privateEdKey)
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
return output.base64EncodedString();
|
||||
})
|
||||
return output.base64EncodedString()
|
||||
}
|
||||
|
||||
let args = CommandLine.arguments;
|
||||
let args = CommandLine.arguments
|
||||
if args.count != 2 {
|
||||
print("Usage: \(args[0]) <archive to sign>\nPrivavte EdDSA (ed25519) key is automatically read from the Keychain.\n");
|
||||
print("Usage: \(args[0]) <archive to sign>\nPrivavte EdDSA (ed25519) key is automatically read from the Keychain.\n")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
let(priv, pub) = findKeys();
|
||||
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)\"");
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user