Skip to main content

securedrop_protocol_minimal/
traits.rs

1use crate::VerifyingKey;
2use crate::message::MessageKeyPair;
3use crate::message::MessagePublicKey;
4use crate::metadata::MetadataPublicKey;
5use crate::primitives::ristretto255::DHPrivateKey;
6use crate::primitives::ristretto255::DHPublicKey;
7use crate::sign::{JournalistEphemeralKey, JournalistLongTermKey, Signature};
8use alloc::vec::Vec;
9
10use crate::wire::bundle::{SignedKeyBundlePublic, SignedLongtermKeyBundle};
11use crate::wire::enrollment::Enrollment;
12
13use crate::client::plaintext::Plaintext;
14use crate::keys::{KeyBundlePublic, MessageKeyBundle};
15
16// Sealed traits that downstream crates should not implement.
17// Do not re-export!
18use crate::sealed;
19
20////////////////////////
21///
22/// Users have the following (public traits) in common:
23/// They expose a fetch pubkey, a message auth pubkey
24/// (implicit authentication),
25/// and a collection of KeyBundles (tuples of keys - a keybundle contains
26/// all the key material required to send a message to a given user).
27/// A Source has a KeyBundle collection of size 1.
28/// A Journalist has KeyBundle collection of size > 1.
29/// Some users (Sources) use a key from their message bundle as
30/// their message auth key.
31pub trait UserPublic {
32    fn fetch_pk(&self) -> &DHPublicKey;
33    /// The long-term SD-APKE public key `pk^APKE`.
34    fn message_auth_pk(&self) -> &MessagePublicKey;
35    fn message_metadata_pk(&self) -> &MetadataPublicKey;
36    /// The ephemeral SD-APKE public key `pk^{APKE_E}` from a key bundle.
37    fn message_enc_pk(&self) -> &MessagePublicKey;
38}
39
40pub trait JournalistPublic: UserPublic {
41    fn verifying_key(&self) -> &VerifyingKey;
42    fn self_signature(&self) -> &Signature<JournalistLongTermKey>;
43    fn signed_keybytes(&self) -> &SignedLongtermKeyBundle;
44    fn ephemeral_bundle(&self) -> &KeyBundlePublic;
45    fn ephemeral_signature(&self) -> &Signature<JournalistEphemeralKey>;
46}
47
48#[cfg(not(hax))]
49pub trait Enrollable: sealed::Sealed {
50    // sealed traits don't play nice with hax right now, so this is a workaround
51    fn signing_key(&self) -> &VerifyingKey;
52    fn enroll(&self) -> Enrollment;
53    /// Each item is a [`SignedKeyBundlePublic`]: the public keys together with the
54    /// journalist's self-signature over them.
55    fn signed_keybundles(&self) -> Vec<SignedKeyBundlePublic>;
56}
57
58#[cfg(hax)]
59pub trait Enrollable {
60    fn signing_key(&self) -> &VerifyingKey;
61    fn enroll(&self) -> Enrollment;
62    /// Each item is a [`SignedKeyBundlePublic`]: the public keys together with the
63    /// journalist's self-signature over them.
64    fn signed_keybundles(&self) -> Vec<SignedKeyBundlePublic>;
65}
66
67/// Users have the following (secret traits) in common:
68/// They have a fetching keypair used to retrieve messages;
69/// They have a message authentication keypair used to implicitly
70/// authenticate their messages (via DH-AKEM);
71/// They can index a KeyBundle (tuple) and use it to attempt to
72/// decrypt a message.
73#[cfg(not(hax))]
74pub trait UserSecret: sealed::Sealed {
75    fn num_bundles(&self) -> usize;
76    fn fetch_keypair(&self) -> (&DHPrivateKey, &DHPublicKey);
77    /// The long-term SD-APKE keypair (`sk^APKE`, `pk^APKE`)
78    fn message_auth_keypair(&self) -> &MessageKeyPair;
79    fn build_message(&self, message: Vec<u8>) -> Plaintext;
80    fn keybundles(&self) -> Vec<&MessageKeyBundle>;
81}
82
83#[cfg(hax)]
84pub trait UserSecret {
85    fn num_bundles(&self) -> usize;
86    fn fetch_keypair(&self) -> (&DHPrivateKey, &DHPublicKey);
87    /// The long-term SD-APKE keypair (`sk^APKE`, `pk^APKE`).
88    fn message_auth_keypair(&self) -> &MessageKeyPair;
89    fn build_message(&self, message: Vec<u8>) -> Plaintext;
90    fn keybundles(&self) -> Vec<&MessageKeyBundle>;
91}
92
93// hax doesn't work well with sealed trait pattern right now
94#[cfg(not(hax))]
95pub trait RestrictedApi: sealed::Sealed {}
96
97#[cfg(hax)]
98pub trait RestrictedApi {}