JAVA Applet加载问题

时间:2013-07-30 13:50:57

标签: java security jnlp japplet digital-certificate

我们在JAVA中开发了一个小程序,主要用于从密钥库访问数字证书。

在大多数情况下,applet运行良好,但在某些安全的银行网络中,applet行为变得无法预测。

我们在HTML中使用applet标签来访问applet。

我的第一个问题是我们需要使用JNLP进行部署吗?

其次,我在过去编写了一个测试应用程序,我只是调用了一个applet方法,它正在加载所有证书公共详细信息并在控制台上打印。它过去工作完全正常。

以下是相同的代码。

Applet方法

   public void init() {
    printMessageToConsole("Applet Initialized Version : " + appletVersion);
    browserName = "Internet Explorer";
    try {
        String osName = System.getProperty("os.name");
        printMessageToConsole("Operating system name =>" + osName);

    } catch (Exception e) {
        printMessageToConsole("Error in Get OS Init.");
        e.printStackTrace();
    }
}


 public List<String> getCertificateAllDetails() throws NoSuchFieldException,
        SecurityException, IllegalArgumentException,
        IllegalAccessException, NoSuchMethodException,
        InvocationTargetException {
    printMessageToConsole("Get All Certificate Details");
    String certString = "";
    int count =0;
    String pubKey = "";
    KeyStore browserKeyStore = null;
    String certDetails = "";
    browserKeyStore = initializeBrowserKeyStore();
    List<String> resultValues = new ArrayList<String>();
    String aliasnew = null;

    printMessageToConsole(browserName);
    if (browserKeyStore != null) {
        printMessageToConsole("INSIDE IE CERTIFICATE READING");
        Field spiField = KeyStore.class.getDeclaredField("keyStoreSpi");
        spiField.setAccessible(true);
        KeyStoreSpi spi = (KeyStoreSpi) spiField.get(browserKeyStore);
        Field entriesField = spi.getClass().getSuperclass().getDeclaredField("entries");
        entriesField.setAccessible(true);
        @SuppressWarnings("rawtypes")
        Collection entries = (Collection) entriesField.get(spi);
        resultValues.add("Total Certificates in Browser : " + entries.size() + "<br><br><br>");
        printMessageToConsole("Total Certificates in Browser : " + entries.size());
        for (Object entry : entries) {
            aliasnew = (String) invokeGetter(entry, "getAlias");
            PrivateKey privateKey = (PrivateKey) invokeGetter(entry,"getPrivateKey");
            X509Certificate[] certificateChain = (X509Certificate[]) invokeGetter(entry, "getCertificateChain");
            for (X509Certificate current : certificateChain) {
                certString = "";
                if (certDetails != null && getkeyUsage(current.getKeyUsage()) != "") {
                    count ++;
                    pubKey = this.bASE64Encoder.encode(current.getPublicKey().getEncoded());
                    certDetails = getX509CertificateDetails(current);
                    Map<String, String> valueMap = new HashMap<String, String>();
                    valueMap = getMetadata(certDetails);
                    certString += "====================== Certificate Details for Certificate No : " + count + "======================<br>";
                    certString += "Alias : " + aliasnew + " <br>";
                    certString += "Name : "+ valueMap.get(CERT_DETAILS.NAME) + " <br>";
                    certString += "Key Usage : " + getkeyUsage(current.getKeyUsage()) + "<br>";
                    certString += "CNName : "+ valueMap.get(CERT_DETAILS.CN_NAME) + "<br>";
                    printMessageToConsole(certString);
                    resultValues.add(certString);
                    break;
                } else {
                    printMessageToConsole("Cert Details is NULL");
                }
            }
        }
    }
    else {
        printMessageToConsole("Keystore is NULL");
    }

    return resultValues;
}

HTML页面

<html>
<head> 
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<SCRIPT LANGUAGE="JavaScript">
    function getAllCertificates()
    {
        document.write("Certificate Reading Started.")
        var certificates = document.securityApplet.getCertificateAllDetails();
        document.write(certificates);


    }
</SCRIPT>
<body>
    <div>Digital Certificate Test Application</div>
    <script src="http://www.java.com/js/deployJava.js"></script>

    <applet name="securityApplet" code="SecurityApplet.class"
    archive="securityApplet.jar" width="0" height="0" MAYSCRIPT="true"
    scriptable="true" > </applet>
    <button type="button" onclick="getAllCertificates()">Load Certificates!</button>

</body>

我最近打开了这个页面,现在在我的本地网络中,applet正在初始化,但是点击按钮后无法再调用任何内容。

加载页面时的控制台输出。

Applet Initialized Version : 30
Operating system name =>Windows 7
basic: Applet initialized
basic: Starting applet
basic: completed perf rollup
basic: Applet made visible
basic: Applet started
basic: Told clients applet is started

在装载

之前一切正常

当我点击加载证书按钮时,以下是控制台日志,然后没有任何反应。在安全的网络中,最后两行甚至没有来。

basic: Starting applet teardown
basic: Finished applet teardown
basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter@1b9bbe8
plugin2manager.parentwindowDispose

以下是控制台输出,它在循环中进行。

期待同样的答案。在此先感谢。

1 个答案:

答案 0 :(得分:0)

我发现了问题。 这里没有任何关于JNLP的事情。 唯一的问题是我已经完成了document.write,它阻止并获取applet来处理。 我已从HTML中删除了document.write,并使用以下HTML代码完全正常。

<html>
<head> 
    <title> Digital Certificate Test Application </title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
 <script src="http://www.java.com/js/deployJava.js"></script>
    <applet name="securityApplet" code="SecurityApplet.class"
    archive="securityApplet.jar" width="0" height="0" MAYSCRIPT="true"
    scriptable="true" > </applet> 
<SCRIPT LANGUAGE="JavaScript">

    function getAllCertificates()
    {
        alert("Certificate Reading Started");
        var certificates = document.securityApplet.getCertificateAllDetails();
        document.getElementById("displaymessage").innerHTML = certificates;
    }
</SCRIPT>
<body>
    <div>Digital Certificate Test Application</div>
    <div id="displaymessage">

    </div>
    <button type="button" onclick="getAllCertificates()">Load Certificates!</button>

</body>