Reject modified Dayu Color bundles at registration, service startup and update
这个提交包含在:
1 父节点
a7508203d1
当前提交
db6b2b05b3
9 个文件已更改
+237
-22
没有与搜索条件相匹配的文件
@@ -1,5 +1,6 @@
|
||||
#import "DYBetaUpdater.h"
|
||||
#import "../Shared/DYBetaDiagnostics.h"
|
||||
#import "../Shared/DYCodeIntegrity.h"
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#include <atomic>
|
||||
@@ -31,6 +32,7 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
NSURL *_package;
|
||||
NSDictionary *_state,*_manifest;
|
||||
std::atomic_uint _generation;
|
||||
BOOL _integrityRejected;
|
||||
}
|
||||
- (void)emit:(NSString *)phase message:(NSString *)message;
|
||||
@end
|
||||
@@ -57,6 +59,21 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
if(!NSThread.isMainThread){dispatch_async(dispatch_get_main_queue(),^{[self emit:phase message:message];});return;}
|
||||
[_state release];_state=[@{@"phase":phase,@"message":message?:@"",@"version":_manifest[@"version"]?:@""}copy];if(self.changed)self.changed(_state);
|
||||
}
|
||||
- (BOOL)requireOfficialInstallation {
|
||||
if (_integrityRejected) return NO;
|
||||
if (DYValidateRunningInstallation(DYCodeRoleWrapper, NULL) == errSecSuccess) return YES;
|
||||
[self stopForIntegrityFailure];
|
||||
return NO;
|
||||
}
|
||||
- (void)stopForIntegrityFailure {
|
||||
if (_integrityRejected) return;
|
||||
_integrityRejected = YES;
|
||||
++_generation;
|
||||
[_task cancel];
|
||||
[_manifest release]; _manifest = nil;
|
||||
[_package release]; _package = nil;
|
||||
[self emit:@"integrity_rejected" message:DYIntegrityRecoveryMessage];
|
||||
}
|
||||
+ (BOOL)validateManifest:(NSDictionary *)manifest error:(NSError **)error {
|
||||
if(![manifest isKindOfClass:NSDictionary.class]){if(error)*error=DYUpdateError(@"公测更新清单格式错误。");return NO;}
|
||||
id build=manifest[@"build"],size=manifest[@"size"];
|
||||
@@ -90,13 +107,12 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
}
|
||||
if(apps.count!=1){if(error)*error=DYUpdateError(@"更新包必须包含一个完整的大鱼调色 APP。");return NO;}
|
||||
NSURL *app=apps.firstObject;NSDictionary *info=[NSDictionary dictionaryWithContentsOfURL:[app URLByAppendingPathComponent:@"Contents/Info.plist"]];
|
||||
NSDictionary *plugin=[NSDictionary dictionaryWithContentsOfURL:[app URLByAppendingPathComponent:@"Contents/PlugIns/大鱼调色 XPC Service.pluginkit/Contents/Info.plist"]];
|
||||
NSURL *service=[app URLByAppendingPathComponent:DYPluginRelativePath isDirectory:YES];
|
||||
NSDictionary *plugin=[NSDictionary dictionaryWithContentsOfURL:[service URLByAppendingPathComponent:@"Contents/Info.plist"]];
|
||||
if(![info[@"CFBundleIdentifier"]isEqual:@"com.dayu.color"]||![plugin[@"CFBundleIdentifier"]isEqual:@"com.dayu.color.XPC"]||
|
||||
[info[@"CFBundleVersion"]integerValue]!=[manifest[@"build"]integerValue]||[plugin[@"CFBundleVersion"]integerValue]!=[manifest[@"build"]integerValue]||
|
||||
![info[@"CFBundleShortVersionString"]isEqual:manifest[@"version"]]){if(error)*error=DYUpdateError(@"更新包产品或版本与清单不一致。");return NO;}
|
||||
if(!command(@"/usr/bin/codesign",@[@"--verify",@"--deep",@"--strict",app.path],error))return NO;
|
||||
NSString *identity=command(@"/usr/bin/codesign",@[@"-dvvv",app.path],error);
|
||||
if(![identity containsString:@"TeamIdentifier=B3W25FX5H5"]){if(error)*error=DYUpdateError(@"包内 APP 签名团队不匹配。");return NO;}
|
||||
if(DYValidateSignedInstallation(app,NULL)!=errSecSuccess){if(error)*error=DYUpdateError(@"更新包内的 APP 或插件未通过官方签名验证。");return NO;}
|
||||
// Product PKGs install the wrapper at its fixed FxPlug location and carry templates.
|
||||
BOOL appTarget=NO,templates=NO;
|
||||
for(NSURL *url in [NSFileManager.defaultManager enumeratorAtURL:inspection includingPropertiesForKeys:nil options:0 errorHandler:nil]){
|
||||
@@ -116,6 +132,7 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
}
|
||||
- (void)check {
|
||||
NSString *phase=_state[@"phase"];if([@[@"checking",@"downloading",@"validating"]containsObject:phase])return;
|
||||
if (![self requireOfficialInstallation]) return;
|
||||
unsigned generation=++_generation;[self emit:@"checking" message:@"正在检查公测更新…"];
|
||||
NSString *url=[NSString stringWithFormat:@"https://dayu.media/wp-json/dayu-color/v1/update?bundle_id=com.dayu.color&channel=beta¤t_build=%@",([NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]?:@"0")];
|
||||
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:6];
|
||||
@@ -137,6 +154,7 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
}
|
||||
- (void)download {
|
||||
if(![_state[@"phase"]isEqual:@"available"])return;NSError *error=nil;
|
||||
if (![self requireOfficialInstallation]) return;
|
||||
if(![DYBetaUpdater validateManifest:_manifest error:&error]){[self emit:@"failed" message:error.localizedDescription];return;}
|
||||
if([_manifest[@"build"]integerValue]<=[[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]integerValue])return;
|
||||
unsigned generation=++_generation;NSDictionary *manifest=[[_manifest copy]autorelease];[self emit:@"downloading" message:@"正在下载公测更新,可随时取消。"];
|
||||
@@ -147,7 +165,9 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
if(!error&&[(NSHTTPURLResponse*)response statusCode]==200&&DYBetaAllowedURL(response.URL,YES)){
|
||||
[NSFileManager.defaultManager removeItemAtURL:destination error:nil];
|
||||
if([NSFileManager.defaultManager moveItemAtURL:temporary toURL:destination error:&error]){
|
||||
[self emit:@"validating" message:@"正在验证完整性、签名、公证和插件版本…"];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if(generation==self->_generation.load()) [self emit:@"validating" message:@"正在验证完整性、签名、公证和插件版本…"];
|
||||
});
|
||||
BOOL valid=[DYBetaUpdater validatePackage:destination manifest:manifest error:&error];
|
||||
if(!valid&&!error)error=DYUpdateError(@"更新包未通过验证。");
|
||||
}
|
||||
@@ -163,15 +183,20 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
}
|
||||
- (void)install {
|
||||
if(![@[@"ready",@"host_wait",@"installer"]containsObject:_state[@"phase"]])return;
|
||||
if (![self requireOfficialInstallation]) return;
|
||||
for(NSString *ID in @[@"com.apple.FinalCut",@"com.apple.FinalCutApp",@"com.apple.motionapp",@"com.apple.motionappApp"])
|
||||
if([NSRunningApplication runningApplicationsWithBundleIdentifier:ID].count){[self emit:@"host_wait" message:@"请先保存并正常退出 FCP / Motion,再点击安装更新。不会强制退出宿主。"];
|
||||
DYBetaEvent(@"update_installer",@{@"status":@"waiting_for_host"});return;}
|
||||
if(_package&&[NSWorkspace.sharedWorkspace openURL:_package]){
|
||||
if (!_package || ![digest(_package) isEqualToString:_manifest[@"sha256"]]) {
|
||||
[self emit:@"failed" message:@"更新包已更改或不可读。请重新检查并下载更新。"];
|
||||
return;
|
||||
}
|
||||
if([NSWorkspace.sharedWorkspace openURL:_package]){
|
||||
[NSUserDefaults.standardUserDefaults setObject:_manifest[@"build"] forKey:@"betaPendingUpdateBuild"];[self emit:@"installer" message:@"已打开系统安装程序,请按提示授权并完成安装。"];
|
||||
DYBetaEvent(@"update_installer",@{@"status":@"system_installer_opened"});}
|
||||
else [self emit:@"failed" message:@"无法打开系统安装程序,请重试。"];
|
||||
}
|
||||
- (void)cancel {++_generation;[_task cancel];BOOL newer=[_manifest[@"build"]integerValue]>[[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]integerValue];[self emit:newer?@"available":@"idle" message:@"已取消,不影响当前插件。"];}
|
||||
- (void)cancel {if(_integrityRejected)return;++_generation;[_task cancel];BOOL newer=[_manifest[@"build"]integerValue]>[[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]integerValue];[self emit:newer?@"available":@"idle" message:@"已取消,不影响当前插件。"];}
|
||||
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest *))completion {
|
||||
BOOL download=[task isKindOfClass:NSURLSessionDownloadTask.class];completion(DYBetaAllowedURL(request.URL,download)?request:nil);
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户