-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3464d64
commit 57acf20
Showing
3 changed files
with
65 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.paypal.messages.io | ||
|
||
import android.annotation.SuppressLint | ||
import okhttp3.OkHttpClient | ||
import java.security.cert.X509Certificate | ||
import javax.net.ssl.SSLContext | ||
import javax.net.ssl.SSLSocketFactory | ||
import javax.net.ssl.TrustManager | ||
import javax.net.ssl.X509TrustManager | ||
|
||
object ApiClient { | ||
// trustAllCerts is only used for connecting to test environments | ||
private val trustAllCerts = arrayOf<TrustManager>( | ||
@SuppressLint("CustomX509TrustManager") | ||
object : X509TrustManager { | ||
@SuppressLint("TrustAllX509TrustManager") | ||
override fun checkClientTrusted( | ||
chain: Array<out X509Certificate>?, | ||
authType: String?, | ||
) {} | ||
|
||
@SuppressLint("TrustAllX509TrustManager") | ||
override fun checkServerTrusted( | ||
chain: Array<out X509Certificate>?, | ||
authType: String?, | ||
) {} | ||
|
||
override fun getAcceptedIssuers() = arrayOf<X509Certificate>() | ||
}, | ||
) | ||
|
||
// sslContext is only used for connecting to test environments | ||
private val sslContext: SSLContext = SSLContext.getInstance("SSL") | ||
.apply { | ||
this.init(null, trustAllCerts, java.security.SecureRandom()) | ||
} | ||
|
||
// sslSocketFactor is only used for connecting to test environments | ||
private val sslSocketFactory: SSLSocketFactory = sslContext.socketFactory | ||
|
||
// insecureClient is only used for connecting to test environments | ||
@Suppress("unused") | ||
internal val insecureClient = OkHttpClient.Builder() | ||
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager) | ||
.hostnameVerifier { _, _ -> true } | ||
.build() | ||
|
||
internal val secureClient = OkHttpClient() | ||
} |