Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

How to read/write a file to client from an applet?

Hello.

I have programmed an applet that reads a file from the clients computer(the applet is accessed trough Explorer 4.0
and the applet is on a webserver), the applet uses a FileInputStream to read the file from the client computer. I know that this is not permitted but i have signed the applet with low so i have full permissions, i used the signcode and cabarc tool from Microsoft. My problem is that i still got the JavaSecurityException(see below). What must i do to make it work. I want the applet to read my file and write it back to the clients computer without the JavaSecurityException.

com.ms.security.SecurityExceptionEx[Host]: cannot access file p.zip
      at com/ms/security/permissions/FileIOPermission.check (FileIOPermission.java)
      at com/ms/security/PolicyEngine.deepCheck (PolicyEngine.java)
      at com/ms/security/PolicyEngine.checkPermission (PolicyEngine.java)
      at com/ms/security/StandardSecurityManager.chk (StandardSecurityManager.java)
      at com/ms/security/StandardSecurityManager.checkRead (StandardSecurityManager.java)
      at java/io/FileInputStream.<init> (FileInputStream.java)
      at ZipApp1.Unpackzip (ZipApp1.java)
      at ZipApp1.init (ZipApp1.java)
      at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
      at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
      at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
      at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
      at com/ms/applet/AppletPanel.run (AppletPanel.java)
      at java/lang/Thread.run (Thread.java)
com.ms.security.SecurityExceptionEx[Host]: cannot access file p.zip
      at com/ms/security/permissions/FileIOPermission.check (FileIOPermission.java)
      at com/ms/security/PolicyEngine.deepCheck (PolicyEngine.java)
      at com/ms/security/PolicyEngine.checkPermission (PolicyEngine.java)
      at com/ms/security/StandardSecurityManager.chk (StandardSecurityManager.java)
      at com/ms/security/StandardSecurityManager.checkRead (StandardSecurityManager.java)
      at java/io/FileInputStream.<init> (FileInputStream.java)
      at ZipApp1.Unpackzip (ZipApp1.java)
      at ZipApp1.init (ZipApp1.java)
      at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
      at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
      at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
      at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
      at com/ms/applet/AppletPanel.run (AppletPanel.java)
      at java/lang/Thread.run (Thread.java)
Microsoft (R) VM for Java (tm), 4.0 Release 4.79.0.2613
==============================================
?  help
c  clear
f  run finalizers
g  garbage collect
m  memory usage
q  quit
t  thread list
==============================================
 
0
pierreandersson
Asked:
pierreandersson
  • 6
  • 5
1 Solution
 
msmolyakCommented:
Java Report Online has a good article describing how to sign applets for both browsers. It is located at
http://www.javareport.com/features/9802/sommers.html

Make sure you've followed all the right steps for signing and using applets in MS Explorer.
0
 
pierreanderssonAuthor Commented:
Now have read the article, but it wont still work, i don't think that the exception is because of the signing because the certificate window is appearing and i have to submit a yes if i am accepting the applet, can't it be in the code, is there another way to load the file instead of FileInputStream(String filename).
0
 
msmolyakCommented:
This is a standard way to do it. There are others like RandomAccessFile, but if the first one fails, the others will probably fail too. So you have to solve the security issue first.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
pierreanderssonAuthor Commented:
I send you the way i did the signing, maybe you can se some error in the steps i did it.

1. makecert -sk PierreKey -n "CN=PubTest" PierreCert.cer

2. cert2spc PierreCert.cer PierreCert.spc

3. cabarc n App1.cab App1.class

4. signcode -j javasign.dll -jp medium -spc PierreCert.spc -k PierreKey App1.cab

5. chkjava App1.cab


My applet is on a webserver. I use a explorer 4.0 on a Internet connected computer. The applet tries to load the file from my Internet connected computer.

If you wan't to try the applet go to www.konsult.net/javalab/javazip/zipapp.html


0
 
msmolyakCommented:
Why don't you sign your CAB file at low security level.

The article at http://www.javareport.com/features/9802/sommers.html explains zones and security levels for MS  Explorer. It also tells you what is permitted to an applet signed with certain security level.  Medium security allows you to use com.ms.io.clientstorage package which will probably give you an access to your file. If you sign it with low security, you will be able to use FileInputStream.

For examples of how to use  com.ms.io.clientstorage for accessing client computer see
http://www.javareport.com/features/9711/sommers.html.
0
 
pierreanderssonAuthor Commented:
I have tried this to but it won't work, it gives me the same error. It is very strange because it seems that i have dont the right thing when i am signing the cab files, can it be the
rights on the file or something like that?
0
 
msmolyakCommented:
Could you provide a piece of code which gives you trouble?
0
 
pierreanderssonAuthor Commented:
Here is the code i think it is this code that gives me problem FileInputStream in =  new FileInputStream("p.zip"); The program does execute in the dos window as an application.

public void Unpackzip()
      {

try {
      
      
FileInputStream in =  new FileInputStream("p.zip");

                  ZipInputStream zi = new ZipInputStream(in);
             
                  FileOutputStream fo = null;
                  
            
                  
                  ZipEntry ze = new ZipEntry("");
                  
      
              

                  
try {            
                while ((ze = zi.getNextEntry())!=null)
                  {
                  String path = new String();
                  String filename = new String();
                filename=filename+path+ze.getName();
                filename = filename.replace('/',File.separatorChar);
                System.out.println("HELLO: "+filename);
                  File destFile = new File(filename);
                      
                        System.out.println("1  "+filename);
                  if (destFile.exists())
                  {
                  System.out.println("OW Not implemented");
                  // Owerwrite
                  
                  }
                  else
                  {
                        System.out.println("27");
                  String parent = destFile.getParent();
                  
                  if (parent!=null)
                  {
                  File parentFile = new File(parent);
                  if (!parentFile.exists())
                  {
                  System.out.println("Makedir");
                  parentFile.mkdirs();
                  }
                  }
                  
                  System.out.println("Innan fo");
                        fo = new FileOutputStream(filename);
           
      System.out.println(ze.getSize()+"   "+ze.getName());
                        
                  while (x < ze.getSize())
                  {      
                        len = zi.read(bArr,0,256);
            
                fo.write(bArr, 0, len);      
                x = x + len;
               }
               x = 0;
         
                           
                        
                        
                  }

}
System.out.println("2");
 in.close();
// fo.close();      
      } catch (ZipException zipex) { System.out.println("Invalid archive!!!"); }


 
 


                  
                  
                  
            }      catch (IOException ioe) {System.out.println(ioe.toString());}
      
      
      


      
      }

0
 
msmolyakCommented:
Code looks ok. What happens if you sign you applet for low security? What if you turn the browser zone to trusted (with low security)? If the browser security is higher than applet's security it should prompt you for permission which it does, right? Does it say that the applet is signed and allows you to view your signing certificate? If it does not, the problem may be in signing.
0
 
pierreanderssonAuthor Commented:
Can the securityexception be that i have a testcertificate?
0
 
msmolyakCommented:
It shouldn't really. If you have a test certificate it should be obvious for anyone who wants to look at your certificate (and thus may want to deny permission) but the program should not care.
0
 
GregLCommented:
I am having exactly the same problem, except that I have a VeriSign Class 2 certificate and private key.  I see the certificate in the window, but I get the same exception.  By the way there is a really good FAQ here...

http://www.suitable.com/Doc_CodeSigning.shtml#explorer

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now