Skip to content

Commit 2465853

Browse files
authored
Remove HostnameVerifier option (#3150)
* Remove HostnameVerifier option * Changelog * Update CHANGELOG.md
1 parent b07b05e commit 2465853

File tree

5 files changed

+8
-55
lines changed

5 files changed

+8
-55
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
- Add options and sampling logic ([#3121](https://github.com/getsentry/sentry-java/pull/3121))
1313
- Add ContentProvider and start profile ([#3128](https://github.com/getsentry/sentry-java/pull/3128))
1414

15+
### Breaking changes
16+
17+
- Remove `HostnameVerifier` option as it's flagged by security tools of some app stores ([#3150](https://github.com/getsentry/sentry-java/pull/3150))
18+
- If you were using this option, you have 3 possible paths going forward:
19+
- Provide a custom `ITransportFactory` through `SentryOptions.setTransportFactory()`, where you can copy over most of the parts like `HttpConnection` and `AsyncHttpTransport` from the SDK with necessary modifications
20+
- Get a certificate for your server through e.g. [Let's Encrypt](https://letsencrypt.org/)
21+
- Fork the SDK and add the hostname verifier back
22+
1523
### Dependencies
1624

1725
- Bump Native SDK from v0.6.7 to v0.7.0 ([#3133](https://github.com/getsentry/sentry-java/pull/3133))

sentry/api/sentry.api

-2
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,6 @@ public class io/sentry/SentryOptions {
21582158
public fun getFlushTimeoutMillis ()J
21592159
public fun getFullyDisplayedReporter ()Lio/sentry/FullyDisplayedReporter;
21602160
public fun getGestureTargetLocators ()Ljava/util/List;
2161-
public fun getHostnameVerifier ()Ljavax/net/ssl/HostnameVerifier;
21622161
public fun getIdleTimeout ()Ljava/lang/Long;
21632162
public fun getIgnoredCheckIns ()Ljava/util/List;
21642163
public fun getIgnoredExceptionsForType ()Ljava/util/Set;
@@ -2269,7 +2268,6 @@ public class io/sentry/SentryOptions {
22692268
public fun setExecutorService (Lio/sentry/ISentryExecutorService;)V
22702269
public fun setFlushTimeoutMillis (J)V
22712270
public fun setGestureTargetLocators (Ljava/util/List;)V
2272-
public fun setHostnameVerifier (Ljavax/net/ssl/HostnameVerifier;)V
22732271
public fun setIdleTimeout (Ljava/lang/Long;)V
22742272
public fun setIgnoredCheckIns (Ljava/util/List;)V
22752273
public fun setInstrumenter (Lio/sentry/Instrumenter;)V

sentry/src/main/java/io/sentry/SentryOptions.java

-22
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.util.concurrent.ConcurrentHashMap;
3636
import java.util.concurrent.CopyOnWriteArrayList;
3737
import java.util.concurrent.CopyOnWriteArraySet;
38-
import javax.net.ssl.HostnameVerifier;
3938
import javax.net.ssl.SSLSocketFactory;
4039
import org.jetbrains.annotations.ApiStatus;
4140
import org.jetbrains.annotations.NotNull;
@@ -286,9 +285,6 @@ public class SentryOptions {
286285
/** whether to send personal identifiable information along with events */
287286
private boolean sendDefaultPii = false;
288287

289-
/** HostnameVerifier for self-signed certificate trust* */
290-
private @Nullable HostnameVerifier hostnameVerifier;
291-
292288
/** SSLSocketFactory for self-signed certificate trust * */
293289
private @Nullable SSLSocketFactory sslSocketFactory;
294290

@@ -1338,24 +1334,6 @@ public void setSslSocketFactory(final @Nullable SSLSocketFactory sslSocketFactor
13381334
this.sslSocketFactory = sslSocketFactory;
13391335
}
13401336

1341-
/**
1342-
* Returns HostnameVerifier
1343-
*
1344-
* @return HostnameVerifier object or null
1345-
*/
1346-
public @Nullable HostnameVerifier getHostnameVerifier() {
1347-
return hostnameVerifier;
1348-
}
1349-
1350-
/**
1351-
* Set custom HostnameVerifier
1352-
*
1353-
* @param hostnameVerifier the HostnameVerifier
1354-
*/
1355-
public void setHostnameVerifier(final @Nullable HostnameVerifier hostnameVerifier) {
1356-
this.hostnameVerifier = hostnameVerifier;
1357-
}
1358-
13591337
/**
13601338
* Sets the SdkVersion object
13611339
*

sentry/src/main/java/io/sentry/transport/HttpConnection.java

-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.nio.charset.Charset;
1919
import java.util.Map;
2020
import java.util.zip.GZIPOutputStream;
21-
import javax.net.ssl.HostnameVerifier;
2221
import javax.net.ssl.HttpsURLConnection;
2322
import javax.net.ssl.SSLSocketFactory;
2423
import org.jetbrains.annotations.NotNull;
@@ -130,12 +129,6 @@ HttpURLConnection open() throws IOException {
130129
connection.setConnectTimeout(options.getConnectionTimeoutMillis());
131130
connection.setReadTimeout(options.getReadTimeoutMillis());
132131

133-
final HostnameVerifier hostnameVerifier = options.getHostnameVerifier();
134-
135-
if (connection instanceof HttpsURLConnection && hostnameVerifier != null) {
136-
((HttpsURLConnection) connection).setHostnameVerifier(hostnameVerifier);
137-
}
138-
139132
final SSLSocketFactory sslSocketFactory = options.getSslSocketFactory();
140133

141134
if (connection instanceof HttpsURLConnection && sslSocketFactory != null) {

sentry/src/test/java/io/sentry/transport/HttpConnectionTest.kt

-24
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import java.net.InetSocketAddress
2222
import java.net.Proxy.Type
2323
import java.net.URL
2424
import java.nio.charset.Charset
25-
import javax.net.ssl.HostnameVerifier
2625
import javax.net.ssl.HttpsURLConnection
2726
import javax.net.ssl.SSLSocketFactory
2827
import kotlin.test.Test
@@ -41,14 +40,12 @@ class HttpConnectionTest {
4140
val authenticatorWrapper = mock<AuthenticatorWrapper>()
4241
val rateLimiter = mock<RateLimiter>()
4342
var sslSocketFactory: SSLSocketFactory? = null
44-
var hostnameVerifier: HostnameVerifier? = null
4543
val requestDetails = mock<RequestDetails>()
4644
val options = SentryOptions()
4745

4846
init {
4947
whenever(connection.outputStream).thenReturn(mock())
5048
whenever(connection.inputStream).thenReturn(mock())
51-
whenever(connection.setHostnameVerifier(any())).thenCallRealMethod()
5249
whenever(connection.setSSLSocketFactory(any())).thenCallRealMethod()
5350
whenever(requestDetails.headers).thenReturn(mapOf("header-name" to "header-value"))
5451
val url = mock<URL>()
@@ -61,7 +58,6 @@ class HttpConnectionTest {
6158
options.setSerializer(serializer)
6259
options.proxy = proxy
6360
options.sslSocketFactory = sslSocketFactory
64-
options.hostnameVerifier = hostnameVerifier
6561

6662
return HttpConnection(options, requestDetails, authenticatorWrapper, rateLimiter)
6763
}
@@ -170,26 +166,6 @@ class HttpConnectionTest {
170166
verify(fixture.connection, never()).sslSocketFactory = any()
171167
}
172168

173-
@Test
174-
fun `When HostnameVerifier is given, set to connection`() {
175-
val hostname = mock<HostnameVerifier>()
176-
fixture.hostnameVerifier = hostname
177-
val transport = fixture.getSUT()
178-
179-
transport.send(createEnvelope())
180-
181-
verify(fixture.connection).hostnameVerifier = eq(hostname)
182-
}
183-
184-
@Test
185-
fun `When HostnameVerifier is not given, do not set to connection`() {
186-
val transport = fixture.getSUT()
187-
188-
transport.send(createEnvelope())
189-
190-
verify(fixture.connection, never()).hostnameVerifier = any()
191-
}
192-
193169
@Test
194170
fun `When connection error message contains formatting symbols, does not crash the logger`() {
195171
fixture.options.isDebug = true

0 commit comments

Comments
 (0)