diff --git a/stripe/src/main/java/com/stripe/android/ConnectionFactory.kt b/stripe/src/main/java/com/stripe/android/ConnectionFactory.kt index 8b316938b8b..cf998f4ea37 100644 --- a/stripe/src/main/java/com/stripe/android/ConnectionFactory.kt +++ b/stripe/src/main/java/com/stripe/android/ConnectionFactory.kt @@ -19,7 +19,6 @@ internal interface ConnectionFactory { connectTimeout = CONNECT_TIMEOUT readTimeout = READ_TIMEOUT useCaches = false - sslSocketFactory = SSL_SOCKET_FACTORY requestMethod = request.method.code request.headers.forEach { (key, value) -> @@ -41,7 +40,6 @@ internal interface ConnectionFactory { } private companion object { - private val SSL_SOCKET_FACTORY = StripeSSLSocketFactory() private val CONNECT_TIMEOUT = TimeUnit.SECONDS.toMillis(30).toInt() private val READ_TIMEOUT = TimeUnit.SECONDS.toMillis(80).toInt() diff --git a/stripe/src/main/java/com/stripe/android/StripePaymentController.kt b/stripe/src/main/java/com/stripe/android/StripePaymentController.kt index 99bd986e33a..069ae6e7c00 100644 --- a/stripe/src/main/java/com/stripe/android/StripePaymentController.kt +++ b/stripe/src/main/java/com/stripe/android/StripePaymentController.kt @@ -56,7 +56,7 @@ internal class StripePaymentController internal constructor( private val config: PaymentAuthConfig = PaymentAuthConfig.get(), private val threeDs2Service: StripeThreeDs2Service = - StripeThreeDs2ServiceImpl(context, StripeSSLSocketFactory(), enableLogging), + StripeThreeDs2ServiceImpl(context, null, enableLogging), private val analyticsRequestExecutor: AnalyticsRequestExecutor = AnalyticsRequestExecutor.Default(Logger.getInstance(enableLogging)), private val analyticsDataFactory: AnalyticsDataFactory = diff --git a/stripe/src/main/java/com/stripe/android/StripeSSLSocketFactory.kt b/stripe/src/main/java/com/stripe/android/StripeSSLSocketFactory.kt deleted file mode 100644 index 825c50b68b9..00000000000 --- a/stripe/src/main/java/com/stripe/android/StripeSSLSocketFactory.kt +++ /dev/null @@ -1,104 +0,0 @@ -package com.stripe.android - -import java.io.IOException -import java.net.InetAddress -import java.net.Socket -import javax.net.ssl.HttpsURLConnection -import javax.net.ssl.SSLContext -import javax.net.ssl.SSLSocket -import javax.net.ssl.SSLSocketFactory - -/** - * Wraps a SSLSocketFactory and enables more TLS versions on older versions of Android. - * Most of the code is taken from stripe-java. - */ -internal class StripeSSLSocketFactory constructor( - private val tlsv11Supported: Boolean, - private val tlsv12Supported: Boolean -) : SSLSocketFactory() { - private val internalFactory: SSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory() - - internal constructor() : this(supportedProtocols = SUPPORTED_PROTOCOLS) - - private constructor(supportedProtocols: Array) : this( - tlsv11Supported = supportedProtocols.any { it == TLS_V11_PROTO }, - tlsv12Supported = supportedProtocols.any { it == TLS_V12_PROTO } - ) - - override fun getDefaultCipherSuites(): Array { - return internalFactory.defaultCipherSuites - } - - override fun getSupportedCipherSuites(): Array { - return internalFactory.supportedCipherSuites - } - - @Throws(IOException::class) - override fun createSocket( - s: Socket, - host: String, - port: Int, - autoClose: Boolean - ): Socket? { - return fixupSocket(internalFactory.createSocket(s, host, port, autoClose)) - } - - @Throws(IOException::class) - override fun createSocket(host: String, port: Int): Socket? { - return fixupSocket(internalFactory.createSocket(host, port)) - } - - @Throws(IOException::class) - override fun createSocket( - host: String, - port: Int, - localHost: InetAddress, - localPort: Int - ): Socket? { - return fixupSocket(internalFactory.createSocket(host, port, localHost, localPort)) - } - - @Throws(IOException::class) - override fun createSocket(host: InetAddress, port: Int): Socket? { - return fixupSocket(internalFactory.createSocket(host, port)) - } - - @Throws(IOException::class) - override fun createSocket( - address: InetAddress, - port: Int, - localAddress: InetAddress, - localPort: Int - ): Socket? { - return fixupSocket( - internalFactory.createSocket(address, port, localAddress, localPort) - ) - } - - private fun fixupSocket(sock: Socket): Socket { - if (sock is SSLSocket) { - sock.enabledProtocols = getEnabledProtocols(sock.enabledProtocols) - } - return sock - } - - fun getEnabledProtocols(enabledProtocols: Array) = - listOfNotNull( - *enabledProtocols, - TLS_V11_PROTO.takeIf { tlsv11Supported }, - TLS_V12_PROTO.takeIf { tlsv12Supported } - ).toSet().toTypedArray() - - private companion object { - private const val TLS_V11_PROTO = "TLSv1.1" - private const val TLS_V12_PROTO = "TLSv1.2" - - // For Android prior to 4.1, TLSv1.1 and TLSv1.2 might not be supported - private val SUPPORTED_PROTOCOLS: Array - get() { - return runCatching { - SSLContext.getDefault().supportedSSLParameters.protocols - }.getOrDefault(emptyArray()) - } - } -} diff --git a/stripe/src/test/java/com/stripe/android/StripeSSLSocketFactoryTest.kt b/stripe/src/test/java/com/stripe/android/StripeSSLSocketFactoryTest.kt deleted file mode 100644 index 2ad80a14022..00000000000 --- a/stripe/src/test/java/com/stripe/android/StripeSSLSocketFactoryTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.stripe.android - -import com.google.common.truth.Truth.assertThat -import kotlin.test.Test - -class StripeSSLSocketFactoryTest { - - @Test - fun getEnabledProtocols() { - val defaultProtocols = arrayOf("protocol") - - assertThat( - StripeSSLSocketFactory(tlsv11Supported = false, tlsv12Supported = false) - .getEnabledProtocols(defaultProtocols) - ).isEqualTo( - arrayOf("protocol") - ) - - assertThat( - StripeSSLSocketFactory(tlsv11Supported = false, tlsv12Supported = true) - .getEnabledProtocols(defaultProtocols) - ).isEqualTo( - arrayOf("protocol", "TLSv1.2") - ) - - assertThat( - StripeSSLSocketFactory(tlsv11Supported = true, tlsv12Supported = true) - .getEnabledProtocols(defaultProtocols) - ).isEqualTo( - arrayOf("protocol", "TLSv1.1", "TLSv1.2") - ) - } -}