having trouble using signed java applet

D

Darren

Hi i wrote an applet recently and posted a request here for help in allowing
it to open a socket. I got some excellent info on creating self signed jar
files that allow me access to functions normally prohibited to java applets.
Now i've follwoed the instructions but now my heml code has trouble
accessing the jar file.

here's the steps i took in creating the self signed jar file.
firstly i created the certificate
c:\j2sdk1.4.2_06\bin\keytool -genkey -keyalg rsa -alias dazkey
c:\j2sdk1.4.2_06\bin\keytool -export -alias dazkey -file dazsuncert.crt
then i created the jar
c:\j2sdk1.4.2_06\bin\jar cvf c:\applets\Helloserver.jar
c:\applets\Helloserver.class
then signed and verified it
c:\j2sdk1.4.2_06\bin\jarsigner c:\applets\Helloserver.jar dazkey
c:\j2sdk1.4.2_06\bin\jarsigner -verify -verbose -certs
c:\applets\Helloserver.jar

to test it i put the jar file and html file on there own on my website

Helloserver.htm
Helloserver.jar

the content of the html file are as follows
<HTML>
<HEAD>
</HEAD>
<BODY>
<CENTER>
<APPLET
codebase = "."
archive = "Helloserver.jar"
code = "Helloserver.class"
width = "500"
height = "300"</APPLET>
</CENTER>
</BODY>
</HTML>

The java consol stated the following
Java Plug-in 1.5.0_04
Using JRE version 1.5.0_04 Java HotSpot(TM) Client VM
User home directory = C:\WINDOWS


load: class Helloserver.class not found.
java.lang.ClassNotFoundException: Helloserver.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed.
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more
Exception in thread "Thread-4" java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "thread applet-Helloserver.class"
java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

now when i put the class file instead of the jar and removed the jar file
and the archive tag from the html file the class loads ok but again i get
the security problems.

Help
 
R

Roedy Green

archive = "Helloserver.jar"
code = "Helloserver.class"

You don't post a class without a package. That is only for
experimenting. I suspect signing presumes packages.
 
R

Roedy Green

archive = "Helloserver.jar"
code = "Helloserver.class"

An Applet should always have a package. Also be careful. Java and some
servers are case sensitive. To avoid getting bitten, I consistently
use a convention:

1. packages are always lower case.
2. jar names are always lower case.
3. classes always start with a capital letter.

e.g.

code="com.mindprod.wassup.Wassup.class"
archive="wassup.jar"
 
R

Roedy Green

now when i put the class file instead of the jar and removed the jar file
and the archive tag from the html file the class loads ok but again i get
the security problems.

Obviously. You can't sign a class file, only a jar.
 
D

Darren

Roedy Green said:
You don't post a class without a package. That is only for
experimenting. I suspect signing presumes packages.
by package you mean like 'java.net' or 'java.io'?
does my package name need to be in a similar format?
how do i include it in my html applet tag?
 
D

Darren

Roedy Green said:
An Applet should always have a package. Also be careful. Java and some
servers are case sensitive. To avoid getting bitten, I consistently
use a convention:

1. packages are always lower case.
2. jar names are always lower case.
3. classes always start with a capital letter.

e.g.

code="com.mindprod.wassup.Wassup.class"
archive="wassup.jar"

How is the com.mindprod.wassup constructed. Is it something you made up on
bespoke or is there a reason the syntax is like that? Also when i put
package in my applet. e.g 'package helloserver;' it creates a subdirector
called helloserver and i suspect if i were to call my package
"com.g7wap.helloserver" it would create a directory tree starting with com
then one below would be g7wap and the one below would be helloserver. if
this is the case then how would i reflect this in the jar archive? would jar
create the directory structure automatically based on the "package" entry in
the applet?
 
R

Roedy Green

How is the com.mindprod.wassup constructed. Is it something you made up on
bespoke or is there a reason the syntax is like that?

I own the domain mindprod.com. So I name all my packages
com.mindprod. That insures they will be globally unique.

wassup is the name of a package, a group of related classes.

Wassup in the name of my Applet and the main class, the one that is
used to get the whole ball rolling.

so archive="wassup.jar" ( to contain all the wassup class files)
code="com.mindprod.wassup.Wassup" to tell the browser the package
and class name of my main class.

If you want to examine the code and html, see
http://mindprod.com/applets/wassup.html

I have posted all kinds of applets you can play with and modify.
 
R

Roedy Green

called helloserver and i suspect if i were to call my package
"com.g7wap.helloserver" it would create a directory tree starting with com

Your package name reflects your directory structure.

What I am about to say is not completely true, but true enough for
your level:

I create a directory structure like this:

C:\com\mindprod\wassup

Than I put my Wassup.java file there.
Then I compile to create Wassup.class in that same directory
then I jar to create wassup.jar
then I sign the jar (a step you can leave out for now).
then I post that on my website or run the jar locally.

I usually give my Applet a main method so I can run it as as
application to debug it without the fuss of a browser.

If you use an IDE it creates the package directories for you in
project directories. You organise your related packages into
projects.
 
R

Roedy Green

jar
create the directory structure automatically based on the "package" entry in
the applet?

not quite automatically, but the jar had bloody BETTER reflect the
package structure with the member name hierarchy. See
http://mindprod.com/jgloss/jar.html
http://mindprod.com/jgloss/jarexe.html
http://mindprod.com/jgloss/classpath

For all this compiling, jaring etc, sooner or later you will want to
use ant scripts. You are welcome to use any of mine posted at
http://mindprod.com/products.html
and strip out what you don't need.
 
D

Darren

Roedy Green said:
com

Your package name reflects your directory structure.

What I am about to say is not completely true, but true enough for
your level:

I create a directory structure like this:

C:\com\mindprod\wassup

Than I put my Wassup.java file there.
Then I compile to create Wassup.class in that same directory
then I jar to create wassup.jar
then I sign the jar (a step you can leave out for now).
then I post that on my website or run the jar locally.

I usually give my Applet a main method so I can run it as as
application to debug it without the fuss of a browser.

If you use an IDE it creates the package directories for you in
project directories. You organise your related packages into
projects.

Do you need to include the directory info in the jar?
 
R

Roedy Green

I have a book on java 2 somewhere, probably in the attic. Bloody hell i hate
the dark. :)

You can get something on eBay or in one of those cheap computer
bookstores that specialise in slightly out of date books.
 
R

Roedy Green

Do you need to include the directory info in the jar?

You need at least a main class. Its java name is for example:

com.mindprod.wassup.Wassup.class

In the jar in will have the name:

com/mindprod/wassup/Wassup.class

You don't need an entry for each directory level, just the files.
Jar.exe handles that. You just tell it which classes and resources you
want in there.

When you sign it will add some additional files of the digests and
digital signatures.


Verify you got it right with Winzip or something similar.
 
D

Dag Sunde

Roedy Green said:
You don't post a class without a package. That is only for
experimenting. I suspect signing presumes packages.

Signing does not presume/need packages, but I agree with you.
(One should use them to keep things globally unique)

I suspect "jar" messes up a little when he doesn't use packages,
but gives a full ms-dos path to his .class file

<quote>
c:\j2sdk1.4.2_06\bin\jar cvf c:\applets\Helloserver.jar
c:\applets\Helloserver.class
c:\j2sdk1.4.2_06\bin\jarsigner c:\applets\Helloserver.jar dazkey
c:\j2sdk1.4.2_06\bin\jarsigner -verify -verbose -certs
c:\applets\Helloserver.jar
</quote>

I think the results will be different if he change to "c:\applets"
and try to jar, and sign it from there, the results might be different:
c:\applets> jar cvf helloserver.jar Helloserver.class
c:\applets> jarsigner helloserver.jar dazkey
c:\applets> jarsigner -verify -verbose -certs helloserver.jar

And Darren...

Can you give us the result the last command you run:
"jarsigner -verify -verbose -certs helloserver.jar"
 
D

Dag Sunde

Darren said:
Hi i wrote an applet recently and posted a request here for help in
allowing
it to open a socket. I got some excellent info on creating self signed jar
files that allow me access to functions normally prohibited to java
applets.
Now i've follwoed the instructions but now my heml code has trouble
accessing the jar file.

Hello Darren...

I promised in another thread to sign an applet, and send it to you
so you could test if it worked at all...

I sendt a test-setup with source & a signed applet to your
"devslashnul.net" address, but i suspect that isn't a valid one.

If you mail me your address, I'll send it to you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top