@@ -187,11 +187,45 @@ values (like the API key) in source-controlled property files!
187187
188188## Set Up Trust Between App and Conjur
189189
190- By default, the Conjur appliance generates and uses self-signed SSL certificates (Java-specific
191- certificates known as cacerts). Without trusting them, your Java app will not be able to connect
192- to the Conjur server over APIs and so you will need to configure your app to trust them. You can
193- accomplish this by loading the Conjur certificate into Java's CA keystore that holds the list of
194- all the allowed certificates for https connections.
190+ By default, the Conjur appliance generates and uses self-signed SSL certificates. Without
191+ trusting them, your Java app will not be able to connect to the Conjur server over APIs
192+ and so you will need to configure your app to trust them. You can accomplish this by using
193+ the [ Client-level ` SSLContext ` ] ( #client--level-trust ) when creating the client or with a
194+ [ JVM-level trust] ( #jvm--level-trust ) by loading the Conjur certificate into Java's CA
195+ keystore that holds the list of all the allowed certificates for https connections.
196+
197+ ### Client-level trust
198+
199+ We can set up a trust between the client application and a Conjur server using
200+ Java ` javax.net.ssl.SSLContext ` . This can be done from Java code during
201+ Conjur class initialization.
202+
203+ Usable in Kubernetes/OpenShift environment to setup TLS trust with Conjur
204+ server dynamically from the Kubernetes secret and/or configmap data.
205+
206+ ``` java
207+ final String conjurTlsCaPath = " /var/conjur-config/tls-ca.pem" ;
208+
209+ final CertificateFactory cf = CertificateFactory . getInstance(" X.509" );
210+ final FileInputStream certIs = new FileInputStream (conjurTlsCaPath);
211+ final Certificate cert = cf. generateCertificate(certIs);
212+
213+ final KeyStore ks = KeyStore . getInstance(" JKS" );
214+ ks. load(null );
215+ ks. setCertificateEntry(" conjurTlsCaPath" , cert);
216+
217+ final TrustManagerFactory tmf = TrustManagerFactory . getInstance(" SunX509" );
218+ tmf. init(ks);
219+
220+ SSLContext conjurSSLContext = SSLContext . getInstance(" TLS" );
221+ conjurSSLContext. init(null , tmf. getTrustManagers(), null );
222+ ```
223+
224+ ### JVM-level trust
225+
226+ For a JVM-level trust between Conjur and the API client, you need to load the Conjur
227+ certificate into Java's CA keystore that holds the list of all the allowed certificates
228+ for https connections.
195229
196230First, we need to get a copy of this certificate, which you can get using ` openssl ` . Run the
197231following step from a terminal with OpenSSL that has access to Conjur:
@@ -287,6 +321,8 @@ import net.conjur.api.Conjur;
287321
288322// Configured using environment variables
289323Conjur conjur = new Conjur ();
324+ // or using custom SSLContext setup as conjurSSLContext variable
325+ Conjur conjur = new Conjur (conjurSSLContext);
290326```
291327
292328### System Properties
@@ -303,6 +339,8 @@ import net.conjur.api.Conjur;
303339
304340// Configured using system properties
305341Conjur conjur = new Conjur ();
342+ // or using custom SSLContext setup as conjurSSLContext variable
343+ Conjur conjur = new Conjur (conjurSSLContext);
306344```
307345
308346### System Properties with Maven
@@ -320,6 +358,8 @@ import net.conjur.api.Conjur;
320358
321359// Configured using system properties
322360Conjur conjur = new Conjur ();
361+ // or using custom SSLContext setup as conjurSSLContext variable
362+ Conjur conjur = new Conjur (conjurSSLContext);
323363```
324364
325365### Username and Password
@@ -337,6 +377,8 @@ import net.conjur.api.Conjur;
337377Conjur conjur = new Conjur (' host/host-id' , ' password-or-api-key' );
338378// or
339379Conjur conjur = new Conjur (' username' , ' password-or-api-key' );
380+ // or using custom SSLContext setup as conjurSSLContext variable
381+ Conjur conjur = new Conjur (' username' , ' password-or-api-key' , conjurSSLContext);
340382```
341383
342384### Credentials
@@ -354,6 +396,8 @@ import net.conjur.api.Credentials;
354396// regarding how 'password-or-api-key' is processed.
355397Credentials credentials = new Credentials (' username' , ' password-or-api-key' );
356398Conjur conjur = new Conjur (credentials);
399+ // or using custom SSLContext setup as conjurSSLContext variable
400+ Conjur conjur = new Conjur (credentials, conjurSSLContext);
357401```
358402
359403### Authorization Token
@@ -371,6 +415,8 @@ import net.conjur.api.Token;
371415
372416Token token = Token . fromFile(Paths . get(' path/to/conjur/authentication/token.json' ));
373417Conjur conjur = new Conjur (token);
418+ // or using custom SSLContext setup as conjurSSLContext variable
419+ Conjur conjur = new Conjur (token, conjurSSLContext);
374420```
375421
376422Alternatively, use the ` CONJUR_AUTHN_TOKEN_FILE ` environment variable:
@@ -387,6 +433,8 @@ import net.conjur.api.Token;
387433
388434Token token = Token . fromEnv();
389435Conjur conjur = new Conjur (token);
436+ // or using custom SSLContext setup as conjurSSLContext variable
437+ Conjur conjur = new Conjur (token, conjurSSLContext);
390438```
391439
392440## Client APIs
@@ -400,10 +448,15 @@ a secret from Conjur, so we provide some sample code for this use case below.
400448The client can be instantiated with any of these methods:
401449``` java
402450Conjur client = Conjur();
451+ Conjur client = Conjur(SSLContext sslContext);
403452Conjur client = Conjur(String username, String password);
453+ Conjur client = Conjur(String username, String password, SSLContext sslContext);
404454Conjur client = Conjur(String username, String password, String authnUrl);
455+ Conjur client = Conjur(String username, String password, String authnUrl, SSLContext sslContext);
405456Conjur client = Conjur(Credentials credentials);
457+ Conjur client = Conjur(Credentials credentials, SSLContext sslContext);
406458Conjur client = Conjur(Token token);
459+ Conjur client = Conjur(Token token, SSLContext sslContext);
407460```
408461
409462_ Note:_ ** As mentioned before, if you use the default ` CONJUR_AUTHN_URL ` value or your
0 commit comments