waitfor任务如何忽略SSL证书问题?

编程入门 行业动态 更新时间:2024-10-28 15:23:17
本文介绍了waitfor任务如何忽略SSL证书问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

考虑到我的应用程序在本地主机上运行,​​以下Ant片段在我的本地环境中运行良好:

The Ant snippet below works well in my local environment, considering my app is running on localhost:

<waitfor maxwait="120" maxwaitunit="second" checkevery="1"> <and> <http url="localhost:${env.https.port}/${env.context.path}/${url}"/> </and> </waitfor>

但是它在Linux测试服务器上不起作用.即使应用程序在本地主机上运行,​​它也会等待2分钟.我通过使用Ant回显任务并在服务器上为其运行"curl",来验证所创建的url是否有效.

But it does not work on a linux test server. It waits 2 minutes even if the application is running on localhost. I verify the created url is valid using an Ant echo task and by running "curl" for it on the server.

运行时在服务器上:

curl localhost:8080/live/index.html

我收到认证错误.但是当我运行(忽略证书)时:

I get a certification error. But when I run (ignore certificate):

curl -k localhost:8080/live/index.html

效果很好.

我想知道Ant脚本是否也由于认证错误而无法使用,如果是,该如何解决?如果没有,关于Ant脚本的任何建议吗?

I am wondering if the Ant script also does not work because of the certification error, and if so, how can I fix it? If not, any suggestions on the Ant script?

推荐答案

这是一个可能的起点.这执行了curl -k的某些功能,但是是在Ant内部执行的.由于这会禁用证书检查,因此应在安全的环境下谨慎使用!您没有说出您遇到了哪个证书错误,但是如果需要,您可以扩展以下内容.

Here's a possible starting point. This does some of what curl -k does, but from within Ant. As this disables certificate checking it should be used with care in a safe context! You didn't say which certificate error you had, but you can likely extend the below if needed.

<script language="javascript"><![CDATA[ // Create a trust manager that does not validate certificate chains var TrustManagerInterface = Java.type( "javax.ssl.X509TrustManager" ); var X509TrustManager = new TrustManagerInterface() { getAcceptedIssuers: function() { return null; }, checkClientTrusted: function() { }, checkServerTrusted: function() { }, }; var TrustManagerArrayType = Java.type( "javax.ssl.TrustManager[]" ); var trust_manager_array = new TrustManagerArrayType( 1 ); trust_manager_array[0] = X509TrustManager; var SecureRandomType = Java.type( "java.security.SecureRandom" ); var secure_random = new SecureRandomType; var SSLContextType = Java.type( "javax.ssl.SSLContext" ); var ssl_context = SSLContextType.getInstance( "SSL" ); ssl_context.init( null, trust_manager_array, secure_random ); var HttpsURLConnectionType = Java.type( "javax.ssl.HttpsURLConnection" ); HttpsURLConnectionType.setDefaultSSLSocketFactory( ssl_context.getSocketFactory( ) ); // Do not validate certificate hostnames var HostnameVerifierType = Java.type( "javax.ssl.HostnameVerifier" ); var host_verifier = new HostnameVerifierType() { verify: function() { return true; } }; HttpsURLConnectionType.setDefaultHostnameVerifier( host_verifier ); ]]> </script> <waitfor maxwait="120" maxwaitunit="second" checkevery="2" checkeveryunit="second"> <http url="wrong.host.badssl" /> </waitfor>

我使用 badssl 进行了上述测试.

I used badssl to test the above.

顺便说一句,我认为check every的默认单位可能不到一秒,因此建议您添加checkeveryunit.

As an aside, I think the default unit for check every might be sub-second, so recommend you add checkeveryunit.

以上是与Nashorn一起使用的.如果您使用的Java是较旧的版本,则也可以使用Rhino版本.

Above is for use with Nashorn. A Rhino version should also be possible if you have an older version of Java.

以上内容源自此来源.

更多推荐

waitfor任务如何忽略SSL证书问题?

本文发布于:2023-10-30 03:03:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541575.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:证书   waitfor   SSL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!