如何使用JSSE实现SSL安全连接(2) * It enhances the default behaviour. */ class StoreCertTrustManager implements X509TrustManager { /** The trustmanager instance used to delegate to default behaviour.*/ private TrustManager tm=null;
/** PassWord for own keystore */ privatefinalchar[] keyStorePassWord=new String("changeit").toCharArray();
/** Path to own keystore. Store it into the home directory to avoid permission problems.*/ privatefinal String keyStorePath=System.getProperty("user.home")+"/https-keystore"; /** The stream for reading from the keystore. */ FileInputStream keyStoreIStream=null; /** The instance of the keystore */ private KeyStore keyStore=null;
/** * Creates a TrustManager which first checks the default behaviour of the X509TrustManager. * If the default behaviour throws a CertificateException ask the user if the certificate * should be declared trustable. * * @throws Exception: If SSL - initialization failed. */
StoreCertTrustManager() throws Exception { /* Try to set the truststore system property to our keystore * if we have the appropriate permissions.*/ try{ File httpsKeyStore=new File(keyStorePath);