You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Tim Wild <ti...@solnetsolutions.co.nz> on 2004/05/24 04:15:31 UTC

client certs - how to choose which cert to use?

Hi all,

Using a link to Sun code that a few people have posted before, I have 
client authentication working using HttpClient by creating my own 
SecureProtocolSocketFactory.

The problem i'm having is that it seems to automatically choose a 
certificate without asking me which one to use. Does anyone know how to 
modify the following code to retrieve a cert by name? Even a way to work 
out which client cert is loaded would be great.

Thanks

Tim

SSLSocketFactory factory = null;
SSLSocket socket = null;
try {
    SSLContext ctx;
    KeyManagerFactory kmf;
    KeyStore ks;
    char[] passphrase = "password".toCharArray();

    ctx = SSLContext.getInstance("TLS");
    kmf = KeyManagerFactory.getInstance("SunX509");
    ks = KeyStore.getInstance("JKS");

    File f = new File(".keystore");
    FileInputStream fis = new FileInputStream(f);
    ks.load(fis, passphrase);

    kmf.init(ks, passphrase);
    ctx.init(kmf.getKeyManagers(), null, null);
    factory = ctx.getSocketFactory();

    socket = (SSLSocket) factory.createSocket(host, port);

} catch (Exception e) {
    e.printStackTrace();
}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org