Skip to main content

mls_spec/drafts/
private_external.rs

1use crate::{
2    SensitiveBytes,
3    crypto::{
4        HpkeCiphertext, HpkePublicKey, HpkePublicKeyRef, SignaturePublicKey, SignaturePublicKeyRef,
5    },
6    defs::{CiphersuiteId, Epoch, ProtocolVersion, WireFormat},
7    drafts::mls_extensions::safe_application::{self, ComponentId},
8    group::{GroupId, GroupIdRef},
9    messages::ContentType,
10};
11
12pub const WIRE_FORMAT_MLS_PRIVATE_EXTERNAL_MESSAGE: u16 = 0xF4E9; // TODO: IANA attribution
13static_assertions::const_assert!(
14    *WireFormat::RESERVED_PRIVATE_USE_RANGE.start() <= WIRE_FORMAT_MLS_PRIVATE_EXTERNAL_MESSAGE
15        && WIRE_FORMAT_MLS_PRIVATE_EXTERNAL_MESSAGE
16            <= *WireFormat::RESERVED_PRIVATE_USE_RANGE.end()
17);
18
19pub const ROOT_PRIVATE_SIGNATURE_ID: ComponentId = 0xF15E;
20static_assertions::const_assert!(
21    *super::mls_extensions::COMPONENT_RESERVED_PRIVATE_RANGE.start() <= ROOT_PRIVATE_SIGNATURE_ID
22        && ROOT_PRIVATE_SIGNATURE_ID
23            <= *super::mls_extensions::COMPONENT_RESERVED_PRIVATE_RANGE.end()
24);
25pub const EXT_ENCRYPTION_INFO_ID: ComponentId = 0xFEE1;
26static_assertions::const_assert!(
27    *super::mls_extensions::COMPONENT_RESERVED_PRIVATE_RANGE.start() <= ROOT_PRIVATE_SIGNATURE_ID
28        && ROOT_PRIVATE_SIGNATURE_ID
29            <= *super::mls_extensions::COMPONENT_RESERVED_PRIVATE_RANGE.end()
30);
31
32#[derive(
33    Debug,
34    Clone,
35    PartialEq,
36    Eq,
37    tls_codec::TlsSize,
38    tls_codec::TlsDeserialize,
39    tls_codec::TlsSerialize,
40)]
41#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
42pub struct RootPrivateSignature {
43    pub root_private_signature_key: SensitiveBytes,
44}
45
46impl safe_application::Component for RootPrivateSignature {
47    fn component_id() -> ComponentId {
48        ROOT_PRIVATE_SIGNATURE_ID
49    }
50}
51
52#[derive(Debug, Clone, PartialEq, Eq, tls_codec::TlsSize, tls_codec::TlsSerialize)]
53#[cfg_attr(feature = "serde", derive(serde::Serialize))]
54pub struct ExternalEncryptionInfoTBS<'a> {
55    pub version: &'a ProtocolVersion,
56    #[tls_codec(with = "crate::tlspl::bytes")]
57    pub group_id: GroupIdRef<'a>,
58    pub epoch: &'a Epoch,
59    pub ciphersuite: &'a CiphersuiteId,
60    pub external_encryption_public_key: HpkePublicKeyRef<'a>,
61    pub root_public_signature_key: SignaturePublicKeyRef<'a>,
62}
63
64#[derive(
65    Debug,
66    Clone,
67    PartialEq,
68    Eq,
69    tls_codec::TlsSize,
70    tls_codec::TlsDeserialize,
71    tls_codec::TlsSerialize,
72)]
73#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
74pub struct ExternalEncryptionInfo {
75    pub ciphersuite: CiphersuiteId,
76    pub external_encryption_public_key: HpkePublicKey,
77    pub root_public_signature_key: SignaturePublicKey,
78    pub external_encryption_signature: SensitiveBytes,
79}
80
81impl safe_application::Component for ExternalEncryptionInfo {
82    fn component_id() -> ComponentId {
83        EXT_ENCRYPTION_INFO_ID
84    }
85}
86
87impl ExternalEncryptionInfo {
88    pub fn to_tbs<'a>(
89        &'a self,
90        version: &'a ProtocolVersion,
91        group_id: GroupIdRef<'a>,
92        epoch: &'a Epoch,
93    ) -> ExternalEncryptionInfoTBS<'a> {
94        ExternalEncryptionInfoTBS {
95            version,
96            group_id,
97            epoch,
98            ciphersuite: &self.ciphersuite,
99            external_encryption_public_key: &self.external_encryption_public_key,
100            root_public_signature_key: &self.root_public_signature_key,
101        }
102    }
103}
104
105#[derive(
106    Debug,
107    Clone,
108    PartialEq,
109    Eq,
110    tls_codec::TlsSize,
111    tls_codec::TlsDeserialize,
112    tls_codec::TlsSerialize,
113)]
114#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
115pub struct PrivateExternalMessageContext;
116
117#[derive(
118    Debug,
119    Clone,
120    PartialEq,
121    Eq,
122    tls_codec::TlsSize,
123    tls_codec::TlsDeserialize,
124    tls_codec::TlsSerialize,
125)]
126#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
127pub struct PrivateExternalMessage {
128    #[tls_codec(with = "crate::tlspl::bytes")]
129    pub group_id: GroupId,
130    pub epoch: Epoch,
131    pub content_type: ContentType,
132    #[tls_codec(with = "crate::tlspl::bytes")]
133    pub authenticated_data: Vec<u8>,
134    pub encrypted_public_message: HpkeCiphertext,
135}