Skip to content

Commit

Permalink
improve ssl certificate handling
Browse files Browse the repository at this point in the history
- enable HttpClientBuilder#useSystemProperties() for better integration with IntelliJ certificate manager
- remove manual setup of PoolingHttpClientConnectionManager (better handled by HttpClientBuilder)
- add support for certificates that are signed by an untrusted authority and are not self signed - thanks to Jordan Armstrong for the hint

Related to issue #55
  • Loading branch information
uwolfer committed Apr 18, 2014
1 parent 1f9cab4 commit b482572
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
Expand Down Expand Up @@ -255,8 +254,7 @@ private HttpClientBuilder getHttpClient(GerritAuthData authData,
HttpContext httpContext) {
HttpClientBuilder client = HttpClients.custom();

PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
client.setConnectionManager(connectionManager);
client.useSystemProperties(); // see also: com.intellij.util.net.ssl.CertificateManager

RequestConfig.Builder requestConfig = RequestConfig.custom()
.setConnectTimeout(CONNECTION_TIMEOUT_MS) // how long it takes to connect to remote host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
import org.jetbrains.annotations.Nullable;
import sun.security.validator.ValidatorException;

import javax.net.ssl.SSLException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.List;

/**
Expand Down Expand Up @@ -93,7 +96,12 @@ private HttpResponse handleCertificateExceptionAndRetry(IOException e,
// creating a special configuration that allows connections to non-trusted HTTPS hosts
try {
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
});
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
sslContextBuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

Expand All @@ -117,6 +125,9 @@ public boolean isCertificateException(Exception e) {
if (throwable instanceof ValidatorException) {
return true;
}
if (throwable instanceof SSLException) { // e.g. "SSLException: hostname in certificate didn't match: <localhost> != <unknown>"
return true;
}
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
<ul>
<li>fix handling of comma separated user names in push dialog</li>
<li>improve HTTP proxy handling</li>
<li>improve SSL certificate handling (support for IntelliJ 13.1 certificate manager,
certificates signed by an untrusted authority)</li>
<li>minor fixes and improvements</li>
</ul>
<li>0.7.0</li>
Expand Down

0 comments on commit b482572

Please sign in to comment.