使用xattr设置Mac OSX隔离属性 [英] Using xattr to set the Mac OSX quarantine property

查看:508
本文介绍了使用xattr设置Mac OSX隔离属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在StackOverflow和其他地方,有很多有关如何清除Mac隔离属性的信息. 就我而言,我想进行设置. 这是为了测试我的应用程序是否已正确签名,以便用户在下载应用程序后立即获得不受信任的开发人员"警告.

There is a lot of information on StackOverflow and elsewhere about how to clear the Mac quarantine property. In my case I would like to set it. This is in order to test that my app is properly signed so that the user will hot get the "Untrusted Developer" warning after downloading it.

我的应用程序特别大(我们通过大文件下载站点而不是商店进行分发),必须上传和下载进行测试并不方便. 过去一周,我在代码签名方面进行了一些角力,因此此测试对我来说很重要.

My app is particularly large (we distribute from a large file download site, not the store) and it is not convenient to have to upload and download to test this. I have had some battles with code signing the past week so this testing is important to me.

文件具有隔离属性后,我将看到如何对其进行更改以具有值:

Once a file has the quarantine property I see how I can alter it to have the values:

0002 = downloaded but never opened (this is the one that causes the warning)
0022 = app aborted by user from the warning dialogue (you hit 'cancel' in the dialogue)
0062 = app opened (at least) once (you hit 'open' in the dialogue)

但是我首先不知道如何赋予它财产.

But I don't know how to give it the property in the first place.

推荐答案

用于此目的的代码并不难,但是您需要FSRef来做到这一点,但不推荐使用.也就是说,它仍然适用于10.9.您必须与CoreServices链接.

The code for this isn't hard, but you need FSRef's to do it, which are deprecated. That said, it still works on 10.9. You have to link with CoreServices.

int main(int argc, const char * argv[]) {
  @autoreleasepool {
    if (argc != 2) {
      printf("quarantine <path>\n");
      exit(1);
    }

    NSString *path = @(argv[1]);
    OSStatus result;
    FSRef pathRef;
    result = FSPathMakeRef((UInt8*)[path UTF8String], &pathRef, 0);
    if (result != noErr) {
      NSLog(@"Error making ref (%d): %s", result, GetMacOSStatusCommentString(result));
      exit(result);
    }

    NSDictionary *quarantineProperties = @{(__bridge id)kLSQuarantineTypeKey: (__bridge id)kLSQuarantineTypeOtherDownload};

    result = LSSetItemAttribute(&pathRef,
                                kLSRolesAll,
                                kLSItemQuarantineProperties,
                                (__bridge CFTypeRef)quarantineProperties);

    if (result != noErr) {
      NSLog(@"Error setting attribute (%d): %s", result, GetMacOSStatusCommentString(result));
    }
    exit(result);
  }
  return 0;
}

另一种方法是将隔离信息从一个文件复制到另一个文件.您可以像这样序列化xattr信息:

Another approach is to just copy the quarantine information from one file to another. You can serialize xattr information like this:

xattr -p com.apple.quarantine file > file.xattr

然后您可以将这些属性应用于另一个文件,如下所示:

You can then apply those attributes to another file like this:

xattr -w com.apple.quarantine "`cat file.xattr`" file

(该应该有效,但是我没有特别进行隔离测试.我使用类似的技术来保存代码签名并重新应用.)

(That should work, but I haven't tested it with quarantining in particular. I use a similar technique to save code signatures and reapply them.)

这篇关于使用xattr设置Mac OSX隔离属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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