Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove a seeming redundant code and possible clerical errors in examples/tls_rustls.rs #176

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions examples/tls_rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{fs::File, io::BufReader, sync::Arc};
use tokio::net::TcpListener;
use tokio_rustls::{
rustls::{
internal::pemfile::certs, internal::pemfile::pkcs8_private_keys, NoClientAuth, ServerConfig,
internal::pemfile::certs, internal::pemfile::rsa_private_keys, internal::pemfile::pkcs8_private_keys, NoClientAuth, ServerConfig,
},
TlsAcceptor,
};
Expand Down Expand Up @@ -52,17 +52,22 @@ async fn handler() -> &'static str {
}

fn rustls_server_config(key: &str, cert: &str) -> Arc<ServerConfig> {
// close Client Auth, important!
let mut config = ServerConfig::new(NoClientAuth::new());

let mut key_reader = BufReader::new(File::open(key).unwrap());
let mut cert_reader = BufReader::new(File::open(cert).unwrap());

let key = pkcs8_private_keys(&mut key_reader).unwrap().remove(0);
// compatiable pkcs1 & pkcs8
let key = match rsa_private_keys(&mut key_reader) {
Ok(mut t) => t.remove(0),
Err(e) => pkcs8_private_keys(&mut key_reader).unwrap().remove(0)
};
let certs = certs(&mut cert_reader).unwrap();

config.set_single_cert(certs, key).unwrap();

config.set_protocols(&[b"h2".to_vec(), b"http/1.1".to_vec()]);
config.set_protocols(&[b"http/1.1".to_vec()]);

Arc::new(config)
}