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