我很难找到我的协同设计问题的答案。
我们有一个在Cocoa下编写的Mac OS应用程序。最后,我们完成了协同设计,但我想在可执行文件本身中添加一个额外的安全检查。
我的想法是在当前可执行文件启动时验证用于签名的证书的指纹。如果它丢失或无效(根据应用程序中的硬编码散列进行检查)-我们将其关闭。
到目前为止,我还不能获得用于以编程方式协同设计可执行文件并检查其数据的证书。
有没有人知道该怎么做?
非常感谢你!马丁·K。
发布于 2009-12-10 09:00:37
谢谢你,朋友!
我设法用新功能在10.6中做到了这一点,但问题是我的目标是10.5和10.6,至少在一段时间内是这样。
我必须投入更多的时间在libsecurity_codesigning上,所以这也可以在10.5完成。
但是,对于正在寻找现成解决方案的人来说,以下是我最终得到的结论:
SecStaticCodeRef ref = NULL;
NSURL * url = [NSURL URLWithString:[[NSBundle mainBundle] executablePath]];
OSStatus status;
// obtain the cert info from the executable
status = SecStaticCodeCreateWithPath((CFURLRef)url, kSecCSDefaultFlags, &ref);
if (ref == NULL) exit(EXIT_STATUS_ON_BAD_CODE_SIGNATURE);
if (status != noErr) exit(EXIT_STATUS_ON_BAD_CODE_SIGNATURE);
SecRequirementRef req = NULL;
// this is the public SHA1 fingerprint of the cert match string
NSString * reqStr = [NSString stringWithFormat:@"%@ %@ = %@%@%@",
@"certificate",
@"leaf",
@"H\"66875745923F01",
@"F122B387B0F943",
@"X7D981183151\""
];
// create the requirement to check against
status = SecRequirementCreateWithString((CFStringRef)reqStr, kSecCSDefaultFlags, &req);
if (status != noErr) exit(EXIT_STATUS_ON_BAD_CODE_SIGNATURE);
if (req == NULL) exit(EXIT_STATUS_ON_BAD_CODE_SIGNATURE);
status = SecStaticCodeCheckValidity(ref, kSecCSCheckAllArchitectures, req);
if (status != noErr) exit(EXIT_STATUS_ON_BAD_CODE_SIGNATURE);
CFRelease(ref);
CFRelease(req);
LogDebug(@"Code signature was checked and it seems OK");发布于 2009-11-30 04:41:25
如果您的目标是10.6+,那么您可以使用安全框架(documentation)中的代码签名函数,特别是SecCodeCheckValidity。否则,代码签名系统的源代码就是libsecurity_codesigning。
由于您要使用代码签名来验证代码,因此还应该使用SecCodeCopyDesignatedRequirement验证指定的需求。
https://stackoverflow.com/questions/1815506
复制相似问题