mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
Deprecate -s flag and add --ed-key-file option to generate_appcast (#2170)
This commit is contained in:
2 files changed
+60
-11
No files matched your search
@@ -59,8 +59,8 @@ struct GenerateAppcast: ParsableCommand {
|
||||
@Option(help: ArgumentHelp("The account name in your keychain associated with your private EdDSA (ed25519) key to use for signing new updates."))
|
||||
var account : String = "ed25519"
|
||||
|
||||
@Option(name: .customShort("s"), help: ArgumentHelp("The private EdDSA string (128 characters). If not specified, the private EdDSA key will be read from the Keychain instead.", valueName: "private-EdDSA-key"))
|
||||
var privateEdString : String?
|
||||
@Option(name: .customLong("ed-key-file"), help: ArgumentHelp("Path to the private EdDSA key file. If not specified, the private EdDSA key will be read from the Keychain instead. '-' can be used to echo the EdDSA key from a 'secret' environment variable to the standard input stream. For example: echo \"$PRIVATE_KEY_SECRET\" | ./\(programName) --ed-key-file -", valueName: "private-EdDSA-key-file"))
|
||||
var privateEdKeyPath: String?
|
||||
|
||||
@Option(name: .customShort("f"), help: ArgumentHelp("Path to the private DSA key file. Only use this option for transitioning to EdDSA from older updates.", valueName: "private-dsa-key-file"), transform: { URL(fileURLWithPath: $0) })
|
||||
var privateDSAKeyURL: URL?
|
||||
@@ -68,6 +68,9 @@ struct GenerateAppcast: ParsableCommand {
|
||||
@Option(name: .customShort("n"), help: ArgumentHelp("The name of the private DSA key. This option must be used together with `-k`. Only use this option for transitioning to EdDSA from older updates.", valueName: "dsa-key-name"))
|
||||
var privateDSAKeyName: String?
|
||||
|
||||
@Option(name: .customShort("s"), help: ArgumentHelp("(DEPRECATED): The private EdDSA string (128 characters). This option is deprecated. Please use the Keychain, or pass the key as standard input when using the --ed-key-file - option instead.", valueName: "private-EdDSA-key"))
|
||||
var privateEdString : String?
|
||||
|
||||
@Option(name: .customShort("k"), help: ArgumentHelp("The path to the keychain to look up the private DSA key. This option must be used together with `-n`. Only use this option for transitioning to EdDSA from older updates.", valueName: "keychain-for-dsa"), transform: { URL(fileURLWithPath: $0) })
|
||||
var keychainURL: URL?
|
||||
|
||||
@@ -178,6 +181,10 @@ struct GenerateAppcast: ParsableCommand {
|
||||
throw ValidationError("-f <private-dsa-key-file> cannot be provided if -n <dsa-key-name> and -k <keychain> is provided")
|
||||
}
|
||||
|
||||
guard (privateEdKeyPath == nil) || (privateEdString == nil) else {
|
||||
throw ValidationError("--ed-key-file <private-EdDSA-key-file> cannot be provided if -s <private-EdDSA-key> is provided")
|
||||
}
|
||||
|
||||
if let versions = versions {
|
||||
guard versions.count > 0 else {
|
||||
throw ValidationError("--versions must specify at least one application version.")
|
||||
@@ -220,7 +227,35 @@ struct GenerateAppcast: ParsableCommand {
|
||||
privateDSAKey = nil
|
||||
}
|
||||
|
||||
let keys = loadPrivateKeys(account, privateDSAKey, privateEdString)
|
||||
let privateEdKeyString: String?
|
||||
if let privateEdString = privateEdString {
|
||||
privateEdKeyString = privateEdString
|
||||
|
||||
print("Warning: The -s option for passing the private EdDSA key is insecure and deprecated. Please see its help usage for more information.")
|
||||
} else if let privateEdKeyPath = privateEdKeyPath {
|
||||
do {
|
||||
let privateKeyString: String
|
||||
if privateEdKeyPath == "-" && !FileManager.default.fileExists(atPath: privateEdKeyPath) {
|
||||
if let line = readLine(strippingNewline: true) {
|
||||
privateKeyString = line
|
||||
} else {
|
||||
print("Unable to read EdDSA private key from standard input")
|
||||
throw ExitCode(1)
|
||||
}
|
||||
} else {
|
||||
privateKeyString = try String(contentsOf: URL(fileURLWithPath: privateEdKeyPath))
|
||||
}
|
||||
|
||||
privateEdKeyString = privateKeyString
|
||||
} catch {
|
||||
print("Unable to load EdDSA private key from", privateEdKeyPath, "\n", error)
|
||||
throw ExitCode(1)
|
||||
}
|
||||
} else {
|
||||
privateEdKeyString = nil
|
||||
}
|
||||
|
||||
let keys = loadPrivateKeys(account, privateDSAKey, privateEdKeyString)
|
||||
|
||||
do {
|
||||
let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, cacheDirectory: GenerateAppcast.cacheDirectory, keys: keys, versions: versions, maximumDeltas: maximumDeltas, deltaCompressionModeDescription: deltaCompression, deltaCompressionLevel: deltaCompressionLevel, disableNestedCodeCheck: disableNestedCodeCheck, verbose: verbose)
|
||||
|
||||
+22
-8
@@ -22,7 +22,7 @@ func findKeysInKeychain(account: String) throws -> (Data, Data) {
|
||||
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 for account \(account). Please run generate_keys tool first or provide key with -f <private_key_file> or -s <private_key> parameter.")
|
||||
print("ERROR! Signing key not found for account \(account). Please run generate_keys tool first or provide key with --ed-key-file <private_key_file>")
|
||||
} 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.")
|
||||
@@ -37,7 +37,17 @@ func findKeysInKeychain(account: String) throws -> (Data, Data) {
|
||||
}
|
||||
|
||||
func findKeys(inFile privateAndPublicBase64KeyFile: String) throws -> (Data, Data) {
|
||||
let privateAndPublicBase64Key = try String(contentsOfFile: privateAndPublicBase64KeyFile)
|
||||
let privateAndPublicBase64Key: String
|
||||
if privateAndPublicBase64KeyFile == "-" && !FileManager.default.fileExists(atPath: privateAndPublicBase64KeyFile) {
|
||||
if let line = readLine(strippingNewline: true) {
|
||||
privateAndPublicBase64Key = line
|
||||
} else {
|
||||
print("ERROR! Unable to read EdDSA private key from standard input")
|
||||
throw ExitCode(1)
|
||||
}
|
||||
} else {
|
||||
privateAndPublicBase64Key = try String(contentsOfFile: privateAndPublicBase64KeyFile)
|
||||
}
|
||||
return try findKeys(inString: privateAndPublicBase64Key)
|
||||
}
|
||||
|
||||
@@ -70,16 +80,15 @@ func edSignature(data: Data, publicEdKey: Data, privateEdKey: Data) -> String {
|
||||
}
|
||||
|
||||
struct SignUpdate: ParsableCommand {
|
||||
static let programName = "sign_update"
|
||||
|
||||
@Option(help: ArgumentHelp("The account name in your keychain associated with your private EdDSA (ed25519) key to use for signing the update."))
|
||||
var account: String = "ed25519"
|
||||
|
||||
@Flag(help: ArgumentHelp("Verify that the update is signed correctly. If this is set, a second argument <verify-signature> denoting the signature must be passed after the <update-path>.", valueName: "verify"))
|
||||
var verify: Bool = false
|
||||
|
||||
@Option(name: .customShort("s"), help: ArgumentHelp("The private EdDSA (ed25519) key.", valueName: "private-key"))
|
||||
var privateKey: String?
|
||||
|
||||
@Option(name: .customShort("f"), help: ArgumentHelp("Path to the file containing the private EdDSA (ed25519) key.", valueName: "private-key-file"))
|
||||
@Option(name: [.customShort("f"), .customLong("ed-key-file")], help: ArgumentHelp("Path to the file containing the private EdDSA (ed25519) key. '-' can be used to echo the EdDSA key from a 'secret' environment variable to the standard input stream. For example: echo \"$PRIVATE_KEY_SECRET\" | ./\(programName) --ed-key-file -", valueName: "private-key-file"))
|
||||
var privateKeyFile: String?
|
||||
|
||||
@Argument(help: "The update archive, delta update, or package (pkg) to sign or verify.")
|
||||
@@ -88,13 +97,16 @@ struct SignUpdate: ParsableCommand {
|
||||
@Argument(help: "The signature to verify when --verify is passed.")
|
||||
var verifySignature: String?
|
||||
|
||||
@Option(name: .customShort("s"), help: ArgumentHelp("(DEPRECATED): The private EdDSA (ed25519) key. Please use the Keychain, or pass the key as standard input when using --ed-key-file - instead.", valueName: "private-key"))
|
||||
var privateKey: String?
|
||||
|
||||
static var configuration: CommandConfiguration = CommandConfiguration(
|
||||
abstract: "Sign or verify an update using your EdDSA (ed25519) keys.",
|
||||
discussion: "The EdDSA keys are automatically read from the Keychain if no <private-key> or <private-key-file> is specified.\n\nWhen signing, this tool will output an EdDSA signature and length attributes to use for your update's appcast item enclosure.")
|
||||
discussion: "The EdDSA keys are automatically read from the Keychain if no <private-key-file> is specified.\n\nWhen signing, this tool will output an EdDSA signature and length attributes to use for your update's appcast item enclosure.")
|
||||
|
||||
func validate() throws {
|
||||
guard privateKey == nil || privateKeyFile == nil else {
|
||||
throw ValidationError("Both -s <private-key> and -f <private-key-file> options cannot be provided.")
|
||||
throw ValidationError("Both --ed-key-file <private-key-file> and -s <private-key> options cannot be provided.")
|
||||
}
|
||||
|
||||
guard !verify || verifySignature != nil else {
|
||||
@@ -106,6 +118,8 @@ struct SignUpdate: ParsableCommand {
|
||||
let (priv, pub): (Data, Data)
|
||||
|
||||
if let privateKey = privateKey {
|
||||
fputs("Warning: The -s option for passing the private EdDSA key is insecure and deprecated. Please see its help usage for more information.\n", stderr)
|
||||
|
||||
(priv, pub) = try findKeys(inString: privateKey)
|
||||
} else if let privateKeyFile = privateKeyFile {
|
||||
(priv, pub) = try findKeys(inFile: privateKeyFile)
|
||||
|
||||
Reference in new issue
Block a user