【问题标题】:HttpsUrlConnection SSLHandshakeException certificate_requiredHttpsUrlConnection SSLHandshakeException certificate_required
【发布时间】:2021-05-15 18:29:08
【问题描述】:

我正在尝试从 java 访问我的 api,但出现以下错误:

javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_required

在我的个人 Windows 计算机上测试代码时,我没有收到此错误。但是这个错误确实发生在我运行 Ubuntu 和 openjdk 11 的 linux 生产服务器上。

服务器托管在同一个 ubuntu 服务器上,并使用 Cloudflare SSL Full 代理

HttpsURLConnection con = null;
    try {
        URL url = new URL("https://www.example.com/");
        con = (HttpsURLConnection) url.openConnection();
        con.addRequestProperty("XF-Api-Key", "key");
        con.addRequestProperty("XF-Api-User", "1");
        con.setConnectTimeout(5000);
        con.setReadTimeout(5000);
        con.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
        con.setRequestMethod("GET");
        con.setRequestProperty("Content-Type", "application/json");
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer content = new StringBuffer();
            while ((inputLine = in.readLine()) != null)
                content.append(inputLine);
            in.close();

            System.out.println(content.toString());
        } catch (Exception e) {
            e.printStackTrace();
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
            String inputLine;
            StringBuffer content = new StringBuffer();
            while ((inputLine = in.readLine()) != null) {
                content.append(inputLine);
            }
            in.close();
            System.out.println(content.toString());
        }
    } catch (Exception exp) {
        System.out.println("Cant load data from API");
        exp.printStackTrace();
    } finally {
        if (con != null)
            con.disconnect();
    }

我的 linux 服务器上是否配置不正确?

更新:我的问题还没有解决,我还在寻找答案。我在互联网上找不到任何信息丰富的博客或信息。

【问题讨论】:

  • 这个问题已经回答here
  • 问题是我已经添加了我的源服务器的证书。如果需要,我不确定如何添加缺少的 cloudflare 证书。此外,您链接的帖子是握手错误

标签: java ssl cloudflare httpsurlconnection


【解决方案1】:

服务器希望客户端提供它信任的证书,因此需要为客户端配置一个 Keystore - 请参阅https://www.baeldung.com/java-https-client-certificate-authentication

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,发生了同样的错误,它帮助我(奇怪的是)在用户的根文件夹中复制证书 - 从启动命令的位置

    /home/{用户}/

    【讨论】:

      猜你喜欢
      • 2011-10-02
      • 2016-08-05
      • 2016-07-28
      • 1970-01-01
      • 2017-05-11
      • 2014-01-08
      • 2023-03-11
      • 2012-07-14
      • 2013-03-02
      相关资源
      最近更新 更多