Restriction for signed applet

Hi all,

i signed applet which is trying to modify file tmp.txt on client machine. Is there any opportunity for client to forbid this action for signed applet?

I tried use policy file but i was unlucky. It is ok for unsigned applet but what about signed one?

Thank you for your response.

benky

[330 byte] By [benky] at [2007-9-26 20:14:15]
# 1

>Is there any opportunity for client to forbid this action for signed applet?

With a signed applet, generally the client will be prompted with a dialog box requesting that he/she grant the permission to do whatever the applet is trying to do. You should be able to programmatically check to see if the permission is granted or not.

>I tried use policy file but i was unlucky. It is ok for unsigned applet but what about signed one?

I could be wrong on this, but my understanding is that a signed applet uses a different mechanism to obtain permission -- it doesn't look to the policy file for permission.

If you want to take a look at a signed applet in action, try the link below (be sure to read the first few links which explain the pain you have to go thru to get a signed applet to work correctly):

http://home.attbi.com/~aokabc/FileIO/FileIOdemo.htm

If this helps, don't forget the Dukes!

V.V.

viravan at 2007-7-3 18:16:56 > top of Java-index,Security,Signed Applets...
# 2

you need to install the jre, and place the win32.dll at JavaSoft\JRE\1.3.1_06\bin, that properties file place at JavaSoft\JRE\1.3.1_06\lib, comm.jar at JavaSoft\JRE\1.3.1_06\lib\ext\

and in ur code try to use it to open ur com port

public String test() {

String drivername = "com.sun.comm.Win32Driver";

try

{

CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();

}

catch (Throwable th)

{/* Discard it */}

drivername = "javax.comm.*";

try

{

CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();

}

catch (Throwable th)

{/* Discard it */}

portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {

portId = (CommPortIdentifier) portList.nextElement();

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

if (portId.getName().equals("COM2")) {

//if (portId.getName().equals("/dev/term/a")) {

try {

serialPort = (SerialPort)

portId.open("SimpleWriteApp", 2000);

} catch (PortInUseException e) {}

try {

outputStream = serialPort.getOutputStream();

} catch (IOException e) {}

try {

serialPort.setSerialPortParams(9600,

SerialPort.DATABITS_8,

SerialPort.STOPBITS_1,

SerialPort.PARITY_NONE);

} catch (UnsupportedCommOperationException e) {}

int i=0;

while(true)

{

try {

messageString="hi";

System.out.println(i++);

outputStream.write(messageString.getBytes());

} catch (IOException e)

{

System.out.println(e);

messageString=String.valueOf(e);

}

}

}

}

}

return messageString;

}

and yet u need to signed the applet

1. Compile the applet

2. Create a JAR file

3. Generate Keys

4. Sign the JAR file

5. Export the Public Key Certificate

6. Import the Certificate as a Trusted Certificate

7. Create the policy file

8. Run the applet

Susan

Susan bundles the applet executable in a JAR file, signs the JAR file, and exports the public key certificate.

1. Compile the Applet

In her working directory, Susan uses the javac command to compile the SignedAppletDemo.java class. The output from the javac command is the SignedAppletDemo.class.

javac SignedAppletDemo.java

2. Make a JAR File

Susan then makes the compiled SignedAppletDemo.class file into a JAR file. The -cvf option to the jar command creates a new archive (c), using verbose mode (v), and specifies the archive file name (f). The archive file name is SignedApplet.jar.

jar cvf SignedApplet.jar SignedAppletDemo.class

3. Generate Keys

Susan creates a keystore database named susanstore that has an entry for a newly generated public and private key pair with the public key in a certificate. A JAR file is signed with the private key of the creator of the JAR file and the signature is verified by the recipient of the JAR file with the public key in the pair. The certificate is a statement from the owner of the private key that the public key in the pair has a particular value so the person using the public key can be assured the public key is authentic. Public and private keys must already exist in the keystore database before jarsigner can be used to sign or verify the signature on a JAR file.

In her working directory, Susan creates a keystore database and generates the keys:

keytool -genkey -alias signFiles -keystore susanstore -keypass kpi135 -dname "cn=jones" -storepass ab987c

This keytool -genkey command invocation generates a key pair that is identified by the alias signFiles. Subsequent keytool command invocations use this alias and the key password (-keypass kpi135) to access the private key in the generated pair.

The generated key pair is stored in a keystore database called susanstore (-keystore susanstore) in the current directory, and accessed with the susanstore password (-storepass ab987c).

The -dname "cn=jones" option specifies an X.500 Distinguished Name with a commonName (cn) value. X.500 Distinguished Names identify entities for X.509 certificates.

You can view all keytool options and parameters by typing:

keytool -help

4. Sign the JAR File

JAR Signer is a command line tool for signing and verifying the signature on JAR files. In her working directory, Susan uses jarsigner to make a signed copy of the SignedApplet.jar file.

jarsigner -keystore susanstore -storepass ab987c -keypass kpi135 -signedjar SSignedApplet.jar SignedApplet.jar signFiles

The -storepass ab987c and -keystore susanstore options specify the keystore database and password where the private key for signing the JAR file is stored. The -keypass kpi135 option is the password to the private key, SSignedApplet.jar is the name of the signed JAR file, and signFiles is the alias to the private key. jarsigner extracts the certificate from the keystore whose entry is signFiles and attaches it to the generated signature of the signed JAR file.

5. Export the Public Key Certificate

The public key certificate is sent with the JAR file to the whoever is going to use the applet. That person uses the certificate to authenticate the signature on the JAR file. To send a certificate, you have to first export it.

The -storepass ab987c and -keystore susanstore options specify the keystore database and password where the private key for signing the JAR file is stored. The -keypass kpi135 option is the password to the private key, SSignedApplet.jar is the name of the signed JAR file, and signFiles is the alias to the private key. jarsigner extracts the certificate from the keystore whose entry is signFiles and attaches it to the generated signature of the signed JAR file.

5: Export the Public Key Certificate

The public key certificate is sent with the JAR file to the whoever is going to use the applet. That person uses the certificate to authenticate the signature on the JAR file. To send a certificate, you have to first export it.

In her working directory, Susan uses keytool to copy the certificate from susanstore to a file named SusanJones.cer as follows:

keytool -export -keystore susanstore -storepass ab987c -alias signFiles -file SusanJones.cer

Ray

Ray receives the JAR file from Susan, imports the certificate, creates a policy file granting the applet access, and runs the applet.

6. Import Certificate as a Trusted Certificate

Ray has received SSignedApplet.jar and SusanJones.cer from Susan. He puts them in his home directory. Ray must now create a keystore database (raystore) and import the certificate into it. Ray uses keytool in his home directory /home/ray to import the certificate:

keytool -import -alias susan -file SusanJones.cer -keystore raystore -storepass abcdefgh

7. Create the Policy File

The policy file grants the SSignedApplet.jar file signed by the alias susan permission to create newfile (and no other file) in the user's home directory.

Ray creates the policy file in his home directory using either policytool or an ASCII editor.

keystore "/home/ray/raystore";

// A sample policy file that lets a JavaTM program

// create newfile in user's home directory

// Satya N Dodda

grant SignedBy "susan"

{

permission java.security.AllPermission;

};

8. Run the Applet in Applet Viewer

Applet Viewer connects to the HTML documents and resources specified in the call to appletviewer, and displays the applet in its own window. To run the example, Ray copies the signed JAR file and HTML file to /home/aURL/public_html and invokes Applet viewer from his home directory as follows:

Html code :

</body>

</html>

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"

width="600" height="400" align="middle"

codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,1,2">

<PARAM NAME="code" VALUE="SignedAppletDemo.class">

<PARAM NAME="archive" VALUE="SSignedApplet.jar">

<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">

</OBJECT>

</body>

</html>

appletviewer -J-Djava.security.policy=Write.jp

http://aURL.com/SignedApplet.html

Note: Type everything on one line and put a space after Write.jp

The -J-Djava.security.policy=Write.jp option tells Applet Viewer to run the applet referenced in the SignedApplet.html file with the Write.jp policy file.

Note: The Policy file can be stored on a server and specified in the appletviewer invocation as a URL.

9. Run the Applet in Browser

Download JRE 1.3 from Javasoft

good luck! roderisland@hotmail.com

i already give u many tips, i use 2 weeks to try this to success, hopw that u understand that, a result of success is not important, the process of how to get things done is most usefull!

roderisland at 2007-7-3 18:16:56 > top of Java-index,Security,Signed Applets...