Skip to content

Commit

Permalink
1.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
plpt88 committed Jun 9, 2023
1 parent e97ce63 commit 4e2032e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
4 changes: 2 additions & 2 deletions GenesisAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'kotlin-kapt'

ext {
PUBLISH_GROUP_ID = 'com.emerchantpay.gateway'
PUBLISH_VERSION = '1.3.8'
PUBLISH_VERSION = '1.3.9'
PUBLISH_ARTIFACT_ID = 'genesis-android'
PUBLISH_DESCRIPTION = 'Genesis Android SDK'
PUBLISH_URL = 'https://github.com/GenesisGateway/android_sdk'
Expand All @@ -27,7 +27,7 @@ android {
minSdkVersion 19
targetSdkVersion 33
versionCode 1
versionName "1.3.8"
versionName "1.3.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import java.io.*
import java.net.HttpURLConnection
import java.net.URL
import java.security.KeyManagementException
import java.security.KeyStore
import java.security.NoSuchAlgorithmException
import java.security.SecureRandom
import java.security.cert.X509Certificate
import java.text.SimpleDateFormat
import java.util.*
import java.util.regex.Pattern
import javax.net.ssl.HttpsURLConnection
import javax.net.ssl.KeyManager
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManager
import javax.net.ssl.TrustManagerFactory
import javax.net.ssl.X509TrustManager
import javax.security.cert.CertificateExpiredException
import javax.xml.transform.OutputKeys
import javax.xml.transform.TransformerFactory
import javax.xml.transform.stream.StreamResult
Expand Down Expand Up @@ -186,20 +189,50 @@ class HttpAsyncTask(private val configuration: Configuration?) : AsyncTask<Any,
?: throw IllegalArgumentException("not an HTTPS connection!")
}

@Throws(IOException::class)
@Throws(IOException::class, NoSuchAlgorithmException::class)
fun getHttpURLConnection(url: URL, compatible: Boolean): HttpURLConnection {
val sslcontext: SSLContext
// Create a trust manager that does not validate certificate chains
val tmf = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm()
)
// Initialise the TMF as you normally would, for example:
tmf.init(null as KeyStore?)

val trustManagers = tmf.trustManagers.toList()
val trustManager = trustManagers?.firstOrNull() as? X509TrustManager

trustManager?: throw NoSuchAlgorithmException("X509 trust manager not supported!")

val wrappedTrustManagers = arrayOf<TrustManager>(
object : X509TrustManager {
override fun getAcceptedIssuers(): Array<X509Certificate> {
return trustManager.acceptedIssuers
}

override fun checkClientTrusted(certs: Array<X509Certificate>, authType: String) {
trustManager.checkClientTrusted(certs, authType)
}

override fun checkServerTrusted(certs: Array<X509Certificate>, authType: String) {
try {
trustManager.checkServerTrusted(certs, authType)
} catch (e: CertificateExpiredException) {

}
}
}
)

try {
sslcontext = SSLContext.getInstance("TLSv1")
sslcontext.init(null as Array<KeyManager>?, null as Array<TrustManager>?, null as SecureRandom?)
val sslContext = SSLContext.getInstance("TLSv1.2")
sslContext.init(null, wrappedTrustManagers, null)
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.socketFactory)
} catch (algorithmException: NoSuchAlgorithmException) {
throw IllegalArgumentException(algorithmException)
} catch (keymanagementException: KeyManagementException) {
throw IllegalArgumentException(keymanagementException)
}

val socketFactory = TLSSocketFactory(sslcontext.socketFactory, compatible)
HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory)
return url.openConnection() as HttpURLConnection
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import javax.net.ssl.HttpsURLConnection

import junit.framework.Assert.assertEquals
import org.mockito.Mockito.mock
import java.security.NoSuchAlgorithmException

@Config(manifest = Config.NONE)
class HttpUnitTest {
Expand Down Expand Up @@ -49,7 +50,7 @@ class HttpUnitTest {
}

@Test
@Throws(IOException::class)
@Throws(IOException::class, NoSuchAlgorithmException::class)
fun testHttpsConnection() {
val url = URL("https://google.com")
val connection = url.openConnection() as HttpsURLConnection
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cd GenesisAndroid
* Add the dependency in your build.gradle:
```
dependencies {
implementation 'com.emerchantpay.gateway:genesis-android:1.3.8'
implementation 'com.emerchantpay.gateway:genesis-android:1.3.9'
}
```

Expand Down

0 comments on commit 4e2032e

Please sign in to comment.