• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Signed an applet

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is from sun's tutorial for signing an applet. But how to do it, use dos command? What is the working directory?

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


When I input keytool command, get errors.

'keytool' is not recognized as an internal or external command,
operable program or batch file.



[ UD: fixed layout to make it readable ]
[ July 18, 2007: Message edited by: Ulf Dittmer ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The keytool program is in your %JAVA_HOME%\bin directory, so you could add that to your permanent PATH, or reference the tool as "%JAVA_HOME%\bin\keytool".
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I developed my code in NetBeans 5.51 plus Java 1.5.
By signing the JAR file under Java 1.5, I can't open the applet.
The console's message is failing reading file. But if I sign it with Java 1.6 with the same JAR file, it successes.Why?
I have to use Java 1.5 for my case.
Thanks!
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the exact and complete error message?
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
**Error: larger_plotdata.bin (The system cannot find the file specified)
java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(EventQueue.java:853)
at Combox.init(Combox.java:55)
at Combox.main(Combox.java:301)
Caused by: java.lang.NullPointerException
at javax.swing.DefaultComboBoxModel.<init>(DefaultComboBoxModel.java:53)

at javax.swing.JComboBox.<init>(JComboBox.java:177)
at Combox.initComponents(Combox.java:94)
at Combox.access$000(Combox.java:28)
at Combox$1.run(Combox.java:57)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So where is this file supposed to be, and where is it in reality?
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is in the same folder as the project.
It works well by using NetBeans.
However when I create the JAR file, it doesn't display any thing even I double click the JAR file except the errors message above.
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My whole process is
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hui Zhao:
It is in the same folder as the project. It works well by using NetBeans.


That leads me to believe that is should be in the classpath - which it won't be for an applet if it's in the same directory as the applet jar file.

Include that file in the jar file. Then it will be in the classpath and might be found. If that still doesn't work, consult the documentation of this software to see what it says about file "larger_plotdata.bin".

However when I create the JAR file, it doesn't display any thing even I double click the JAR file except the errors message above.


Since this is an applet, double-clicking does no good (it's for applications).
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found there is a policy file somewhere. Do I need change its content but I already
signed the JAR file?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, why are you fiddling with policy files, when the error you are getting has nothing to do with that?

And no, if the applet is signed, then you don't need to alter the local security policy.
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess my problem is what I created the JAR file can't find the path.
But I used the automated creating JAR file function provided by Netbeans.
Just right click the project code, is there any handy method or sweet way to get it?

Any suggestion?
Regards!
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you don't know where that file should go, how could an IDE get it right?
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but what is wrong?I followed the tutorial.

To compile a project, package, or file in the IDE, select it in the Projects window and do one of the following:

In the main menu, choose Build > Build Main Project (F11) to build the main project. Alternately, you can click the Build button in the toolbar.
In the main menu, choose Build > Clean and Build Main Project (Shift-F11) to clean and build the main project. Alternately, you can click the Clean & Build button in the toolbar.
In the Projects window, right-click the project node and choose Build Project to build the project.
In the Projects window, right-click the project and choose Clean Project to clean the project.
In the Projects window, right-click the package and choose Compile Package (F9) to compile a package.
In the Projects window, right-click the file and choose Compile File (F9) to compile a file. Alternatively, choose Build > Compile File (F9). Note that if you are using a free-form project, this command is disabled by default. You have to write an Ant target for compiling the currently selected file in the IDE and map it to the Compile File command.


Here I did got the result:

Then I signed this JAR file, no pass anyway.

[ UD: changed CODE to QUOTE tags to preserve formatting ]
[ July 28, 2007: Message edited by: Ulf Dittmer ]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're missing the point. The applet is not finding a resource it needs, and there's nothing any IDE can do about that until you find out where this resource needs to be at runtime, and you put it there. Once you have made sure where the file needs to go, you can work on how to tell the IDE to put it there, but for the moment, concentrate on finding out why the file is not found, and where it needs to go. Once you know that, put it there manually to make sure that it's working correctly. Then you can look at how to automate that using the IDE.
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please look at my files structure.

And my html code is

Thanks for any hint.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're still missing the point. You need to figure out where the file needs to go. We don't know how your code accesses it, so we can't tell you where it should go. If you're using HTTP to access it, then it probably needs to be in the same directory as the jar file. If you're using the resource/class loading mechanism, then it should probably be inside of the jar file.

I'll take a wild guess and say that where it is now it can't possibly be of any use.
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The file is in the same directory as the jar file.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, and how is the code trying to access it?
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Combox.java

Then accessing the file in the TestCell.java
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

file = new RandomAccessFile("larger_plotdata.bin", "r");
DataInputStream in = new DataInputStream(new FileInputStream("larger_plotdata.bin"));



That's the key piece of information. You can't use file I/O in an applet, because the file is not on the client (where the applet runs), but on the server. The following will give you an InputStream for the file from which you can construct a DataInputStream. Note that the file needs to be at the top level of the jar file for this to work, not as a separate file.



I'm not sure what the best way to replace the RandomAccessFile functionality is; probably to read the whole file into a byte array, and then use indices into that array.

Not using file I/O also has the advantage that the applet doesn't need to be signed. Was that the only reason you wanted to do that?
[ July 28, 2007: Message edited by: Ulf Dittmer ]
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I insist on File I/O and signed applet,so you mean I need to merge two classes together?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you can't insist on file I/O - it simply won't work. Whichever ways you're thinking of to make it work will be in vain in the end.

Why don't you try the way I outlined - it works, and does not require a signed applet. You might need to rework the I/O part of the applet somewhat, but that's most likely not too bad.
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get error "null"


another class is

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I get error "null"


Where does that come from? Which object is null, and thus produces a NullPointerException?
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnaks.
I put the file in a wrong place.
Now it works well.
Post closed.

Best Regards!
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[ UD: Please DontWakeTheZombies, and don't post unrelated questions into existing topics. That's called "hijacking" and is considered inappropriate all over the net. ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic