Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sign a Java applet for use in a browser?

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?

like image 939
user107312 Avatar asked May 26 '09 02:05

user107312


People also ask

Can a Java applet be executed from a web browser?

A Java applet can be executed from a Web browser. The class name must be the same as the file name that contains the class. A file may contain several classes. Each class in the file is compiled into a separate bytecode file.


2 Answers

3 easy steps

  1. keytool -genkey -keystore myKeyStore -alias me

  2. keytool -selfcert -keystore myKeyStore -alias me

  3. jarsigner -keystore myKeyStore jarfile.jar me

like image 139
Nuno Avatar answered Sep 20 '22 10:09

Nuno


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").

like image 42
EdSG Avatar answered Sep 19 '22 10:09

EdSG