我正在尝试创建一个小型的类似 REST 的 API,它应该使用 HTTPS 进行保护。我想为服务器使用 nickel crate,为客户端使用 hyper_ruSTLs 和 hyper。
只要我使用浏览器、curl 或 REST 客户端访问它,服务器就运行良好,但是当我开始使用 hyper_ruSTLs 时,我总是会收到握手错误:
TLS error: AlertReceived(HandshakeFailure)
Connection closed
为了定位错误,我设置了一个最小的服务器:
#[macro_use]
extern crate nickel;
extern crate hyper;
use hyper::net::Openssl;
use nickel::Nickel;
fn main() {
let mut server = Nickel::new();
server.utilize(router! {
get "**" => |_req, _res| {
"Hello world!"
}
});
// FIXME: Add Match Error and OK instead of unwreap and add a propper error handling
let ssl = Openssl::with_cert_and_key("/etc/letsencrypt/live/www.example.de/fullchain.\
pem",
"/etc/letsencrypt/live/www.example.de/privkey.pem")
.unwrap();
server.listen_https("0.0.0.0:6767", ssl).expect("Failed to launch server");
}
Chrome 中的有效证书:
- The complete output of tlsclient when accessing the nickel server
- The complete output of tlsclient when accessing badssl.com
为了避免 hyper_ruSTLs 中的错误,我使用了 rustls tlsclient example但错误仍然出现。
Let's Encrypt 证书不是问题,因为我可以使用 tlsclient 使用这些证书连接到 Apache2 服务器。
我对它的运作方式的想法有误吗?
最佳答案
看起来 hyper 的 Openssl::with_cert_and_key
告诉 openssl 使用 DEFAULT
密码套件列表,这非常糟糕。在这种情况下,ruSTLs 无法握手,原因与 chrome 所说的“过时 key 交换 (RSA)”相同。如果您运行服务器并将 ssllabs.com 指向它,您应该获得更多信息。
我认为最近的 hyper 版本已经删除了这段代码,以支持从其他 crate 获得 TLS 支持。你能试试吗?
关于ssl - 使用 Let's Encrypt 证书的 Nickel 服务器在使用 ruSTL 访问时出现握手错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41846521/