Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
Allow insecure connections to fix issue #11 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmook authored Jun 8, 2019
1 parent 52718ba commit b780735
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ sealed class VerificationResult {
*/
override fun toString() = "Success: SCT trusted logs $scts"
}

data class InsecureConnection(val host: String) : Success() {
/**
* Returns a string representation of the object.
*/
override fun toString() = "Success: SCT not enabled for insecure connection to $host"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import okhttp3.Interceptor
import okhttp3.Response
import java.security.cert.X509Certificate
import javax.net.ssl.SSLPeerUnverifiedException
import javax.net.ssl.SSLSocket
import javax.net.ssl.X509TrustManager

internal class CertificateTransparencyInterceptor(
Expand All @@ -39,7 +40,11 @@ internal class CertificateTransparencyInterceptor(
val host = chain.request().url().host()
val certs = chain.connection()?.handshake()?.peerCertificates()?.map { it as X509Certificate } ?: emptyList()

val result = verifyCertificateTransparency(host, certs)
val result = if (chain.connection()?.socket() is SSLSocket) {
verifyCertificateTransparency(host, certs)
} else {
VerificationResult.Success.InsecureConnection(host)
}

logger?.log(host, result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ class CertificateTransparencyInterceptorIntegrationTest {
client.newCall(request).execute()
}

@Test
fun insecureConnectionAllowed() {
val client = OkHttpClient.Builder().addNetworkInterceptor(networkInterceptor).build()

val request = Request.Builder()
.url("http://www.babylonhealth.com")
.build()

client.newCall(request).execute()
}

@Test
fun letsEncryptAllowed() {
val client = OkHttpClient.Builder().addNetworkInterceptor(networkInterceptor).build()
Expand Down

0 comments on commit b780735

Please sign in to comment.