Skip to content

Commit d7ffc22

Browse files
committed
wip: client identity refactoring
1 parent 39b4480 commit d7ffc22

5 files changed

Lines changed: 38 additions & 25 deletions

File tree

libs/wire-api/src/Wire/API/Error/Galley.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ data GroupInfoDiagnostics = GroupInfoDiagnostics
631631
{ commit :: ByteString,
632632
groupInfo :: ByteString,
633633
groupId :: GroupId,
634-
clients :: [(Int, ClientIdentity)],
634+
clients :: [(Int, GroupMember)],
635635
convId :: ConvOrSubConvId,
636636
domain :: Domain
637637
}
@@ -649,7 +649,7 @@ instance APIError GroupInfoDiagnostics where
649649
headers = []
650650
}
651651

652-
indexedClientSchema :: ValueSchema NamedSwaggerDoc (Int, ClientIdentity)
652+
indexedClientSchema :: ValueSchema NamedSwaggerDoc (Int, GroupMember)
653653
indexedClientSchema =
654654
object $
655655
(,)

libs/wire-api/src/Wire/API/MLS/Credential.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
13
-- This file is part of the Wire Server implementation.
24
--
35
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
@@ -17,7 +19,7 @@
1719

1820
module Wire.API.MLS.Credential where
1921

20-
import Control.Lens ((?~))
22+
import Control.Lens (makePrisms, (?~))
2123
import Data.Aeson (FromJSON (..), ToJSON (..))
2224
import Data.Binary
2325
import Data.Binary.Get
@@ -167,3 +169,11 @@ instance SerialiseMLS ClientIdentity where
167169

168170
mkClientIdentity :: Qualified UserId -> ClientId -> ClientIdentity
169171
mkClientIdentity (Qualified uid domain) = ClientIdentity domain uid
172+
173+
makePrisms ''GroupMember
174+
175+
instance ToSchema GroupMember where
176+
schema =
177+
named "GroupMember" $
178+
tag _RegularClient (unnamed schema)
179+
<> tag _HistoryClient (unnamed schema)

libs/wire-subsystems/src/Wire/ConversationSubsystem/MLS/Commit/Core.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ getCommitData senderIdentity lConvOrSub epoch ciphersuite bundle = do
122122
runState convOrSub.indexMap $ do
123123
creatorAction <-
124124
if epoch == Epoch 0
125-
then addProposedClient (Left senderIdentity.client)
125+
then addProposedClient (Left . RegularClient $ senderIdentity.client)
126126
else mempty
127127
proposals <-
128128
traverse
@@ -260,7 +260,7 @@ checkUpdatePath ::
260260
checkUpdatePath lConvOrSub senderIdentity ciphersuite path = for_ senderIdentity.index $ \index -> do
261261
let groupId = cnvmlsGroupId (tUnqualified lConvOrSub).mlsMeta
262262
let extra = LeafNodeTBSExtraCommit groupId index
263-
case validateLeafNode ciphersuite (Just senderIdentity.client) extra path.leaf.value of
263+
case validateLeafNode ciphersuite (Just . RegularClient $ senderIdentity.client) extra path.leaf.value of
264264
Left InvalidLeafNodeSignature -> throwS @'MLSInvalidLeafNodeSignature
265265
Left errMsg ->
266266
throw $

libs/wire-subsystems/src/Wire/ConversationSubsystem/MLS/Commit/ExternalCommit.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ getExternalCommitData senderIdentity lConvOrSub epoch commit = do
114114

115115
-- add sender client
116116
im <- get
117-
let (addedIndex, im') = imAddClient im senderIdentity
117+
let (addedIndex, im') = imAddClient im (RegularClient senderIdentity)
118118
put im'
119119

120120
pure

libs/wire-subsystems/src/Wire/ConversationSubsystem/MLS/Proposal.hs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,26 @@ import Wire.Util
8080
data ProposalAction = ProposalAction
8181
{ paAdd :: ClientMap (LeafIndex, Maybe KeyPackage),
8282
paRemove :: ClientMap LeafIndex,
83-
historyClientAction :: Maybe HistoryClientAction
83+
paHistoryClientAdd :: Maybe (HistoryClientId, LeafIndex, Maybe KeyPackage),
84+
paHistoryClientRemove :: Maybe (HistoryClientId, LeafIndex)
8485
}
8586
deriving (Show)
8687

87-
data HistoryClientAction
88-
= AddHistoryClient HistoryClientId
89-
| RemoveHistoryClient HistoryClientId
90-
88+
-- TODO: (leif) check this
9189
instance Semigroup ProposalAction where
92-
ProposalAction add1 rem1 <> ProposalAction add2 rem2 =
93-
ProposalAction (add1 <> add2) (rem1 <> rem2)
90+
ProposalAction add1 rem1 hadd1 hrem1 <> ProposalAction add2 rem2 hadd2 hrem2 =
91+
ProposalAction (add1 <> add2) (rem1 <> rem2) (hadd1 <|> hadd2) (hrem1 <|> hrem2)
9492

9593
instance Monoid ProposalAction where
96-
mempty = ProposalAction mempty mempty
94+
mempty = ProposalAction mempty mempty Nothing Nothing
9795

9896
paAddClient :: GroupMember -> LeafIndex -> Maybe KeyPackage -> ProposalAction
99-
paAddClient (RegularMember cid) idx kp = mempty {paAdd = cmSingleton cid (idx, kp)}
97+
paAddClient (RegularClient cid) idx kp = mempty {paAdd = cmSingleton cid (idx, kp)}
98+
paAddClient (HistoryClient hid) idx kp = mempty {paHistoryClientAdd = Just (hid, idx, kp)}
10099

101100
paRemoveClient :: GroupMember -> LeafIndex -> ProposalAction
102-
paRemoveClient cid idx = mempty {paRemove = cmSingleton cid idx}
101+
paRemoveClient (RegularClient cid) idx = mempty {paRemove = cmSingleton cid idx}
102+
paRemoveClient (HistoryClient hid) idx = mempty {paHistoryClientRemove = Just (hid, idx)}
103103

104104
-- | This is used to sort proposals into the correct processing order, as defined by the spec
105105
data ProposalProcessingStage
@@ -309,15 +309,18 @@ checkExternalProposalUser qusr prop = do
309309
loc
310310
( \lusr -> case prop of
311311
AddProposal kp -> do
312-
ClientIdentity {ciUser, ciClient} <- getKeyPackageIdentity kp.value
313-
-- requesting user must match key package owner
314-
when (tUnqualified lusr /= ciUser) $ throwS @'MLSUnsupportedProposal
315-
-- client referenced in key package must be one of the user's clients
316-
UserClients {userClients} <- lookupClients [ciUser]
317-
maybe
318-
(throwS @'MLSUnsupportedProposal)
319-
(flip when (throwS @'MLSUnsupportedProposal) . Set.null . Set.filter (== ciClient))
320-
$ userClients Map.!? ciUser
312+
groupMember <- getKeyPackageIdentity kp.value
313+
case groupMember of
314+
RegularClient (ClientIdentity {ciUser, ciClient}) -> do
315+
-- requesting user must match key package owner
316+
when (tUnqualified lusr /= ciUser) $ throwS @'MLSUnsupportedProposal
317+
-- client referenced in key package must be one of the user's clients
318+
UserClients {userClients} <- lookupClients [ciUser]
319+
maybe
320+
(throwS @'MLSUnsupportedProposal)
321+
(flip when (throwS @'MLSUnsupportedProposal) . Set.null . Set.filter (== ciClient))
322+
$ userClients Map.!? ciUser
323+
HistoryClient _ -> pure ()
321324
_ -> throwS @'MLSUnsupportedProposal
322325
)
323326
(const $ pure ()) -- FUTUREWORK: check external proposals from remote backends

0 commit comments

Comments
 (0)