Search in sources :

Example 1 with ConfirmingTrustManager

use of com.intellij.util.net.ssl.ConfirmingTrustManager in project intellij-community by JetBrains.

the class EduStepicClient method getBuilder.

@NotNull
static HttpClientBuilder getBuilder() {
    final HttpClientBuilder builder = HttpClients.custom().setSSLContext(CertificateManager.getInstance().getSslContext()).setMaxConnPerRoute(100000).setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
    final HttpConfigurable proxyConfigurable = HttpConfigurable.getInstance();
    final List<Proxy> proxies = proxyConfigurable.getOnlyBySettingsSelector().select(URI.create(EduStepicNames.STEPIC_URL));
    final InetSocketAddress address = proxies.size() > 0 ? (InetSocketAddress) proxies.get(0).address() : null;
    if (address != null) {
        builder.setProxy(new HttpHost(address.getHostName(), address.getPort()));
    }
    final ConfirmingTrustManager trustManager = CertificateManager.getInstance().getTrustManager();
    try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[] { trustManager }, new SecureRandom());
        builder.setSSLContext(sslContext);
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        LOG.error(e.getMessage());
    }
    return builder;
}
Also used : Proxy(java.net.Proxy) ConfirmingTrustManager(com.intellij.util.net.ssl.ConfirmingTrustManager) HttpConfigurable(com.intellij.util.net.HttpConfigurable) InetSocketAddress(java.net.InetSocketAddress) HttpHost(org.apache.http.HttpHost) SecureRandom(java.security.SecureRandom) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HttpConfigurable (com.intellij.util.net.HttpConfigurable)1 ConfirmingTrustManager (com.intellij.util.net.ssl.ConfirmingTrustManager)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SecureRandom (java.security.SecureRandom)1 SSLContext (javax.net.ssl.SSLContext)1 HttpHost (org.apache.http.HttpHost)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1 NotNull (org.jetbrains.annotations.NotNull)1