Skip to content

Commit

Permalink
Additional tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed May 8, 2019
1 parent fbaf7c1 commit 52a0b90
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<revision>2.5.3</revision>
<changelist>-SNAPSHOT</changelist>
<java.level>8</java.level>
<jenkins.version>2.121.3</jenkins.version>
<jenkins.version>2.138.4</jenkins.version>
<scm-api.version>2.3.0</scm-api.version>
<okhttp3.version>3.12.2</okhttp3.version>
<okio.version>2.2.2</okio.version>
Expand Down Expand Up @@ -245,6 +245,11 @@
</executions>
<configuration>
<compatibleSinceVersion>2.2.0</compatibleSinceVersion>
<!-- <pluginFirstClassLoader>true</pluginFirstClassLoader> -->
<maskClasses>
okhttp3.
okio.
</maskClasses>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jenkinsci.plugins.github_branch_source;


import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;
import okhttp3.OkUrlFactory;
Expand All @@ -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}.
Expand All @@ -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<ConnectionSpec> TlsConnectionSpecs() {
return Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT);
Expand Down

0 comments on commit 52a0b90

Please sign in to comment.