mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-23 04:34:27 +00:00
This provides enhanced opt-in security preventing informational attacks that for example suggest the user the auto-updater is broken and an update needs to be installed from a compromised website (assuming the developer's website is hijacked). To opt in, developers need to add SURequireSignedFeed Info.plist key to their bundle. generate_appcast and sign_update have been updated to support signing appcast feeds and release note files (both need to be signed). By default, they embed a HTML comment warning in the files that further modifications will invalidate previously signed signatures. Signed appcasts include a signing block comment at the end of the XML file describing the signature of the content preceding it. Signed release notes will have their signatures annotated in the <sparkle:releaseNotesLink> element with a sparkle:edSignature attribute (and optionally a sparkle:length attribute for diagnostic purposes). A signingValidationStatus property is also now added to SUAppcast and SUAppcastItem indicating the signing status (skipped, succeeded, failed). The standard user driver's release notes HTML web view rejects external file references when appcasts are signed. A bug has also been fixed where the update alert would not provide errors when loading external release note files fails. These changes also introduce a showing new error / localizable strings when the release notes is not signed correctly or fails to load. As a hardening policy, we also enforce SUVerifyUpdateBeforeExtraction when opting into signed feeds, so key rotation is only possible with Developer ID code signed dmg archives. A fallback feed signing failure expiration policy has also been added. When a signed feed has failed validation for more than a configurable period of time (by default SUSignedFeedFailureExpirationInterval is set to 20 days), Sparkle will allow appcast items to be shown to the user. However, these items operate in a safe mode that strip abusable information like release notes / descriptions / links, sanitize the version strings, and they cannot be marked critical or informational, nor be installed automatically. After this policy expires, this allows users installing updates as long as the updates are signed correctly, or be aware that the updater has not been functioning correctly. Fixes #971.
86 lines
2.8 KiB
Swift
86 lines
2.8 KiB
Swift
//
|
|
// secret.swift
|
|
// Sparkle
|
|
//
|
|
// Created on 11/19/23.
|
|
// Copyright © 2023 Sparkle Project. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
func secretUsesRegularSeed(secret: Data) -> Bool {
|
|
return (secret.count == 32)
|
|
}
|
|
|
|
func secretUsesOldHashedSeed(secret: Data) -> Bool {
|
|
return (secret.count == 64 + 32)
|
|
}
|
|
|
|
// Secret is the data we store in the keychain
|
|
// For newer generated keys, secret is the private seed
|
|
// For older generated keys, secret is the private orlp/Ed25519 key concatenated with the public key
|
|
// If the secret is of invalid length, this returns nil
|
|
func decodePrivateAndPublicKeys(secret: Data) -> (privateKey: Data, publicKey: Data)? {
|
|
let privateKey: Data
|
|
let publicKey: Data
|
|
|
|
if secretUsesRegularSeed(secret: secret) {
|
|
let seed = secret
|
|
|
|
var privateEdKey = Array<UInt8>(repeating: 0, count: 64)
|
|
var publicEdKey = Array<UInt8>(repeating: 0, count: 32)
|
|
seed.withUnsafeBytes { seedBytes in
|
|
let seedBuffer: UnsafePointer<UInt8> = seedBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
|
ed25519_create_keypair(&publicEdKey, &privateEdKey, seedBuffer)
|
|
}
|
|
|
|
privateKey = Data(privateEdKey)
|
|
publicKey = Data(publicEdKey)
|
|
} else if secretUsesOldHashedSeed(secret: secret) {
|
|
privateKey = secret[0..<64]
|
|
publicKey = secret[64...]
|
|
} else {
|
|
return nil
|
|
}
|
|
|
|
return (privateKey, publicKey)
|
|
}
|
|
|
|
enum DecodeSecretStringError : LocalizedError {
|
|
case unableToReadData
|
|
case unableToDecodeDataAsUTF8String
|
|
|
|
public var errorDescription: String? {
|
|
switch self {
|
|
case .unableToReadData:
|
|
return "Unable to read EdDSA private key data"
|
|
case .unableToDecodeDataAsUTF8String:
|
|
return "Unable to read EdDSA private key data as UTF-8 string"
|
|
}
|
|
}
|
|
}
|
|
|
|
// Reads secret base64 string from a file
|
|
func decodeSecretString(filePath: String) throws -> String {
|
|
let privateKeyString: String
|
|
if #available(macOS 10.15.4, *) {
|
|
// Prefer to use FileHandle which supports process substitution:
|
|
// https://github.com/sparkle-project/Sparkle/issues/2605
|
|
let fileHandle = try FileHandle(forReadingFrom: URL(fileURLWithPath: filePath))
|
|
|
|
guard let data = try fileHandle.readToEnd() else {
|
|
throw DecodeSecretStringError.unableToReadData
|
|
}
|
|
|
|
guard let decodedPrivateKeyString = String(data: data, encoding: .utf8) else {
|
|
throw DecodeSecretStringError.unableToDecodeDataAsUTF8String
|
|
}
|
|
|
|
privateKeyString = decodedPrivateKeyString
|
|
} else {
|
|
privateKeyString = try String(contentsOf: URL(fileURLWithPath: filePath))
|
|
}
|
|
|
|
return privateKeyString.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
}
|