mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-30 05:28:50 +00:00
Switch the signature verifier to use SUSignatures (like 6df898f on 1.x)
This commit is contained in:
1 parent
261f5dc797
commit
5dc407ddc5
6 files changed
+32
-25
No files matched your search
@@ -16,6 +16,7 @@
|
||||
#define SUDSAVERIFIER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
@class SUSignatures;
|
||||
|
||||
#if __MAC_OS_X_VERSION_MAX_ALLOWED < 1090
|
||||
@interface NSData (SUDSAVerifier)
|
||||
@@ -25,12 +26,12 @@
|
||||
|
||||
@interface SUDSAVerifier : NSObject
|
||||
|
||||
+ (BOOL)validatePath:(NSString *)path withDSASignature:(NSData *)signature withPublicDSAKey:(NSString *)pkeyString;
|
||||
+ (BOOL)validatePath:(NSString *)path withSignatures:(SUSignatures *)signatures withPublicDSAKey:(NSString *)pkeyString;
|
||||
|
||||
- (instancetype)initWithPublicKeyData:(NSData *)data;
|
||||
|
||||
- (BOOL)verifyFileAtPath:(NSString *)path signature:(NSData *)signature;
|
||||
- (BOOL)verifyStream:(NSInputStream *)stream signature:(NSData *)signature;
|
||||
- (BOOL)verifyFileAtPath:(NSString *)path signatures:(SUSignatures *)signatures;
|
||||
- (BOOL)verifyStream:(NSInputStream *)stream signatures:(SUSignatures *)signatures;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#import "SUDSAVerifier.h"
|
||||
#import "SULog.h"
|
||||
#import "SUSignatures.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
|
||||
|
||||
@@ -23,9 +24,9 @@
|
||||
SecKeyRef _secKey;
|
||||
}
|
||||
|
||||
+ (BOOL)validatePath:(NSString *)path withDSASignature:(NSData *)signature withPublicDSAKey:(NSString *)pkeyString
|
||||
+ (BOOL)validatePath:(NSString *)path withSignatures:(SUSignatures *)signatures withPublicDSAKey:(NSString *)pkeyString
|
||||
{
|
||||
if (!signature) {
|
||||
if (!signatures) {
|
||||
SULog(SULogLevelError, @"There is no DSA signature to check");
|
||||
return NO;
|
||||
}
|
||||
@@ -40,7 +41,7 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
return [verifier verifyFileAtPath:path signature:signature];
|
||||
return [verifier verifyFileAtPath:path signatures:signatures];
|
||||
}
|
||||
|
||||
- (instancetype)initWithPublicKeyData:(NSData *)data
|
||||
@@ -87,18 +88,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)verifyFileAtPath:(NSString *)path signature:(NSData *)signature
|
||||
- (BOOL)verifyFileAtPath:(NSString *)path signatures:(SUSignatures *)signatures
|
||||
{
|
||||
if (!path.length) {
|
||||
return NO;
|
||||
}
|
||||
NSInputStream *dataInputStream = [NSInputStream inputStreamWithFileAtPath:path];
|
||||
return [self verifyStream:dataInputStream signature:signature];
|
||||
return [self verifyStream:dataInputStream signatures:signatures];
|
||||
}
|
||||
|
||||
- (BOOL)verifyStream:(NSInputStream *)stream signature:(NSData *)signature
|
||||
- (BOOL)verifyStream:(NSInputStream *)stream signatures:(SUSignatures *)signatures
|
||||
{
|
||||
if (!stream || !signature) {
|
||||
NSData *dsaSignature = signatures.dsaSignature;
|
||||
|
||||
if (!stream || !dsaSignature) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -130,10 +133,10 @@
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
||||
dataVerifyTransform = SecVerifyTransformCreate(_secKey, (__bridge CFDataRef)signature, &error);
|
||||
dataVerifyTransform = SecVerifyTransformCreate(_secKey, (__bridge CFDataRef)dsaSignature, &error);
|
||||
#pragma clang diagnostic pop
|
||||
if (!dataVerifyTransform || error) {
|
||||
SULog(SULogLevelError, @"Could not understand format of the signature: %@; Signature data: %@", error, signature);
|
||||
SULog(SULogLevelError, @"Could not understand format of the signature: %@; Signature data: %@", error, dsaSignature);
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
|
||||
@@ -1560,8 +1560,10 @@
|
||||
0867D69AFE84028FC02AAC07 /* Frameworks */,
|
||||
034768DFFF38A50411DB9C8B /* Products */,
|
||||
);
|
||||
indentWidth = 4;
|
||||
name = Sparkle;
|
||||
sourceTree = "<group>";
|
||||
tabWidth = 4;
|
||||
usesTabs = 0;
|
||||
};
|
||||
0867D69AFE84028FC02AAC07 /* Frameworks */ = {
|
||||
|
||||
Vendored
+1
-1
@@ -251,7 +251,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
|
||||
_fileURL = [NSURL URLWithString:fileURLString];
|
||||
}
|
||||
if (enclosure) {
|
||||
_signatures = [[SUSignatures alloc] initWithDsa:[enclosure objectForKey:SUAppcastAttributeDSASignature] ed:nil];
|
||||
_signatures = [[SUSignatures alloc] initWithDsa:[enclosure objectForKey:SUAppcastAttributeDSASignature] ed:[enclosure objectForKey:SUAppcastAttributeEDSignature]];
|
||||
}
|
||||
|
||||
_versionString = [(NSString *)newVersion copy];
|
||||
|
||||
Vendored
+7
-8
@@ -42,16 +42,15 @@
|
||||
BOOL prevalidatedDsaSignature;
|
||||
if (performingPrevalidation) {
|
||||
NSString *publicDSAKey = host.publicDSAKey;
|
||||
NSData *dsaSignature = signatures.dsaSignature;
|
||||
|
||||
if (publicDSAKey == nil) {
|
||||
prevalidatedDsaSignature = NO;
|
||||
SULog(SULogLevelError, @"Failed to validate update before unarchiving because no DSA key was found");
|
||||
} else if (dsaSignature == nil) {
|
||||
} else if (signatures == nil || signatures.dsaSignature == nil) {
|
||||
prevalidatedDsaSignature = NO;
|
||||
SULog(SULogLevelError, @"Failed to validate update before unarchiving because no DSA signature was found");
|
||||
} else {
|
||||
prevalidatedDsaSignature = [SUDSAVerifier validatePath:downloadPath withDSASignature:dsaSignature withPublicDSAKey:host.publicDSAKey];
|
||||
prevalidatedDsaSignature = [SUDSAVerifier validatePath:downloadPath withSignatures:signatures withPublicDSAKey:host.publicDSAKey];
|
||||
if (!prevalidatedDsaSignature) {
|
||||
SULog(SULogLevelError, @"DSA signature validation before unarchiving failed for update %@", downloadPath);
|
||||
}
|
||||
@@ -76,7 +75,7 @@
|
||||
{
|
||||
assert(self.canValidate);
|
||||
|
||||
NSData *DSASignature = self.signatures.dsaSignature;
|
||||
SUSignatures *signatures = self.signatures;
|
||||
NSString *downloadPath = self.downloadPath;
|
||||
SUHost *host = self.host;
|
||||
|
||||
@@ -98,14 +97,14 @@
|
||||
if (isPackage) {
|
||||
// If we get here, then the appcast installation type was lying to us.. This error will be caught later when starting the installer.
|
||||
// For package type updates, all we do is check if the DSA signature is valid
|
||||
BOOL validationCheckSuccess = [SUDSAVerifier validatePath:downloadPath withDSASignature:DSASignature withPublicDSAKey:host.publicDSAKey];
|
||||
BOOL validationCheckSuccess = [SUDSAVerifier validatePath:downloadPath withSignatures:signatures withPublicDSAKey:host.publicDSAKey];
|
||||
if (!validationCheckSuccess) {
|
||||
SULog(SULogLevelError, @"DSA signature validation of the package failed. The update contains an installer package, and valid DSA signatures are mandatory for all installer packages. The update will be rejected. Sign the installer with a valid DSA key or use an .app bundle update instead.");
|
||||
}
|
||||
return validationCheckSuccess;
|
||||
} else {
|
||||
// For application bundle updates, we check both the DSA and Apple code signing signatures
|
||||
return [self validateBundleUpdateForHost:host newBundleURL:installSourceURL archivePath:downloadPath DSASignature:DSASignature];
|
||||
return [self validateBundleUpdateForHost:host newBundleURL:installSourceURL archivePath:downloadPath signatures:signatures];
|
||||
}
|
||||
} else if (isPackage) {
|
||||
// We already prevalidated the package and nothing else needs to be done
|
||||
@@ -123,7 +122,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)validateBundleUpdateForHost:(SUHost *)host newBundleURL:(NSURL *)newBundleURL archivePath:(NSString *)archivePath DSASignature:(NSData *)DSASignature
|
||||
- (BOOL)validateBundleUpdateForHost:(SUHost *)host newBundleURL:(NSURL *)newBundleURL archivePath:(NSString *)archivePath signatures:(SUSignatures *)signatures
|
||||
{
|
||||
NSBundle *newBundle = [NSBundle bundleWithURL:newBundleURL];
|
||||
if (newBundle == nil) {
|
||||
@@ -148,7 +147,7 @@
|
||||
// In that case, the check ensures that the app author has correctly used DSA keys, so that the app will be updateable in the next version.
|
||||
// However if the new and old DSA keys are the same, then this is a security measure.
|
||||
if (newPublicDSAKey != nil) {
|
||||
if (![SUDSAVerifier validatePath:archivePath withDSASignature:DSASignature withPublicDSAKey:newPublicDSAKey]) {
|
||||
if (![SUDSAVerifier validatePath:archivePath withSignatures:signatures withPublicDSAKey:newPublicDSAKey]) {
|
||||
SULog(SULogLevelError, @"DSA signature validation failed. The update has a public DSA key and is signed with a DSA key, but the %@ doesn't match the signature. The update will be rejected.",
|
||||
dsaKeysMatch ? @"public key" : @"new public key shipped with the update");
|
||||
return NO;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "SUDSAVerifier.h"
|
||||
#import "SUSignatures.h"
|
||||
|
||||
@interface SUDSAVerifierTest : XCTestCase
|
||||
@property NSString *testFile, *pubKeyFile;
|
||||
@@ -67,18 +68,19 @@
|
||||
{
|
||||
SUDSAVerifier *v = [[SUDSAVerifier alloc] initWithPublicKeyData:pubKey];
|
||||
|
||||
NSData *sig = [[NSData alloc] initWithBase64EncodedString:sigString options:(NSDataBase64DecodingOptions)0];
|
||||
SUSignatures *sig = [[SUSignatures alloc] initWithDsa:sigString ed:nil];
|
||||
|
||||
return [v verifyFileAtPath:aFile signature:sig];
|
||||
return [v verifyFileAtPath:aFile signatures:sig];
|
||||
}
|
||||
|
||||
- (void)testValidatePath
|
||||
{
|
||||
NSString *pubkey = [NSString stringWithContentsOfFile:self.pubKeyFile encoding:NSASCIIStringEncoding error:nil];
|
||||
NSData *signature = [[NSData alloc] initWithBase64EncodedString:@"MC0CFFMF3ha5kjvrJ9JTpTR8BenPN9QUAhUAzY06JRdtP17MJewxhK0twhvbKIE=" options:(NSDataBase64DecodingOptions)0];
|
||||
|
||||
SUSignatures *sig = [[SUSignatures alloc] initWithDsa:@"MC0CFFMF3ha5kjvrJ9JTpTR8BenPN9QUAhUAzY06JRdtP17MJewxhK0twhvbKIE=" ed:nil];
|
||||
|
||||
XCTAssertTrue([SUDSAVerifier validatePath:self.testFile
|
||||
withDSASignature:signature
|
||||
withSignatures:sig
|
||||
withPublicDSAKey:pubkey],
|
||||
@"Expected valid signature");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user