How to access the certificates stored in the Modeler or in the Mendix Cloud from java

4
I have to implement a call to a service that is protected with a client certificate. I'm able to upload the certificate in the Modeler under Project > Settings > Certificates and in the Mendix Cloud under Project > Deploy > Environment details > Network > Certificates for outgoing connections. My question is how to access the certificates uploaded there from Java? I'm setting up a connection with the help of SSLContext and HttpsURLConnection.setDefaultSSLSocketFactory(). I have to provide a KeyManager[] to SSLContext.init(). When i hard code this in the app it works. However i don't like storing the certificates with the code/model. So i hope that anybody has an idea how to access the certificates from java? I have seen the List<String> getClientCertificatePasswords() and List<InputStream> getClientCertificates() methods, but i can't seem to put them to use. .
asked
1 answers
2
Configuration conf = Core.getConfiguration();
List<InputStream> mxcerts = conf.getClientCertificates();
List<String> mxpwds = conf.getClientCertificatePasswords();

for (int i = 0; i < mxcerts.size(); i++) {
  InputStream mxcert = mxcerts.get(i);
  String mxpwd = mxpwds.get(i);
  KeyStore ks = KeyStore.getInstance("pkcs12");
  ks.load(mxcert, mxpwd.toCharArray());
...
}

 

answered