如何使用JSSE实现SSL安全连接(4)try{ keyStore=KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(keyStoreIStream,keyStorePassWord); }catch(KeyStoreException ke) { System.out.println("Loading of https keystore from file <"+keyStorePath+"> failed. error message: "+ke.getMessage()); keyStore=null; } }
/** * Authenticates a client certificate. For we don't need that case only implement the * default behaviour. * * @param chain In: The certificate chain to be authenticated. * @param authType In: The key exchange algorithm. */ publicvoid checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { ((X509TrustManager)tm).checkClientTrusted(chain,authType); }
/** * Authenticates a server certificate. If the given certificate is untrusted ask the * user whether to proceed or not. * * @param chain In: The certificate chain to be authenticated. * @param authType In: The key exchange algorithm. */
publicvoid checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { /* Output the certifcate chain for debugging purposes */ System.out.println("got X509 certificate from server:"); for(int i=0; i<chain.length; i++) { System.out.println("chain["+i+"]: "+chain[i].getIssuerDN().getName()); }