472,126 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

Problem with access to signed javascript file

Hello,

I'm trying to load and write file on local disc drive using signed
javascript file. But I have experienced problem running this url:

jar:http://www.domain.com/secure-scripts...!/thepage.html
(sample)

in browser (Firefox) which simply won't work. I can't access to
html file embedded in jar file. My sample applet IO.java together
with IO.html was properly signed with valid certificate (real one,
no test certificate) by using signtool as is written here:

http://www.mozilla.org/projects/secu...d-scripts.html .

Is there someone who can help me or experienced same problems
with running embeded html file in signed jar file? Your help
is very appreciated. Thank you.


Expand|Select|Wrap|Line Numbers
  1. Sample IO.java:
  2.  
  3. import java.applet.*;
  4. import java.awt.*;
  5. import java.io.*;
  6.  
  7. import java.util.regex.*;
  8. import java.util.Map;
  9. import java.util.ArrayList;
  10.  
  11. @SuppressWarnings("deprecation")
  12. public class IO extends Applet {
  13.     private ArrayList<String[]> envvars = new ArrayList<String[]>();    
  14.     public static String newLine = System.getProperty("line.separator");    
  15.  
  16.     public boolean boolSwitch = true;
  17.  
  18.     public void init() {
  19.         Map<String, String> env = System.getenv();
  20.         for (String envName : env.keySet()) {
  21.             String[] tmpfield;
  22.             tmpfield = new String[2];
  23.             tmpfield[0] = envName;
  24.             tmpfield[1] = env.get(envName);
  25.             envvars.add(tmpfield);
  26.         }    
  27.     }    
  28.  
  29.     public void write(String path, String data) {
  30.         try {
  31.             path = expEnvironment(path);
  32.             File file = new File(path);
  33.             DataOutputStream dos = new DataOutputStream(
  34.                 new BufferedOutputStream(
  35.                     new FileOutputStream(file)));
  36.             dos.writeBytes(data);
  37.             dos.close();                    
  38.         }
  39.         catch (SecurityException se) {
  40.             System.err.println(se.getMessage());
  41.         }
  42.         catch (IOException ioe) {
  43.             System.err.println(ioe.getMessage());
  44.         }
  45.     }
  46.  
  47.     public String load(String path) {
  48.         String tmpStr = new String();
  49.         try {
  50.             path = expEnvironment(path);
  51.             File file = new File(path);
  52.             DataInputStream dis = new DataInputStream(
  53.                 new BufferedInputStream(
  54.                     new FileInputStream(file)));
  55.             do {
  56.                 tmpStr = tmpStr.concat(dis.readLine());
  57.                 if (dis.available() != 0) {
  58.                     tmpStr = tmpStr.concat(newLine);
  59.                 }
  60.             } while (dis.available() != 0);
  61.             dis.close();                    
  62.         }
  63.         catch (SecurityException se) {
  64.             System.err.println(se.getMessage());
  65.         }
  66.         catch (IOException ioe) {
  67.             System.err.println(ioe.getMessage());
  68.         }
  69.         return tmpStr;
  70.     }
  71.  
  72.     public void paint(Graphics g) {
  73.     }
  74.  
  75.     private String expEnvironment(String path) {
  76.         String envPer = new String();
  77.         String env = new String();
  78.         Pattern pattern = Pattern.compile("%\\w+%");
  79.         Matcher matcher = pattern.matcher(path);
  80.         while (matcher.find()) {
  81.             envPer = matcher.group();
  82.             env = envPer.replace("%", "");
  83.             for (int i = 0; i < envvars.size(); i++) {
  84.                 if (env.equalsIgnoreCase(envvars.get(i)[0])) {
  85.                     path = path.replace(envPer, envvars.get(i)[1]);
  86.                 }
  87.             }
  88.         }
  89.         return path;
  90.     }    
  91. }
Sample IO.html:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <applet archive="IO.jar" code="IO.class" name="io" width="0" height="0"></applet>
  3. <script type="text/javascript">
  4.  
  5. function saveText() {
  6.     var strFile = document.getElementById("file").value;;
  7.     var strText = document.getElementById("text").value;
  8.     document.applets[0].write(strFile, strText);
  9. }
  10.  
  11. function loadText() {
  12.     var strFile = document.getElementById("file").value;;
  13.     document.getElementById("text").value = document.applets[0].load(strFile);
  14. }
  15.  
  16. </script>
  17. <input type="text" id="file" value="c:\\test.txt" /><br />
  18. <textarea rows="25" cols="100" id="text">text</textarea><br />
  19. <input type="button" value="Save" onclick="saveText()" />
  20. <input type="button" value="Load" onclick="loadText()" />
  21. </html>
Apr 24 '09 #1
2 3751
pronerd
392 Expert 256MB
@JohnLorac
The description starts off talking about accessing a JavaScript file, but the URL is for a JAR file. Which is it you are trying to use? They are completely different un-related technologies. Are you trying to load a Java Applet in the page?



@JohnLorac
Meaning what exactly? Is there an error, is something happening that should not, or something not happening that should be?



@JohnLorac
Is something actually accessing it. I see where what I assume is supposed to be an applet being loaded in the page, but do not see where there is an attempt to access its contents.
Apr 29 '09 #2
Thank you for your reply.

@pronerd
I'm trying to open html file embedded in Java applet file. And then from this page control Java Applet itself. I think there is a logical error in my example, because of refence to JAR file in html file. But, basically what I need is to control Java Applet functions from html file with using javascript.

@pronerd
Originally I was trying to open html file with embedded Java Applet and then control it with javascript. But this doesn't work because I was trying to access signed (trusted) content from unsigned html file. So, I signed html file with Java class file and tries somehow access Java Applet functions from this html file. But when I put that weird link accessing html file embedded in JAR file into browser html file won't open :(. So, what is not working is that link to html file embedded in JAR file.

@pronerd
Here is the attempt to access its contents:
document.getElementById("text").value = document.applets[0].load(strFile);

But this will propably won't work because of invalid JAR reference in html file:
<applet archive="IO.jar" code="IO.class" name="io" width="0" height="0"></applet>

Inside IO.jar is this IO.html which is trying to access IO.class. (IO.class and IO.html are together inside IO.jar) I assume archive="IO.jar" is wrong reference.
But first real problem for me is that this "jar:http://www.domain.com/secure-scripts...!/thepage.html" link won't open.

Hopes it is little clearer now ;).
Apr 30 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Sruli Ganor | last post: by
1 post views Thread by sean | last post: by
3 posts views Thread by eft0 | last post: by
10 posts views Thread by chanma | last post: by
8 posts views Thread by David Gravereaux | last post: by
2 posts views Thread by Terry Chapman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.