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

chore(deps): rustls-pemfile 2 #20

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ rand = "0.8"
ring = { version = "0.17.7", features = ["std"], default-features = false }
rsa = { version = "0.9.6", features = ["sha2"] }
rustls = { version = "0.22" }
rustls-pemfile = "1"
rustls-pemfile = "2"
sec1 = { version = "0.7.3", features = ["der"], default-features = false }
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
Expand Down
29 changes: 13 additions & 16 deletions bin/tee-vault-unseal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use actix_web::http::header;
use actix_web::rt::time::sleep;
use actix_web::web::Data;
use actix_web::{web, App, HttpServer};
use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use attestation::get_attestation;
use awc::{Client, Connector};
use clap::Parser;
Expand Down Expand Up @@ -310,23 +310,20 @@ pub fn load_rustls_config() -> Result<(ServerConfig, Arc<ClientConfig>, [u8; 64]
);

// convert files to key/cert objects
let cert_chain: Vec<_> = certs(cert_file)
.unwrap()
.into_iter()
.map(rustls::pki_types::CertificateDer::from)
.collect();
let priv_key: rustls::pki_types::PrivateKeyDer = match read_one(key_file).unwrap() {
Some(rustls_pemfile::Item::RSAKey(key)) => {
rustls::pki_types::PrivatePkcs1KeyDer::from(key).into()
}
Some(rustls_pemfile::Item::PKCS8Key(key)) => {
rustls::pki_types::PrivatePkcs8KeyDer::from(key).into()
}
_ => panic!("no keys found"),
};
let cert_chain = certs(cert_file)
.collect::<Result<Vec<_>, _>>()
.context("Failed to load TLS cert file")?;

let priv_key: rustls::pki_types::PrivateKeyDer =
match read_one(key_file).context("Failed to read TLS key file")? {
Some(rustls_pemfile::Item::Sec1Key(key)) => key.into(),
Some(rustls_pemfile::Item::Pkcs1Key(key)) => key.into(),
Some(rustls_pemfile::Item::Pkcs8Key(key)) => key.into(),
_ => bail!("no keys found in TLS key file"),
};

let tls_config = Arc::new(
rustls::ClientConfig::builder()
ClientConfig::builder()
.dangerous()
.with_custom_certificate_verifier(Arc::new(make_verifier(
cert_chain[0].as_ref().into(),
Expand Down