SMJobBless返回错误4098 [英] SMJobBless returning error 4098

查看:164
本文介绍了SMJobBless返回错误4098的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SMJobBless安装安全的帮助程序工具.当它失败时,在调用SMJobBless之前,我正在调用SMJobRemove,因为我需要删除该工具的较旧版本,并且此操作成功. SMJobBless返回的错误代码为4098.NSError对象只是告诉我操作无法完成.CodeSigning子系统中存在错误."

I am trying to install a secure helper tool with SMJobBless. When it fails and before calling SMJobBless, I am calling SMJobRemove because I need to remove an older version of the tool and this succeeds. SMJobBless is returning an error code of 4098. The NSError object is only telling me that "The operation couldn't be completed. There was an error in the CodeSigning subsystem."

如果我重新运行代码,SMJobBless函数将起作用.我认为这是因为它先前已被删除,但是为什么它第一次不能使用?然后,我可以与该工具进行通信,并且一切正常.观察到一切正常,我相信可以确定我满足文档中描述的SMJobBless的五个要求.

If I rerun my code, the SMJobBless function works. I would assume this is because it was removed previously, but why would it have not worked the first time? I can then communicate with the tool and everything functions normally. Observing that everything is functioning normally, I believe I can be certain that I am meeting the five requirements for SMJobBless as described in the documentation.

如果我增加工具的版本并重试,SMJobRemove将起作用,但是SMJobBless仍将出现错误代码4098.

If I increment the version of my tool and try again, SMJobRemove will work, but, again, SMJobBless with the error code 4098.

如果有关系,我正在使用OS X 10.7.3.

If it matters, I am using OS X 10.7.3.

推荐答案

是在代码签名的帮助程序工具上调用CFBundleCopyInfoDictionaryForURL吗?

Could it be that you're calling CFBundleCopyInfoDictionaryForURL on the code signed helper tool?

如果是这样,则似乎该函数似乎破坏了代码签名的有效性. (大概是因为CFBundle修改了内存中的Info.plist数据,但这只是我的猜测.)

If so, it appears as though this function seems to break the code signing validity. (Presumably because CFBundle modifies the Info.plist data in memory, but this is just my guess.)

解决方案是使用SecCodeCopySigningInformation来读取帮助程序工具的版本信息:

The solution is to use SecCodeCopySigningInformation to read the helper tool's version info:

-(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的SMJobKit .

To give credit where it's due: the vital piece of information regarding CFBundleCopyInfoDictionaryForURL came from Ian MacLeod's SMJobKit.

这篇关于SMJobBless返回错误4098的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆