我现在对Applet数字签名有点疑惑,我在服务器端有一个Test.jar文件,它调用每一个客户端的Writer.jar文件进行对C盘写操作。注意这里Test.jar文件在服务端,Writer.jar文件是在每一个客户端都存在。代码如下
public class Test extends JApplet{
public void start()
{
new Write().write() ;
}
}public class Write 
{
public void write()
{
try
{
FileWriter write = new FileWriter("C:/temp.txt") ;
write.write("abcdef") ;
write.flush() ;
write.close() ;
}
catch(Exception e)
{
e.printStackTrace() ;
}
}
}我的签名如下
keytool -genkey -keystore pepper.store -alias pepperkeytool -export -keystore pepper.store -alias pepper -file pepper.certjarsigner -keystore pepper.store Test.jar pepperjarsigner -keystore pepper.store Writer.jar pepper
(这里的Writer.jar文件是签名后在每一个客户端都存在)每一个客户端的JAVA_plugin 的JAVA RunTime参数设置如下
-classpath C:/src/Write.jar服务器端的client.policy文件内容如下keystore "file:http://10.0.0.4:8080/testsign/pepper.store", "JKS";grant signedBy "pepper"
{ permission java.security.AllPermission;
};客户端的jre/lib/java.security添加了下面一句
policy.url.3=http://10.0.0.4:8080/testsign/client.policy服务端的Test.html文件内容如下
<applet code="Test.class" archive="Test.jar" width=800,height=600></applet>但我在客户端访问时,他提示启用证书,确定后,但客户端还是报没有权限错误,但如果我将Writer.jar文件也放在服务器端Test.html文件内容如下
<applet code="Test.class" archive="Test.jar,Writer.jar" width=800,height=600></applet>这时客户端是可以写C盘文件的但我的现实情况是这样的,Writer.jar文件很大,在每一个客户端都存在,只是要对Test.jar文件进行签名,请问要如何做,非常感谢!

解决方案 »

  1.   

    在java中的 applet 的认证和签名 确实麻烦。。
     java.sun.com  的tutorial 上有用apple 在本地写一个文件的例子:
     http://java.sun.com/docs/books/tutorial/security1.2/tour1/
     但只能用AppletViewer 可以看:
     appletviewer http://java.sun.com/docs/books/tutorial/security1.2/tour1/example-1dot2/WriteFile.html
      又在[阿费]的帮助下找到可以用ie or Nescape 查看你的applet 的例子:
      http://www.intelligentsearch.org/namesearch_from_java.htm#_Toc490550108大致过程如下::服务器端:
     
    1。 Compile the java classes --写applet并编译。
        javac *.class
    2.   Place the class files in a JAR file    --打包:
        jar cvf  yourjarname.jar  yourdir/*.class
        1). Create a Keystore and Keys for signing the JAR file 
            keytool –genkey –keystore ist.keystore –alias IST
        2). Sign the JAR file                  --对jar 签名
            jarsigner –keystore ist.keystore ist.jar IST
        3). Create the Public Key Certificate  --创建公钥
            keytool –export –keystore ist.keystore –alias IST –file IstPubKey.cert
    客户端:   1。Import the Public Key Certificate --导入公钥
          keytool –import –alias IST –file IstPubKey.cert –keystore client.store
       2。Modifing a policy file  --修改 policy文件
       3。 Run the applet   --运行applet
       !!! 这还只能用Applet viewer 查看你的applet 
       
    用ie访问:
    First, the <APPLET> tag will not be able to activate the Java Plug-in for use in IE. This tag should be substituted by the <OBJECT> tag
     ---由于IE 的java Plug-in 不能被<APPLET>标签激活。你还要将他换成<OBJECT>标签。 these changes to the HTML file can also be done with the help of HTMLConverter. You can go to download this software from http://java.sun.com/products/plugin/index.html. 
    ---- 这样你还要去下一个HTMLConverter
    ---- 将经过转换的html 和 class 文件copy 到你的服务器上。
    -- 好了。终于可以享受一下成果了。
         用ie 访问:http://yourserver: youreport/WriteFile.html
         还不行?? 
         --IE 还要下载Plug-in 才能执行,
         在1小时加26分46秒后:
         kao ,终于在本地写了一个文件。
      

  2.   

    我这样也是可以的,可是我现在是在每个客户端都存在一个Writer.jar文件,服务器端的Test.jar文件只是要调用客户端的Writer.jar文件,请问要如何做,谢谢!
      

  3.   

    你把很大的Writer.jar放到客户端?请问你怎么把此jar载入java虚拟机呢?
      

  4.   

    我在控制面板的JAVA_PLUGIN里的RunTime参数设置了
    -classpath C:/src/Write.jar
      

  5.   

    JAVA_PLUGIN里的RunTime参数设置了-classpath C:/src/Write.jar,这就是把Write.jar放入classpath而已,这个Write.jar如果是在客户端,虚拟机怎么找得到呢.
      

  6.   

    这是可以的,在客户端的Java_Plugin的 Java Rutime Enviroment里已设置了JRE路径,客户端加载Applet程序时就是用这个指定的JRE装载。