| versions | ALL |
|---|---|
| contributors | irag |
| started on | 2008-09-20 09:53 |
By default Java applications are considered safe to run, or in Java speak trusted, since they are executed explicitly by users on their own computers. Applets by comparison are considered untrusted since they are initiated automatically in the browser. This restriction prevents applets from doing certain things, such as loading content from a different domain than the one hosting the applet. The error generated will look something like:java.security.AccessControlException: access denied (java.net.SocketPermission some URL here connect,resolve). To override this restriction, you can can sign the applet.
There are a couple different approaches to signing an applet, but they each involve connecting a certificate to your jar file. Certificates are digital signatures that incorporate a public key with some identity. There are companies (Certificate Authorities) that sell certificates for hundreds of dollars, but it is also possible to create a self-sign certificate for free, which is the approach shown below.
The select_image sketch below the instructions attempts to load an image from your computer using a standard file browser. When run as an applet, it needs to be signed.
Assume you have a sketch named loadImage.pde
keytool -genkey -keystore pKeyStore -alias p5geekkeytool -selfcert -keystore pKeyStore -alias p5geekjarsigner -keystore pKeyStore loadImage.jar p5geek* obviously replace loadImage with the real name of your .jar file
/** How to sign an applet taken from http://processinghacks.com/hacks:signapplet @author Ira Greenberg */ /* To run this sketch as an applet, it MUST be signed */ void setup(){ size(400, 400); PImage img; String imgName = selectInput(); img = requestImage(imgName); image(img, 0, 0); }
Please list any links you think are essential reading related to this hack: