MPESA SSL Guide PDF
MPESA SSL Guide PDF
such as after a reboot or crash. mod_ssl includes the ability to use an external program
in place of the built-in pass-phrase dialog, however, this is not necessarily the most
secure option either. It is possible to remove the Triple-DES encryption from the
key, thereby no longer needing to type in a pass-phrase. If the private key is no longer
encrypted, it is critical that this file only be readable by the root user! If your system is
ever compromised and a third party obtains your unencrypted private key, the
corresponding certificate will need to be revoked. With that being said, use the following
command to remove the pass-phrase from the key:
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
The newly created server.key file has no more passphrase in it.
-rw-r--r-- 1 root root 745 Jun 29 12:19 server.csr
-rw-r--r-- 1 root root 891 Jun 29 13:22 server.key
-rw-r--r-- 1 root root 963 Jun 29 13:22 server.key.org
try {
KeyStore certStore = KeyStore.getInstance("PKCS12");
if (!isKeyStore) {
File certFile = new File(keyStorePath);
InputStream keyInput = new FileInputStream(certFile);
certStore.load(keyInput, certPass.toCharArray());
keyInput.close();
}
else {
//FileInputStream kfis = new FileInputStream(keyStorePath +
File.separatorChar + "keystore.keystore");
FileInputStream kfis = new FileInputStream("bob_pfx.pfx");
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(kfis, keyStorePass.toCharArray());
// Get certificate
Certificate cert = keyStore.getCertificate(certAlias);
certStore =
KeyStore.getInstance(KeyStore.getDefaultType());
certStore.load(null, null);
certStore.setCertificateEntry(certAlias, cert);
keyManagerFactory.init(certStore, certPass.toCharArray());
}
catch (KeyStoreException ke) {
System.out.println(gt.getDateTime() + "|Error loading client
certificate: " + ke.toString());
}
catch (CertificateException ce) {
System.out.println(gt.getDateTime() + "|Error loading client
certificate: " + ce.toString());
}
catch (NoSuchAlgorithmException ne) {
System.out.println(gt.getDateTime() + "|Error loading client
certificate: " + ne.toString());
}
catch (UnrecoverableKeyException ue) {
System.out.println(gt.getDateTime() + "|Error loading client
certificate: " + ue.toString());
}
catch (IOException io) {
System.out.println(gt.getDateTime() + "|Error loading client
certificate: " + io.toString());
}
finally {
sc.init(keyManagerFactory.getKeyManagers(), trustAllCerts, new
java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(hv);
}
Done!