Можно ли использовать VisualTreeHelper. HitTest?
http://lukieb.blogspot.com/2008/07/visualtreehelperhittest.html
If you're targeting 10.6+ you can use the code signing functions in the Security framework (documentation), in particular SecCodeCheckValidity. Otherwise, the source code to the code signing system is in libsecurity_codesigning.
Since you're using the code signature to authenticate your code you should also validate the designated requirement with SecCodeCopyDesignatedRequirement.
Спасибо, друг!
Мне удалось сделать это для 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");