I am using Akka 2.4.x and trying to configure the truststore with Akka Http - so that I can validate incoming request to the server.
My Stack is: 1. AWS API Gateway - Sending a Client certificate 2. AKKA HTTP using java truststore for Validation
final Http http = Http.get(system);
if (properties.useSSL()) {
log.info("Starting on " + properties.url() + ":" + properties.port());
HttpsConnectionContext https = useHttps(system);
ConnectHttp connect = ConnectHttp.toHostHttps(properties.urlSSL(), properties.portSSL())
.withCustomHttpsContext(https);
http.bindAndHandle(appRoute().flow(system, materializer), connect, materializer);
log.info("Started on " + properties.urlSSL() + ":" + properties.portSSL());
} else {
log.info("Starting on " + properties.url() + ":" + properties.port());
final ConnectHttp host = ConnectHttp.toHost(properties.url(), properties.port());
http.bindAndHandle(appRoute().flow(system, materializer), host, materializer);
log.info("Started on " + properties.url() + ":" + properties.port());
}
public HttpsConnectionContext useHttps(ActorSystem system) {
HttpsConnectionContext https = null;
try {
final char[] password = properties.keystorePassword().toCharArray();
final KeyStore keyStore = KeyStore.getInstance("PKCS12");
final InputStream keyStoreStream = WDService.class.getClassLoader()
.getResourceAsStream(properties.keystoreFileName());
if (keyStoreStream == null) {
throw new RuntimeException("Keystore required!");
}
keyStore.load(keyStoreStream, password);
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(keyStore, password);
final TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(keyStore);
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom());
https = ConnectionContext.https(sslContext);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
log.debug(" while configuring HTTPS." + e.getCause(), e);
} catch (CertificateException | KeyStoreException | UnrecoverableKeyException | IOException e) {
log.debug(e.getCause() + " while ", e);
} catch (Exception e) {
log.debug(e.getCause() + " Exception", e);
}
return https;
}
My Issue is : My truststore settings are not being honoured, although i get no error as such but this settings do not work. My System accept request from postman when I am not sending client certificate with it.
Is there a issue with the Algorithm I am using ? or where can I look for errors/problem - so that I can move furthur