如何使用JSSE实现SSL安全连接(5) ((X509TrustManager)tm).checkServerTrusted(chain,authType); }catch(CertificateException ce) { System.out.println("in checkServerTrusted: authType: "+authType+", got certificate exception: "+ce.getMessage()); /* If we got here the certificate is untrusted. */
/* If we could not craete a keystore instance forward the certificate exception. So we have * at least the default behaviour. */ if(keyStore==null chain == null chain.length==0) { throw(ce); } try{ /* If we could not find the certificate in the keystore * ask the user if it should be treated trustable. */ AskForTrustability ask=new AskForTrustability (chain); boolean trustCert=ask.showCertificateAndGetDecision(); if(trustCert==true) { // Add Chain to the keyStore. for (int i = 0; i < chain.length; i++){ keyStore.setCertificateEntry(chain[i].getIssuerDN().toString(), chain[i]); } // Save keystore to file. FileOutputStream keyStoreOStream = new FileOutputStream(keyStorePath); keyStore.store(keyStoreOStream, keyStorePassWord); keyStoreOStream.close(); keyStoreOStream = null; System.out.println("Keystore saved in " + keyStorePath); } else { throw(ce); } }catch(Exception ge) { /* Got an uneXPected exception so throw the original exception. */