gpt4 book ai didi

rust - 在 Rust 中使用 RuSTLs 和 Hyper 实现 HTTPS 服务器

转载 作者:行者123 更新时间:2023-12-03 11:35:41 26 4
gpt4 key购买 nike

我正在尝试使用带有 Hyper 的 RuSTLs 实现 HTTPS 服务器,但无法获得如何实现相同的正确示例。为此,我遵循并尝试了 hyper-ruSTLs 存储库 here (Hyper Rustls server example) 上给出的示例

它总是给出这个错误

FAILED: error accepting connection: TLS Error: Custom { kind: InvalidData, error: AlertReceived(CertificateUnknown) }

我对 Rust 完全陌生,因此不知道如何通过 Hyper 正确实现 HTTPS。我也经历过与此相关的问题 here

但仍然无法找到解决方案。如果需要更多信息,请让我知道。

最佳答案

看起来您的问题不在于 Hyper 或 Rust,而在于 TLS。默认情况下,当您通过 HTTPS 建立连接时,客户端会验证服务器证书的真实性。证书需要由受信任的机构签署:有关详细信息,请参见例如 this page .

要验证,请使用 curl :

$ curl https://localhost:1337/echo -X POST -v --insecure
...
* SSL certificate verify result: self signed certificate in certificate chain (19), continuing anyway.
...
< HTTP/2 200
< date: Sun, 12 Apr 2020 12:45:03 GMT
<

所以这很好用。如果删除 --insecure旗帜, curl将拒绝建立连接:

$ curl https://localhost:1337/echo -X POST -v
...
curl: (60) SSL certificate problem: self signed certificate in certificate chain
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

要解决此问题,您需要:
  • 使用正确签名的证书而不是自签名证书,或
  • 配置您的客户端不验证证书,或
  • 配置您的客户端以信任您的特定自签名证书。

  • 在生产中,您唯一的选择是 (1)。在开发过程中,您可以使用 (2) 或 (3)。

    关于rust - 在 Rust 中使用 RuSTLs 和 Hyper 实现 HTTPS 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61169422/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com