簡體   English   中英

JAVA Applet加載問題

[英]JAVA Applet Loading Issue

我們已經在JAVA中開發了一個applet,主要用於從密鑰庫訪問數字證書。

小程序在大多數情況下都可以正常工作,但是在某些安全的銀行網絡中,小程序的行為變得不可預測。

我們正在HTML中使用applet標記來訪問applet。

我的第一個問題是我們是否需要為此使用JNLP進行部署?

其次,我過去編寫了一個測試應用程序,當時我只是簡單地調用一種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 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

以下是控制台輸出,它在循環中進入。

期待在同一答案。 提前致謝。

我發現了問題。 這里沒有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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM