简体   繁体   English

如何为OSX和Gatekeeper签署(动态)JNLP文件

[英]How to sign (dynamic) JNLP files for OSX and Gatekeeper

My company produces Java Applications for Servers and delivers JNLP files to start local Applications. 我的公司为服务器生成Java应用程序并提供JNLP文件以启动本地应用程序。 Since OSX 10.8.4 it is required to sign JNLP files with a Developer ID to keep Gatekeeper happy (it's actually in the release notes at the very bottom). 从OSX 10.8.4开始,需要使用开发者ID对JNLP文件进行签名,以保持Gatekeeper的满意度(实际上它位于最底层的发行说明中)。

The question is: how to accomplish this? 问题是:如何实现这一目标? AFAIK you can sign Apps (we have some Java Apps signed with Developer IDs) - but JNLP - Files are just that: files. AFAIK你可以签署应用程序(我们有一些使用开发者ID签名的Java应用程序) - 但JNLP - 文件只是:文件。

Next: how to do this with generated JNLP files. 下一步:如何使用生成的JNLP文件执行此操作。 We have to modify them as they come from a server - eg properties, base URL and so forth. 我们必须修改它们来自服务器 - 例如属性,基本URL等等。

AFAIK Java has a certain mechanism to say JNLP files are signed via their respective JAR file (the one that holds the main class) - but: Jar files are signed with a different certificate they will not satisfy Gatekeeper as well. AFAIK Java有一定的机制可以说JNLP文件是通过它们各自的JAR文件(持有主类的文件)签署的 - 但是:Jar文件使用不同的证书进行签名,它们也不会满足Gatekeeper。

I did find one reference on how to sign tools and stuff , but it does not apply the scenario of dynamic files. 我确实找到了一个关于如何签名工具和东西的参考 ,但它不适用于动态文件的场景。

What I do not want as answers: Right-Click and Open to override the Gatekeeper or change the System- or Java settings. 我不想要的答案:右键单击并打开以覆盖关守或更改系统或Java设置。 This is not an option. 这不是一个选择。

[UPDATE] Since OSX 10.9.5 you also have to sign using OSX 10.9+ and have valid version 2 signatures. [更新]自OSX 10.9.5起,您还必须使用OSX 10.9+进行签名并拥有有效的版本2签名。 How will this be done? 怎么做?

I think I found a solution. 我想我找到了解决方案。 The only one I can currently think up. 我目前唯一能想到的。 We basically need to wrap the JNLP with a custom app launcher, sign the app, make sure we can modify the JNLP on the fly on a server and then have it run. 我们基本上需要用自定义应用程序启动器包装JNLP,签署应用程序,确保我们可以在服务器上动态修改JNLP然后让它运行。

As you may be aware, there is an app bundler project which can wrap up any JAR files into an OSX executable. 您可能知道,有一个应用程序捆绑项目可以将任何JAR文件包装到OSX可执行文件中。 This can be signed, delivered and will not fail Gatekeeper. 这可以签名,交付,也不会失败Gatekeeper。 I made a custom fork (which is up for a pull int o the main fork) that can take an JNLP file, wrap it up and you have a custom application doing just all the stuff a JNLP should do. 我创建了一个自定义分支(主要用于主分叉),它可以获取JNLP文件,将其包装起来,并且您有一个自定义应用程序,只执行JNLP应该执行的所有操作。

A Requirement is, however, that you do have a valid "Developer ID Application" certificate 但是,要求是您拥有有效的“开发者ID申请”证书

  1. Head over to bitbucket.org and download the current version 前往bitbucket.org并下载当前版本
  2. Run the ant task and build the appbundler package. 运行ant任务并构建appbundler包。
  3. Have a look at the documentation for an example build script that will create the app container. 查看将创建应用程序容器的示例构建脚本的文档。
    • The example does not include the JNLP into the application right now. 该示例现在不将JNLP包含到应用程序中。
    • The applications signature is created in a way so that the JNLP file can be modified later. 应用程序签名以某种方式创建,以便稍后可以修改JNLP文件。
    • The application is being put into a zip file. 该应用程序被放入一个zip文件。 This is important for downloading an application since they are only directories 这对于下载应用程序很重要,因为它们只是目录
  4. Create your server code. 创建服务器代码。 Load the ZIP file, put the JNLP File into the directory <yourapp>.app/Contents/Java/ 加载ZIP文件,将JNLP文件放入目录<yourapp>.app/Contents/Java/
  5. Deliver the zip file. 提供zip文件。

Now, if everything went fine, the zip file should automatically be unpacked in the Download folder and you should see your application icon. 现在,如果一切顺利,zip文件应该自动解压缩到Download文件夹中,你应该看到你的应用程序图标。 If you really made no mistake, you can execute the application as if it was a normal one. 如果你真的没有弄错,你可以执行应用程序,就像它是正常的一样。

I hope this will help a lot of developers fixing the broken JNLP behavior with OSX. 我希望这将有助于许多开发人员用OSX修复损坏的JNLP行为。

[UPDATE for modifiable JNLPs] Since OSX 10.9.5 it is required to have valid version 2 signatures on your app. [可修改的JNLP的更新]自OSX 10.9.5起,它需要在您的应用程序上拥有有效的版本2签名。 This means that it the trick that was previously used by the app bundler (set a resource list file) does not work anymore. 这意味着应用程序捆绑器以前使用的技巧(设置资源列表文件)不再起作用。 Everything and anything has to be signed now and it is virtually impossible to change the signed app afterwards. 现在必须签署所有内容和任何内容,之后几乎无法更改已签名的应用程序。

I did however find a way: Use the app bundler. 但我确实找到了一种方法:使用app bundler。 Set the JNLP to a file inside the Contents/_CodeSignature directory. 将JNLP设置为Contents/_CodeSignature目录中的文件。 Do not yet copy your modifiable JNLP in there but do this eg using Java later on when patching the zip (you'll need some code here anyway). 还没有复制你可修改的JNLP,但是这样做,例如稍后在修补zip时使用Java(无论如何你都需要一些代码)。

Please note: this should really only be needed if you have to put another JNLP file dynamically into the app container (thats is what the questions was about) 请注意:如果您必须动态地将另一个JNLP文件放入应用程序容器中(这就是问题所在),这应该只需要这样做

UPDATE (08-2017) 更新(08-2017)

Oracle will be releasing Java 9 by the end of September. Oracle将在9月底发布Java 9。 The appbundler does not handle the java9 vm correctly. appbundler没有正确处理java9 vm。 They changed a whole lot of the API and the way that javaws works. 他们改变了很多API和javaws的工作方式。 For I need to say: stick with java8 if you want to use wrapped JNLP apps. 因为我需要说:如果你想使用包装的JNLP应用程序,请坚持使用java8。

We've been able to determine that you can sign a jnlp file with codesign, using the "Developer ID Application" Certificate, like this: 我们已经能够确定您可以使用“开发者ID应用程序”证书签署带有codesign的jnlp文件,如下所示:

codesign -f -s "Developer ID Application: " foo.jnlp

The result from this operation seems to pass Gatekeeper on the local machine. 此操作的结果似乎通过本地计算机上的Gatekeeper。 However, it seems like the signature gets stored as extended HFS attributes, and as a result, it is not transmitted if a user fetches the file from a HTTP transaction. 但是,似乎签名被存储为扩展HFS属性,因此,如果用户从HTTP事务中获取文件,则不会传输该签名。

It might work if you took the .jnlp file, and packaged it in some kind of container, like a .dmg or maybe a .tar.gz, however, that's both a lot of work, and it provides a fairly challenging user experience. 如果您使用.jnlp文件并将其打包在某种容器中(例如.dmg或.tar.gz),它可能会有效,但是,这既是很多工作,又提供了相当具有挑战性的用户体验。

From an email thread with Apple tech support, it seems the official word is to use the xip tool to work around the reliance on HFS extended attributes with codesign : 从具有Apple技术支持的电子邮件主题,似乎官方的说法是使用xip工具来解决依赖于带有代码codesign HFS扩展属性:

Instead of codesign, use xip (pronounced "chip") to create a signed archive of your JNLP file. 而不是使用codeign,使用xip(发音为“chip”)来创建JNLP文件的签名存档。 Provide your Developer ID Installer identity as the argument to the --sign option, not your Developer ID Application identity. 提供您的Developer ID安装程序标识作为--sign选项的参数,而不是您的开发者ID应用程序标识。

A xip archive is essentially a signed zip archive so it can be served over the Internet in the same way as a zip archive. xip存档本质上是一个签名的zip存档,因此它可以通过Internet以与zip存档相同的方式提供。 It will be unarchived automatically on the client Mac. 它将在客户端Mac上自动取消归档。

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xip.1.html https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xip.1.html

From my experimentation the xip tool always generates an archive with the jnlp contained in a folder when unxip'd. 从我的实验中, xip工具总是生成一个存档,当解压缩时,jnlp包含在文件夹中。

Just to summarise the discussion; 只是总结一下讨论; currently there is no existing solution on how to come around this. 目前还没有关于如何解决这个问题的现有解决方案。

This means that end users cannot launch an application via JNLP easily. 这意味着最终用户无法轻松地通过JNLP启动应用程序。 Basically one needs to tell the user to Right-Click and Open to override the Gatekeeper. 基本上,需要告诉用户右键单击并打开以覆盖Gatekeeper。

The other solution would be to make an signed Mac application and have users install that via disk image. 另一个解决方案是制作一个已签名的Mac应用程序,并让用户通过磁盘映像安装它。

Would it work to bundle a simple executable shell script called something like "myapp" in a signed .dmg which looks like this: 是否可以将一个名为“myapp”的简单可执行shell脚本捆绑在一个签名的.dmg ,如下所示:

javaws http://path/to/my/app.jnlp

that way you can change the .jnlp however you like without changing your .dmg . 这样你可以改变你喜欢的.jnlp而不用改变你的.dmg I don't have an Apple Developer ID, so I can't try it myself right now. 我没有Apple开发者ID,所以我现在不能自己尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM