< 返回版块

zaq7434 发表于 2022-05-19 10:08

Tags:axum,axum_server, reqwest

错误: Error: reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Ipv4(127.0.0.1)), port: Some(3000), path: "/", query: None, fragment: None }, source: hyper::Error(Connect, Ssl(Error { code: ErrorCode(1), cause: Some(Ssl(ErrorStack([Error { code: 336151578, library: "SSL routines", function: "ssl3_read_bytes", reason: "tlsv1 alert decode error", file: "ssl/record/rec_layer_s3.c", line: 1544, data: "SSL alert number 50" }]))) }, X509VerifyResult { code: 0, error: "ok" })) }

服务端,用curl 命令请求正常,加-k 能获取到数据,不加-k 报证书错误。 但是 用reqwest起的服务就报上面的错, 访问python flask 起的(不配置证书)https 服务可以访问。

求组各位大佬帮解答下。

server: serverConfig 生成如下:

fn tls_config() -> ServerConfig { let cert = rcgen::generate_simple_self_signed(vec!["localhost".to_owned()]).unwrap(); let cert_file = cert.serialize_pem().unwrap(); let key_file = cert.serialize_private_key_pem();

let cert_file = &mut BufReader::new(cert_file.as_bytes());
let key_file = &mut BufReader::new(key_file.as_bytes());

let cert_chain = certs(cert_file)
    .unwrap()
    .into_iter()
    .map(Certificate)
    .collect();
let mut keys = pkcs8_private_keys(key_file).unwrap();

ServerConfig::builder()
    .with_safe_defaults()
    .with_no_client_auth()
    .with_single_cert(cert_chain, PrivateKey(keys.remove(0)))
    .unwrap()

}

client :

let client = reqwest::Client::builder()
    .tls_built_in_root_certs(true)
    .danger_accept_invalid_certs(true)
    .no_proxy()
    .build()
    .unwrap();

评论区

写评论
作者 zaq7434 2022-05-20 09:11

最后使用 .use_rustls_tls() 解决该问题。 具体原因不清楚。有明白人麻烦解答下。

1 共 1 条评论, 1 页