3 releases
0.5.0-rc | Mar 20, 2020 |
---|---|
0.5.0-beta | Mar 4, 2020 |
0.5.0-alpha | Mar 3, 2020 |
#6 in #tls-acceptor
105KB
2K
SLoC
Roa-tls
This crate provides an acceptor implementing roa_core::Accept
and an app extension.
TlsIncoming
use roa_core::App;
use roa_tls::TlsIncoming;
use roa_tls::rustls::{ServerConfig, NoClientAuth};
use roa_tls::rustls::internal::pemfile::{certs, rsa_private_keys};
use std::fs::File;
use std::io::BufReader;
# fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut config = ServerConfig::new(NoClientAuth::new());
let mut cert_file = BufReader::new(File::open("../assets/cert.pem")?);
let mut key_file = BufReader::new(File::open("../assets/key.pem")?);
let cert_chain = certs(&mut cert_file).unwrap();
let mut keys = rsa_private_keys(&mut key_file).unwrap();
config.set_single_cert(cert_chain, keys.remove(0))?;
let incoming = TlsIncoming::bind("127.0.0.1:0", config)?;
let server = App::new(()).accept(incoming);
// server.await
Ok(())
# }
TlsListener
use roa_core::App;
use roa_tls::TlsListener;
use roa_tls::rustls::{ServerConfig, NoClientAuth};
use roa_tls::rustls::internal::pemfile::{certs, rsa_private_keys};
use std::fs::File;
use std::io::BufReader;
# fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut config = ServerConfig::new(NoClientAuth::new());
let mut cert_file = BufReader::new(File::open("../assets/cert.pem")?);
let mut key_file = BufReader::new(File::open("../assets/key.pem")?);
let cert_chain = certs(&mut cert_file).unwrap();
let mut keys = rsa_private_keys(&mut key_file).unwrap();
config.set_single_cert(cert_chain, keys.remove(0))?;
let (addr, server) = App::new(()).listen_tls_on("127.0.0.1:0", config)?;
// server.await
Ok(())
# }
Dependencies
~20–34MB
~591K SLoC