All 2 entries tagged Ssl
View all 4 entries tagged Ssl on Warwick Blogs | View entries tagged Ssl at Technorati | There are no images tagged Ssl on this blog
June 07, 2006
Apache with SSL and client auth on windows
I've always run any SSL I need on Tomcat on Windows as it was just really easy and less complicated and messy than getting Apache to work with SSL on Windows. Unfortunately I eventually needed to do it because of the extra power of Apache in that you can set different SSL options under different directories.
If you need to do client certificate authentication in Tomcat it is easy, but that is it, everything under that port is now protected with client auth.
In Apache you can do this:
... <Location /clientauth> SSLVerifyClient require SSLVerifyDepth 2 </Location> ...
Kindly a few people have written up some instructions on this:
Apache and SSL on Windows
Someone has also pre–built a Windows version of Apache with SSL built in:
Hunter Apache SSL builds as Apache doesn't provide it because they believe Windows is just not secure enough and allowing SSL on Windows lulls people into a false sense of security.
Anyway, most of it worked, but I just couldn't get Apache to trust my client certificates. The problem was this:
SSLEngine On SSLCertificateFile conf/ssl/my.crt SSLCertificateKeyFile conf/ssl/my.key SSLCACertificatePath conf/ssl.crt SSLCACertificateFile conf/ssl.crt/cabundle.crt
If you put certificates in the conf/ssl.crt path, when Apache starts up, it lists them all nicely saying that it has found them all, but will it trust them, will it hell. Only if you specifically put the certificate in the cabundle.crt (or whatever you've set SSLCACertificateFile to) will it work! Gah!
Anyway, working now so soon we should have a test membership of the SDSS federation so that we can do further tests on our Shibboleth SSO system.
December 14, 2005
Creating a Java KeyStore (JKS) with an existing key
We are using a lot more SSL than we used to in e-lab because of the new super powerful and secure Single Sign On system. This means we need to programatically access SSL keys and certificates with Java. If you just want to create a new key and use it in Java, you just create a Java KeyStore with the keytool program. However, if you want to use the key and certificate that you already had, things are a little trickier.
I came up with this little unix shell script which should make life easier:
host=$1
storepass=$2
echo Creating keystore for ${host}
certFile=${host}.crt
keyFile=${host}.key
echo "Creating pkcs12 file from $certFile and $keyFile"
openssl pkcs12 -export -in $certFile -inkey $keyFile -out ${host}.pkcs12
-name ${host} -passout pass:$storepass
java -classpath . KeystoreKeyImporter ${host}.pkcs12 $storepass ${host}.keystore $storepass Basically you run:importscript.sh myhostname.com mypass It will look for an existing myhostname.com.key and myhostname.com.crt and turn them into myhostname.com.pkcs12 which is then imported into myhostname.com.keystore with the KeystoreKeyImporter java program.
public class KeystoreKeyImporter {
public static void main(String[] args) throws Exception {
if (args.length < 4) {
System.out.println("Usage: KeystoreKeyImporter <inputpkcs12.file> <inputpkcs12.pass>
<outputkeystore.file> <outputkeystore.pass>");
return;
}
String pkcs12Location = args[0];
String pkcs12Password = args[1];
String keystoreLocation = args[2];
String keystorePassword = args[3];
// openssl pkcs12 -export -in test.crt -inkey test.key.nopass
// -out test.pkcs12 -name test
KeyStore kspkcs12 = KeyStore.getInstance("PKCS12");
String alias = null;
FileInputStream fis = new FileInputStream(pkcs12Location);
kspkcs12.load(fis, pkcs12Password.toCharArray());
if (kspkcs12.aliases().hasMoreElements()) {
System.out.println("Has keys!");
Enumeration aliases = kspkcs12.aliases();
while (aliases.hasMoreElements()) {
alias = (String) aliases.nextElement();
System.out.println("Alias:" + alias);
Key key = kspkcs12.getKey(alias,pkcs12Password.toCharArray());
if (key == null) {
System.out.println("No key found for alias: " + alias);
System.exit(0);
}
System.out.println("Key:" + key.getFormat());
Certificate cert = kspkcs12.getCertificate(alias);
if (cert == null) {
System.out.println("No certificate found for alias: " + alias);
System.exit(0);
}
System.out.println("Cert:" + cert.getType());
}
} else {
System.out.println("No keys!");
}
KeyStore ksjks = KeyStore.getInstance("JKS");
ksjks.load(null,keystorePassword.toCharArray());
Certificate c[] = kspkcs12.getCertificateChain(alias);
Key key = kspkcs12.getKey(alias, pkcs12Password.toCharArray());
ksjks.setKeyEntry(alias, key, keystorePassword.toCharArray(), c);
ksjks.store(new FileOutputStream(keystoreLocation), keystorePassword.toCharArray());
System.out.println("Created " + keystoreLocation);
}
}
You now have a nice JKS with your key and certificate in it.
Please wait - comments are loading
