Skip to content
Snippets Groups Projects
Commit 3bc260fd authored by Jawnnypoo's avatar Jawnnypoo
Browse files

Get the X509 Trust manager the way OkHttp gets it so that we always have the...

Get the X509 Trust manager the way OkHttp gets it so that we always have the same results as they would
parent 003ab468
No related branches found
No related tags found
No related merge requests found
Pipeline #
Loading
Loading
@@ -3,7 +3,9 @@ package com.commit451.gitlab.api;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
 
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
Loading
Loading
@@ -17,6 +19,7 @@ public class X509TrustManagerProvider {
 
/**
* Get the static {@link X509TrustManager} for the system
*
* @return the static instance
*/
public static X509TrustManager get() {
Loading
Loading
@@ -31,18 +34,19 @@ public class X509TrustManagerProvider {
return sX509TrustManager;
}
 
/**
* Getting the {@link X509TrustManager} as shown in the {@link okhttp3.OkHttpClient.Builder#sslSocketFactory(SSLSocketFactory, X509TrustManager)} docs
* @throws NoSuchAlgorithmException
* @throws KeyStoreException
*/
private static void init() throws NoSuchAlgorithmException, KeyStoreException {
TrustManagerFactory factory = TrustManagerFactory.getInstance("X509");
factory.init((KeyStore) null);
TrustManager[] trustManagers = factory.getTrustManagers();
if (trustManagers != null) {
for (TrustManager trustManager : trustManagers) {
if (trustManager instanceof X509TrustManager) {
sX509TrustManager = (X509TrustManager) trustManager;
break;
}
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
throw new IllegalStateException("Unexpected default trust managers:"
+ Arrays.toString(trustManagers));
}
sX509TrustManager = (X509TrustManager) trustManagers[0];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment