From 4d6eeb363c143f58e4989c3e19ccb6ead65e2fd8 Mon Sep 17 00:00:00 2001 From: Isaac Wankerl Date: Mon, 13 Apr 2015 11:25:44 -0500 Subject: [PATCH] Add +[SUCodeSigningVerifier applicationAtPathIsCodeSigned:] Tests whether a particular app is code signed or not. It does not verify the signature. --- Sparkle/SUCodeSigningVerifier.h | 1 + Sparkle/SUCodeSigningVerifier.m | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) 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