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

时间:2014-11-14 20:36:15

标签: java macos code-signing osx-gatekeeper app-bundle

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

这是我的方法:

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

(2)使用此处所述的appbundlerhttps://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

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

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

1 个答案:

答案 0 :(得分:6)

您无法使用--deep。这听起来是正确的选择,因为您还需要签署嵌入式JRE,但它不会起作用。来自Apple's docs

  

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

经过大量的拉扯,我从各种教程中拼凑出来。 This one是最有帮助的。这是我作为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>

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

相关问题