mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Move code from SPUInstallerValidation.m to SUUpdateValidator.m
This commit is contained in:
1 parent
b482f55e46
commit
65c0c1e7fe
4 files changed
+72
-160
No files matched your search
@@ -1,34 +0,0 @@
|
||||
//
|
||||
// SPUInstallerValidation.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/30/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class SUHost;
|
||||
|
||||
@interface SPUInstallerValidation : NSObject
|
||||
|
||||
/**
|
||||
* If the update is a bundle, then the download must also be signed using DSA.
|
||||
* However, a change of DSA public keys is allowed if the Apple Code Signing identities match and are valid.
|
||||
* Likewise, a change of Apple Code Signing identities is allowed if the DSA public keys match and the update is valid.
|
||||
*/
|
||||
+ (BOOL)validateBundleUpdateForHost:(SUHost *)host newBundleURL:(NSURL *)newBundleURL archivePath:(NSString *)archivePath DSASignature:(NSString *)DSASignature;
|
||||
|
||||
/*
|
||||
* Use this for validating updates by validating the DSA signature using the host's public DSA key
|
||||
*/
|
||||
+ (BOOL)validateUpdateForHost:(SUHost *)host archivePath:(NSString *)archivePath DSASignature:(NSString *)DSASignature;
|
||||
|
||||
/*
|
||||
* Use this for validating a code signature for a bundle.
|
||||
* This is simply a consistency check rather than a security one.
|
||||
* This will return YES if the code signature is valid on the bundle, or if the bundle is not code signed at all, otherwise returns NO.
|
||||
*/
|
||||
+ (BOOL)validateCodeSignatureIfAvailableForBundleURL:(NSURL *)bundleURL;
|
||||
|
||||
@end
|
||||
@@ -1,115 +0,0 @@
|
||||
//
|
||||
// SPUInstallerValidation.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/30/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SPUInstallerValidation.h"
|
||||
#import "SUHost.h"
|
||||
#import "SULog.h"
|
||||
#import "SUDSAVerifier.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a "daemon-safe" class and should NOT import AppKit
|
||||
#endif
|
||||
|
||||
@implementation SPUInstallerValidation
|
||||
|
||||
+ (BOOL)validateBundleUpdateForHost:(SUHost *)host newBundleURL:(NSURL *)newBundleURL archivePath:(NSString *)archivePath DSASignature:(NSString *)DSASignature
|
||||
{
|
||||
NSBundle *newBundle = [NSBundle bundleWithURL:newBundleURL];
|
||||
if (newBundle == nil) {
|
||||
SULog(@"No suitable bundle is found in the update. The update will be rejected.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
SUHost *newHost = [[SUHost alloc] initWithBundle:newBundle];
|
||||
NSString *newPublicDSAKey = newHost.publicDSAKey;
|
||||
|
||||
NSString *publicDSAKey = host.publicDSAKey;
|
||||
|
||||
// Downgrade in DSA security should not be possible
|
||||
if (publicDSAKey != nil && newPublicDSAKey == nil) {
|
||||
SULog(@"A public DSA key is found in the old bundle but no public DSA key is found in the new update. For security reasons, the update will be rejected.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
BOOL dsaKeysMatch = (publicDSAKey == nil || newPublicDSAKey == nil) ? NO : [publicDSAKey isEqualToString:newPublicDSAKey];
|
||||
|
||||
// If the new DSA key differs from the old, then this check is not a security measure, because the new key is not trusted.
|
||||
// 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 withEncodedDSASignature:DSASignature withPublicDSAKey:newPublicDSAKey]) {
|
||||
SULog(@"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;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL updateIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:newBundleURL];
|
||||
|
||||
if (dsaKeysMatch) {
|
||||
NSError *error = nil;
|
||||
if (updateIsCodeSigned && ![SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:newBundleURL error:&error]) {
|
||||
SULog(@"The update archive has a valid DSA signature, but the app is also signed with Code Signing, which is corrupted: %@. The update will be rejected.", error);
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
NSURL *hostBundleURL = host.bundle.bundleURL;
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:hostBundleURL];
|
||||
|
||||
NSString *dsaStatus = newPublicDSAKey ? @"has a new DSA key that doesn't match the previous one" : (publicDSAKey ? @"removes the DSA key" : @"isn't signed with a DSA key");
|
||||
if (!hostIsCodeSigned || !updateIsCodeSigned) {
|
||||
NSString *acsStatus = !hostIsCodeSigned ? @"old app hasn't been signed with app Code Signing" : @"new app isn't signed with app Code Signing";
|
||||
SULog(@"The update archive %@, and the %@. At least one method of signature verification must be valid. The update will be rejected.", dsaStatus, acsStatus);
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSError *error = nil;
|
||||
if (![SUCodeSigningVerifier codeSignatureAtBundleURL:hostBundleURL matchesSignatureAtBundleURL:newBundleURL error:&error]) {
|
||||
SULog(@"The update archive %@, and the app is signed with a new Code Signing identity that doesn't match code signing of the original app: %@. At least one method of signature verification must be valid. The update will be rejected.", dsaStatus, error);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
+ (BOOL)validateUpdateForHost:(SUHost *)host archivePath:(NSString *)archivePath DSASignature:(NSString *)DSASignature
|
||||
{
|
||||
NSString *publicDSAKey = host.publicDSAKey;
|
||||
if (publicDSAKey ==nil){
|
||||
SULog(@"Failed to validate delta update because no DSA key was found");
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (DSASignature == nil) {
|
||||
SULog(@"Failed to validate delta update because no DSA signature was found");
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (![SUDSAVerifier validatePath:archivePath withEncodedDSASignature:DSASignature withPublicDSAKey:publicDSAKey]) {
|
||||
SULog(@"DSA signature validation failed for delta update. This update will be skipped.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
+ (BOOL)validateCodeSignatureIfAvailableForBundleURL:(NSURL *)bundleURL
|
||||
{
|
||||
BOOL updateIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:bundleURL];
|
||||
|
||||
NSError *error = nil;
|
||||
if (updateIsCodeSigned && ![SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:bundleURL error:&error]) {
|
||||
SULog(@"Failed to validate code sign signature on bundle at %@ with error: %@", bundleURL, error);
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -122,7 +122,6 @@
|
||||
721D8A811D498B9B0032E472 /* Updater.app in Copy Tools */ = {isa = PBXBuildFile; fileRef = 721C24451CB753E6005440CB /* Updater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
721D8A861D4ADFEB0032E472 /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; };
|
||||
721D8A871D4C5BF10032E472 /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; };
|
||||
721D8A8C1D4D3A6F0032E472 /* SPUInstallerValidation.m in Sources */ = {isa = PBXBuildFile; fileRef = 721D8A8B1D4D3A6F0032E472 /* SPUInstallerValidation.m */; };
|
||||
7223E7631AD1AEFF008E3161 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; };
|
||||
7229E1B61C97C91100CB50D0 /* SPUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7229E1B51C97C91100CB50D0 /* SPUUpdateDriver.h */; };
|
||||
7229E1B91C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7229E1B71C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h */; };
|
||||
@@ -901,8 +900,6 @@
|
||||
721C24581CB7567D005440CB /* InstallerProgress-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "InstallerProgress-Info.plist"; path = "Sparkle/InstallerProgress/InstallerProgress-Info.plist"; sourceTree = SOURCE_ROOT; };
|
||||
721D8A831D498F1D0032E472 /* set-agent-signing.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "set-agent-signing.sh"; sourceTree = "<group>"; };
|
||||
721D8A881D4D272E0032E472 /* Installation.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Installation.md; sourceTree = "<group>"; };
|
||||
721D8A8A1D4D3A6F0032E472 /* SPUInstallerValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUInstallerValidation.h; path = Autoupdate/SPUInstallerValidation.h; sourceTree = SOURCE_ROOT; };
|
||||
721D8A8B1D4D3A6F0032E472 /* SPUInstallerValidation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPUInstallerValidation.m; path = Autoupdate/SPUInstallerValidation.m; sourceTree = SOURCE_ROOT; };
|
||||
722194511D3BF987004C34FF /* SPUInstallerAgentProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SPUInstallerAgentProtocol.h; path = Sparkle/InstallerProgress/SPUInstallerAgentProtocol.h; sourceTree = SOURCE_ROOT; };
|
||||
722194521D3BFEB7004C34FF /* SUInstallerAgentInitiationProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SUInstallerAgentInitiationProtocol.h; path = Sparkle/InstallerProgress/SUInstallerAgentInitiationProtocol.h; sourceTree = SOURCE_ROOT; };
|
||||
7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = "<group>"; };
|
||||
@@ -1457,8 +1454,6 @@
|
||||
7267E5A11D3D8A7E00D1BF90 /* AppInstaller.m */,
|
||||
729924921DF4A45000DBCDF5 /* SUUpdateValidator.h */,
|
||||
729924931DF4A45000DBCDF5 /* SUUpdateValidator.m */,
|
||||
721D8A8A1D4D3A6F0032E472 /* SPUInstallerValidation.h */,
|
||||
721D8A8B1D4D3A6F0032E472 /* SPUInstallerValidation.m */,
|
||||
7267E5A61D3D8A9900D1BF90 /* AgentConnection.h */,
|
||||
7267E5A71D3D8A9900D1BF90 /* AgentConnection.m */,
|
||||
7267E5A91D3D8AA800D1BF90 /* TerminationListener.h */,
|
||||
@@ -3015,7 +3010,6 @@
|
||||
7267E5771D3D895B00D1BF90 /* SUBinaryDeltaCommon.m in Sources */,
|
||||
7267E5871D3D89B300D1BF90 /* SUPipedUnarchiver.m in Sources */,
|
||||
7267E5751D3D895B00D1BF90 /* SUBinaryDeltaApply.m in Sources */,
|
||||
721D8A8C1D4D3A6F0032E472 /* SPUInstallerValidation.m in Sources */,
|
||||
7267E59D1D3D8A5A00D1BF90 /* SUDSAVerifier.m in Sources */,
|
||||
7267E5791D3D895B00D1BF90 /* SUBinaryDeltaCreate.m in Sources */,
|
||||
7267E5C21D3D8B2700D1BF90 /* SUGuidedPackageInstaller.m in Sources */,
|
||||
|
||||
Vendored
+72
-5
@@ -7,7 +7,8 @@
|
||||
//
|
||||
|
||||
#import "SUUpdateValidator.h"
|
||||
#import "SPUInstallerValidation.h"
|
||||
#import "SUDSAVerifier.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUInstaller.h"
|
||||
#import "SUHost.h"
|
||||
#import "SULog.h"
|
||||
@@ -49,7 +50,7 @@
|
||||
prevalidatedDsaSignature = NO;
|
||||
SULog(@"Failed to validate update before unarchiving because no DSA signature was found");
|
||||
} else {
|
||||
prevalidatedDsaSignature = [SPUInstallerValidation validateUpdateForHost:host archivePath:downloadPath DSASignature:dsaSignature];
|
||||
prevalidatedDsaSignature = [SUDSAVerifier validatePath:downloadPath withEncodedDSASignature:dsaSignature withPublicDSAKey:host.publicDSAKey];
|
||||
if (!prevalidatedDsaSignature) {
|
||||
SULog(@"DSA signature validation before unarchiving failed for update %@", downloadPath);
|
||||
}
|
||||
@@ -96,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 = [SPUInstallerValidation validateUpdateForHost:host archivePath:downloadPath DSASignature:DSASignature];
|
||||
BOOL validationCheckSuccess = [SUDSAVerifier validatePath:downloadPath withEncodedDSASignature:DSASignature withPublicDSAKey:host.publicDSAKey];
|
||||
if (!validationCheckSuccess) {
|
||||
SULog(@"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 [SPUInstallerValidation validateBundleUpdateForHost:host newBundleURL:installSourceURL archivePath:downloadPath DSASignature:DSASignature];
|
||||
return [self validateBundleUpdateForHost:host newBundleURL:installSourceURL archivePath:downloadPath DSASignature:DSASignature];
|
||||
}
|
||||
} else if (isPackage) {
|
||||
// We already prevalidated the package and nothing else needs to be done
|
||||
@@ -112,8 +113,74 @@
|
||||
// Because we already validated the DSA signature, this is just a consistency check to see
|
||||
// if the developer signed their application properly with their Apple ID
|
||||
// Currently, this case only gets hit for binary delta updates
|
||||
return [SPUInstallerValidation validateCodeSignatureIfAvailableForBundleURL:installSourceURL];
|
||||
NSError *error = nil;
|
||||
if ([SUCodeSigningVerifier bundleAtURLIsCodeSigned:installSourceURL] && ![SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:installSourceURL error:&error]) {
|
||||
SULog(@"Failed to validate apple code sign signature on bundle after archive validation with error: %@", error);
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)validateBundleUpdateForHost:(SUHost *)host newBundleURL:(NSURL *)newBundleURL archivePath:(NSString *)archivePath DSASignature:(NSString *)DSASignature
|
||||
{
|
||||
NSBundle *newBundle = [NSBundle bundleWithURL:newBundleURL];
|
||||
if (newBundle == nil) {
|
||||
SULog(@"No suitable bundle is found in the update. The update will be rejected.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
SUHost *newHost = [[SUHost alloc] initWithBundle:newBundle];
|
||||
NSString *newPublicDSAKey = newHost.publicDSAKey;
|
||||
|
||||
NSString *publicDSAKey = host.publicDSAKey;
|
||||
|
||||
// Downgrade in DSA security should not be possible
|
||||
if (publicDSAKey != nil && newPublicDSAKey == nil) {
|
||||
SULog(@"A public DSA key is found in the old bundle but no public DSA key is found in the new update. For security reasons, the update will be rejected.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
BOOL dsaKeysMatch = (publicDSAKey == nil || newPublicDSAKey == nil) ? NO : [publicDSAKey isEqualToString:newPublicDSAKey];
|
||||
|
||||
// If the new DSA key differs from the old, then this check is not a security measure, because the new key is not trusted.
|
||||
// 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 withEncodedDSASignature:DSASignature withPublicDSAKey:newPublicDSAKey]) {
|
||||
SULog(@"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;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL updateIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:newBundleURL];
|
||||
|
||||
if (dsaKeysMatch) {
|
||||
NSError *error = nil;
|
||||
if (updateIsCodeSigned && ![SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:newBundleURL error:&error]) {
|
||||
SULog(@"The update archive has a valid DSA signature, but the app is also signed with Code Signing, which is corrupted: %@. The update will be rejected.", error);
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
NSURL *hostBundleURL = host.bundle.bundleURL;
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:hostBundleURL];
|
||||
|
||||
NSString *dsaStatus = newPublicDSAKey ? @"has a new DSA key that doesn't match the previous one" : (publicDSAKey ? @"removes the DSA key" : @"isn't signed with a DSA key");
|
||||
if (!hostIsCodeSigned || !updateIsCodeSigned) {
|
||||
NSString *acsStatus = !hostIsCodeSigned ? @"old app hasn't been signed with app Code Signing" : @"new app isn't signed with app Code Signing";
|
||||
SULog(@"The update archive %@, and the %@. At least one method of signature verification must be valid. The update will be rejected.", dsaStatus, acsStatus);
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSError *error = nil;
|
||||
if (![SUCodeSigningVerifier codeSignatureAtBundleURL:hostBundleURL matchesSignatureAtBundleURL:newBundleURL error:&error]) {
|
||||
SULog(@"The update archive %@, and the app is signed with a new Code Signing identity that doesn't match code signing of the original app: %@. At least one method of signature verification must be valid. The update will be rejected.", dsaStatus, error);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user