Crates.io | pki |
lib.rs | pki |
version | 0.2.2 |
source | src |
created_at | 2022-05-30 11:38:11.303079 |
updated_at | 2024-04-20 15:52:42.752217 |
description | Public key infrastructure tools for Rust |
homepage | |
repository | https://github.com/ancwrd1/pki-rs |
max_upload_size | |
id | 596941 |
size | 45,447 |
This project contains Rust library for PKI-related tasks such as generating and validating certificate chains. It can be used to easily create certificate chains on the fly for testing purposes.
See tests/test_gen_chain.rs
and examples/tls-server.rs
for detailed examples.
fn main() -> Result<(), Box<dyn std::error::Error>> {
let key_store = pki::util::create_easy_server_chain(HOSTNAME)?;
let pkcs8 = key_store.to_pkcs8()?;
let identity = Identity::from_pkcs8(&pkcs8, &pkcs8)?;
let acceptor = TlsAcceptor::builder(identity).build()?;
let server = TcpListener::bind(format!("{}:{}", HOSTNAME, PORT))?;
for stream in server.incoming() {
let mut stream = acceptor.accept(stream?)?;
}
}
fn client(key_store: &KeyStore) -> Result<(), Box<dyn std::error::Error>> {
let client = TcpStream::connect(format!("{}:{}", HOSTNAME, PORT))?;
let connector = TlsConnector::builder()
.add_root_certificate(Certificate::from_der(
&key_store.certs().last().unwrap().to_der()?,
)?)
.build()?;
let mut client = connector.connect(HOSTNAME, client)?;
}
Licensed under MIT or Apache license (LICENSE-MIT or LICENSE-APACHE)