用于OS X Gatekeeper的代码签名Java应用程序

Hug*_*otl 6 java macos code-signing app-bundle osx-gatekeeper

我正在尝试将Java应用程序分发给OS X用户.我没有使用Mac商店 - 它将通过我自己的网站分发.无论我尝试什么,OS X的Gatekeeper拒绝该应用程序.

这是我的方法:

(1)像往常一样构建应用程序,获取一个JAR文件

(2)appbundler按照此处的描述使用:https://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html.这会在我的JAR周围创建一个运行良好的.app,并在MyApp.app/Contents/PlugIns目录中包含JVM .

(3)使用我的开发者证书签署应用程序:

codesign -s 'Developer ID Application: MyCompany Ltd' --deep MyApp.app

...过程成功完成

(4)确认.app将遵守关守的铁拳法则:

spctl --assess --verbose=4 --type execute MyApp.app

......我得到的结果是:

MyApp.app: a sealed resource is missing or invalid
Run Code Online (Sandbox Code Playgroud)

对我来说似乎不是很啰嗦!我能做错什么?或者我怎样才能获得更多信息?

SO /谷歌搜索"密封的资源......"是指签名框架(我没有)或建议使用--force选项签名(我尝试但不起作用).

whi*_*der 7

你不能使用--deep.这听起来像是正确的选项,因为您还需要对嵌入式JRE进行签名,但它不起作用.来自Apple的文档:

重要提示:虽然--deep选项可以应用于签名操作,但不建议这样做.我们建议您在各个阶段内部签署代码(因为Xcode会自动执行).使用--deep签名仅用于紧急维修和临时调整.

经过大量的拉扯,我从各种教程中拼凑出来. 这个是最有帮助的.这是我作为Ant脚本的最终解决方案:

<!-- code sign -->
<exec executable="chmod">
    <arg line="a+w ${build.dir}/Mac/MyApp.app/Contents/PlugIns/jre"/>
</exec>

<apply executable="codesign"> <!-- note: this loops through the contents of dir -->
    <arg line="-f -s 'Developer ID Application: My Organization'"/>
    <fileset dir="${build.dir}/Mac/MyApp.app/Contents/PlugIns/jre" />
</apply>

<exec executable="codesign" dir="${build.dir}/Mac"> 
    <arg line="-f -s 'Developer ID Application: My Organization' MyApp.app/Contents/PlugIns/jre"/>
</exec>

<exec executable="codesign" dir="${build.dir}/Mac"> 
    <arg line="-f -s 'Developer ID Application: My Organization' MyApp.app/Contents/PlugIns/jre/Contents/_CodeSignature/CodeResources"/>
</exec>

<!-- also codesign anything else in _CodeSignature (see comments) -->

<exec executable="codesign" dir="${build.dir}/Mac">
    <arg line="-f -s 'Developer ID Application: My Organization' MyApp.app"/>
</exec>


<!-- verify codesign -->
<exec executable="codesign" dir="${build.dir}/Mac" failonerror="true">
    <arg line="-vv MyApp.app"/>
</exec>


<!-- verify gatekeeper -->
<exec executable="spctl" dir="${build.dir}/Mac" failonerror="true">
    <arg line="-vv --assess --type execute MyApp.app"/>
</exec>
Run Code Online (Sandbox Code Playgroud)

需要注意的另一件事是zip在签名后不使用命令行打包您的应用程序,因为它会破坏应用程序的协同设计.您应该使用productbuild,PackageMaker xip或dmg 打包它.