【问题标题】:How to skip SSL certificate verification with karate?如何使用空手道跳过 SSL 证书验证?
【发布时间】:2021-08-25 07:09:38
【问题描述】:

我正在尝试通过空手道关闭 SSL 证书验证。现在我收到错误:

       13:27:14.668 [main] ERROR com.intuit.karate - javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target, http call failed after 133 milliseconds for URL: https://VRNV02AS04294.int.carlsonwagonlit.com:8443/admin/property/filters/APFilter/true
       13:27:14.668 [main] ERROR com.intuit.karate - http request failed: 

javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径

【问题讨论】:

    标签: karate


    【解决方案1】:

    请这样做:

    * configure ssl = true
    

    阅读文档了解更多信息:https://github.com/intuit/karate#configure

    编辑:对于那些将来登陆这里的人(并且在空手道版本

    有两种解决方案:

    1. 使用karate-jersey 而不是karate-apache
    2. 像这样强制 Apache 依赖项的版本:
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${apache.version}</version>
         </dependency>
    

    apache.version 的值取决于您的项目需要什么以及空手道依赖什么,在大多数情况下,使用latest possible version 会起作用。

    【讨论】:

    • 它不工作。首先,“* configure ssl = true”给了我错误“NoSuchMethod”,因此配置如下“And eval function(){return karate.configure('ssl', true);}”。但我仍然收到 SSL 错误
    • @mirchik 请遵循这些指示,一切顺利:github.com/intuit/karate/wiki/How-to-Submit-an-Issue
    • 我解决了这个问题。其中一个依赖项(Apache http)正在使用不推荐使用的 ssl 方法。所以我只是升级了一个版本的依赖,它现在可以工作了!
    • @mirchik 谢谢!在项目中添加 Apache httpclient 依赖解决了这个问题。
    【解决方案2】:

    我遇到了类似的情况,为了解决这个问题,我添加了

    karate.configure('ssl', true);
    

    在 karate-config.js 文件中让 Karate 知道全局跳过 SSL 认证验证。

    我还必须添加一个 http-core 依赖项

    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.13</version>
    </dependency>
    

    【讨论】:

      【解决方案3】:

      首先在空手道中关闭 SSL 证书验证:

      * configure ssl = true
      

      并在您的 pom.xml 中添加以下依赖项。我这样做解决了我的问题:

          <dependency>
              <groupId>org.apache.httpcomponents</groupId>
              <artifactId>httpclient</artifactId>
              <version>${httpclient.version}</version>
          </dependency>
      

      【讨论】:

        【解决方案4】:

        对我来说,以下方法有效:

        在 karate-config.js 文件中定义密钥库:

        // get system property keystore
        var keystore = karate.properties['keystore'];
        if (!keystore) {
            keystore = 'C:/Program Files/keystore/certificateName.pfx';
        }
        
        // get system property keystorepwd
        var keystorepwd = karate.properties['keystorepwd'];
        if (!keystorepwd) {
            keystorepwd = '00000';
        }
        

        在 .feature 文件的背景中定义以下行:

        configure ssl = { keyStore: #("file:"+keystore), keyStorePassword: #(keystorepwd), 
        keyStoreType: 'pkcs12' }
        

        【讨论】:

          猜你喜欢
          • 2019-09-05
          • 1970-01-01
          • 2021-02-08
          • 1970-01-01
          • 2014-07-07
          • 2020-01-05
          • 1970-01-01
          • 2022-01-09
          相关资源
          最近更新 更多