简体   繁体   English

如何使用NetBeans自签名Applet?

[英]How to self-sign an applet with NetBeans?

In the previous months I developed a sandbox applet for an academic project. 在过去的几个月中,我为一个学术项目开发了一个沙盒小程序。 Due to the Java 1.7.51 security restrictions to applets, I have been trying to self-sign my applet with the hope that it can comply or overcome JRE's requisites for applets. 由于Java 1.7.51对applet的安全性限制,我一直在尝试对自己的applet进行自签名,希望它可以符合或克服JRE对applet的要求。

I'm using NetBeans and I have taken as a point of departure some links that show how to self-sign a jar file. 我使用的是NetBeans,我以一些链接为出发点,这些链接显示了如何自签名jar文件。 Unfortunately, I haven't been able to get it working. 不幸的是,我无法使其正常运行。

I have tried to add the following instructions on the build.xml file: 我试图在build.xml文件中添加以下说明:

<target name="-post-jar" depends="signing_procedure">
</target>

<target name="signing_procedure" depends="">
    <echo message="Signing ${dist.dir}/MyFile.jar"/>
    <exec dir="C:/Program Files/Java/jdk1.7.0_25/bin/" executable="jarsigner.exe">
        <arg value="-verbose" />
        <arg value="-keystore" />
        <arg value="C:/Program Files/Java/jdk1.7.0_25/bin/MyKeyStore.jks" />
        <arg value="-storepass" />
        <arg value="mystorepass" />
        <arg value="-keypass" />
        <arg value="mykeypass" />
        <arg value="C:/Users/Charles/Documents/ProjectsFolder/MyProject/dist/MyFile.jar" />
        <arg value="MyAlias" />
    </exec>
</target>

I receive the following error message: 我收到以下错误消息:

Execute failed: java.io.IOException: Cannot run program "jarsigner.exe": error=2, The specified file is not found

I would deeply thank you for your help, and much more if it is adressed to NetBeans! 非常感谢您的帮助,如果NetBeans有此帮助,还要感谢您!

The parameter dir is not where your executable is located. 参数dir不在可执行文件所在的位置。 It is the directory where it will be executed. 这是将在其中执行的目录。

<exec executable="C:/Program Files/Java/jdk1.7.0_25/bin/jarsigner.exe">

If you want to keep the exec like it was, you'll need to set resolveexecutable parameter to true. 如果要保持exec resolveexecutable ,则需要将resolveexecutable参数设置为true。 From Ant manual : Ant手册

When this attribute is true, the name of the executable is resolved firstly against the project basedir and if that does not exist, against the execution directory if specified. 当此属性为true时,将首先针对基于项目的项目解析可执行文件的名称,如果不存在,则针对执行目录进行解析(如果已指定)。 On Unix systems, if you only want to allow execution of commands in the user's path, set this to false. 在Unix系统上,如果只想允许在用户路径中执行命令,请将其设置为false。 since Ant 1.6 从Ant 1.6开始

I figured out how to do it. 我想出了怎么做。 The following lines need to be added to the build.xml, under the tab Files of the corresponding project on NetBeans: 需要在NetBeans上相应项目的文件选项卡下,将以下行添加到build.xml中:

<target name="-post-jar" depends="Signing Procedure">
</target>

<target name="Signing procedure" depends="">
    <echo message="Signing ${dist.dir}/MyAppet.jar..."/>
    <exec dir="${dist.dir}" executable="C:/Program Files/Java/jdk1.7.0_25/bin/jarsigner.exe">
        <arg value="-verbose" />
        <arg value="-keystore" />
        <arg value="C:/Program Files/Java/jdk1.7.0_25/bin/MyKeyStore.jks" />
        <arg value="-storepass" />
        <arg value="mystorepassword" />
        <arg value="-keypass" />
        <arg value="mykeypassword" />
        <arg value="C:/Users/Charles/Documents/MyNetBeansProjects/MyProject/dist/MyApplet.jar" />
        <arg value="MySelfSignatureAlias" />
    </exec>
</target>

I hope this is useful to other users! 我希望这对其他用户有用!

In Netbeans 8.0.1 (and likely others), there is a project properties setting that gives you the option to sign your project by specifying a key or using generating a key. 在Netbeans 8.0.1(以及其他可能的版本)中,有一个项目属性设置,使您可以通过指定密钥或使用生成密钥来对项目进行签名。

  1. Open and select your project. 打开并选择您的项目。
  2. Select File -> Project Properties. 选择文件->项目属性。
  3. Select "Web Start" 选择“ Web Start”
  4. If not already enabled, Check the "Enable Web Start" check box. 如果尚未启用,请选中“启用Web启动”复选框。
  5. Select the Customize... button in the Signing: section of the Webstart properties tab. 在Webstart属性选项卡的“签名:”部分中选择“自定义...”按钮。
  6. Click the radio button for either Self-sign by generated key -or- Sign by a specified key and enter the Key information. 单击单选按钮以使用“通过生成的密钥进行自签名”或“通过指定的密钥进行签名”,然后输入“密钥”信息。
  7. Select how to handle mixed code. 选择如何处理混合代码。

For a more detailed description of this, you can view the help in Netbeans and search for Standard Java SE Project Properties Dialog Box: Web Start . 有关此内容的详细说明,您可以在Netbeans中查看帮助,并搜索“ Standard Java SE Project Properties Dialog Box: Web Start The details should be in the first result that pops up. 详细信息应在弹出的第一个结果中。

Also note the following warning you can expect to sign if you do not have a trusted certificate. 另外,请注意以下警告,如果您没有受信任的证书,则可能会希望对其进行签名。

Warning: Unsigned and self-signed WebStart applications and Applets are deprecated from JDK7u21 onwards due to security reasons. 警告:由于安全原因,从JDK7u21开始不推荐使用未签名和自签名的WebStart应用程序和Applet。 To ensure future correct functionality please sign WebStart applications and Applets using trusted certificate. 为了确保将来的正确功能,请使用受信任的证书对WebStart应用程序和小程序进行签名。

My JavaFX application needed to run in the sandbox. 我的JavaFX应用程序需要在沙箱中运行。 Here is my path to success.. 这是我的成功之路。

Development environment: 开发环境:

  • Netbeans 8.0.2, Netbeans 8.0.2,
  • jre1.8.0_45 jre1.8.0_45
  • jdk1.8.0_25 jdk1.8.0_25
  • apache-tomcat-7.0.61-windows-x64 Apache的Tomcat的7.0.61-Windows的64位
  • Window 7 Pro 视窗7专业版
  • Firefox 37.0.2 Firefox 37.0.2

Step 1: Getting the app to run with an "Unrestricted Access" popup. 步骤1:通过“不受限制的访问”弹出窗口使应用运行。

  • Since all applets and JNLPs (RIAs) must be signed, create a self-signed cert outside of NetBeans. 由于必须对所有小程序和JNLP(RIA)进行签名,因此请在NetBeans外部创建一个自签名证书。
  • Add the cert to java's cacerts by using the Java Console. 使用Java控制台将证书添加到Java的cacerts中。 This will allow you to test without buying a cert. 这将使您无需购买证书即可进行测试。 BTW, do not buy the inexpensive "Java Code Signing" Comodo cert as I did. 顺便说一句,不要像我那样买便宜的“ Java代码签名” Comodo证书。 The Comodo root certificate is not in Java's cacerts. Comodo根证书不在Java的cacerts中。 As a result applets will not run in Firefox. 结果,小程序将无法在Firefox中运行。
  • Add your cert to IE's keystore to enable your applet to run in IE. 将证书添加到IE的密钥库中,以使小程序能够在IE中运行。 BTW, a Comodo cert will run in IE. 顺便说一句,Comodo证书将在IE中运行。 IE uses the Windows keystore instead of Java's. IE使用Windows密钥库而不是Java。 Microsoft recognizes Comodo as a root CA while Oracle does not. Microsoft将Comodo识别为根CA,而Oracle没有。
  • Go to Project->Properties->Build->Deployment. 转到项目->属性->构建->部署。
  • Check "Request unrestricted access (enable signing)." 选中“请求不受限制的访问(启用签名)”。 This will cause the main and dependent jars to be signed. 这将导致对主jar和从属jar进行签名。
  • Click the "Edit" button and configure the self-signed certificate. 单击“编辑”按钮并配置自签名证书。
  • Go to Project->Properties->Build->Packaging->Custom Manifest Properties. 转到项目->属性->构建->包装->自定义清单属性。
  • Click "Edit." 点击“编辑”。 Add the property "Application-Name" and give it a value. 添加属性“ Application-Name”并为其提供一个值。
  • Go to Files->nbproject->project.properties->manifest.custom.permissions. 转到文件-> nbproject-> project.properties-> manifest.custom.permissions。
  • Set the value to "all-permissions". 将该值设置为“所有权限”。
  • Go to Files->nbproject->project.properties->manifest.custom.codebase. 转到文件-> nbproject-> project.properties-> manifest.custom.codebase。
  • Set the value to "*". 将值设置为“ *”。
  • Click "Clean and Build." 单击“清理并生成”。 Note that the script signs the project jar as well as the dependent jars. 请注意,脚本对项目jar以及从属jar进行签名。 It places the signed jars in dist/lib. 它将签名的罐子放在dist / lib中。
  • Click "Run." 点击“运行”。 Note that Netbean's run script deletes the dist/lib folder and copies the unsigned ones to dist/lib. 请注意,Netbean的运行脚本会删除dist / lib文件夹,并将未签名的文件夹复制到dist / lib。
  • The project should now run with the "Unsigned code detected error" popup. 现在,该项目应在“未检测到代码错误”弹出窗口中运行。
  • To save confusion you may want to sign any dependent jars outside of Netbeans since Clean and Build signs the dependent jars and then deletes them at Run time. 为了避免混淆,您可能需要在Netbeans之外签名任何依赖的jar,因为Clean and Build在依赖的jar上签名,然后在运行时将其删除。 Curiously if you just click Run instead of preceding it with a Clean and Build Netbeans copies the dependent jars and then signs them before running. 奇怪的是,如果您仅单击“运行”而不是在其前面添加“清理并构建”,则Netbeans将复制相关的jar,然后在运行之前对其进行签名。 Is this a feature or a bug? 这是功能还是错误? Inquiring minds would like to know. 想问的人想知道。
  • Make a nonfunctional edit. 进行无功能的编辑。 Click "Run." 点击“运行”。
  • The applet and JNLP should now run with an "Unrestricted access" popup. 小程序和JNLP现在应该在“不受限制的访问”弹出窗口中运行。

Step 2: Getting the app to run with a "Restricted Access" popup. 第2步:通过“受限访问”弹出窗口使应用运行。

  • Go to Files->nbproject->project.properties->manifest.custom.permissions. 转到文件-> nbproject-> project.properties-> manifest.custom.permissions。
  • Set the value to "sandbox". 将值设置为“ sandbox”。
  • Go to Files->nbproject->project.properties->javafx.deploy.permissionselevated. 转到文件-> nbproject-> project.properties-> javafx.deploy.permissionselevated。
  • Set the value to "false." 将该值设置为“ false”。
  • Start up a server, for example Tomcat. 启动服务器,例如Tomcat。 I installed it separately from Netbeans. 我将其与Netbeans分开安装。
  • Build and deploy the dist folder to Tomcat's webapps folder. 将dist文件夹构建并部署到Tomcat的webapps文件夹。 them in the project. 他们在项目中。
  • Go to Files->nbproject->project.properties->manifest.custom.codebase. 转到文件-> nbproject-> project.properties-> manifest.custom.codebase。 Set the value to the server's network address, for example 192.168.1.45. 将值设置为服务器的网络地址,例如192.168.1.45。
  • Invoke the applet by running it from the server, for example http:192.168.1.45:8080/dist/MyApp.html. 通过从服务器运行小程序来调用该小程序,例如http:192.168.1.45:8080 / dist / MyApp.html。

Tested with Firefox and IE. 经过Firefox和IE测试。 Does not work with Chrome. 不适用于Chrome。

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

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