diff --git a/Sparkle/SUCodeSigningVerifier.h b/Sparkle/SUCodeSigningVerifier.h index 1f01d1b5..7c51e0e6 100644 --- a/Sparkle/SUCodeSigningVerifier.h +++ b/Sparkle/SUCodeSigningVerifier.h @@ -14,6 +14,7 @@ @interface SUCodeSigningVerifier : NSObject + (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError **)error; + (BOOL)hostApplicationIsCodeSigned; ++ (BOOL)applicationAtPathIsCodeSigned:(NSString *)applicationPath; @end #endif diff --git a/Sparkle/SUCodeSigningVerifier.m b/Sparkle/SUCodeSigningVerifier.m index 69286592..47eaa179 100644 --- a/Sparkle/SUCodeSigningVerifier.m +++ b/Sparkle/SUCodeSigningVerifier.m @@ -114,4 +114,35 @@ static id valueOrNSNull(id value) { return (result == 0); } ++ (BOOL)applicationAtPathIsCodeSigned:(NSString *)applicationPath +{ + OSStatus result; + SecStaticCodeRef staticCode = NULL; + NSBundle *newBundle; + + newBundle = [NSBundle bundleWithPath:applicationPath]; + if (!newBundle) { + SULog(@"Failed to load NSBundle"); + return NO; + } + + result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode); + if (result == errSecCSUnsigned) { + return NO; + } + + SecRequirementRef requirement = NULL; + result = SecCodeCopyDesignatedRequirement(staticCode, kSecCSDefaultFlags, &requirement); + if (staticCode) { + CFRelease(staticCode); + } + if (requirement) { + CFRelease(requirement); + } + if (result == errSecCSUnsigned) { + return NO; + } + return (result == 0); +} + @end