Skip to content
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
1 change: 0 additions & 1 deletion tls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
clap.workspace = true
anyhow.workspace = true
attest-data.workspace = true
camino.workspace = true
cfg-if.workspace = true
Expand Down
27 changes: 13 additions & 14 deletions tls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ use rustls::crypto::ring::cipher_suite::TLS13_CHACHA20_POLY1305_SHA256;
use rustls::crypto::ring::kx_group::X25519;
use rustls::crypto::CryptoProvider;
use slog::error;
use std::io::prelude::*;
use std::io::IoSlice;
use std::marker::Unpin;

#[cfg(any(unix, target_os = "wasi"))]
use std::os::fd::{AsRawFd, RawFd};

use anyhow::Context;
use std::fs::File;
use std::pin::Pin;
use std::task::{self, Poll};
use std::{fs, io};
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf};
use tokio_rustls::TlsStream;
use x509_cert::{
Expand Down Expand Up @@ -51,9 +49,12 @@ pub enum Error {
#[error("io error: {0}")]
Io(#[from] std::io::Error),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you surmised, John's doc is helpful here. There is no need to lose this context, it just gets a tad more tedious in usage. We should add specific errors for opening and reading files as described in https://github.com/oxidecomputer/omicron/blob/john/error-docs/docs/error-types-and-logging.adoc#2-defining-error-enums-with-thiserror.

We'd then change the #[from] to #[source] for the underlying error and add a path field that we could report in the Display impl with the same messages as we did previously in with_context.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/oxidecomputer/omicron/blob/main/docs/error-types-and-logging.adoc this is now merged if like me you went to click on the link and it now 404's


// TODO: Return a more specific error / errors from dice-util
#[error("dice error: {0}")]
Dice(#[from] anyhow::Error),
#[error("io error: {path}")]
FailedRead {
path: Utf8PathBuf,
#[source]
err: io::Error,
},

#[error("RotRequest: {0}")]
RotRequest(#[from] ipcc::RotRequestError),
Expand Down Expand Up @@ -220,15 +221,13 @@ where
}

pub fn load_root_cert(path: &Utf8PathBuf) -> Result<Certificate, Error> {
let mut root_cert_pem = Vec::new();
File::open(path)
.with_context(|| format!("failed to open {}", &path))?
.read_to_end(&mut root_cert_pem)
.with_context(|| format!("failed to read {}", &path))?;
let root = Certificate::from_pem(&root_cert_pem).with_context(|| {
format!("failed to convert pem read from {}", &path)
let cert = fs::read(path).map_err(|err| Error::FailedRead {
path: path.to_owned(),
err,
})?;
Ok(root)
let cert = Certificate::from_pem(&cert)?;

Ok(cert)
}

fn certs_to_der(certs: &[Certificate]) -> Result<Vec<u8>, Error> {
Expand Down
Loading