2

How do I set a client side keystore and truststore in an Apache Wink Client

I cannot find any documentation on how to do it.

http://wink.apache.org/documentation/1.2.1/Apache_Wink_User_Guide.pdf

Tarlog
  • 10,024
  • 2
  • 43
  • 67
DarVar
  • 16,882
  • 29
  • 97
  • 146

1 Answers1

0

I think the "usual" code initializing the SSLContext will work.

Example how to load the truststore:

String path = ....
char[] password = ....
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(new FileInputStream(path), password );
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, tmf.getTrustManagers(), null);

If you also need a keystore for client certificate, use the KeyStoreFactory in a similar way or implement a KeyManager

Tarlog
  • 10,024
  • 2
  • 43
  • 67
  • Did I not need to add the KeyStore and TrustStore to ClientConfig like the Jersey Client? // import com.sun.jersey.api.client.config.ClientConfig; // import com.sun.jersey.api.client.config.DefaultClientConfig; ClientConfig config = new DefaultClientConfig(); // import com.sun.jersey.client.urlconnection.HTTPSProperties config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(getHostnameVerifier(), getSSLContext())); – DarVar Jan 29 '14 at 12:15
  • As far as I remember, Wink by default uses HttpsURLConnection, which means that the default SSLContext will be used. – Tarlog Jan 29 '14 at 13:17
  • You can configure Wink to use the Apache HTTP Client, in this case you need to pass the SSL configuration to the client – Tarlog Jan 29 '14 at 13:17
  • I got this working with org.apache.http.impl.client.DefaultHttpClient org.apache.wink.client.httpclient.ApacheHttpClientConfig But I have to set the https port: httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 9443, socketFactory)); Anyway to avoid having to do this each time as I won't know the port before hand – DarVar Jan 29 '14 at 17:50