views:

1443

answers:

3

Hi there,

I've got a signed java applet (using a self-signed-certificate) which has to access the user's file system. I have to do it, so please no replies ala "you shouldn't do it" :)

The thing is, when I execute the Applet from Firefox 3.0 / Mac, everything works as desired, I get all access just as it should.

When I use Safar 4 / Mac, I don't get access. The line I especially have problems with is System.getProperty() (although when I stub that out, the FS access doesn't work either)

String home = System.getProperty("user.home");

The Exception I get is the following:

java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
at java.security.AccessController.checkPermission(AccessController.java:427)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
at java.lang.System.getProperty(System.java:628)
at de.samedi.searcher.Searcher.<init>(Searcher.java:49)
at de.samedi.searcher.Applet.getSearcher(Applet.java:193)
at de.samedi.searcher.Applet.getSearcher(Applet.java:187)
at de.samedi.searcher.Applet.addPatient(Applet.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.plugin.javascript.invoke.JSInvoke.invoke(JSInvoke.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.plugin.javascript.JSClassLoader.invoke(JSClassLoader.java:44)
at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(SecureInvocation.java:658)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation$2.run(SecureInvocation.java:214)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation.CallMethod(SecureInvocation.java:192)
at sun.plugin.liveconnect.SecureInvocation.access$300(SecureInvocation.java:52)
at sun.plugin.liveconnect.SecureInvocation$CallMethodThread.run(SecureInvocation.java:123)

As I said, this works perfectly on Firefox. Gotta check Windows Browser today...

Any Ideas?

A: 

Has the user accepted full access for your applet in Safari? Sounds like the security manager kicking in.

Thorbjørn Ravn Andersen
yes. the user said "trust this applet". and it doesnt work.I even think FF is behaving strangely, because I just tried it on IE7 and I've got the same results as in Safari...I must be doing something wrong...
Michael Siebert
Please list the steps you take to prepare your jar file.
Thorbjørn Ravn Andersen
A: 

I remember having a similar problem in an older version of Safari (this was years ago), and the solution I found was adding a delay to the applet. It seemed Safari for some reason was allowing the applet to run before the user was given the "trust this applet" dialogue (other browsers would not start the applet until after the user granted or denied access). At that point the applet was not trusted and a security exception would occur. Even though the user would then allow trust, it was too late as the applet had already run and failed. I had to add a delay for safari, so it would not try doing anything that needed secure access until a period of time had passed, allowing the user to give access before the applet tried doing anything needing security access.

joe p
+2  A: 

Once you have your jar compiled and signed you should run the -verify option to ensure its signed properly.

If the verification is ok look at the installed certificates on your browsers. I haven't done anything in Safari only IE, but I imagine there is a place similar to I.E. where you can at least view the installed certificates. I would verify the certificate is installed.

Also make sure your code is running in a privileged block.

 String home = System.getProperty("user.home");

will always throw an error in 1.4 or higher. Unless you have edited the java.policy file for All Permissions

Try using this in combination with your signed jar.

 String home = (String) AccessController.doPrivileged(new PrivilegedAction() 
 {
      public Object run() 
      {
     return System.getProperty("user.home");
      }
 });
Knife-Action-Jesus
this is exactly what i came up with. unfortunately, i had to do this at 6 places, each with different arguments to the run method (which takes no arguments) so i had to define 6 private inner classes.and coming from ruby, this really sucks :-)is there a way to "mark" the whole applet as privileged?anyways, why does this work in firefox without doPrivileged?
Michael Siebert
No way to mark the entire applet as privileged unless you use a custom policy file, but that opens up allot of security issues and would require work on the client machines. Not sure why firefox handles this differently The security you are fighting here is in the JRE container and shouldn't be affected by the browser to my knowledge. If anyone knows more about this I would be curious.
Knife-Action-Jesus