Kenny Wyland
Kenny Wyland

Reputation: 21870

Valid SSL certificate but Groovy is giving: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

I have already tried using http.ignoreSSLIssues() to make the script ignore the problem.

I have already tried importing the certificate into a trusted keystore and then using that keystore to create a new SSLSocketFactory as instructed by the http-builder wiki page.

I have already tried installing the Unlimited Security policy jars.

HTTPBuilder http = new HTTPBuilder("${host}${path}")
println("Fetching ${host}${path}")

println("Supposedly ignoring SSL issues")
http.ignoreSSLIssues()

def keyStore = KeyStore.getInstance( KeyStore.defaultType )

getClass().getResource( "truststore.jks" ).withInputStream {
    keyStore.load( it, "test1234".toCharArray() )
    println("Loaded keystore")
}

http.client.connectionManager.schemeRegistry.register(new Scheme("https", 443, new SSLSocketFactory(keyStore)) )
println("Loaded new socket factory with keystore")

http.request( Method.GET, ContentType.URLENC ) { req ->
    uri.query = params

    response.contentType = ContentType.JSON

    response.success = { resp, Map map ->
        def json = map.keySet()[0]

        def slurper = new JsonSlurper()
        ret = slurper.parseText(json)

    }
}

And yet, I get the same SSLPeerUnverifiedException every time. Here is the console output:

Fetching https://myhost.mydomain.com/report.aspx
Supposedly ignoring SSL issues
Loaded keystore
Loaded new socket factory with keystore
Caught: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
    at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:572)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1066)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1044)
    at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
    at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:434)
    at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:383)
    at groovyx.net.http.HTTPBuilder$request$0.call(Unknown Source)
    at fetch_windows_direct_report.httpget(fetch_windows_direct_report.groovy:93)
    at fetch_windows_direct_report$httpget$0.callCurrent(Unknown Source)
    at fetch_windows_direct_report.fetchanalytics(fetch_windows_direct_report.groovy:58)
    at fetch_windows_direct_report$fetchanalytics.callCurrent(Unknown Source)
    at fetch_windows_direct_report.run(fetch_windows_direct_report.groovy:31)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code 1

Line 93, where my code experiences the exception, is the http.request( Method.GET, ContentType.URLENC ) { req -> line.

I've verified that my SSL certificate is valid and signed by a Trusted Root Authority by using Chrome (as well as using https://www.sslshopper.com/ssl-checker.html)

enter image description here

Why is this not working?

Upvotes: 2

Views: 1375

Answers (0)

Related Questions