Rust 具有自签名PEM证书的HTTPS请求

Rust 具有自签名PEM证书的HTTPS请求,rust,Rust,免责声明:为JS/TS而来,几个月来一直在摆弄锈迹 我正在对一个非常简单的后端进行原型设计,并使用actixweb进行服务器端TLS,通过rustls中的ServerConfig使用'server.pem'和'server\u key.pem'。我认为一切正常。问题是,我需要执行一个从服务到另一个使用相同证书设置的服务的HTTPS请求。我已经研究了一些SSL/TLS方法和一些HTTP库,但没有找到任何可以使用的方法 尝试使用reqwest,大致如下所示: 注意:以下是证书类型: root\u文

免责声明:为JS/TS而来,几个月来一直在摆弄锈迹

我正在对一个非常简单的后端进行原型设计,并使用
actixweb
进行服务器端TLS,通过
rustls
中的
ServerConfig
使用'server.pem'和'server\u key.pem'。我认为一切正常。问题是,我需要执行一个从服务到另一个使用相同证书设置的服务的HTTPS请求。我已经研究了一些SSL/TLS方法和一些HTTP库,但没有找到任何可以使用的方法

尝试使用
reqwest
,大致如下所示:

注意:以下是证书类型:

  • root\u文件
    结果
  • 客户端文件
    结果
  • 客户端密钥文件
    结果
此请求未通过,将导致403禁止。我怀疑
Identity
部分是大错特错的,因为我在阅读
reqwest
文档时有点把它拼凑在一起了

而我将使用的Node.js方法如下:

注意:
root
client
clientKey
属于(node.js)
Buffer
类型

const{root,client,clientKey}=getCertificates();
const res=wait requestPromise.get(uri{
ca:[根],
证书:客户,
key:clientKey,
代理机构:{
secureOptions:getConfig().ssl,
},
});
是否有一个现有的板条箱可以帮助我实现node.js版本对
请求承诺所做的事情


感谢您的指导

actixweb
已经提供了一个http客户端,您不需要额外的板条箱,所有东西都在模块中,您可以找到示例(使用
openssl
,但与
rustls
完全相同)
let CertificateContents {
    root_file,
    client_file,
    client_key_file,
    ..
} = get_cert_contents(None);
let root_cert =
    Certificate::from_pem(&root_file?).map_err(|e| AppError::FileRead(e.to_string()))?;

// Identity represents the client cert and client key
let client_file = client_file?;
let client_key_file = client_key_file?;
let combined = format!("{}{}", client_key_file, client_file);
let identity = Identity::from_pem(combined.as_bytes()).unwrap();

// https://docs.rs/reqwest/0.10.6/reqwest/struct.ClientBuilder.html
let client = reqwest::Client::builder()
    .add_root_certificate(root_cert)
    .identity(identity) // client + client key
    .default_headers(headers)
    .build()
    .unwrap();

let http_res = client
    .get(&uri)
    .send()
    .await
    .map_err(|e| AppError::Internal(format!("Request error: {}", e.to_string())))?;