Problem with access to signed javascript file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JohnLorac
    New Member
    • Apr 2009
    • 5

    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.


    [code=java]
    Sample IO.java:

    import java.applet.*;
    import java.awt.*;
    import java.io.*;

    import java.util.regex .*;
    import java.util.Map;
    import java.util.Array List;

    @SuppressWarnin gs("deprecation ")
    public class IO extends Applet {
    private ArrayList<Strin g[]> envvars = new ArrayList<Strin g[]>();
    public static String newLine = System.getPrope rty("line.separ ator");

    public boolean boolSwitch = true;

    public void init() {
    Map<String, String> env = System.getenv() ;
    for (String envName : env.keySet()) {
    String[] tmpfield;
    tmpfield = new String[2];
    tmpfield[0] = envName;
    tmpfield[1] = env.get(envName );
    envvars.add(tmp field);
    }
    }

    public void write(String path, String data) {
    try {
    path = expEnvironment( path);
    File file = new File(path);
    DataOutputStrea m dos = new DataOutputStrea m(
    new BufferedOutputS tream(
    new FileOutputStrea m(file)));
    dos.writeBytes( data);
    dos.close();
    }
    catch (SecurityExcept ion se) {
    System.err.prin tln(se.getMessa ge());
    }
    catch (IOException ioe) {
    System.err.prin tln(ioe.getMess age());
    }
    }

    public String load(String path) {
    String tmpStr = new String();
    try {
    path = expEnvironment( path);
    File file = new File(path);
    DataInputStream dis = new DataInputStream (
    new BufferedInputSt ream(
    new FileInputStream (file)));
    do {
    tmpStr = tmpStr.concat(d is.readLine());
    if (dis.available( ) != 0) {
    tmpStr = tmpStr.concat(n ewLine);
    }
    } while (dis.available( ) != 0);
    dis.close();
    }
    catch (SecurityExcept ion se) {
    System.err.prin tln(se.getMessa ge());
    }
    catch (IOException ioe) {
    System.err.prin tln(ioe.getMess age());
    }
    return tmpStr;
    }

    public void paint(Graphics g) {
    }

    private String expEnvironment( String path) {
    String envPer = new String();
    String env = new String();
    Pattern pattern = Pattern.compile ("%\\w+%");
    Matcher matcher = pattern.matcher (path);
    while (matcher.find() ) {
    envPer = matcher.group() ;
    env = envPer.replace( "%", "");
    for (int i = 0; i < envvars.size(); i++) {
    if (env.equalsIgno reCase(envvars. get(i)[0])) {
    path = path.replace(en vPer, envvars.get(i)[1]);
    }
    }
    }
    return path;
    }
    }[/code]

    Sample IO.html:
    [code=html]
    <html>
    <applet archive="IO.jar " code="IO.class" name="io" width="0" height="0"></applet>
    <script type="text/javascript">

    function saveText() {
    var strFile = document.getEle mentById("file" ).value;;
    var strText = document.getEle mentById("text" ).value;
    document.applet s[0].write(strFile, strText);
    }

    function loadText() {
    var strFile = document.getEle mentById("file" ).value;;
    document.getEle mentById("text" ).value = document.applet s[0].load(strFile);
    }

    </script>
    <input type="text" id="file" value="c:\\test .txt" /><br />
    <textarea rows="25" cols="100" id="text">text </textarea><br />
    <input type="button" value="Save" onclick="saveTe xt()" />
    <input type="button" value="Load" onclick="loadTe xt()" />
    </html>[/code]
    Last edited by Nepomuk; Apr 24 '09, 10:54 PM. Reason: Please use the [code] tags
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    Originally posted by JohnLorac
    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
    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?



    Originally posted by JohnLorac
    in browser (Firefox) which simply won't work.
    Meaning what exactly? Is there an error, is something happening that should not, or something not happening that should be?



    Originally posted by JohnLorac
    I can't access to
    html file embedded in jar file.
    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.

    Comment

    • JohnLorac
      New Member
      • Apr 2009
      • 5

      #3
      Thank you for your reply.

      Originally posted by pronerd
      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?
      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.

      Originally posted by pronerd
      Meaning what exactly? Is there an error, is something happening that should not, or something not happening that should be?
      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.

      Originally posted by pronerd
      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.
      Here is the attempt to access its contents:
      document.getEle mentById("text" ).value = document.applet s[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 ;).

      Comment

      Working...