Skip to content

Commit

Permalink
Remove OpenMlsProvider dependency of PublicGroup. (openmls#1642)
Browse files Browse the repository at this point in the history
* Remove OpenMlsProvider dependency of PublicGroup.

* Remove OpenMlsProvider from processing as well

Co-authored-by: Konrad Kohbrok <[email protected]>

* Fix error types

---------

Co-authored-by: Konrad Kohbrok <[email protected]>
  • Loading branch information
raphaelrobert and kkohbrok authored Aug 12, 2024
1 parent 5269b2c commit 7d3cb92
Show file tree
Hide file tree
Showing 29 changed files with 130 additions and 129 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1637](https://github.com/openmls/openmls/pull/1637): Remove `serde` from `MlsGroup`.
- [#1638](https://github.com/openmls/openmls/pull/1638): Remove `serde` from `PublicGroup`. `PublicGroup::load()` becomes public to load a group from the storage provider.
- [#1640](https://github.com/openmls/openmls/pull/1640): The storage provider function `treesync()` was renamed to `tree()` so that it is consistent with other treesync functions.
- [#1642](https://github.com/openmls/openmls/pull/1642): `OpenMlsProvider` is no longer required for the `PublicGroup` API. The `PublicGroup` API now uses the `PublicStorageProvider` trait directly. `ProcessMessageError::InvalidSignature` was removed and replaced with `ValidationError::InvalidSignature`.

### Fixed

Expand Down
22 changes: 7 additions & 15 deletions openmls/src/framing/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ use crate::{
core_group::{proposals::QueuedProposal, staged_commit::StagedCommit},
errors::ValidationError,
},
storage::OpenMlsProvider,
tree::sender_ratchet::SenderRatchetConfiguration,
treesync::TreeSync,
versions::ProtocolVersion,
};

use self::mls_group::errors::ProcessMessageError;

use super::{
mls_auth_content::AuthenticatedContent,
mls_auth_content_in::{AuthenticatedContentIn, VerifiableAuthenticatedContentIn},
Expand Down Expand Up @@ -271,23 +268,18 @@ impl UnverifiedMessage {

/// Verify the [`UnverifiedMessage`]. Returns the [`AuthenticatedContent`]
/// and the internal [`Credential`].
pub(crate) fn verify<Provider: OpenMlsProvider>(
pub(crate) fn verify(
self,
ciphersuite: Ciphersuite,
provider: &Provider,
crypto: &impl OpenMlsCrypto,
protocol_version: ProtocolVersion,
) -> Result<(AuthenticatedContent, Credential), ProcessMessageError<Provider::StorageError>>
{
) -> Result<(AuthenticatedContent, Credential), ValidationError> {
let content: AuthenticatedContentIn = self
.verifiable_content
.verify(provider.crypto(), &self.sender_pk)
.map_err(|_| ProcessMessageError::InvalidSignature)?;
let content = content.validate(
ciphersuite,
provider.crypto(),
self.sender_context,
protocol_version,
)?;
.verify(crypto, &self.sender_pk)
.map_err(|_| ValidationError::InvalidSignature)?;
let content =
content.validate(ciphersuite, crypto, self.sender_context, protocol_version)?;
Ok((content, self.credential))
}

Expand Down
3 changes: 2 additions & 1 deletion openmls/src/group/core_group/new_from_external_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ impl CoreGroup {
};

let (public_group, group_info) = PublicGroup::from_external(
provider,
provider.crypto(),
provider.storage(),
ratchet_tree,
verifiable_group_info,
// Existing proposals are discarded when joining by external commit.
Expand Down
3 changes: 2 additions & 1 deletion openmls/src/group/core_group/new_from_welcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ pub(in crate::group) fn build_staged_welcome<Provider: OpenMlsProvider>(
// Since there is currently only the external pub extension, there is no
// group info extension of interest here.
let (public_group, _group_info_extensions) = PublicGroup::from_external(
provider,
provider.crypto(),
provider.storage(),
ratchet_tree,
verifiable_group_info.clone(),
ProposalStore::new(),
Expand Down
6 changes: 3 additions & 3 deletions openmls/src/group/core_group/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ impl CoreGroup {
unverified_message: UnverifiedMessage,
old_epoch_keypairs: Vec<EncryptionKeyPair>,
leaf_node_keypairs: Vec<EncryptionKeyPair>,
) -> Result<ProcessedMessage, ProcessMessageError<Provider::StorageError>> {
) -> Result<ProcessedMessage, ProcessMessageError> {
// Checks the following semantic validation:
// - ValSem010
// - ValSem246 (as part of ValSem010)
let (content, credential) =
unverified_message.verify(self.ciphersuite(), provider, self.version())?;
unverified_message.verify(self.ciphersuite(), provider.crypto(), self.version())?;

match content.sender() {
Sender::Member(_) | Sender::NewMemberCommit | Sender::NewMemberProposal => {
Expand Down Expand Up @@ -173,7 +173,7 @@ impl CoreGroup {
message: impl Into<ProtocolMessage>,
sender_ratchet_configuration: &SenderRatchetConfiguration,
own_leaf_nodes: &[LeafNode],
) -> Result<ProcessedMessage, ProcessMessageError<Provider::StorageError>> {
) -> Result<ProcessedMessage, ProcessMessageError> {
let message: ProtocolMessage = message.into();

// Checks the following semantic validation:
Expand Down
2 changes: 1 addition & 1 deletion openmls/src/group/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ pub enum CreateGroupContextExtProposalError<StorageError> {
LeafNodeValidation(#[from] LeafNodeValidationError),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
MlsGroupStateError(#[from] MlsGroupStateError<StorageError>),
MlsGroupStateError(#[from] MlsGroupStateError),
/// See [`CreateCommitError`] for more details.
#[error(transparent)]
CreateCommitError(#[from] CreateCommitError<StorageError>),
Expand Down
2 changes: 1 addition & 1 deletion openmls/src/group/mls_group/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl MlsGroup {
provider: &Provider,
signer: &impl Signer,
message: &[u8],
) -> Result<MlsMessageOut, CreateMessageError<Provider::StorageError>> {
) -> Result<MlsMessageOut, CreateMessageError> {
if !self.is_active() {
return Err(CreateMessageError::GroupStateError(
MlsGroupStateError::UseAfterEviction,
Expand Down
64 changes: 36 additions & 28 deletions openmls/src/group/mls_group/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum EmptyInputError {

/// Group state error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum MlsGroupStateError<StorageError> {
pub enum MlsGroupStateError {
/// See [`LibraryError`] for more details.
#[error(transparent)]
LibraryError(#[from] LibraryError),
Expand All @@ -79,25 +79,22 @@ pub enum MlsGroupStateError<StorageError> {
/// Requested pending proposal hasn't been found in local pending proposals
#[error("Requested pending proposal hasn't been found in local pending proposals.")]
PendingProposalNotFound,
/// An error ocurred while writing to storage
#[error("An error ocurred while writing to storage")]
StorageError(StorageError),
}

/// Error merging pending commit
#[derive(Error, Debug, PartialEq, Clone)]
pub enum MergePendingCommitError<StorageError> {
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
MlsGroupStateError(#[from] MlsGroupStateError<StorageError>),
MlsGroupStateError(#[from] MlsGroupStateError),
/// See [`MergeCommitError`] for more details.
#[error(transparent)]
MergeCommitError(#[from] MergeCommitError<StorageError>),
}

/// Process message error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProcessMessageError<StorageError> {
pub enum ProcessMessageError {
/// See [`LibraryError`] for more details.
#[error(transparent)]
LibraryError(#[from] LibraryError),
Expand All @@ -109,10 +106,7 @@ pub enum ProcessMessageError<StorageError> {
ValidationError(#[from] ValidationError),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
/// The message's signature is invalid.
#[error("The message's signature is invalid.")]
InvalidSignature,
GroupStateError(#[from] MlsGroupStateError),
/// See [`StageCommitError`] for more details.
#[error(transparent)]
InvalidCommit(#[from] StageCommitError),
Expand All @@ -126,13 +120,13 @@ pub enum ProcessMessageError<StorageError> {

/// Create message error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CreateMessageError<StorageError> {
pub enum CreateMessageError {
/// See [`LibraryError`] for more details.
#[error(transparent)]
LibraryError(#[from] LibraryError),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
}

/// Add members error
Expand All @@ -149,7 +143,7 @@ pub enum AddMembersError<StorageError> {
CreateCommitError(#[from] CreateCommitError<StorageError>),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// Error writing to storage.
#[error("Error writing to storage")]
StorageError(StorageError),
Expand All @@ -166,7 +160,7 @@ pub enum ProposeAddMemberError<StorageError> {
UnsupportedExtensions,
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// See [`LeafNodeValidationError`] for more details.
#[error(transparent)]
LeafNodeValidation(#[from] LeafNodeValidationError),
Expand All @@ -183,7 +177,7 @@ pub enum ProposeRemoveMemberError<StorageError> {
LibraryError(#[from] LibraryError),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// The member that should be removed can not be found.
#[error("The member that should be removed can not be found.")]
UnknownMember,
Expand All @@ -206,7 +200,7 @@ pub enum RemoveMembersError<StorageError> {
CreateCommitError(#[from] CreateCommitError<StorageError>),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// The member that should be removed can not be found.
#[error("The member that should be removed can not be found.")]
UnknownMember,
Expand All @@ -223,7 +217,10 @@ pub enum LeaveGroupError<StorageError> {
LibraryError(#[from] LibraryError),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// An error ocurred while writing to storage
#[error("An error ocurred while writing to storage")]
StorageError(StorageError),
}

/// Self update error
Expand All @@ -237,7 +234,7 @@ pub enum SelfUpdateError<StorageError> {
CreateCommitError(#[from] CreateCommitError<StorageError>),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// Error accessing the storage.
#[error("Error accessing the storage.")]
StorageError(StorageError),
Expand All @@ -252,7 +249,7 @@ pub enum ProposeSelfUpdateError<StorageError> {

/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// Error accessing storage.
#[error("Error accessing storage.")]
StorageError(StorageError),
Expand All @@ -275,26 +272,26 @@ pub enum CommitToPendingProposalsError<StorageError> {
CreateCommitError(#[from] CreateCommitError<StorageError>),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// Error writing to storage
#[error("Error writing to storage: {0}")]
StorageError(StorageError),
}

/// Errors that can happen when exporting a group info object.
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ExportGroupInfoError<StorageError> {
pub enum ExportGroupInfoError {
/// See [`LibraryError`] for more details.
#[error(transparent)]
LibraryError(#[from] LibraryError),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
}

/// Export secret error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ExportSecretError<StorageError> {
pub enum ExportSecretError {
/// See [`LibraryError`] for more details.
#[error(transparent)]
LibraryError(#[from] LibraryError),
Expand All @@ -303,24 +300,24 @@ pub enum ExportSecretError<StorageError> {
KeyLengthTooLong,
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
}

/// Propose PSK error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposePskError<StorageError> {
pub enum ProposePskError {
/// See [`PskError`] for more details.
#[error(transparent)]
Psk(#[from] PskError),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// See [`LibraryError`] for more details.
#[error(transparent)]
LibraryError(#[from] LibraryError),
}

/// Export secret error
/// Proposal error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposalError<StorageError> {
/// See [`LibraryError`] for more details.
Expand All @@ -340,7 +337,7 @@ pub enum ProposalError<StorageError> {
ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError<StorageError>),
GroupStateError(#[from] MlsGroupStateError),
/// See [`ValidationError`] for more details.
#[error(transparent)]
ValidationError(#[from] ValidationError),
Expand All @@ -351,3 +348,14 @@ pub enum ProposalError<StorageError> {
#[error("error writing proposal to storage")]
StorageError(StorageError),
}

/// Remove proposal error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum RemoveProposalError<StorageError> {
/// Couldn't find the proposal for the given `ProposalRef`.
#[error("Couldn't find the proposal for the given `ProposalRef`")]
ProposalNotFound,
/// Error erasing proposal from storage.
#[error("error writing proposal to storage")]
Storage(StorageError),
}
4 changes: 2 additions & 2 deletions openmls/src/group/mls_group/exporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl MlsGroup {
label: &str,
context: &[u8],
key_length: usize,
) -> Result<Vec<u8>, ExportSecretError<Provider::StorageError>> {
) -> Result<Vec<u8>, ExportSecretError> {
let crypto = provider.crypto();

if self.is_active() {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl MlsGroup {
provider: &Provider,
signer: &impl Signer,
with_ratchet_tree: bool,
) -> Result<MlsMessageOut, ExportGroupInfoError<Provider::StorageError>> {
) -> Result<MlsMessageOut, ExportGroupInfoError> {
Ok(self
.group
.export_group_info(provider.crypto(), signer, with_ratchet_tree)?
Expand Down
2 changes: 1 addition & 1 deletion openmls/src/group/mls_group/membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl MlsGroup {
&queued_remove_proposal.proposal_reference(),
&queued_remove_proposal,
)
.map_err(MlsGroupStateError::StorageError)?;
.map_err(LeaveGroupError::StorageError)?;

self.proposal_store_mut().add(queued_remove_proposal);

Expand Down
6 changes: 2 additions & 4 deletions openmls/src/group/mls_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ impl MlsGroup {

/// Returns own credential. If the group is inactive, it returns a
/// `UseAfterEviction` error.
pub fn credential<Provider: OpenMlsProvider>(
&self,
) -> Result<&Credential, MlsGroupStateError<Provider::StorageError>> {
pub fn credential(&self) -> Result<&Credential, MlsGroupStateError> {
if !self.is_active() {
return Err(MlsGroupStateError::UseAfterEviction);
}
Expand Down Expand Up @@ -439,7 +437,7 @@ impl MlsGroup {

/// Check if the group is operational. Throws an error if the group is
/// inactive or if there is a pending commit.
fn is_operational<StorageError>(&self) -> Result<(), MlsGroupStateError<StorageError>> {
fn is_operational(&self) -> Result<(), MlsGroupStateError> {
match self.group_state {
MlsGroupState::PendingCommit(_) => Err(MlsGroupStateError::PendingCommit),
MlsGroupState::Inactive => Err(MlsGroupStateError::UseAfterEviction),
Expand Down
2 changes: 1 addition & 1 deletion openmls/src/group/mls_group/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl MlsGroup {
&mut self,
provider: &Provider,
message: impl Into<ProtocolMessage>,
) -> Result<ProcessedMessage, ProcessMessageError<Provider::StorageError>> {
) -> Result<ProcessedMessage, ProcessMessageError> {
// Make sure we are still a member of the group
if !self.is_active() {
return Err(ProcessMessageError::GroupStateError(
Expand Down
Loading

0 comments on commit 7d3cb92

Please sign in to comment.