Reject modified Dayu Color bundles at registration, service startup and update

这个提交包含在:
mac 于 2026-11-05 23:06:15 +08:00 提交
1 父节点 a7508203d1
当前提交 db6b2b05b3
9 个文件已更改
+237 -22

没有与搜索条件相匹配的文件

+13
查看文件
@@ -0,0 +1,13 @@
#import <Foundation/Foundation.h>
#import <Security/Security.h>
typedef NS_ENUM(NSInteger, DYCodeRole) {
DYCodeRoleWrapper,
DYCodeRoleService,
};
FOUNDATION_EXPORT NSString *const DYPluginRelativePath;
FOUNDATION_EXPORT NSString *const DYIntegrityRecoveryMessage;
FOUNDATION_EXPORT OSStatus DYValidateSignedInstallation(NSURL *wrapperURL, NSString **failedComponent);
FOUNDATION_EXPORT OSStatus DYValidateRunningInstallation(DYCodeRole role, NSString **failedComponent);
+88
查看文件
@@ -0,0 +1,88 @@
#import "DYCodeIntegrity.h"
NSString *const DYPluginRelativePath = @"Contents/PlugIns/大鱼调色 XPC Service.pluginkit";
NSString *const DYIntegrityRecoveryMessage = @"大鱼调色未通过官方签名或完整性验证。请使用原始安装包重新安装。";
static NSString *const DYWrapperIdentifier = @"com.dayu.color";
static NSString *const DYServiceIdentifier = @"com.dayu.color.XPC";
static OSStatus DYCreateSigningRequirement(NSString *identifier, SecRequirementRef *requirement) {
// Pin the Developer ID team and signing identifier, allowing certificate renewal.
NSString *text = [NSString stringWithFormat:
@"identifier \"%@\" and anchor apple generic and "
"certificate 1[field.1.2.840.113635.100.6.2.6] exists and "
"certificate leaf[field.1.2.840.113635.100.6.1.13] exists and "
"certificate leaf[subject.OU] = \"B3W25FX5H5\"", identifier];
return SecRequirementCreateWithString((__bridge CFStringRef)text, kSecCSDefaultFlags, requirement);
}
static OSStatus DYValidateRunningCode(NSString *identifier) {
SecRequirementRef requirement = NULL;
OSStatus status = DYCreateSigningRequirement(identifier, &requirement);
if (status != errSecSuccess) return status;
SecCodeRef code = NULL;
status = SecCodeCopySelf(kSecCSDefaultFlags, &code);
if (status == errSecSuccess) {
status = SecCodeCheckValidity(code, kSecCSDefaultFlags, requirement);
CFRelease(code);
}
CFRelease(requirement);
return status;
}
static OSStatus DYValidateBundle(NSURL *url, NSString *identifier, SecCSFlags flags) {
SecRequirementRef requirement = NULL;
OSStatus status = DYCreateSigningRequirement(identifier, &requirement);
if (status != errSecSuccess) return status;
SecStaticCodeRef code = NULL;
status = SecStaticCodeCreateWithPath((__bridge CFURLRef)url, kSecCSDefaultFlags, &code);
if (status == errSecSuccess) {
status = SecStaticCodeCheckValidity(code, flags | kSecCSStrictValidate | kSecCSCheckAllArchitectures,
requirement);
CFRelease(code);
}
CFRelease(requirement);
return status;
}
OSStatus DYValidateSignedInstallation(NSURL *wrapperURL, NSString **failedComponent) {
if (failedComponent) *failedComponent = @"wrapper";
OSStatus status = DYValidateBundle(wrapperURL, DYWrapperIdentifier, kSecCSDefaultFlags);
if (status != errSecSuccess) return status;
if (failedComponent) *failedComponent = @"service";
NSURL *serviceURL = [wrapperURL URLByAppendingPathComponent:DYPluginRelativePath isDirectory:YES];
status = DYValidateBundle(serviceURL, DYServiceIdentifier, kSecCSCheckNestedCode);
if (status != errSecSuccess) return status;
// A separately signed older service with the same identity must not be mixed into this build.
NSDictionary *wrapper = [NSDictionary dictionaryWithContentsOfURL:[wrapperURL URLByAppendingPathComponent:@"Contents/Info.plist"]];
NSDictionary *service = [NSDictionary dictionaryWithContentsOfURL:[serviceURL URLByAppendingPathComponent:@"Contents/Info.plist"]];
if (failedComponent) *failedComponent = @"component-build";
if (![wrapper[@"CFBundleVersion"] isEqual:service[@"CFBundleVersion"]] ||
![wrapper[@"CFBundleShortVersionString"] isEqual:service[@"CFBundleShortVersionString"]]) return errSecCSReqFailed;
if (failedComponent) *failedComponent = nil;
return errSecSuccess;
}
OSStatus DYValidateRunningInstallation(DYCodeRole role, NSString **failedComponent) {
BOOL isService = role == DYCodeRoleService;
if (failedComponent) *failedComponent = isService ? @"running-service" : @"running-wrapper";
OSStatus status = DYValidateRunningCode(isService ? DYServiceIdentifier : DYWrapperIdentifier);
if (status != errSecSuccess) return status;
NSURL *bundleURL = NSBundle.mainBundle.bundleURL.URLByResolvingSymlinksInPath;
NSURL *wrapperURL = bundleURL;
if (isService) {
// The service must be embedded in the wrapper being verified.
for (NSInteger level = 0; level < 3; level++) wrapperURL = wrapperURL.URLByDeletingLastPathComponent;
NSURL *expected = [wrapperURL URLByAppendingPathComponent:DYPluginRelativePath isDirectory:YES];
if (failedComponent) *failedComponent = @"service-location";
if (![wrapperURL.pathExtension isEqualToString:@"app"] ||
![bundleURL.path isEqualToString:expected.path]) return errSecCSBadBundleFormat;
}
return DYValidateSignedInstallation(wrapperURL, failedComponent);
}