我正在尝试用SMJobBless安装一个安全的助手工具。当它失败时,在调用SMJobBless之前,我调用SMJobRemove,因为我需要删除该工具的一个较旧版本,而这成功了。SMJobBless返回错误代码4098。NSError对象只告诉我“操作无法完成,CodeSigning子系统出现错误”。
如果我重新运行我的代码,SMJobBless函数可以工作。我假设这是因为它之前被删除了,但为什么它在第一次就不能工作呢?然后我就可以和这个工具通信了,一切都正常了。观察到一切都运行正常,我相信我可以确定我满足了文档中描述的SMJobBless的五个要求。
如果我递增工具的版本并重试,SMJobRemove将工作,但再次执行SMJobBless,错误代码为4098。
如果重要的话,我使用的是OS 10.7.3。
发布于 2013-03-01 02:16:37
会不会是你在代码签名帮助器工具上调用CFBundleCopyInfoDictionaryForURL?
如果是这样的话,这个函数似乎破坏了代码签名的有效性。(可能是因为CFBundle修改了内存中的Info.plist数据,但这只是我的猜测。)
解决方案是使用SecCodeCopySigningInformation读取辅助工具的版本信息:
-(NSString *) bundleVersionForCodeSignedItemAtURL:(NSURL *)url {
OSStatus status;
// Sanity check -- nothing begets nothing
if (!url) {
return nil;
}
// Get the binary's static code
SecStaticCodeRef codeRef;
status = SecStaticCodeCreateWithPath((CFURLRef)url, kSecCSDefaultFlags, &codeRef);
if (status != noErr) {
NSLog(@"SecStatucCodeCreateWithPath() error for %@: %d", url, status);
return nil;
}
// Get the code signature info
CFDictionaryRef codeInfo;
status = SecCodeCopySigningInformation(codeRef, kSecCSDefaultFlags, &codeInfo);
if (status != noErr) {
NSLog(@"SecCodeCopySigningInformation() error for %@: %d", url, status);
CFRelease(codeRef);
return nil;
}
// The code signature info gives us the Info.plist that was signed, and
// from there we can retrieve the version
NSDictionary *bundleInfo = (NSDictionary *) CFDictionaryGetValue(codeInfo, kSecCodeInfoPList);
NSString *version = [bundleInfo objectForKey:@"CFBundleVersion"];
// We have ownership of the code signature info, so we must release it.
// Before we do that, we need to hold onto the version otherwise we go
// crashing and burning.
[[version retain] autorelease];
CFRelease(codeInfo);
CFRelease(codeRef);
return version;
}值得称赞的是:关于CFBundleCopyInfoDictionaryForURL的重要信息来自Ian MacLeod's SMJobKit。
https://stackoverflow.com/questions/10817785
复制相似问题