rustls-mitm 0.1.0

SNI-based certificate resolver for rustls that generates per-host TLS certificates on the fly, enabling man-in-the-middle TLS interception
Documentation
pub mod ca;
mod resolver;

pub use ca::CertificateAuthority;
pub use resolver::MitmCertResolver;

use std::fmt;

/// Errors produced by `rustls-mitm`.
#[derive(Debug)]
pub enum Error {
    Rcgen(rcgen::Error),
    Rustls(rustls::Error),
    Io(std::io::Error),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Rcgen(e) => write!(f, "{e}"),
            Error::Rustls(e) => write!(f, "{e}"),
            Error::Io(e) => write!(f, "{e}"),
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Error::Rcgen(e) => Some(e),
            Error::Rustls(e) => Some(e),
            Error::Io(e) => Some(e),
        }
    }
}

impl From<rcgen::Error> for Error {
    fn from(e: rcgen::Error) -> Self {
        Error::Rcgen(e)
    }
}

impl From<rustls::Error> for Error {
    fn from(e: rustls::Error) -> Self {
        Error::Rustls(e)
    }
}

impl From<std::io::Error> for Error {
    fn from(e: std::io::Error) -> Self {
        Error::Io(e)
    }
}