mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Added sandbox check.
This commit is contained in:
1 parent
406f3da615
commit
5bd4c1ecb6
3 files changed
+54
-8
No files matched your search
@@ -14,6 +14,7 @@
|
||||
@interface SUCodeSigningVerifier : NSObject
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError **)error;
|
||||
+ (BOOL)hostApplicationIsCodeSigned;
|
||||
+ (BOOL)hostApplicationIsSandboxed;
|
||||
@end
|
||||
|
||||
#endif
|
||||
+47
-4
@@ -13,13 +13,11 @@
|
||||
@implementation SUCodeSigningVerifier
|
||||
|
||||
extern OSStatus SecCodeCopySelf(SecCSFlags flags, SecCodeRef *self) __attribute__((weak_import));
|
||||
|
||||
extern OSStatus SecCodeCopyDesignatedRequirement(SecStaticCodeRef code, SecCSFlags flags, SecRequirementRef *requirement) __attribute__((weak_import));
|
||||
|
||||
extern OSStatus SecStaticCodeCreateWithPath(CFURLRef path, SecCSFlags flags, SecStaticCodeRef *staticCode) __attribute__((weak_import));
|
||||
|
||||
extern OSStatus SecStaticCodeCheckValidityWithErrors(SecStaticCodeRef staticCode, SecCSFlags flags, SecRequirementRef requirement, CFErrorRef *errors) __attribute__((weak_import));
|
||||
|
||||
extern OSStatus SecRequirementCreateWithString(CFStringRef text, SecCSFlags flags, SecRequirementRef *requirement) __attribute__((weak_import));
|
||||
extern OSStatus SecCodeCheckValidity(SecCodeRef code, SecCSFlags flags, SecRequirementRef requirement) __attribute__((weak_import));
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError **)error
|
||||
{
|
||||
@@ -83,4 +81,49 @@ finally:
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
+ (BOOL)hostApplicationIsSandboxed
|
||||
{
|
||||
// This API didn't exist prior to 10.6
|
||||
if (SecCodeCopySelf == NULL) return NO;
|
||||
|
||||
BOOL isSandboxed = NO;
|
||||
do
|
||||
{
|
||||
SecCodeRef hostCode = NULL;
|
||||
SecRequirementRef hostRequirement = NULL;
|
||||
|
||||
#define Cleanup() \
|
||||
{ \
|
||||
if (hostCode) CFRelease(hostCode); \
|
||||
if (hostRequirement) CFRelease(hostRequirement); \
|
||||
}
|
||||
|
||||
OSStatus status = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
|
||||
|
||||
if (status != noErr || hostCode == NULL)
|
||||
{
|
||||
Cleanup();
|
||||
break;
|
||||
}
|
||||
|
||||
CFStringRef requirementString = CFSTR("entitlement[\"com.apple.security.app-sandbox\"] exists");
|
||||
status = SecRequirementCreateWithString(requirementString, kSecCSDefaultFlags, &hostRequirement);
|
||||
|
||||
if (status != noErr || hostRequirement == NULL)
|
||||
{
|
||||
Cleanup();
|
||||
break;
|
||||
}
|
||||
|
||||
status = SecCodeCheckValidity(hostCode, kSecCSDefaultFlags, hostRequirement);
|
||||
if (noErr == status)
|
||||
isSandboxed = YES;
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
while (NO);
|
||||
|
||||
return isSandboxed;
|
||||
}
|
||||
|
||||
@end
|
||||
+6
-4
@@ -556,10 +556,12 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
|
||||
|
||||
+ (BOOL)shouldUseXPC
|
||||
{
|
||||
BOOL running10_7 = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
|
||||
BOOL useXPC = running10_7 && [[NSFileManager defaultManager] fileExistsAtPath:
|
||||
[[[[SUUpdater sharedUpdater] hostBundle] bundlePath] stringByAppendingPathComponent:@"Contents/XPCServices/com.andymatuschak.Sparkle.install-service.xpc"]];
|
||||
return useXPC;
|
||||
if (![SUCodeSigningVerifier hostApplicationIsSandboxed])
|
||||
return NO;
|
||||
|
||||
NSString *xpcServicePrefixPath = [[[SUUpdater sharedUpdater] hostBundle] bundlePath];
|
||||
NSString *xpcServiceSuffixPath = @"Contents/XPCServices/com.andymatuschak.Sparkle.install-service.xpc";
|
||||
return [[NSFileManager defaultManager] fileExistsAtPath:[xpcServicePrefixPath stringByAppendingPathComponent:xpcServiceSuffixPath]];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user