| 1 |
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
// Copyright by contributors to this project. |
| 3 |
// SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 4 |
|
| 5 |
use crate::{error::IntoAnyError, extension::ExtensionList, group::GroupContext, time::MlsTime}; |
| 6 |
#[cfg(mls_build_async)] |
| 7 |
use alloc::boxed::Box; |
| 8 |
use alloc::vec::Vec; |
| 9 |
|
| 10 |
use super::{CredentialType, SigningIdentity}; |
| 11 |
|
| 12 |
#[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 13 |
#[cfg_attr(feature = "serde", derive(serde::Serialize,))] |
| 14 |
#[non_exhaustive] |
| 15 |
pub enum MemberValidationContext<'a> { |
| 16 |
ForCommit { |
| 17 |
current_context: &'a GroupContext, |
| 18 |
new_extensions: &'a ExtensionList, |
| 19 |
}, |
| 20 |
ForNewGroup { |
| 21 |
current_context: &'a GroupContext, |
| 22 |
}, |
| 23 |
None, |
| 24 |
} |
| 25 |
|
| 26 |
impl MemberValidationContext<'_> { |
| 27 |
pub fn new_extensions(&self) -> Option<&ExtensionList> { |
| 28 |
match self { |
| 29 |
Self::ForCommit { new_extensions, .. } => Some(*new_extensions), |
| 30 |
Self::ForNewGroup { current_context } => Some(¤t_context.extensions), |
| 31 |
Self::None => None, |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
/// Identity system that can be used to validate a |
| 37 |
/// [`SigningIdentity`](mls-rs-core::identity::SigningIdentity) |
| 38 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 39 |
#[cfg_attr(mls_build_async, maybe_async::must_be_async)] |
| 40 |
pub trait IdentityProvider: Send + Sync { |
| 41 |
/// Error type that this provider returns on internal failure. |
| 42 |
type Error: IntoAnyError; |
| 43 |
|
| 44 |
/// Determine if `signing_identity` is valid for a group member. |
| 45 |
/// |
| 46 |
/// A `timestamp` value can optionally be supplied to aid with validation |
| 47 |
/// of a [`Credential`](mls-rs-core::identity::Credential) that requires |
| 48 |
/// time based context. For example, X.509 certificates can become expired. |
| 49 |
async fn validate_member( |
| 50 |
&self, |
| 51 |
signing_identity: &SigningIdentity, |
| 52 |
timestamp: Option<MlsTime>, |
| 53 |
context: MemberValidationContext<'_>, |
| 54 |
) -> Result<(), Self::Error>; |
| 55 |
|
| 56 |
/// Determine if `signing_identity` is valid for an external sender in |
| 57 |
/// the ExternalSendersExtension stored in the group context. |
| 58 |
/// |
| 59 |
/// A `timestamp` value can optionally be supplied to aid with validation |
| 60 |
/// of a [`Credential`](mls-rs-core::identity::Credential) that requires |
| 61 |
/// time based context. For example, X.509 certificates can become expired. |
| 62 |
async fn validate_external_sender( |
| 63 |
&self, |
| 64 |
signing_identity: &SigningIdentity, |
| 65 |
timestamp: Option<MlsTime>, |
| 66 |
extensions: Option<&ExtensionList>, |
| 67 |
) -> Result<(), Self::Error>; |
| 68 |
|
| 69 |
/// A unique identifier for `signing_identity`. |
| 70 |
/// |
| 71 |
/// The MLS protocol requires that each member of a group has a unique |
| 72 |
/// set of identifiers according to the application. |
| 73 |
async fn identity( |
| 74 |
&self, |
| 75 |
signing_identity: &SigningIdentity, |
| 76 |
extensions: &ExtensionList, |
| 77 |
) -> Result<Vec<u8>, Self::Error>; |
| 78 |
|
| 79 |
/// Determines if `successor` can remove `predecessor` as part of an external commit. |
| 80 |
/// |
| 81 |
/// The MLS protocol allows for removal of an existing member when adding a |
| 82 |
/// new member via external commit. This function determines if a removal |
| 83 |
/// should be allowed by providing the target member to be removed as |
| 84 |
/// `predecessor` and the new member as `successor`. |
| 85 |
async fn valid_successor( |
| 86 |
&self, |
| 87 |
predecessor: &SigningIdentity, |
| 88 |
successor: &SigningIdentity, |
| 89 |
extensions: &ExtensionList, |
| 90 |
) -> Result<bool, Self::Error>; |
| 91 |
|
| 92 |
/// Credential types that are supported by this provider. |
| 93 |
fn supported_types(&self) -> Vec<CredentialType>; |
| 94 |
} |