Crates.io | rustls-pin |
lib.rs | rustls-pin |
version | 0.1.2 |
source | src |
created_at | 2021-03-21 06:51:16.097897 |
updated_at | 2021-03-23 20:46:58.643257 |
description | Server certificate pinning with `rustls` |
homepage | |
repository | https://gitlab.com/leonhard-llc/ops |
max_upload_size | |
id | 371600 |
size | 21,498 |
Server certificate pinning with rustls
.
forbid(unsafe_code)
Before switching the server to a new certificate, you need to upgrade the clients to accept both the current certificate and the new one.
If your users update their client software infrequently, you may need to wait a long time before switching to a new certificate.
You can change certificates frequently by having multiple pending 'new' certificates. Example:
let mut stream = rustls_pin::connect_pinned(
addr,
vec![server_cert1, server_cert2],
).unwrap();
let mut response = String::new();
match std::io::Read::read_to_string(
&mut stream, &mut response) {
Ok(_) => {},
Err(e) if &e.to_string() ==
"invalid certificate: UnknownIssuer"
=> panic!("Update required."),
Err(e) => {
// panic!("{}", e)
}
}
When the client software reads/writes the stream and gets an
invalid certificate: UnknownIssuer
error,
it can assume that it is outdated.
It can tell the user to update.
The rustls client terminates the TLS connection by sending the
'bad certificate' reason to the server.
The server's stream read/write fails with:
"Custom { kind: InvalidData, error: AlertReceived(BadCertificate) }"
.
Fixing bugs and adding features is easy and fast. Send us a pull request and we intend to:
License: Apache-2.0