如何对 Java 小程序进行签名以便在浏览器中使用?

发布于 2024-07-22 04:43:32 字数 869 浏览 8 评论 0原文

我正在尝试在我的网站上部署 Java 小程序。 我还需要签名,因为我需要访问剪贴板。 我已经遵循了我能找到的所有签名教程,但没有取得任何成功。 以下是我到目前为止所做的工作:

  • 在 NetBeans 中编写了一个小程序。 它在小程序查看器中运行良好。
  • 用它制作了一个 .jar 文件。
  • 通过这样做创建了一个证书:
keytool -genkey -keyalg rsa -alias myKeyName 
  keytool -export -alias myKeyName -file myCertName.crt 
  
  • 像这样用 jarsigner 签名:
jarsigner "C:\my path\myJar.jar" myKeyName 
  
  • 制作了一个包含以下内容的 html 文件:
<代码> 
    <正文> 
  /> 
     
   
   

当我打开该 html 文件时,我从未出现安全确认对话框(因此出现“java.security.AccessControlException:访问被拒绝”错误)。 所有浏览器都会发生这种情况。

我是不是少了一步?

I'm trying to deploy a Java applet on my website. I also need to sign it, because I need to access the clipboard. I've followed all the signing tutorials I could find but have not had any success. Here is what I've done so far:

  • Wrote an applet in NetBeans. It runs fine in the applet viewer.
  • Made a .jar file out of it.
  • Created a certificate by doing this:
keytool -genkey -keyalg rsa -alias myKeyName
keytool -export -alias myKeyName -file myCertName.crt
  • Signed it wtih jarsigner like this:
jarsigner "C:\my path\myJar.jar" myKeyName
  • Made an html file containing this:
<html>
  <body>
<applet code="my/path/name/myApplet.class" archive="../dist/myJar.jar"/>
  </body>
</html>

When I open that html file, I never get the security confirmation dialog box (and thus get the "java.security.AccessControlException: access denied" error). This happens on all browsers.

Am I missing a step?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

初心未许 2024-07-29 04:43:33

也许是因为您在 jar 文件外部打开了一些 .class 文件?

这样它可能不会显示警告。 我尝试这样做,但它仍然向我显示证书警告,对于一个简单的情况,它实际上阻止我从具有分离类的 JAR 中访问类。

也许您的特定设置或文件组织会导致该行为。 如果您可以更详细地布局,我们可以提供更好的帮助(或者更确切地说,尝试将所有这些 .class 文件放入另一个签名的 Jar 中并将其添加到存档“..., anotherJar.jar”)。

Perhaps it's because you're opening some .class files outside the jar file?

That way it may not display the warning. I tried doing it that way but it still showed me the certificate warning and for a simple case it actually prevented me from accessing a class from the JAR with the separated class.

Maybe your specific setup or file organization causes that behavior. If you can layout that in more detail we could help better (or rather, try putting all those .class files in yet another signed Jar and add it to the archive"..., anotherJar.jar").

遗心遗梦遗幸福 2024-07-29 04:43:33

首先,我建议获得有效的代码签名证书。 您可以从 解冻。 虽然这些证书通常用于 S/MIME,但它们对于代码签名也有效。

第二个选项是将自签名证书导入到浏览器正在调用的 JRE 的 cacert 文件中。

接下来要检查的是确保您的浏览器正在运行最新的 jar。 一种方法是始终增加版本号。 另一个选项是清除 Java 小程序缓存。 我通常也会清除浏览器的缓存,但这不是必需的。

First, I'd suggest getting a valid code signing certificate. You can get a free cert from Thawte. Although generally these certs are used for S/MIME, they are also valid for code signing.

The second option is to import your self signed cert into the cacert file of the JRE which your browser is invoking.

The next thing to check is to make sure your browser is running your latest jar. One way to do this is to always increment your version number. The other option is for you to clear your Java applet cache. I usually clear my browser's cache as well, but this shouldn't be needed.

往日 2024-07-29 04:43:33

您提到:

当我打开该 html 文件时,我从未出现安全确认对话框...

您是从本地文件系统打开该文件,还是通过托管 HTML 文件和 applet jar 的 Web 服务器的 URL 打开该文件? 这可能就是为什么您没有收到警告的原因。

You mentioned:

When I open that html file, I never get the security confirmation dialog box...

Are you opening the file from your local file system, or via a URL to a web server hosting the HTML file and applet jar(s)? That could be why you get no warning.

别把无礼当个性 2024-07-29 04:43:33

这是一种对 jar 进行签名,然后检查所有类文件是否都使用您的密钥库进行签名的方法。

#!/bin/bash
KEYSTORE=/home/user/NetBeansProjects/sign/keystore
FILES=`find /home/user/NetBeansProjects/Project/dist/ -name "*.jar"`
for f in $FILES; 
   do echo password |  /usr/bin/jarsigner -keystore $KEYSTORE -verbose $f myself;
   echo "Signed $f"; 
  /usr/bin/jarsigner -verify -verbose -certs $f | grep X.509 | sort -u;
done

Here is a way to sign your jars and then check to see that all the class files are signed with your keystore.

#!/bin/bash
KEYSTORE=/home/user/NetBeansProjects/sign/keystore
FILES=`find /home/user/NetBeansProjects/Project/dist/ -name "*.jar"`
for f in $FILES; 
   do echo password |  /usr/bin/jarsigner -keystore $KEYSTORE -verbose $f myself;
   echo "Signed $f"; 
  /usr/bin/jarsigner -verify -verbose -certs $f | grep X.509 | sort -u;
done
独﹏钓一江月 2024-07-29 04:43:33

编辑:这个答案是历史性的。 JDK9 显然将弃用小程序。 在撰写本文时(2017 年 1 月 1 日),您应该对小程序进行签名,但不给予它们额外的权限,然后过渡到更新的技术。

我建议您不要签署代码。 如果你在玩弄别人的安全,那么你真的应该知道自己在做什么。

JTextComponent 应该允许复制和粘贴文本(如果足够的话)。

jarsigner -verify 将检查您的 jar 是否已签名。 您还可以快速查看清单文件和 META-INF/ 中的文件。

信任证书的弹出对话框可能被禁用。 在Sun的实现中:打开Java控制面板; 转到高级选项卡; 展开安全节点; 最上面的两个复选框应该是“允许用户向签名上下文授予权限”和“允许用户向不受信任的机构授予内容权限”。

Edit: This answer is historical. JDK9 will apparently deprecate applets. At the time of writing (1 Jan 2017), you should sign applets but give them no additional privileges, then transition to a more current technology.

I suggest that you don't sign the code. If you're playing about with other people's security, then you really should know what you are doing.

JTextComponent should allow copy and paste of text, if that is sufficient.

jarsigner -verify will check that your jar is signed. You can also have a quick look at the manifest file and files within META-INF/.

The pop up dialog to trust certificates may be disabled. In Sun's implementation: open the Java Control Panel; go to the Advanced tab; expand the Security node; the top two tickboxes should be "Allow user to grant permissions to signed context" and "Allow user to grant permissions to content from an untrusted authority".

甜警司 2024-07-29 04:43:32

3 个简单步骤

  1. keytool -genkey -keystore myKeyStore -alias me

  2. keytool -selfcert -keystore myKeyStore -alias me

  3. jarsigner -keystore myKeyStore jarfile.jar me

3 easy steps

  1. keytool -genkey -keystore myKeyStore -alias me

  2. keytool -selfcert -keystore myKeyStore -alias me

  3. jarsigner -keystore myKeyStore jarfile.jar me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文