public RespondingX509TrustManager() throws Exception {
// create a "default" JSSE X509TrustManager.
- File file = null;
- FileInputStream cacertsFileInputStream = null;
- char cacertsPass[] = null;
-
- //Create&load KeyStore
- KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
- //KeyStore ks = KeyStore.getInstance("JKS");
- //ks.load(new FileInputStream("trustedCerts"), "passphrase".toCharArray());
- try {
- //Check file at sytem property javax.net.ssl.trustStore.
- String cacertsFileName = System.getProperty("javax.net.ssl.trustStore");
- if (cacertsFileName != null) {
- file = new File(cacertsFileName);
- System.out.println("System property javax.net.ssl.trustStore:"
- + cacertsFileName);
- }
- if (file == null) {
- //Check Default trustStore
- char SEP = File.separatorChar;
- String cacertsDirName = System.getProperty("java.home") + SEP + "lib"
- + SEP + "security";
- file = new File(cacertsDirName, "jssecacerts");
- if (!file.canRead()) {
- System.err.println("NotFound:" + file.getPath());
- file = new File(cacertsDirName, "cacerts");
- }
- }
- if (!file.canRead()) {
- System.err.println("NotFound:" + file.getPath());
- cacertsFileInputStream = null;
- } else {
- cacertsFileInputStream = new FileInputStream(file);
- System.err.println("Load trustStore:" + file.getPath());
- String cacertsPassString = System.getProperty("javax.net.ssl.trustStorePassword");
- if (cacertsPassString != null) {
- cacertsPass = cacertsPassString.toCharArray();
- }
- }
- } catch (NullPointerException npEx) {
- npEx.printStackTrace(System.out);
- cacertsFileInputStream = null;
- } catch (FileNotFoundException fnfEx) {
- System.err.println("CanNotRead(" + fnfEx + "):" + file.getPath());
- cacertsFileInputStream = null;
- } catch (SecurityException ex) {
- cacertsFileInputStream = null;
- System.err.println("CanNotRead(" + ex + "):" + file.getPath());
- }
- ks.load(cacertsFileInputStream, cacertsPass);
- cacertsFileInputStream.close();
-
+ //KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
TrustManagerFactory tmf =
TrustManagerFactory.getInstance("PKIX");
- tmf.init(ks);
+ tmf.init((KeyStore)null); //Default KeyStore by null argument.
TrustManager tms[] = tmf.getTrustManagers();