Skip to content

Commit

Permalink
Improved error type for unexpected sender client on creation for
Browse files Browse the repository at this point in the history
Self/GTC
  • Loading branch information
elland committed Nov 28, 2022
1 parent 15eb936 commit 81fb3f8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 56 deletions.
3 changes: 3 additions & 0 deletions libs/wire-api/src/Wire/API/Error/Galley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ data GalleyError
| MLSWelcomeMismatch
| MLSMissingGroupInfo
| MLSMissingSenderClient
| MLSUnexpectedSenderClient
| --
NoBindingTeamMembers
| NoBindingTeam
Expand Down Expand Up @@ -203,6 +204,8 @@ type instance MapError 'MLSGroupConversationMismatch = 'StaticError 400 "mls-gro

type instance MapError 'MLSClientSenderUserMismatch = 'StaticError 400 "mls-client-sender-user-mismatch" "User ID resolved from Client ID does not match message's sender user ID"

type instance MapError 'MLSUnexpectedSenderClient = 'StaticError 422 "mls-unexpected-sender-client-found" "Unexpected creator client set. This is a newly created conversation and it expected exactly one client."

type instance MapError 'MLSWelcomeMismatch = 'StaticError 400 "mls-welcome-mismatch" "The list of targets of a welcome message does not match the list of new clients in a group"

type instance MapError 'MLSMissingGroupInfo = 'StaticError 404 "mls-missing-group-info" "The conversation has no group information"
Expand Down
3 changes: 3 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Public/Galley/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type MLSMessagingAPI =
:> CanThrow 'MLSStaleMessage
:> CanThrow 'MLSUnsupportedMessage
:> CanThrow 'MLSUnsupportedProposal
:> CanThrow 'MLSUnexpectedSenderClient
:> CanThrow 'MLSClientSenderUserMismatch
:> CanThrow 'MLSGroupConversationMismatch
:> CanThrow 'MLSMissingSenderClient
Expand Down Expand Up @@ -88,6 +89,7 @@ type MLSMessagingAPI =
:> CanThrow 'MLSStaleMessage
:> CanThrow 'MLSUnsupportedMessage
:> CanThrow 'MLSUnsupportedProposal
:> CanThrow 'MLSUnexpectedSenderClient
:> CanThrow 'MLSClientSenderUserMismatch
:> CanThrow 'MLSGroupConversationMismatch
:> CanThrow 'MLSMissingSenderClient
Expand Down Expand Up @@ -116,6 +118,7 @@ type MLSMessagingAPI =
:> CanThrow 'MLSStaleMessage
:> CanThrow 'MLSUnsupportedMessage
:> CanThrow 'MLSUnsupportedProposal
:> CanThrow 'MLSUnexpectedSenderClient
:> CanThrow 'MLSClientSenderUserMismatch
:> CanThrow 'MLSGroupConversationMismatch
:> CanThrow 'MLSMissingSenderClient
Expand Down
127 changes: 71 additions & 56 deletions services/galley/src/Galley/API/MLS/Message.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type MLSMessageStaticErrors =
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSGroupConversationMismatch,
ErrorS 'MLSMissingSenderClient
]
Expand All @@ -122,15 +123,16 @@ postMLSMessageFromLocalUserV1 ::
ErrorS 'ConvAccessDenied,
ErrorS 'ConvMemberNotFound,
ErrorS 'ConvNotFound,
ErrorS 'MissingLegalholdConsent,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSGroupConversationMismatch,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSUnsupportedMessage,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
Resource,
Expand All @@ -157,15 +159,16 @@ postMLSMessageFromLocalUser ::
ErrorS 'ConvAccessDenied,
ErrorS 'ConvMemberNotFound,
ErrorS 'ConvNotFound,
ErrorS 'MissingLegalholdConsent,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSGroupConversationMismatch,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSUnsupportedMessage,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
Resource,
Expand Down Expand Up @@ -367,15 +370,16 @@ postMLSMessage ::
ErrorS 'ConvAccessDenied,
ErrorS 'ConvMemberNotFound,
ErrorS 'ConvNotFound,
ErrorS 'MissingLegalholdConsent,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSGroupConversationMismatch,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSUnsupportedMessage,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
Resource,
Expand Down Expand Up @@ -455,14 +459,15 @@ postMLSMessageToLocalConv ::
'[ Error FederationError,
Error InternalError,
ErrorS 'ConvNotFound,
ErrorS 'MissingLegalholdConsent,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSUnsupportedMessage,
ErrorS 'MissingLegalholdConsent,
ProposalStore,
Resource,
TinyLog
Expand Down Expand Up @@ -539,26 +544,29 @@ postMLSMessageToRemoteConv loc qusr _senderClient con smsg rcnv = do
pure (LocalConversationUpdate e update)

type HasProposalEffects r =
( Member BrigAccess r,
Member ConversationStore r,
Member (Error InternalError) r,
Member (Error MLSProposalFailure) r,
Member (Error MLSProtocolError) r,
Member (ErrorS 'MLSClientMismatch) r,
Member (ErrorS 'MLSKeyPackageRefNotFound) r,
Member (ErrorS 'MLSUnsupportedProposal) r,
Member ExternalAccess r,
Member FederatorAccess r,
Member GundeckAccess r,
Member (Input Env) r,
Member (Input (Local ())) r,
Member (Input Opts) r,
Member (Input UTCTime) r,
Member LegalHoldStore r,
Member MemberStore r,
Member ProposalStore r,
Member TeamStore r,
Member TinyLog r
( Members
'[ BrigAccess,
ConversationStore,
Error InternalError,
Error MLSProposalFailure,
Error MLSProtocolError,
ErrorS 'MLSClientMismatch,
ErrorS 'MLSKeyPackageRefNotFound,
ErrorS 'MLSUnsupportedProposal,
ExternalAccess,
FederatorAccess,
GundeckAccess,
Input Env,
Input (Local ()),
Input Opts,
Input UTCTime,
LegalHoldStore,
MemberStore,
ProposalStore,
TeamStore,
TinyLog
]
r
)

data ProposalAction = ProposalAction
Expand Down Expand Up @@ -616,20 +624,24 @@ getCommitData lconv mlsMeta epoch commit = do

processCommit ::
( HasProposalEffects r,
Member (Error FederationError) r,
Member (Error InternalError) r,
Member (ErrorS 'ConvNotFound) r,
Member (ErrorS 'MLSClientSenderUserMismatch) r,
Member (ErrorS 'MLSCommitMissingReferences) r,
Member (ErrorS 'MLSMissingSenderClient) r,
Member (ErrorS 'MLSProposalNotFound) r,
Member (ErrorS 'MLSSelfRemovalNotAllowed) r,
Member (ErrorS 'MLSStaleMessage) r,
Member (ErrorS 'MissingLegalholdConsent) r,
Member (Input (Local ())) r,
Member ProposalStore r,
Member BrigAccess r,
Member Resource r
Members
'[ Error FederationError,
Error InternalError,
ErrorS 'ConvNotFound,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
BrigAccess,
Resource
]
r
) =>
Qualified UserId ->
Maybe ClientId ->
Expand Down Expand Up @@ -758,20 +770,24 @@ processExternalCommit qusr mSenderClient lconv mlsMeta cm epoch action updatePat
processCommitWithAction ::
forall r.
( HasProposalEffects r,
Member (Error FederationError) r,
Member (Error InternalError) r,
Member (ErrorS 'ConvNotFound) r,
Member (ErrorS 'MLSClientSenderUserMismatch) r,
Member (ErrorS 'MLSCommitMissingReferences) r,
Member (ErrorS 'MLSMissingSenderClient) r,
Member (ErrorS 'MLSProposalNotFound) r,
Member (ErrorS 'MLSSelfRemovalNotAllowed) r,
Member (ErrorS 'MLSStaleMessage) r,
Member (ErrorS 'MissingLegalholdConsent) r,
Member (Input (Local ())) r,
Member ProposalStore r,
Member BrigAccess r,
Member Resource r
Members
'[ Error FederationError,
Error InternalError,
ErrorS 'ConvNotFound,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
BrigAccess,
Resource
]
r
) =>
Qualified UserId ->
Maybe ClientId ->
Expand Down Expand Up @@ -803,6 +819,7 @@ processInternalCommit ::
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
Expand Down Expand Up @@ -848,8 +865,7 @@ processInternalCommit qusr senderClient con lconv mlsMeta cm epoch action sender
(Left _, SelfConv, _) ->
-- this is a newly created conversation, and it should contain exactly one
-- client (the creator)
throw . InternalErrorWithDescription $
"Unexpected creator client set in a self-conversation"
throwS @'MLSUnexpectedSenderClient
(Left _, GlobalTeamConv, []) -> do
creatorClient <- noteS @'MLSMissingSenderClient senderClient
creatorRef <-
Expand All @@ -868,8 +884,7 @@ processInternalCommit qusr senderClient con lconv mlsMeta cm epoch action sender
qusr
(Set.singleton (creatorClient, creatorRef))
(Left _, GlobalTeamConv, _) ->
throw . InternalErrorWithDescription $
"Unexpected creator client set in a global team conversation"
throwS @'MLSUnexpectedSenderClient
(Left lm, _, [(qu, (creatorClient, _))])
| qu == qUntagged (qualifyAs lconv (lmId lm)) -> do
-- use update path as sender reference and if not existing fall back to sender
Expand Down

0 comments on commit 81fb3f8

Please sign in to comment.