[英]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(以及其他可能的版本)中,有一个项目属性设置,使您可以通过指定密钥或使用生成密钥来对项目进行签名。
- Open and select your project. 打开并选择您的项目。
- Select File -> Project Properties. 选择文件->项目属性。
- Select "Web Start" 选择“ Web Start”
- If not already enabled, Check the "Enable Web Start" check box. 如果尚未启用,请选中“启用Web启动”复选框。
- Select the Customize... button in the Signing: section of the Webstart properties tab. 在Webstart属性选项卡的“签名:”部分中选择“自定义...”按钮。
- Click the radio button for either Self-sign by generated key -or- Sign by a specified key and enter the Key information. 单击单选按钮以使用“通过生成的密钥进行自签名”或“通过指定的密钥进行签名”,然后输入“密钥”信息。
- 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: 开发环境:
Step 1: Getting the app to run with an "Unrestricted Access" popup. 步骤1:通过“不受限制的访问”弹出窗口使应用运行。
Step 2: Getting the app to run with a "Restricted Access" popup. 第2步:通过“受限访问”弹出窗口使应用运行。
Tested with Firefox and IE. 经过Firefox和IE测试。 Does not work with Chrome. 不适用于Chrome。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.