Skip to content

Commit

Permalink
Merge pull request #1028 from sozu-proxy/devel/fdubois/fix/tls
Browse files Browse the repository at this point in the history
fix(tls): certificate replacement and remove is still-in-use security
  • Loading branch information
FlorentinDUBOIS authored Nov 15, 2023
2 parents 7f46b73 + cc12789 commit cfe32cc
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 103 deletions.
14 changes: 13 additions & 1 deletion command/src/certificate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashSet, fmt, str::FromStr};

use hex::FromHex;
use hex::{FromHex, FromHexError};
use serde::de::{self, Visitor};
use sha2::{Digest, Sha256};
use x509_parser::{
Expand All @@ -22,6 +22,8 @@ pub enum CertificateError {
InvalidCertificate(String),
#[error("failed to parse tls version '{0}'")]
InvalidTlsVersion(String),
#[error("failed to parse fingerprint, {0}")]
InvalidFingerprint(FromHexError),
}

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -101,6 +103,16 @@ impl FromStr for TlsVersion {
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Fingerprint(pub Vec<u8>);

impl FromStr for Fingerprint {
type Err = CertificateError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
hex::decode(s)
.map_err(CertificateError::InvalidFingerprint)
.map(Fingerprint)
}
}

impl fmt::Debug for Fingerprint {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "CertificateFingerprint({})", hex::encode(&self.0))
Expand Down
4 changes: 2 additions & 2 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use crate::{
server::{ListenSession, ListenToken, ProxyChannel, Server, SessionManager, SessionToken},
socket::{server_bind, FrontRustls},
timer::TimeoutContainer,
tls::{MutexWrappedCertificateResolver, ResolveCertificate, StoredCertificate},
tls::{CertifiedKeyWrapper, MutexWrappedCertificateResolver, ResolveCertificate},
util::UnwrapLog,
AcceptError, CachedTags, FrontendFromRequestError, L7ListenerHandler, L7Proxy, ListenerError,
ListenerHandler, Protocol, ProxyConfiguration, ProxyError, ProxySession, SessionIsToBeClosed,
Expand Down Expand Up @@ -600,7 +600,7 @@ impl L7ListenerHandler for HttpsListener {
impl ResolveCertificate for HttpsListener {
type Error = ListenerError;

fn get_certificate(&self, fingerprint: &Fingerprint) -> Option<StoredCertificate> {
fn get_certificate(&self, fingerprint: &Fingerprint) -> Option<CertifiedKeyWrapper> {
let resolver = self
.resolver
.0
Expand Down
1 change: 1 addition & 0 deletions lib/src/router/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn find_last_dot(input: &[u8]) -> Option<usize> {
(0..input.len()).rev().find(|&i| input[i] == b'.')
}

/// A custom implementation of the [Trie data structure](https://www.wikiwand.com/en/Trie)
#[derive(Debug, PartialEq)]
pub struct TrieNode<V> {
key_value: Option<KeyValue<Key, V>>,
Expand Down
Loading

0 comments on commit cfe32cc

Please sign in to comment.