Java PKCS11 with iaik - java

I created an applet using the iaik libraries it works perfectly in my applet viewer but in my web browser I get this: trusted loader attempted to load sandboxed resource any idea ?
Amm ok so I got it to work but I would like to also know why ... I am using netbeans ... after I set the option for self signed I compiled and in my dist folder it created a jar file with my classes...after that I copied my jar file, libs ...etc. to the folder with my applet ... and ran it ... so what does the sandbox ment and how come I do not get it anymore... I also copied that PKCS11Wrapper to my jdk/bin folder....

The problems is appear because your applet tried to access to native library and your applet has to be signed, BUT you've written that you sign it, so, if you place the code in the jre/lib/ext directory, signing the code is not required, try to create console application from applet and try to start it. I think you will see that all is work , and your IDE signature is not working. How to start applet from main method

Related

java- How to build the executable for the applet application

I implemented the java applet application. I searching for the process of how to create the executable file for this application.I am not find any good solution. Please can anybody help me.
thanks
The executable of a Java applet is either a .jar file, or the .class directory.
You execute a Java applet within a web page. You place the .jar file or the .class directory in your web directory structure.
Here's an example HTML applet:
<applet code=NameOfApplet.class name=NameOfApplet archive=NameOfApplet.jar
width=300 height=300>
<param name="bgcolor" value="ffffff">
<param name="fontcolor" value="000000">
Your browser is not Java enabled.
</applet>
Further information can be found at How to Make Applets.
It's been a while since I've had to code an applet, but the archive parameter can include directories.
Instead of creating an Applet or JApplet, create a JFrame.
Jar the classes.
Add a manifest file that specifies the main-class
Double click the Jar to launch.
If you would like to make it a nicer experience for the end user, create a web page that uses deployJava.js to check that a suitable JRE is installed, then launch the JFrame using Java Web Start.
Otherwise, if you want to run the applet outside the browser, you can create the JAR file normally and then user appletviewer to launch it.
Executable applet is nothing but the .class file of the applet, which is obtained by compiling the source code of the applet. Compiling an applet is exactly the same as compiling an application. Therefore, we can use the Java compiler to compile the applet.
Assume that we have created a file called HelloJava.java for our applet. Here are the steps required for compiling the HelloJava applet.
Move to the directory containing the source code and type the following command: javac HelloJava.java
The compiled output file called HelloJava.class is placed in the same directory as the source.
If any error message is received, then we must check for errors, correct them and compile the applet again.

Signed Applet trying to copy .jar file from Server URL to local filesystem. Works, but .jar gets corrupted

I'm trying to write an applet that installs files to the users system for use with an local Java mapping utility. I have a jar file with the main method for my Java utility along with a couple of other files that are used with my local mapping utility.
I use the following method from the Apache commons File-IO: Documentation here
Everything seemingly works fine. The file is copied upon runnning the Applet (the user is prompted with a warning requesting the permissions) and everything seems fine at this point.
When the file is run, however, the .jar gets corrupted and I literally watch as the file size goes from 250 kB to 0 right after it is run.
What would cause such behavior? I try extracting the archive and looking at the contents...all my classes seem to be there. What would cause a .jar to "self destruct" like this?
Also, if I just download the file normally. It works fine. It only corrupts like this when I download from the signed applet.
Thanks in advance for any insight!

Read .jar file in Java applet

I have a little Java applet game where you can choose between some themes. It works very well but the downloading time of the huge .jar is not acceptably. Now I want to split the .jar into single .jars, a default one and one for every theme. Now there is just one question: (How) can I read a .jar file from a Java applet which is also a .jar?
Take a look at the URLClassLoader. You can give the URL to the theme.jar as a parameter and use the getResource* methods to access the files inside.
Another approach would be to manually download the JAR and open it with the java.util.jar classes, but I would go with the first approach.
Deploy the applet using Java Web
Start. From Java 1.2 this could be
done to get a 'free floating' applet
(outside a web page), but since
1.6.0_10+, it can also be done for embedded applets.
Put each theme in
a separate Jar and in the JNLP
(launch file) & mark them as 'lazy'
download.
Notate which package is
contained in which Jar (also in the
JNLP file) so the JWS client knows
which Jar to download for each
theme. (a)
Everything else will work 'like magic', and the JWS client will show a progress bar when downloading the lazy Jars.
(a) For this to work properly, each theme needs to be in a separate package, as well as a separate Jar.

Why does Java tell me my applet contains both signed and unsigned code?

My signed Java applet has been running fine until Java update 19. Now some but not all of our users on Java Update 19 report a java security message stating that our applet contains both signed and unsigned code.
The process for creating our applet is as follows:
Clean and Build the applet project in Netbeans IDE.
Open the Applet jar file in WinRAR and add the required mysql JDBC driver .class files to the jar file.
Sign the applet jar file.
Can someone please tell me how to determine what code is signed and what code is not signed in our applet? Is there a better way to include the mysql JDBC driver jar file in our applet other than copying the jar file contents into our applet jar file?
Thanks
EDIT: Due to a bug in Java 7 Update 45 you should not add Trusted-Library to your manifest file. Just add the new attribute Caller-Allowable-Codebase. See this question for more info: Java applet manifest - Allow all Caller-Allowable-Codebase
Java 7 Update 21 was released on April 16 2013 and caused our applet to start showing this warning dialog.
Per the release notes:
As of JDK 7u21, JavaScript code that calls code within a privileged applet is treated as mixed code and warning dialogs are raised if the signed JAR files are not tagged with the Trusted-Library attribute.
To fix this edit your manifest.mf file and add a line like this:
Trusted-Library: true
You should be very careful before doing this though. If your signed applet can be called from javascript then a malicious user can potentially do harmful things on your users' computers.
One quick way to secure your applet is to prevent it from being run on other websites. Do this by putting code in the init() method that looks at getCodeBase().getHost() and throws an exception if it does not match your site.
Java 7 Update 25 introduces another way to limit the sites where your applet can be run. You can set the Codebase attribute in your manifest file like this:
Codebase: test.example.com www.example.com
Java 7 Update 45 (releated October 16 2013) introduces more changes to the LiveConnect system (javascript-to-applet bridge) that may cause another prompt. This article talks about the 7u45 changes: https://blogs.oracle.com/java-platform-group/entry/liveconnect_changes_in_7u45
Basically you'll also want to add the following to your manifest file to avoid the prompts:
Caller-Allowable-Codebase: test.example.com www.example.com
If you are selling a product that includes an applet and you don't know what domains it can be deployed on you can populate * here.
Some things to try:
Go to the java plugin control panel ($JAVA_HOME/bin/ControlPanel).
Go to the Advanced tab.
Expand Debug
Check Enable tracing, Enable logging, and Show applet lifecycle exceptions
Expand Java console
Check Show console
Click OK (or Close, depending on your OS)
When your applet loads the Java console will open. Click on it and immediately press '5'. It will log the jars and classes being fetched to run your applet. Somewhere in this there should be a message indicating what jars or classes are consider "unsigned". If you miss it the first time, just reload the window to try it again.
Mixing trusted and untrusted code together is a vulnerability that has been fixed in the 6u19 (the current CPU/SSR release at the time of writing). See the docs. Blocking the mix or using a debugger should show where the problem is.

Permissions error for a signed Java applet when including external JAR files

I have a signed Java applet. And it works fine. But now I have to integrate some 3rd party JAR files with it. When I test it from Eclipse, the whole thing works correctly. But when I test it as an applet, it gives me a java.security.AccessControlException: access denied (java.io.FilePermission ...)
I thought this was because those 3rd party JAR files don't have a java.policy.applet within them. But manually adding the policy file doesn't get rid of the error.
What am I missing? Thanks!
============================
All the 3rd party JAR files sit on the server filesystem like so: A.jar, B.jar, C.jar. And I include them in the applet tag like so:
<applet
archive="my.jar,A.jar,B.jar,C.jar">
</applet>
Also, in the MANIFEST/MANIFEST.MF file in my.jar, I include those JAR files like so:
Class-Path: A.jar,B.jar,C.jar
You have to sign these jars as well, if they are attempting restricted operations.

Categories