Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] - Possibility to obtain server certificates #1025

Open
wojciechUrbanski opened this issue Jun 30, 2021 · 1 comment
Open

[FR] - Possibility to obtain server certificates #1025

wojciechUrbanski opened this issue Jun 30, 2021 · 1 comment
Labels
enhancement todo issue is still valid and waiting for contributor

Comments

@wojciechUrbanski
Copy link

Feature:

I would like to have the possibility to retrieve the server certificates, something like:

val Url = new URL(url)
val con = Url.openConnection
val scon = con.asInstanceOf[HttpsURLConnection]
scon.connect()
val certs = scon.getServerCertificates

After initial talk with Adam, certs might be added to ResponseMetadata and the syntax may look as: (ignore: ResponseAs[Unit]).mapWithMetadata(m => extract cert)

@Pask423 Pask423 self-assigned this Feb 28, 2022
@Pask423 Pask423 added enhancement todo issue is still valid and waiting for contributor labels Mar 1, 2022
@Pask423 Pask423 removed their assignment Aug 29, 2022
@Hiroki6
Copy link

Hiroki6 commented Nov 3, 2022

This issue was created when I asked @wojciechUrbanski how I can do certificate pinning via sttp because I didn't find the way at that time.

But, I found the way after that.
The X509TrustManager class enables us to access server certificates as it's written here

// custom X509TrustManager
val TrustAllCerts: X509TrustManager = new X509TrustManager() {
  def getAcceptedIssuers: Array[X509Certificate] = Array[X509Certificate]()
  override def checkServerTrusted(x509Certificates: Array[X509Certificate], s: String): Unit = {
     // here you can access server certificates
  }
  override def checkClientTrusted(x509Certificates: Array[X509Certificate], s: String): Unit = ()
}
// configure trusted server certificates
ks.load(new FileInputStream("/path/to/server_trust"), "password".toCharArray)

// check the certificate with the default algorithm (normally PKIX)
// reference: [https://docs.oracle.com/en/java/javase/11/docs/api/java.base/javax/net/ssl/TrustManagerFactory.html]
val tmf: TrustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)  
tmf.init(ks)

Also, if you use OkHttp as a backend, it supports certificate pinning.
https://square.github.io/okhttp/4.x/okhttp/okhttp3/-certificate-pinner/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement todo issue is still valid and waiting for contributor
Projects
None yet
Development

No branches or pull requests

3 participants