diff --git a/pom.xml b/pom.xml index e84729026..a44ef9106 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ 2.5.2 -SNAPSHOT 8 - 2.121.3 + 2.138.4 2.3.0 3.12.2 2.2.2 @@ -245,6 +245,11 @@ 2.2.0 + + + okhttp3. + okio. + diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/Connector.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/Connector.java index b74992598..d19b7c7b3 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/Connector.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/Connector.java @@ -403,9 +403,9 @@ public static void checkApiUrlValidity(@Nonnull GitHub gitHub, @CheckForNull Sta OkHttpClient client = clientBuilder.build(); if (client.cache() != null) { - gb.withConnector(new ForceValidationOkHttpConnector(new OkUrlFactory(client))); + gb.withConnector(new ForceValidationOkHttpConnector(client)); } else { - gb.withConnector(new OkHttp3Connector(new OkUrlFactory(client))); + gb.withConnector(new OkHttp3Connector(client)); } if (username != null) { @@ -743,8 +743,8 @@ public String toString() { private static final String HEADER_NAME = "Cache-Control"; private final OkHttp3Connector delegate; - public ForceValidationOkHttpConnector(OkUrlFactory okUrlFactory) { - this.delegate = new OkHttp3Connector(okUrlFactory); + public ForceValidationOkHttpConnector(OkHttpClient client) { + this.delegate = new OkHttp3Connector(client); } /*package*/ HttpConnector getDelegate() { diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/OkHttp3Connector.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/OkHttp3Connector.java index 302a5ab49..e81f3e5a4 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/OkHttp3Connector.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/OkHttp3Connector.java @@ -1,6 +1,5 @@ package org.jenkinsci.plugins.github_branch_source; - import okhttp3.ConnectionSpec; import okhttp3.OkHttpClient; import okhttp3.OkUrlFactory; @@ -11,15 +10,9 @@ import java.net.HttpURLConnection; import java.net.URL; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; - import java.util.Arrays; import java.util.List; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocketFactory; - /** * {@link HttpConnector} for {@link OkHttpClient}. @@ -33,37 +26,22 @@ * @author Kohsuke Kawaguchi */ public class OkHttp3Connector implements HttpConnector { + private final OkHttpClient client; private final OkUrlFactory urlFactory; - public OkHttp3Connector(OkUrlFactory urlFactory) { - OkHttpClient.Builder builder = urlFactory.client().newBuilder(); - builder.sslSocketFactory(TlsSocketFactory()); - builder.connectionSpecs(TlsConnectionSpecs()); - urlFactory.setClient(builder.build()); + public OkHttp3Connector(OkHttpClient client) { - this.urlFactory = urlFactory; + OkHttpClient.Builder builder = client.newBuilder(); + + builder.connectionSpecs(TlsConnectionSpecs()); + this.client = builder.build(); + this.urlFactory = new OkUrlFactory(this.client); } public HttpURLConnection connect(URL url) throws IOException { return urlFactory.open(url); } - /** Returns TLSv1.2 only SSL Socket Factory. */ - private SSLSocketFactory TlsSocketFactory() { - SSLContext sc; - try { - sc = SSLContext.getInstance("TLSv1.2"); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e.getMessage(), e); - } - try { - sc.init(null, null, null); - return sc.getSocketFactory(); - } catch (KeyManagementException e) { - throw new RuntimeException(e.getMessage(), e); - } - } - /** Returns connection spec with TLS v1.2 in it */ private List TlsConnectionSpecs() { return Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT);