admin管理员组文章数量:1277901
I'm using groovy and below is my code, which is not working as expected, its saying, unable to find valid certification path to requested target, although while doing ls I find the file there, can someone help? Thanks in Advance.
def certificateFactory = CertificateFactory.getInstance("X.509")
def trustStore = KeyStore.getInstance(KeyStore.getDefaultType())
trustStore.load(null, null)
def pemFilePath = "/etc/ca/cacerts.pem"
FileInputStream fis = new FileInputStream(pemFilePath)
try {
def cert = certificateFactory.generateCertificate(fis) as X509Certificate
trustStore.setCertificateEntry("customCA", cert)
} finally {
fis.close()
}
def trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
trustManagerFactory.init(trustStore)
def trustManagers = trustManagerFactory.trustManagers
def sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, trustManagers, new SecureRandom())
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory())
def vaultApiUrl = "URL"
def vaultToken = "TOKEN"
def connection = new URL(vaultApiUrl).openConnection() as HttpsURLConnection
connection.setRequestMethod("GET")
connection.setRequestProperty("X-Vault-Token", vaultToken)
connection.setRequestProperty("Accept", "application/json")
def responseCode = connection.responseCode
if (responseCode == 200) {
def responseText = connection.inputStream.text
def vaultResponse = new JsonSlurper().parseText(responseText)
dsl.echo("response is: ${vaultResponse}")
} else {
dsl.echo("Error: HTTP ${responseCode}")
}
本文标签:
版权声明:本文标题:I'm attempting to establish an HTTPS connection from my Jenkins server to the Vault server using certificates (ca certs. 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741272092a2369490.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论