我已尝试使用http.ignoreSSLIssues()
to make the script ignore the problem。
我已经按照http-builder维基页面的指示尝试了importing the certificate into a trusted keystore and then using that keystore to create a new SSLSocketFactory。
我已经尝试了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)
}
}
然而,我每次都得到相同的SSLPeerUnverifiedException。这是控制台输出:
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
我的代码遇到异常的第93行是http.request( Method.GET, ContentType.URLENC ) { req ->
行。
我已经验证我的SSL证书是有效的,并且由受信任的根管理局使用Chrome进行签名(以及使用https://www.sslshopper.com/ssl-checker.html)
我不明白为什么这不起作用。请帮忙!