1use thiserror::Error;
6
7pub use super::mls_group::errors::*;
8use super::public_group::errors::CreationFromExternalError;
9use crate::{
10 ciphersuite::signable::SignatureError,
11 error::LibraryError,
12 extensions::errors::{ExtensionError, InvalidExtensionError},
13 framing::errors::MessageDecryptionError,
14 key_packages::errors::{KeyPackageExtensionSupportError, KeyPackageVerifyError},
15 messages::{group_info::GroupInfoError, GroupSecretsError},
16 schedule::errors::PskError,
17 treesync::errors::*,
18};
19
20#[cfg(doc)]
21use crate::treesync::LeafNodeParameters;
22
23#[derive(Error, Debug, PartialEq, Clone)]
25pub enum WelcomeError<StorageError> {
26 #[error(transparent)]
28 GroupSecrets(#[from] GroupSecretsError),
29 #[error("Private part of `init_key` not found in key store.")]
31 PrivateInitKeyNotFound,
32 #[error(transparent)]
34 LibraryError(#[from] LibraryError),
35 #[error("Ciphersuites in Welcome and key package bundle don't match.")]
37 CiphersuiteMismatch,
38 #[error(transparent)]
40 GroupInfo(#[from] GroupInfoError),
41 #[error("No joiner secret found in the Welcome message.")]
43 JoinerSecretNotFound,
44 #[error("No ratchet tree available to build initial tree after receiving a Welcome message.")]
46 MissingRatchetTree,
47 #[error("The computed confirmation tag does not match the expected one.")]
49 ConfirmationTagMismatch,
50 #[error("The signature on the GroupInfo is not valid.")]
52 InvalidGroupInfoSignature,
53 #[error("We don't support the version of the group we are trying to join.")]
55 UnsupportedMlsVersion,
56 #[error("We don't support all capabilities of the group.")]
58 UnsupportedCapability,
59 #[error("Sender not found in tree.")]
61 UnknownSender,
62 #[error("Not a Welcome message.")]
64 NotAWelcomeMessage,
65 #[error("Malformed Welcome message.")]
67 MalformedWelcomeMessage,
68 #[error("Could not decrypt the Welcome message.")]
70 UnableToDecrypt,
71 #[error("Unsupported extensions found in the KeyPackage of another member.")]
73 UnsupportedExtensions,
74 #[error(transparent)]
76 Psk(#[from] PskError),
77 #[error("No matching encryption key was found in the key store.")]
79 NoMatchingEncryptionKey,
80 #[error("No matching key package was found in the key store.")]
82 NoMatchingKeyPackage,
83 #[error(transparent)]
85 PublicTreeError(#[from] PublicTreeError),
86 #[error(transparent)]
89 PublicGroupError(#[from] CreationFromExternalError<StorageError>),
90 #[error(transparent)]
92 LeafNodeValidation(#[from] LeafNodeValidationError),
93 #[error("An error occurred when querying storage")]
95 StorageError(StorageError),
96}
97
98#[derive(Error, Debug, PartialEq, Clone)]
100pub enum ExternalCommitError<StorageError> {
101 #[error(transparent)]
103 LibraryError(#[from] LibraryError),
104 #[error("No ratchet tree available to build initial tree.")]
106 MissingRatchetTree,
107 #[error("No external_pub extension available to join group by external commit.")]
109 MissingExternalPub,
110 #[error("We don't support the ciphersuite of the group we are trying to join.")]
112 UnsupportedCiphersuite,
113 #[error("Sender not found in tree.")]
115 UnknownSender,
116 #[error("The signature over the given group info is invalid.")]
118 InvalidGroupInfoSignature,
119 #[error("Error creating external commit.")]
121 CommitError,
122 #[error(transparent)]
125 PublicGroupError(#[from] CreationFromExternalError<StorageError>),
126 #[error("Credential is missing from external commit.")]
128 MissingCredential,
129 #[error("An error occurred when writing group to storage.")]
131 StorageError(StorageError),
132}
133
134#[derive(Error, Debug, PartialEq, Clone)]
136pub enum StageCommitError {
137 #[error(transparent)]
139 LibraryError(#[from] LibraryError),
140 #[error("The epoch of the group context and PublicMessage didn't match.")]
142 EpochMismatch,
143 #[error("The Commit was created by this client.")]
145 OwnCommit,
146 #[error("stage_commit was called with an PublicMessage that is not a Commit.")]
148 WrongPlaintextContentType,
149 #[error("Unable to verify the leaf node signature.")]
151 PathLeafNodeVerificationFailure,
152 #[error("Unable to determine commit path.")]
154 RequiredPathNotFound,
155 #[error("The confirmation Tag is missing.")]
157 ConfirmationTagMissing,
158 #[error("The confirmation tag is invalid.")]
160 ConfirmationTagMismatch,
161 #[error("The committer can't remove themselves.")]
163 AttemptedSelfRemoval,
164 #[error("The proposal queue is missing a proposal for the commit.")]
166 MissingProposal,
167 #[error("Missing own key to apply proposal.")]
169 OwnKeyNotFound,
170 #[error("External Committer used the wrong index.")]
172 InconsistentSenderIndex,
173 #[error("The sender is of type external, which is not valid.")]
175 SenderTypeExternal,
176 #[error("The sender is of type NewMemberProposal, which is not valid.")]
178 SenderTypeNewMemberProposal,
179 #[error("Too many new members: the tree is full.")]
181 TooManyNewMembers,
182 #[error(transparent)]
184 ProposalValidationError(#[from] ProposalValidationError),
185 #[error(transparent)]
187 PskError(#[from] PskError),
188 #[error(transparent)]
190 ExternalCommitValidation(#[from] ExternalCommitValidationError),
191 #[error(transparent)]
193 UpdatePathError(#[from] ApplyUpdatePathError),
194 #[error("Missing decryption key.")]
196 MissingDecryptionKey,
197 #[error(transparent)]
199 VerifiedUpdatePathError(#[from] UpdatePathError),
200 #[error(transparent)]
202 GroupContextExtensionsProposalValidationError(
203 #[from] GroupContextExtensionsProposalValidationError,
204 ),
205 #[error(transparent)]
207 LeafNodeValidation(#[from] LeafNodeValidationError),
208}
209
210#[derive(Error, Debug, PartialEq, Clone)]
212pub enum CreateCommitError {
213 #[error(transparent)]
215 LibraryError(#[from] LibraryError),
216 #[error("Missing own key to apply proposal.")]
218 OwnKeyNotFound,
219 #[error("The Commit tried to remove self from the group. This is not possible.")]
221 CannotRemoveSelf,
222 #[error("The proposal queue is missing a proposal for the commit.")]
224 MissingProposal,
225 #[error("A proposal has the wrong sender type.")]
227 WrongProposalSenderType,
228 #[error(transparent)]
230 PskError(#[from] PskError),
231 #[error(transparent)]
233 ProposalValidationError(#[from] ProposalValidationError),
234 #[error(transparent)]
236 SignatureError(#[from] SignatureError),
237 #[error("Credential is missing from external commit.")]
239 MissingCredential,
240 #[error(transparent)]
242 PublicTreeError(#[from] PublicTreeError),
243 #[error(transparent)]
245 InvalidExtensionError(#[from] InvalidExtensionError),
246 #[error(transparent)]
248 GroupContextExtensionsProposalValidationError(
249 #[from] GroupContextExtensionsProposalValidationError,
250 ),
251 #[error(transparent)]
253 TreeSyncAddLeaf(#[from] TreeSyncAddLeaf),
254 #[error("Invalid LeafNodeParameters. CredentialWithKey can't be set with new signer.")]
256 InvalidLeafNodeParameters,
257}
258
259#[derive(Error, Debug, PartialEq, Clone)]
261pub enum CommitBuilderStageError<StorageError> {
262 #[error(transparent)]
264 LibraryError(#[from] LibraryError),
265 #[error("Error interacting with storage.")]
267 KeyStoreError(StorageError),
268}
269
270#[derive(Error, Debug, PartialEq, Clone)]
272pub enum ValidationError {
273 #[error(transparent)]
275 LibraryError(#[from] LibraryError),
276 #[error("Message group ID differs from the group's group ID.")]
278 WrongGroupId,
279 #[error("Message epoch differs from the group's epoch.")]
281 WrongEpoch,
282 #[error("The PublicMessage is not a Commit despite the sender begin of type NewMemberCommit.")]
284 NotACommit,
285 #[error("The PublicMessage is not an external Add proposal despite the sender begin of type NewMemberProposal.")]
287 NotAnExternalAddProposal,
288 #[error("The Commit doesn't have a path despite the sender being of type NewMemberCommit.")]
290 NoPath,
291 #[error("The PublicMessage contains an application message but was not encrypted.")]
293 UnencryptedApplicationMessage,
294 #[error("Sender is not part of the group.")]
296 UnknownMember,
297 #[error("Membership tag is missing.")]
299 MissingMembershipTag,
300 #[error("Membership tag is invalid.")]
302 InvalidMembershipTag,
303 #[error("The confirmation tag is missing.")]
305 MissingConfirmationTag,
306 #[error("Wrong wire format.")]
308 WrongWireFormat,
309 #[error("Verifying the signature failed.")]
311 InvalidSignature,
312 #[error("An application message was sent from an external sender.")]
314 NonMemberApplicationMessage,
315 #[error(transparent)]
317 UnableToDecrypt(#[from] MessageDecryptionError),
318 #[error("The message is from an epoch too far in the past.")]
320 NoPastEpochData,
321 #[error("The provided external sender is not authorized to send external proposals")]
323 UnauthorizedExternalSender,
324 #[error("The group doesn't contain external senders extension")]
326 NoExternalSendersExtension,
327 #[error(transparent)]
329 KeyPackageVerifyError(#[from] KeyPackageVerifyError),
330 #[error(transparent)]
332 UpdatePathError(#[from] UpdatePathError),
333 #[error("Invalid LeafNode signature.")]
335 InvalidLeafNodeSignature,
336 #[error("Invalid LeafNode source type")]
338 InvalidLeafNodeSourceType,
339 #[error("Invalid sender type")]
341 InvalidSenderType,
342 #[error("The Commit includes update proposals from the committer.")]
344 CommitterIncludedOwnUpdate,
345 #[error(
347 "The ciphersuite in the KeyPackage of the Add proposal does not match the group context."
348 )]
349 InvalidAddProposalCiphersuite,
350 #[error("Cannot decrypt own messages.")]
352 CannotDecryptOwnMessage,
353 #[error(transparent)]
355 ExternalCommitValidation(#[from] ExternalCommitValidationError),
356}
357
358#[derive(Error, Debug, PartialEq, Clone)]
360pub enum ProposalValidationError {
361 #[error(transparent)]
363 LibraryError(#[from] LibraryError),
364 #[error("The sender could not be matched to a member of the group.")]
366 UnknownMember,
367 #[error("Duplicate signature key in proposals and group.")]
369 DuplicateSignatureKey,
370 #[error("Duplicate encryption key in proposals and group.")]
372 DuplicateEncryptionKey,
373 #[error("Duplicate init key in proposals.")]
375 DuplicateInitKey,
376 #[error("The HPKE init and encryption keys are the same.")]
378 InitEncryptionKeyCollision,
379 #[error("Duplicate remove proposals for the same member.")]
381 DuplicateMemberRemoval,
382 #[error("The remove proposal referenced a non-existing member.")]
384 UnknownMemberRemoval,
385 #[error("Found an update from a non-member.")]
387 UpdateFromNonMember,
388 #[error("The Commit includes update proposals from the committer.")]
390 CommitterIncludedOwnUpdate,
391 #[error("The capabilities of the add proposal are insufficient for this group.")]
393 InsufficientCapabilities,
394 #[error(
396 "The add proposal's ciphersuite or protocol version do not match the ones in the group context."
397 )]
398 InvalidAddProposalCiphersuiteOrVersion,
399 #[error(transparent)]
401 Psk(#[from] PskError),
402 #[error("The proposal type is not supported by all group members.")]
404 UnsupportedProposalType,
405 #[error(transparent)]
407 LeafNodeValidation(#[from] LeafNodeValidationError),
408 #[error("Found ExternalInit proposal in regular commit")]
410 ExternalInitProposalInRegularCommit,
411}
412
413#[derive(Error, Debug, PartialEq, Clone)]
415pub enum ExternalCommitValidationError {
416 #[error(transparent)]
418 LibraryError(#[from] LibraryError),
419 #[error("No ExternalInit proposal found.")]
421 NoExternalInitProposals,
422 #[error("Multiple ExternalInit proposal found.")]
424 MultipleExternalInitProposals,
425 #[error("Found inline Add or Update proposals.")]
427 InvalidInlineProposals,
428 #[error("Found multiple inline Remove proposals.")]
430 MultipleRemoveProposals,
431 #[error("Remove proposal targets the wrong group member.")]
433 InvalidRemoveProposal,
434 #[error("External Commit has to contain a path.")]
436 NoPath,
437 #[error("Found a referenced proposal in an External Commit.")]
439 ReferencedProposal,
440}
441
442#[derive(Error, Debug, PartialEq, Clone)]
444pub enum CreateAddProposalError {
445 #[error(transparent)]
447 LibraryError(#[from] LibraryError),
448 #[error(transparent)]
450 LeafNodeValidation(#[from] LeafNodeValidationError),
451}
452
453#[derive(Error, Debug, PartialEq, Clone)]
457pub(crate) enum ProposalQueueError {
458 #[error(transparent)]
460 LibraryError(#[from] LibraryError),
461 #[error("Not all proposals in the Commit were found locally.")]
463 ProposalNotFound,
464 #[error("Update proposal from external sender.")]
466 UpdateFromExternalSender,
467 #[error("SelfRemove proposal from a non-Member.")]
469 SelfRemoveFromNonMember,
470}
471
472#[derive(Error, Debug, PartialEq, Clone)]
475pub(crate) enum FromCommittedProposalsError {
476 #[error(transparent)]
478 LibraryError(#[from] LibraryError),
479 #[error("Not all proposals in the Commit were found locally.")]
481 ProposalNotFound,
482 #[error("The sender of a Commit tried to remove themselves.")]
484 SelfRemoval,
485}
486
487#[derive(Error, Debug, PartialEq, Clone)]
489pub enum CreateGroupContextExtProposalError<StorageError> {
490 #[error(transparent)]
492 LibraryError(#[from] LibraryError),
493 #[error(transparent)]
495 KeyPackageExtensionSupport(#[from] KeyPackageExtensionSupportError),
496 #[error(transparent)]
498 Extension(#[from] ExtensionError),
499 #[error(transparent)]
501 LeafNodeValidation(#[from] LeafNodeValidationError),
502 #[error(transparent)]
504 MlsGroupStateError(#[from] MlsGroupStateError),
505 #[error(transparent)]
507 CreateCommitError(#[from] CreateCommitError),
508 #[error(transparent)]
510 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
511 #[error("Error writing updated group data to storage.")]
513 StorageError(StorageError),
514}
515
516#[derive(Error, Debug, PartialEq, Clone)]
518pub enum MergeCommitError<StorageError> {
519 #[error(transparent)]
521 LibraryError(#[from] LibraryError),
522 #[error("Error writing updated group data to storage.")]
524 StorageError(StorageError),
525}
526
527#[derive(Error, Debug, PartialEq, Clone)]
529pub enum GroupContextExtensionsProposalValidationError {
530 #[error("Commit has more than one GroupContextExtensions proposal.")]
532 TooManyGCEProposals,
533
534 #[error(transparent)]
536 LibraryError(#[from] LibraryError),
537
538 #[error(
540 "The new required capabilties contain extension types that are not supported by all group members."
541 )]
542 ExtensionNotSupportedByAllMembers,
543 #[error("Proposal changes the immutable metadata extension, which is not allowed.")]
545 ChangedImmutableMetadata,
546
547 #[error(
549 "The new required capabilties contain extension types that are not supported by all group members."
550 )]
551 RequiredExtensionNotSupportedByAllMembers,
552
553 #[error(
556 "An extension in the group context extensions is not listed in the required capabilties' extension types."
557 )]
558 ExtensionNotInRequiredCapabilities,
559}