Skip to content
New issue

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

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

Already on GitHub? # to your account

X509 #1770

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

X509 #1770

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.apache.hc.core5.http.config.RegistryBuilder
import org.apache.hc.core5.http.message.BasicHeader
import org.apache.hc.core5.ssl.SSLContexts
import org.apache.hc.core5.util.TimeValue
import java.io.File
import java.net.URI

private val logger = KotlinLogging.logger {}
Expand Down Expand Up @@ -146,6 +147,8 @@ object HttpClient {
setupInsecureTLS(builder)
}

setupX509Certificate(builder)

return builder.build() to credsProvider
}

Expand Down Expand Up @@ -184,4 +187,24 @@ object HttpClient {
)
)
}

private fun setupX509Certificate(builder: HttpClientBuilder) {
val keystorePath = "tmp/machine-id/keystore.p12"
val keystorePassword = "".toCharArray()

val sslContext = SSLContexts.custom()
.loadKeyMaterial(File(keystorePath), keystorePassword, keystorePassword)
.build()

val sslSocketFactory = SSLConnectionSocketFactoryBuilder.create().setSslContext(sslContext).build()

builder.setConnectionManager(
BasicHttpClientConnectionManager(
RegistryBuilder.create<ConnectionSocketFactory>()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslSocketFactory)
.build()
)
)
}
}