Skip to content

Check TLS through HTTP Proxy if configured #119

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions scriptler/checkSSLConnection.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
]
} END META**/

import javax.net.ssl.HttpsURLConnection
import hudson.ProxyConfiguration
import javax.net.ssl.TrustManager
import javax.net.ssl.TrustManagerFactory
import javax.net.ssl.X509TrustManager
import java.net.http.HttpResponse
import java.security.KeyStore
import java.security.Principal
import java.security.cert.Certificate
import java.security.cert.X509Certificate

try {

println("## DUMP JVM TRUST MANAGERS ##")
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
tmf.init((KeyStore) null)
Expand All @@ -28,7 +27,7 @@ try {
if (trustManager instanceof X509TrustManager) {
X509TrustManager x509TrustManager = (X509TrustManager) trustManager
for (X509Certificate certificate: x509TrustManager.getAcceptedIssuers()) {
println("\t" + certificate.getSubjectDN())
println("\t" + certificate.getSubjectX500Principal())
}
println("\tAccepted issuers count : " + x509TrustManager.getAcceptedIssuers().length)
println("###################")
Expand All @@ -42,12 +41,15 @@ try {
}
try {
String url = "${serverUrl}"
HttpsURLConnection urlConnection = (HttpsURLConnection) new URL(url).openConnection()
println(url + "->" + urlConnection.getResponseCode() + " " + urlConnection.getResponseMessage())
for (Certificate certificate : urlConnection.getServerCertificates()) {
def response = ProxyConfiguration.newHttpClient().send(
ProxyConfiguration.newHttpRequestBuilder(new URI(url)).build(),
HttpResponse.BodyHandlers.discarding()
)
println("$url -> ${response.statusCode()}")
for (Certificate certificate : response.sslSession().get().getPeerCertificates()) {
if (certificate instanceof X509Certificate) {
X509Certificate x509Certificate = (X509Certificate) certificate
Principal subjectDN = x509Certificate.getSubjectDN()
def subjectDN = x509Certificate.getSubjectX500Principal()
println("\t" + subjectDN.getClass() + " - " + subjectDN)
} else {
println(certificate)
Expand Down