Improved app update validation. See discussion in issue #441

If an invalid DSA or invalid code signature is provided, the update will fail, regardless if one of these requirements is valid. The logic before is that the update will succeed if either a valid DSA or matched code signature is provided.
This still allows a code signature to change, be added, or be removed, as long as the DSA and the code signature (if provided) is valid. If no DSA is provided, then this is not possible, and the code signature from the host and update app must match.
This commit is contained in:
Zorg committed 2015-04-26 13:58:40 -04:00
1 parent 9646b0b790
commit 28ea47f796
1 file changed
+27 -16
+27 -16
View File
@@ -221,27 +221,38 @@
- (BOOL)validateUpdateDownloadedToPath:(NSString *)downloadedPath extractedToPath:(NSString *)extractedPath DSASignature:(NSString *)DSASignature publicDSAKey:(NSString *)publicDSAKey
{
NSString *newBundlePath = [SUInstaller appPathInUpdateFolder:extractedPath forHost:self.host];
if (newBundlePath) {
if ([SUCodeSigningVerifier hostApplicationIsCodeSigned]) {
NSError *error = nil;
if ([SUCodeSigningVerifier codeSignatureMatchesHostAndIsValidAtPath:newBundlePath error:&error]) {
return YES;
} else {
SULog(@"Code signature check on update failed: %@. Sparkle will use DSA signature instead.", error);
}
} else {
SULog(@"The host app is not signed using Apple Code Signing, and therefore cannot verify updates this way. Sparkle will use DSA signature instead.");
}
if (DSASignature && ![SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:publicDSAKey]) {
SULog(@"The provided DSA signature is not valid. The update will be rejected.");
return NO;
}
NSString *newBundlePath = [SUInstaller appPathInUpdateFolder:extractedPath forHost:self.host];
if (!newBundlePath) {
return (DSASignature != nil);
}
BOOL canValidateByCodeSignature = [SUCodeSigningVerifier hostApplicationIsCodeSigned] && [SUCodeSigningVerifier applicationAtPathIsCodeSigned:newBundlePath];
if (DSASignature) {
return [SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:publicDSAKey];
} else {
if (!DSASignature && !canValidateByCodeSignature) {
SULog(@"The appcast item for the update has no DSA signature. The update will be rejected, because both DSA and Apple Code Signing verification failed.");
return NO;
}
NSError *error = nil;
if (DSASignature) {
if (canValidateByCodeSignature && ![SUCodeSigningVerifier codeSignatureIsValidAtPath:newBundlePath error:&error]) {
SULog(@"The application to update has an invalid code signature: %@. The update will be rejected.", error);
return NO;
}
} else {
if (![SUCodeSigningVerifier codeSignatureMatchesHostAndIsValidAtPath:newBundlePath error:&error]) {
SULog(@"The update will be rejected, because DSA verification failed and the code signature from the original and updated application failed to match: %@", error);
return NO;
}
}
return YES;
}
- (void)downloadDidFinish:(NSURLDownload *)__unused d