【问题标题】:Unknown issuer on tls handshake in Rust with async-tls在 Rust 中使用 async-tls 进行 tls 握手的未知发行者
【发布时间】:2020-03-01 11:05:18
【问题描述】:

我正在使用async-tls 构建我的客户端-服务器应用程序,做的事情与examples 非常相似,但是当我尝试执行 TLS 握手时,它会出现以下错误:

thread 'main' panicked at 'Awaiting TLS failed: Custom { kind: InvalidData, error: WebPKIError(UnknownIssuer) }', src/main.rs:15:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

我在客户端的代码很简单:

let tcp_stream = TcpStream::connect("localhost:5568")
    .await
    .expect("TCP handshake failed.");

let tls_connector = TlsConnector::default();
let mut tls_stream = tls_connector
    .connect("localhost", tcp_stream)
    .expect("TLS handshake failed.")
    .await
    .expect("Awaiting TLS failed");

我还复制了/usr/local/share/ca-certificates/ 下的 CA 证书并运行 sudo update-ca-certificates (当然是linux)。 知道我做错了什么吗?谢谢。

【问题讨论】:

    标签: ssl rust backend


    【解决方案1】:

    我使用的是rustls,它没有集成操作系统证书。

    解决了这个问题:

    let mut config = ClientConfig::new();
    
    let cafile = Path::new("path of trusted CA chain");
    let file = async_std::fs::read(cafile)
        .await
        .expect("Failed to read file.");
    let mut pem = Cursor::new(file);
    config
        .root_store
        .add_pem_file(&mut pem)
        .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid cert"))
        .expect("Unable to create configuration object.");
    
    let tls_connector = TlsConnector::from(Arc::new(config));
    

    感谢 u/Wilem82(来自 reddit)的提示。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-02
    • 2013-03-08
    • 1970-01-01
    • 2017-12-04
    • 2010-09-20
    • 2020-02-14
    • 2012-06-11
    • 2016-03-21
    相关资源
    最近更新 更多