diff --git a/x509_credential/src/lib.rs b/x509_credential/src/lib.rs index 562ff04ceb..b37f806bb3 100644 --- a/x509_credential/src/lib.rs +++ b/x509_credential/src/lib.rs @@ -18,7 +18,8 @@ use openmls_traits::{ pub struct CertificateKeyPair(pub SignatureKeyPair); impl CertificateKeyPair { - /// Constructs the `CertificateKeyPair` from a private key and a der encoded certificate chain + /// Constructs the `CertificateKeyPair` from a private key and a der encoded + /// certificate chain pub fn new(sk: Vec, cert_chain: Vec>) -> Result { if cert_chain.len() < 2 { return Err(CryptoError::IncompleteCertificateChain); @@ -105,8 +106,6 @@ pub trait X509Ext { fn identity(&self) -> Result, CryptoError>; } -const CLIENT_ID_PREFIX: &str = "im:wireapp="; - impl X509Ext for Certificate { fn is_valid(&self) -> Result<(), CryptoError> { if !self.is_time_valid()? { @@ -214,11 +213,14 @@ impl X509Ext for Certificate { } } +/// Turn 'wireapp://ZHpLZLZMROeMWp4sJlL2XA!dee090f1ed94e4c8@wire.com' into +/// '647a4b64-b64c-44e7-8c5a-9e2c2652f65c:dee090f1ed94e4c8@wire.com' fn try_to_qualified_wire_client_id(client_id: &str) -> Option> { const COLON: u8 = 58; + const WIRE_URI_SCHEME: &str = "wireapp://"; - let client_id = client_id.strip_prefix(CLIENT_ID_PREFIX)?; - let (user_id, rest) = client_id.split_once('/')?; + let client_id = client_id.strip_prefix(WIRE_URI_SCHEME)?; + let (user_id, rest) = client_id.split_once('!')?; let user_id = to_hyphenated_user_id(user_id)?; let client_id = [&user_id[..], &[COLON], rest.as_bytes()].concat(); @@ -237,3 +239,14 @@ fn to_hyphenated_user_id(user_id: &str) -> Option<[u8; uuid::fmt::Hyphenated::LE Some(buf) } + +#[test] +fn to_qualified_wire_client_id_should_work() { + let input = "wireapp://ZHpLZLZMROeMWp4sJlL2XA!dee090f1ed94e4c8@wire.com"; + let output = try_to_qualified_wire_client_id(input).unwrap(); + let output = std::str::from_utf8(&output).unwrap(); + assert_eq!( + output, + "647a4b64-b64c-44e7-8c5a-9e2c2652f65c:dee090f1ed94e4c8@wire.com" + ); +}