I am able to make the following curl command:
curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET ${APISERVER}/api
now I am trying to do the same with scala code, I saw many examples of SSL connection, but I am just presenting CA cert to use the specified certificate file to verify the peer.
I tried something like this:
object HttpsServerContext {
InputStream is = new FileInputStream("cacert.crt");
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate caCert = (X509Certificate)cf.generateCertificate(is);
TrustManagerFactory tmf = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null);
ks.setCertificateEntry("caCert", caCert);
tmf.init(ks);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
}
// this is the way I used the httpsConnections
val nvl4RcGet = HttpRequest(uri = uri)
.withMethod(HttpMethods.GET)
.withHeaders(RawHeader("Authorization", "Bearer" + tokenfileContents))
val res = Http().singleRequest(nvl4RcGet, getSslContextForNoCertificateCheck)
but it still does not works, and failed with error:
[ERROR] [06/07/2022 12:50:16.572] [EVENTSystem-akka.actor.default-dispatcher-9] [akka://EVENTSystem/system/Materializers/StreamSupervisor-17/TLS-for-flow-1-1] host and port supplied for connection based on server connection context
akka.actor.ActorInitializationException: akka://EVENTSystem/system/Materializers/StreamSupervisor-17/TLS-for-flow-1-1: exception during creation
any suggestion?