June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,29 @@
|
|||
import java.io.FileInputStream
|
||||
import java.net.URL
|
||||
import java.security.KeyStore
|
||||
|
||||
import javax.net.ssl.{HttpsURLConnection, KeyManagerFactory, SSLContext}
|
||||
|
||||
import scala.io.BufferedSource
|
||||
|
||||
object ClientAuthenticated extends App {
|
||||
|
||||
val con: HttpsURLConnection =
|
||||
new URL("https://somehost.com").openConnection().asInstanceOf[HttpsURLConnection]
|
||||
|
||||
def getSSLContext(p12Path: String, password: String): SSLContext = {
|
||||
val ks = KeyStore.getInstance("pkcs12")
|
||||
val pwd = password.toCharArray
|
||||
ks.load(new FileInputStream(p12Path), pwd)
|
||||
val kmf = KeyManagerFactory.getInstance("PKIX")
|
||||
kmf.init(ks, pwd)
|
||||
val sc = SSLContext.getInstance("TLS")
|
||||
sc.init(kmf.getKeyManagers, null, null)
|
||||
sc
|
||||
}
|
||||
|
||||
// The .p12 file contains the client certificate and private key
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(getSSLContext("whatever.p12", "password").getSocketFactory)
|
||||
new BufferedSource(con.getInputStream).getLines.foreach(println(_))
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue