| 1 |
// Copyright (c) 2024 Mozilla Corporation and contributors. |
| 2 |
// SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 3 |
|
| 4 |
/// |
| 5 |
/// Get the current epoch. |
| 6 |
/// |
| 7 |
|
| 8 |
pub type GroupContext = Vec<u8>; |
| 9 |
|
| 10 |
pub fn mls_group_context( |
| 11 |
_state: &PlatformState, |
| 12 |
_gid: &GroupId, |
| 13 |
_myself: &Identity, |
| 14 |
) -> Result<GroupContext, PlatformError> { |
| 15 |
unimplemented!() |
| 16 |
// return Json(GroupContext { |
| 17 |
// ... |
| 18 |
// }); |
| 19 |
} |
| 20 |
|
| 21 |
// TODO: Expose auditable |
| 22 |
pub struct PendingJoinState { |
| 23 |
identifier: Vec<u8>, |
| 24 |
} |
| 25 |
|
| 26 |
pub fn mls_group_process_welcome( |
| 27 |
pstate: &PlatformState, |
| 28 |
myself: &Identity, |
| 29 |
welcome: MlsMessage, |
| 30 |
ratchet_tree: Option<ExportedTree<'static>>, |
| 31 |
) -> Result<PendingJoinState, PlatformError> { |
| 32 |
let client = pstate.client_default(myself)?; |
| 33 |
let (mut group, _info) = client.join_group(ratchet_tree, welcome)?; |
| 34 |
let gid = group.group_id().to_vec(); |
| 35 |
|
| 36 |
// Store the state |
| 37 |
group.write_to_storage()?; |
| 38 |
|
| 39 |
// Return the group identifier |
| 40 |
Ok(gid) |
| 41 |
} |
| 42 |
|
| 43 |
pub fn mls_group_inspect_welcome( |
| 44 |
pstate: &PlatformState, |
| 45 |
myself: &Identity, |
| 46 |
welcome: MlsMessage, |
| 47 |
ratchet_tree: Option<ExportedTree<'static>>, |
| 48 |
) -> Result<PendingJoinState, PlatformError> { |
| 49 |
unimplemented!() |
| 50 |
} |
| 51 |
|
| 52 |
/// |
| 53 |
/// Leave a group. |
| 54 |
/// |
| 55 |
pub fn mls_group_propose_leave( |
| 56 |
pstate: PlatformState, |
| 57 |
gid: GroupId, |
| 58 |
myself: &Identity, |
| 59 |
) -> Result<mls_rs::MlsMessage, PlatformError> { |
| 60 |
let mut group = pstate.client_default(myself)?.load_group(&gid)?; |
| 61 |
let self_index = group.current_member_index(); |
| 62 |
let proposal = group.propose_remove(self_index, vec![])?; |
| 63 |
|
| 64 |
Ok(proposal) |
| 65 |
} |
| 66 |
|
| 67 |
/// |
| 68 |
/// Import a group state into the storage |
| 69 |
/// |
| 70 |
pub fn mls_import_group_state( |
| 71 |
group_state: Vec<u8>, |
| 72 |
signature_key: SignatureKeypair, |
| 73 |
myself: SigningIdentity, |
| 74 |
) -> Result<(), MlsError> { |
| 75 |
unimplemented!() |
| 76 |
// https://github.com/awslabs/mls-rs/blob/main/mls-rs/src/client.rs#L605 |
| 77 |
} |
| 78 |
|
| 79 |
/// |
| 80 |
/// Export a group state into the storage |
| 81 |
/// |
| 82 |
pub fn mls_export_group_state(gid: GroupId) -> Result<Vec<u8>, MlsError> { |
| 83 |
unimplemented!() |
| 84 |
} |
| 85 |
|
| 86 |
/// |
| 87 |
/// Validate a KeyPackage. |
| 88 |
/// |
| 89 |
|
| 90 |
pub fn validate_key_package(key_package: KeyPackage) -> Result<(), MlsError> { |
| 91 |
unimplemented!() |
| 92 |
} |
| 93 |
|
| 94 |
/// |
| 95 |
/// Extract Signing Identity from a KeyPackage. |
| 96 |
/// |
| 97 |
|
| 98 |
pub fn identity_from_key_package(key_package: KeyPackage) -> Result<SigningIdentity, MlsError> { |
| 99 |
unimplemented!() |
| 100 |
} |
| 101 |
|
| 102 |
/// Group configuration. |
| 103 |
/// |
| 104 |
/// This is more or less only for Ciphersuites and GroupContext extensions |
| 105 |
/// V8 - Update group context extensions |
| 106 |
/// Discuss: do we want to pass the version number explicitly to avoid compat problems with future versions ? (likely yes) |
| 107 |
/// |
| 108 |
/// # Parameters |
| 109 |
/// - `external_sender`: Availibility of the external sender extension |
| 110 |
/// - Default: None (We don't expose that) |
| 111 |
/// - `required_capabilities`: Needed to specify extensions |
| 112 |
/// - Option: None (Expose the ability to provide a 3-tuple of Vec<u8>) |
| 113 |
/// |
| 114 |
/// Note, external_sender is an Extension but other config options might be different |
| 115 |
|
| 116 |
pub fn mls_create_group_config( |
| 117 |
cs: CipherSuite, |
| 118 |
v: ProtocolVersion, |
| 119 |
options: ExtensionList, |
| 120 |
) -> Result<GroupConfig, MlsError> { |
| 121 |
Ok(GroupConfig { |
| 122 |
ciphersuite: cs, |
| 123 |
version: v, |
| 124 |
options, |
| 125 |
}) |
| 126 |
} |
| 127 |
|
| 128 |
/// Client configuration. |
| 129 |
/// |
| 130 |
/// V8 - We could require the library to update the client configuration at runtime |
| 131 |
/// Options: |
| 132 |
/// - WireFormatPolicy |
| 133 |
/// - Default: None (We don't expose that) |
| 134 |
/// - padding_size |
| 135 |
/// - Default: to some to complete the block to 64 bytes (pick a good value) |
| 136 |
/// - max_past_epochs |
| 137 |
/// - This is for application messages (cross-epoch) |
| 138 |
/// - Option: set the default some small value |
| 139 |
/// - number_of_resumption_psks |
| 140 |
/// - Default: 0 (We don't expose that) |
| 141 |
/// - use_ratchet_tree_extension |
| 142 |
/// - Option: default to true |
| 143 |
/// - out_of_order_tolerance |
| 144 |
/// - This is within an epoch |
| 145 |
/// - Option: set the default to small number |
| 146 |
/// - maximum_forward_distance |
| 147 |
/// - Maximum generation forward within an epoch from the same sender |
| 148 |
/// - Default: set to something like 1000 (Signal uses 2000) |
| 149 |
/// - Lifetime |
| 150 |
/// - Lifetime of a keypackage |
| 151 |
/// - This is to indicate the amount of time before which an update needs to happen |
| 152 |
|
| 153 |
pub struct ClientConfig { |
| 154 |
// Add fields as needed |
| 155 |
} |
| 156 |
|
| 157 |
// Question: should clients have consistent values for ratchet_tree_exrtensions |
| 158 |
pub fn mls_create_client_config( |
| 159 |
max_past_epoch: Option<u32>, |
| 160 |
use_ratchet_tree_extension: bool, |
| 161 |
out_of_order_tolerance: Option<u32>, |
| 162 |
maximum_forward_distance: Option<u32>, |
| 163 |
) -> Result<ClientConfig, MlsError> { |
| 164 |
unimplemented!() |
| 165 |
} |
| 166 |
|
| 167 |
// pub fn mls_group_propose_update( |
| 168 |
// _pstate: &mut PlatformState, |
| 169 |
// _gid: GroupId, |
| 170 |
// _myself: &Identity, |
| 171 |
// _signature_key: Option<Vec<u8>>, |
| 172 |
// // Below is client config |
| 173 |
// _group_context_extensions: Option<ExtensionList>, |
| 174 |
// _leaf_node_extensions: Option<ExtensionList>, |
| 175 |
// _leaf_node_capabilities: Option<Capabilities>, |
| 176 |
// _lifetime: Option<u64>, |
| 177 |
// ) -> Result<MlsMessage, PlatformError> { |
| 178 |
// unimplemented!() |
| 179 |
// } |
| 180 |
|
| 181 |
/// |
| 182 |
/// TODO: Pending commit API |
| 183 |
/// |
| 184 |
|
| 185 |
// List pending |
| 186 |
// Apply pending |
| 187 |
// Discard pending |