if (ks != null) {
keyStore = ks;
} else {
// BEGIN android-added
if (System.getProperty("javax.net.ssl.trustStore") == null) {
String file = System.getProperty("java.home")
+ java.io.File.separator + "etc" + java.io.File.separator
+ "security" + java.io.File.separator
+ "cacerts.bks";
System.setProperty("javax.net.ssl.trustStore", file);
}
// END android-added
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
String keyStoreName = AccessController
.doPrivileged(new java.security.PrivilegedAction<String>() {
public String run() {
return System
.getProperty("javax.net.ssl.trustStore");
}
});
String keyStorePwd = null;
if (keyStoreName == null || keyStoreName.equalsIgnoreCase("NONE")
|| keyStoreName.length() == 0) {
try {
keyStore.load(null, null);
} catch (IOException e) {
throw new KeyStoreException(e);
} catch (CertificateException e) {
throw new KeyStoreException(e);
} catch (NoSuchAlgorithmException e) {
throw new KeyStoreException(e);
}
} else {
keyStorePwd = AccessController
.doPrivileged(new java.security.PrivilegedAction<String>() {
public String run() {
return System
.getProperty("javax.net.ssl.trustStorePassword");
}
});
char[] pwd;
if (keyStorePwd == null) {
pwd = new char[0];
} else {
pwd = keyStorePwd.toCharArray();
}
try {
keyStore.load(new FileInputStream(new File(keyStoreName)), pwd);
} catch (FileNotFoundException e) {
throw new KeyStoreException(e);
} catch (IOException e) {
throw new KeyStoreException(e);
} catch (CertificateException e) {
throw new KeyStoreException(e);
} catch (NoSuchAlgorithmException e) {
throw new KeyStoreException(e);
}
}
}