Skip to main content

xmtp_proto/
secret_drop.rs

1//! Push notification messages carry the recipient secret, the webhook signing
2//! key and derived HMAC keys; a device-sync `HmacKeyUpdate` carries an HMAC
3//! root key; group mutable metadata and the metadata-update intent can carry
4//! the commit-log signer. Each message wipes those fields when it drops, so
5//! every copy wipes itself: decoded requests, retry clones, the copies a
6//! transport owns, and a value prost drops when a decode fails part way.
7//! Buffers that prost and tonic encode into or copy through are not covered.
8
9use crate::backend_v1::{
10    HttpDelivery, RegisterRequest, Subscription, UnregisterRequest, UpdateSubscriptionsRequest,
11};
12use crate::xmtp::device_sync::content::HmacKeyUpdate;
13use crate::xmtp::mls::database::send_message_data::V1 as SendMessageV1;
14use crate::xmtp::mls::database::update_metadata_data::V1 as UpdateMetadataV1;
15use crate::xmtp::mls::message_contents::GroupMutableMetadataV1;
16use crate::xmtp::mls::message_contents::content_types::RemoteAttachmentInfo;
17use crate::xmtp::mls::message_contents::plaintext_envelope::V1 as PlaintextEnvelopeV1;
18use zeroize::Zeroize;
19
20impl Drop for RegisterRequest {
21    fn drop(&mut self) {
22        self.recipient_secret.zeroize();
23    }
24}
25
26impl Drop for HttpDelivery {
27    fn drop(&mut self) {
28        self.signing_key.zeroize();
29    }
30}
31
32impl Drop for UnregisterRequest {
33    fn drop(&mut self) {
34        self.recipient_secret.zeroize();
35    }
36}
37
38impl Drop for UpdateSubscriptionsRequest {
39    fn drop(&mut self) {
40        self.recipient_secret.zeroize();
41    }
42}
43
44impl Drop for Subscription {
45    fn drop(&mut self) {
46        self.hmac_keys.zeroize();
47    }
48}
49
50impl Drop for HmacKeyUpdate {
51    fn drop(&mut self) {
52        self.key.zeroize();
53    }
54}
55
56impl Drop for GroupMutableMetadataV1 {
57    fn drop(&mut self) {
58        // Attribute names are public; any value can be the commit-log signer.
59        for value in self.attributes.values_mut() {
60            value.zeroize();
61        }
62    }
63}
64
65impl Drop for UpdateMetadataV1 {
66    fn drop(&mut self) {
67        self.field_value.zeroize();
68        self.expected_field_value.zeroize();
69    }
70}
71
72impl Drop for SendMessageV1 {
73    fn drop(&mut self) {
74        self.payload_bytes.zeroize();
75    }
76}
77
78impl Drop for PlaintextEnvelopeV1 {
79    fn drop(&mut self) {
80        self.content.zeroize();
81    }
82}
83
84impl Drop for RemoteAttachmentInfo {
85    fn drop(&mut self) {
86        self.secret.zeroize();
87        self.salt.zeroize();
88        self.nonce.zeroize();
89    }
90}
91
92impl std::fmt::Debug for RemoteAttachmentInfo {
93    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
94        f.debug_struct("RemoteAttachmentInfo")
95            .finish_non_exhaustive()
96    }
97}