Commit 169f57f0 authored by Waweic's avatar Waweic 💬
Browse files

Do not check certificates

parent 41af74c2
......@@ -22,9 +22,9 @@ If you want to download the Application without building it yourself, you can do
* The "Back"-button
* An (internal and temporary) browsing history
* Gemini INPUT
* Connecting to hosts with self signed certificates
## Stuff that doesn't work (aka wishlist for the future)
* Connecting to hosts with self signed certificates
* Certain SSL/TLS Versions on older Android versions (I probably can't fix this)
* Downloading anything that is not of type text/*
* Crashes when page is too big (feels just like a "real" web browser! #inabiaf)
......@@ -39,4 +39,5 @@ If you want to download the Application without building it yourself, you can do
## Stuff that probably should be done differently
* Handling other character encodings than utf-8
* Implement some form of TOFU for self signed certificates
* Probably a lot
\ No newline at end of file
package rocks.ism.decentral.geminiclient
import android.util.Log
import java.io.*
import java.net.URI
import javax.net.ssl.SSLSocket
import javax.net.ssl.SSLSocketFactory
import java.security.SecureRandom
import java.security.cert.X509Certificate
import javax.net.ssl.*
import javax.security.cert.CertificateException
class GeminiConnection {
......@@ -21,7 +22,33 @@ class GeminiConnection {
port = uri.port
}
val factory: SSLSocketFactory = SSLSocketFactory.getDefault() as SSLSocketFactory
// Create a trust manager that does not validate certificate chains
val trustAllCerts = arrayOf<TrustManager>(
object : X509TrustManager {
@Throws(CertificateException::class)
override fun checkClientTrusted(
chain: Array<X509Certificate?>?,
authType: String?
) {
}
@Throws(CertificateException::class)
override fun checkServerTrusted(
chain: Array<X509Certificate?>?,
authType: String?
) {
}
override fun getAcceptedIssuers(): Array<X509Certificate?>? {
return arrayOf()
}
}
)
val sslContext = SSLContext.getInstance("TLSv1.2")
sslContext.init(null, trustAllCerts, SecureRandom())
val factory: SSLSocketFactory = sslContext.socketFactory //SSLSocketFactory.getDefault() as SSLSocketFactory
val socket: SSLSocket = factory.createSocket(uri.host, port) as SSLSocket
socket.enabledProtocols = arrayOf("TLSv1.2")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment