how to create a signed applet

Hello, I made a game that will download an image from a remote url. I printed out my error and it was a security exception.

I read that I will need to create a signed applet.

I have no clue about this. I have seen some tutorials and they confused the heck out of me. I did use one tutorial where I created a mypolicy.policy file but I am not sure how to attach it to my jar file or apply it or whatever the term is called for what I need to do.

If I am on the right or wrong track can anyone please help me.

Thanks.

[546 byte] By [synergy_guya] at [2007-11-27 10:01:14]
# 1
keytool -genkey -keyalg rsa -keystore .test.ks -alias test -validity 365[fill out the questions as requested]jarsigner -keystore .test.ks -signedjar MySignedJar.jar Original.jar test[fill out the questions as requested]You're done.
Navy_Codera at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 2
I just tried to enter this "keytool -genkey -keyalg rsa -keystore .test.ks -alias test -validity 365" in the command prompt and it says it cant recognize keytoolI just tried to google keytool to download it and couldnt find it.Need a little more help.
synergy_guya at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 3
http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html
petes1234a at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 4
keytool is in the same directory as javac. Make sure your path points to your /jdk/bin directory.
Navy_Codera at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 5

ok im getting there

I entered "jarsigner -keystore .test.ks -signedjar MySignedJar.jar Original.jar test"

I replaced Original.jar with my jar filename is there anything else in that line that I need to change.

I do want to note that my jar file I want to assign is on my desktop and not in the java/bin folder. Not sure if that matters but wanted you to know

Thanks

synergy_guya at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 6

> ok im getting there

>

> I entered "jarsigner -keystore .test.ks -signedjar

> MySignedJar.jar Original.jar test"

>

> I replaced Original.jar with my jar filename is there

> anything else in that line that I need to change.

>

> I do want to note that my jar file I want to assign

> is on my desktop and not in the java/bin folder. Not

> sure if that matters but wanted you to know

>

> Thanks

Doesn't matter where your jar is. You can reference that from wherever you want. I mentioned the /java/bin folder because that is where the keytool executable resides.

Navy_Codera at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 7
It told me it was un-able to open my jar file. Do I need to specify where it is located
synergy_guya at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 8
> It told me it was un-able to open my jar file. Do I> need to specify where it is located[blinks in astonishment] Yes.(I've got to submit this to intel's PEBKAC files...)
Navy_Codera at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 9

LOL sorry about that. But thanks so far for the help

C:\Program Files\Java\jdk1.6.0_01\bin>jarsigner -keystore .test.ks -signedjar My

SignedJar.jar C:\Documents and Settings\god\Desktop\java_programming\picturepuzz

le\distpicturepuzzle.jar test

Enter Passphrase for keystore:

jarsigner: Certificate chain not found for: and. and must reference a valid Key

Store key entry containing a private key and corresponding public key certificat

e chain.

What is the next step

synergy_guya at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 10

> LOL sorry about that. But thanks so far for the help

>

> C:\Program Files\Java\jdk1.6.0_01\bin>jarsigner

> -keystore .test.ks -signedjar My

> SignedJar.jar C:\Documents and

> Settings\god\Desktop\java_programming\picturepuzz

> le\distpicturepuzzle.jar test

> Enter Passphrase for keystore:

> jarsigner: Certificate chain not found for: and. and

> must reference a valid Key

> Store key entry containing a private key and

> corresponding public key certificat

> e chain.

>

> What is the next step

Did you run keytool to generate the .test.ks keystore file yet? And if so, where did you save it? You may have to put the absolute path to the keystore (just as you did with your jar files)

Navy_Codera at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 11

Yes I did run it and i placed the file in C:\.test.ks

C:\Program Files\Java\jdk1.6.0_01\bin>jarsigner -keystore C:\.test.ks -signedjar

MySignedJar.jar C:\Documents and Settings\god\Desktop\java_programming\picturep

uzzle\distpicturepuzzle.jar test

Enter Passphrase for keystore:

jarsigner: Certificate chain not found for: and. and must reference a valid Key

Store key entry containing a private key and corresponding public key certificat

e chain.

C:\Program Files\Java\jdk1.6.0_01\bin>

synergy_guya at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 12
Post the command you used to generate your keystore.
Navy_Codera at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 13
C:\Program Files\Java\jdk1.6.0_01\bin>keytool -genkey -keyalg rsa -keystore .test.ks -alias test -validity 365
synergy_guya at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 14

> C:\Program Files\Java\jdk1.6.0_01\bin>keytool -genkey

> -keyalg rsa -keystore .tes

> t.ks -alias test -validity 365

AH HAH! You're not creating .test.ks in your C:\ directory, you're creating it in C:\Program Files\Java\jdk1.6.0_01\bin

Ammend your path in your jarsigner command to reflect the location of your .test.ks file and you should be set ;-)

Navy_Codera at 2007-7-13 0:33:20 > top of Java-index,Java Essentials,Java Programming...
# 15

I did this and I still get error. It looks like in the error I get an error right after the word program. Do I need to use a special character for spaces?

C:\Program Files\Java\jdk1.6.0_01\bin>jarsigner -keystore C:\Program Files\Java\

jdk1.6.0_01\bin\.test.ks -signedjar MySignedJar.jar C:\Documents and Settings\go

d\Desktop\java_programming\picturepuzzle\distpicturepuzzle.jar test

Enter Passphrase for keystore:

jarsigner error: java.lang.RuntimeException: keystore load: C:\Program (The syst

em cannot find the file specified)

synergy_guya at 2007-7-21 23:14:33 > top of Java-index,Java Essentials,Java Programming...
# 16

> I did this and I still get error. It looks like in

> the error I get an error right after the word

> program. Do I need to use a special character for

> spaces?

>

> C:\Program Files\Java\jdk1.6.0_01\bin>jarsigner

> -keystore C:\Program Files\Java\

> jdk1.6.0_01\bin\.test.ks -signedjar MySignedJar.jar

> C:\Documents and Settings\go

> d\Desktop\java_programming\picturepuzzle\distpicturepu

> zzle.jar test

> Enter Passphrase for keystore:

> jarsigner error: java.lang.RuntimeException: keystore

> load: C:\Program (The syst

> em cannot find the file specified)

Well, if you're already executing from the bin directory, just use .\.test.ks (or put the whole path in double quotes "c:\Program Files\..."

Navy_Codera at 2007-7-21 23:14:33 > top of Java-index,Java Essentials,Java Programming...
# 17

I did this and got this error. I executed ran the command lines you posted in a previous post and then answered those questions. maybe there are additional commands to run. from the error it looks like I need a public and private key.

C:\Program Files\Java\jdk1.6.0_01\bin>jarsigner -keystore .\.test.ks -signedjar

MySignedJar.jar C:\Documents and Settings\god\Desktop\java_programming\picturepu

zzle\distpicturepuzzle.jar test

Enter Passphrase for keystore:

jarsigner: Certificate chain not found for: and. and must reference a valid Key

Store key entry containing a private key and corresponding public key certificat

e chain.

synergy_guya at 2007-7-21 23:14:33 > top of Java-index,Java Essentials,Java Programming...
# 18

> I did this and got this error. I executed ran the

> command lines you posted in a previous post and then

> answered those questions. maybe there are additional

> commands to run. from the error it looks like I need

> a public and private key.

>

> C:\Program Files\Java\jdk1.6.0_01\bin>jarsigner

> -keystore .\.test.ks -signedjar

> MySignedJar.jar C:\Documents and

> Settings\god\Desktop\java_programming\picturepu

> zzle\distpicturepuzzle.jar test

> Enter Passphrase for keystore:

> jarsigner: Certificate chain not found for: and. and

> must reference a valid Key

> Store key entry containing a private key and

> corresponding public key certificat

> e chain.

No. It's telling you what the problem is and I missed it, too. "and" is the name of the keystore it is trying to load. Everywhere that you have a full path (i.e. "documents and settings") you need to put the whole thing in quotes.

Try this:

jarsigner -keystore .\.test.ks -signedjar MySignedJar.jar "C:\Documents and Settings\god\Desktop\java_programming\picturepuzzle\distpicturepuzzle.jar" test

Message was edited by:

Navy_Coder

-- Added the "-" in front of the keystore switch

Navy_Codera at 2007-7-21 23:14:33 > top of Java-index,Java Essentials,Java Programming...
# 19

I just got it to work. I just checked out the tutorial on

http://java.sun.com/j2se/1.4.2/docs/guide/jws/developersguide/development.html#signing

and did it from scratch. However it said that my certificate that I created will expire in 6 months. Is there a way to make it never expire?

synergy_guya at 2007-7-21 23:14:33 > top of Java-index,Java Essentials,Java Programming...
# 20

> I just got it to work. I just checked out the

> tutorial on

>

> http://java.sun.com/j2se/1.4.2/docs/guide/jws/develope

> rsguide/development.html#signing

>

> and did it from scratch. However it said that my

> certificate that I created will expire in 6 months.

> Is there a way to make it never expire?

No. The validity switch that I gave you will set it to 1 year. You can set that to whatever you want.

For future reference:

You really should read up on environment variables; path, classpath, etc. It would have saved you a bit of heartache. ;-)

Navy_Codera at 2007-7-21 23:14:33 > top of Java-index,Java Essentials,Java Programming...
# 21

Yes Defininitely. I am not very familiar or good when it comes to commands in cmd and understanding certain functions in the java api but thanks so much for the help. I rewarded you 2 duke stars. I would have done more but 2 was the most it could let me. Not sure if that really helps. If so let me know and I will give you more.

Thanks again

synergy_guya at 2007-7-21 23:14:33 > top of Java-index,Java Essentials,Java Programming...
# 22

> Yes Defininitely. I am not very familiar or good when

> it comes to commands in cmd and understanding certain

> functions in the java api but thanks so much for the

> help. I rewarded you 2 duke stars. I would have done

> more but 2 was the most it could let me. Not sure if

> that really helps. If so let me know and I will give

> you more.

>

> Thanks again

Don't worry about the duke stars - they aren't really worth anything here. (I honestly don't know why they have them at all...) I'm just glad that you got things working and that I could help.

Navy_Codera at 2007-7-21 23:14:33 > top of Java-index,Java Essentials,Java Programming...
# 23
Thanks again. Now that I know how to do this I will be able to program so much more. I will now try to do some database stuff (hopefully).
synergy_guya at 2007-7-21 23:14:33 > top of Java-index,Java Essentials,Java Programming...