Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support overriding SSLSocketFactory #35

Merged
merged 1 commit into from
Aug 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/main/java/com/launchdarkly/eventsource/EventSource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.launchdarkly.eventsource;

import javax.net.ssl.SSLSocketFactory;
import okhttp3.*;
import okio.BufferedSource;
import okio.Okio;
Expand Down Expand Up @@ -512,6 +513,13 @@ public static final class Builder {
.readTimeout(DEFAULT_READ_TIMEOUT_MS, TimeUnit.MILLISECONDS)
.writeTimeout(DEFAULT_WRITE_TIMEOUT_MS, TimeUnit.MILLISECONDS)
.retryOnConnectionFailure(true);
{
try {
clientBuilder.sslSocketFactory(new ModernTLSSocketFactory(), defaultTrustManager());
} catch (GeneralSecurityException e) {
// TLS is not available, so don't set up the socket factory, swallow the exception
}
}

/**
* Creates a new builder.
Expand Down Expand Up @@ -752,6 +760,19 @@ public Builder connectionErrorHandler(ConnectionErrorHandler handler) {
return this;
}

/**
* Sets the {@link SSLSocketFactory} for making TLS connections.
*
* @param sslSocketFactory the ssl socket factory
* @param trustManager the trust manager
* @return the builder
*/
public Builder sslSocketFactory(SSLSocketFactory sslSocketFactory,
X509TrustManager trustManager) {
this.clientBuilder.sslSocketFactory(sslSocketFactory, trustManager);
return this;
}

/**
* Constructs an {@link EventSource} using the builder's current properties.
* @return the new EventSource instance
Expand All @@ -761,12 +782,6 @@ public EventSource build() {
clientBuilder.proxy(proxy);
}

try {
clientBuilder.sslSocketFactory(new ModernTLSSocketFactory(), defaultTrustManager());
} catch (GeneralSecurityException e) {
// TLS is not available, so don't set up the socket factory, swallow the exception
}

if (proxyAuthenticator != null) {
clientBuilder.proxyAuthenticator(proxyAuthenticator);
}
Expand Down