having trouble using signed java applet

Discussion in 'Java' started by Darren, Sep 20, 2005.

  1. Darren

    Darren Guest

    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
     
    Darren, Sep 20, 2005
    #1
    1. Advertising

  2. Darren

    Roedy Green Guest

    On Tue, 20 Sep 2005 17:59:03 GMT, "Darren" <> wrote
    or quoted :

    > 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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 20, 2005
    #2
    1. Advertising

  3. Darren

    Roedy Green Guest

    On Tue, 20 Sep 2005 17:59:03 GMT, "Darren" <> wrote
    or quoted :

    > codebase = "."


    that does not do anything. Just leave it out.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 20, 2005
    #3
  4. Darren

    Roedy Green Guest

    On Tue, 20 Sep 2005 17:59:03 GMT, "Darren" <> wrote
    or quoted :

    > 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"
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 20, 2005
    #4
  5. Darren

    Roedy Green Guest

    On Tue, 20 Sep 2005 17:59:03 GMT, "Darren" <> wrote
    or quoted :

    >load: class Helloserver.class not found.


    look in your jar. Is the class in there with no package, spelled
    EXACTLY like that including case. Use Winzip or the like to peek.

    JarLook will produce a list of what is in a jar.


    see http://mindprod.com/products1.html#JARLOOK
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 20, 2005
    #5
  6. Darren

    Roedy Green Guest

    On Tue, 20 Sep 2005 17:59:03 GMT, "Darren" <> wrote
    or quoted :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 20, 2005
    #6
  7. Darren

    Darren Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Tue, 20 Sep 2005 17:59:03 GMT, "Darren" <> wrote
    > or quoted :
    >
    > > 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.

    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?

    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Again taking new Java programming contracts.
     
    Darren, Sep 20, 2005
    #7
  8. Darren

    Darren Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Tue, 20 Sep 2005 17:59:03 GMT, "Darren" <> wrote
    > or quoted :
    >
    > > codebase = "."

    >
    > that does not do anything. Just leave it out.

    Will do. Wasn't sure if java was finnicky about such things.
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Again taking new Java programming contracts.
     
    Darren, Sep 20, 2005
    #8
  9. Darren

    Darren Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Tue, 20 Sep 2005 17:59:03 GMT, "Darren" <> wrote
    > or quoted :
    >
    > > 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"


    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?
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Again taking new Java programming contracts.
     
    Darren, Sep 20, 2005
    #9
  10. Darren

    Oliver Wong Guest

    "Darren" <> wrote in message
    news:Uz_Xe.11826$...
    > 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?


    Here's a tutorial on how to use packages in java:

    http://jarticles.com/package/package_eng.html

    - Oliver
     
    Oliver Wong, Sep 20, 2005
    #10
  11. Darren

    Roedy Green Guest

    On Tue, 20 Sep 2005 20:47:48 GMT, "Darren" <> wrote
    or quoted :

    >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?


    See http://mindprod.com/jgloss/package.html
    http://mindprod.com/jgloss/applet.html

    also see http://mindprod.com/jgloss/gettingstarted.html

    You need an intro textbook of some sort, even a very out of date one
    to explain these basic.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 21, 2005
    #11
  12. Darren

    Roedy Green Guest

    On Tue, 20 Sep 2005 21:34:45 GMT, "Darren" <> wrote
    or quoted :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 21, 2005
    #12
  13. Darren

    Roedy Green Guest

    On Tue, 20 Sep 2005 21:34:45 GMT, "Darren" <> wrote
    or quoted :

    >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.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 21, 2005
    #13
  14. Darren

    Roedy Green Guest

    On Tue, 20 Sep 2005 21:34:45 GMT, "Darren" <> wrote
    or quoted :

    > 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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 21, 2005
    #14
  15. Darren

    Darren Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Tue, 20 Sep 2005 20:47:48 GMT, "Darren" <> wrote
    > or quoted :
    >
    > >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?

    >
    > See http://mindprod.com/jgloss/package.html
    > http://mindprod.com/jgloss/applet.html

    Lovely site that. :)

    path like a directory structure, got it :)
    >
    > also see http://mindprod.com/jgloss/gettingstarted.html


    >
    > You need an intro textbook of some sort, even a very out of date one
    > to explain these basic.


    I have a book on java 2 somewhere, probably in the attic. Bloody hell i hate
    the dark. :)
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Again taking new Java programming contracts.
     
    Darren, Sep 21, 2005
    #15
  16. Darren

    Darren Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Tue, 20 Sep 2005 21:34:45 GMT, "Darren" <> wrote
    > or quoted :
    >
    > >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.


    Do you need to include the directory info in the jar?
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Again taking new Java programming contracts.
     
    Darren, Sep 21, 2005
    #16
  17. Darren

    Roedy Green Guest

    On Wed, 21 Sep 2005 00:24:01 GMT, "Darren" <> wrote
    or quoted :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 21, 2005
    #17
  18. Darren

    Roedy Green Guest

    On Wed, 21 Sep 2005 00:32:31 GMT, "Darren" <> wrote
    or quoted :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 21, 2005
    #18
  19. Darren

    Dag Sunde Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Tue, 20 Sep 2005 17:59:03 GMT, "Darren" <> wrote
    > or quoted :
    >
    >> 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.


    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"

    --
    Dag.
     
    Dag Sunde, Sep 21, 2005
    #19
  20. Darren

    Dag Sunde Guest

    "Darren" <> wrote in message
    news:H5YXe.11784$...
    > 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.

    --
    Dag.
     
    Dag Sunde, Sep 21, 2005
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Terri I.
    Replies:
    3
    Views:
    6,641
  2. kyrpa83
    Replies:
    1
    Views:
    653
    kyrpa83
    Oct 17, 2007
  3. Rob1bureau
    Replies:
    1
    Views:
    837
    joris
    Feb 27, 2010
  4. Krist
    Replies:
    3
    Views:
    1,581
    Andrew Thompson
    May 15, 2010
  5. Thomas Richter
    Replies:
    1
    Views:
    212
    Robert Klemme
    Nov 14, 2013
Loading...

Share This Page