Skip to content

Commit

Permalink
Remove proposals now have indices instead of refs
Browse files Browse the repository at this point in the history
  • Loading branch information
pcapriotti committed Mar 31, 2023
1 parent bc3424f commit b79b7da
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 191 deletions.
39 changes: 27 additions & 12 deletions libs/wire-api/src/Wire/API/MLS/Proposal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,24 @@ import Cassandra
import Control.Lens (makePrisms)
import Data.Binary
import Data.Binary.Get
import Data.Binary.Put
import qualified Data.ByteString.Lazy as LBS
import Imports
import Wire.API.MLS.CipherSuite
import Wire.API.MLS.Context
import Wire.API.MLS.Extension
import Wire.API.MLS.Group
import Wire.API.MLS.KeyPackage
import Wire.API.MLS.LeafNode
import Wire.API.MLS.ProposalTag
import Wire.API.MLS.ProtocolVersion
import Wire.API.MLS.Serialisation
import Wire.Arbitrary

data Proposal
= AddProposal (RawMLS KeyPackage)
| UpdateProposal KeyPackage
| RemoveProposal KeyPackageRef
| PreSharedKeyProposal PreSharedKeyID -- TODO
| ReInitProposal ReInit
| UpdateProposal (RawMLS LeafNode)
| RemoveProposal Word32
| PreSharedKeyProposal (RawMLS PreSharedKeyID)
| ReInitProposal (RawMLS ReInit)
| ExternalInitProposal ByteString
| GroupContextExtensionsProposal [Extension]
deriving stock (Eq, Show)
Expand All @@ -59,12 +58,28 @@ instance ParseMLS Proposal where
GroupContextExtensionsProposalTag ->
GroupContextExtensionsProposal <$> parseMLSVector @VarInt parseMLS

mkRemoveProposal :: KeyPackageRef -> RawMLS Proposal
mkRemoveProposal ref = RawMLS bytes (RemoveProposal ref)
where
bytes = LBS.toStrict . runPut $ do
serialiseMLS RemoveProposalTag
serialiseMLS ref
instance SerialiseMLS Proposal where
serialiseMLS (AddProposal kp) = do
serialiseMLS AddProposalTag
serialiseMLS kp
serialiseMLS (UpdateProposal ln) = do
serialiseMLS UpdateProposalTag
serialiseMLS ln
serialiseMLS (RemoveProposal i) = do
serialiseMLS RemoveProposalTag
serialiseMLS i
serialiseMLS (PreSharedKeyProposal k) = do
serialiseMLS PreSharedKeyProposalTag
serialiseMLS k
serialiseMLS (ReInitProposal ri) = do
serialiseMLS ReInitProposalTag
serialiseMLS ri
serialiseMLS (ExternalInitProposal ko) = do
serialiseMLS ExternalInitProposalTag
serialiseMLSBytes @VarInt ko
serialiseMLS (GroupContextExtensionsProposal es) = do
serialiseMLS GroupContextExtensionsProposalTag
serialiseMLSVector @VarInt serialiseMLS es

-- | Compute the proposal ref given a ciphersuite and the raw proposal data.
proposalRef :: CipherSuiteTag -> RawMLS Proposal -> ProposalRef
Expand Down
10 changes: 3 additions & 7 deletions libs/wire-api/src/Wire/API/MLS/Welcome.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ import Imports
import Wire.API.MLS.CipherSuite
import Wire.API.MLS.Commit
import Wire.API.MLS.KeyPackage
import Wire.API.MLS.ProtocolVersion
import Wire.API.MLS.Serialisation
import Wire.Arbitrary

data Welcome = Welcome
{ welProtocolVersion :: ProtocolVersion,
welCipherSuite :: CipherSuite,
{ welCipherSuite :: CipherSuite,
welSecrets :: [GroupSecrets],
welGroupInfo :: ByteString
}
Expand All @@ -41,14 +39,12 @@ instance S.ToSchema Welcome where
instance ParseMLS Welcome where
parseMLS =
Welcome
<$> parseMLS @ProtocolVersion
<*> parseMLS
<$> parseMLS
<*> parseMLSVector @VarInt parseMLS
<*> parseMLSBytes @VarInt

instance SerialiseMLS Welcome where
serialiseMLS (Welcome pv cs ss gi) = do
serialiseMLS pv
serialiseMLS (Welcome cs ss gi) = do
serialiseMLS cs
serialiseMLSVector @VarInt serialiseMLS ss
serialiseMLSBytes @VarInt gi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ type ConversationAPI =
:> CanThrow 'MissingLegalholdConsent
:> Description "This returns 201 when a new conversation is created, and 200 when the conversation already existed"
:> ZLocalUser
:> ZOptClient
:> ZOptConn
:> "conversations"
:> VersionedReqBody 'V2 '[Servant.JSON] NewConv
Expand All @@ -366,7 +365,6 @@ type ConversationAPI =
:> CanThrow 'MissingLegalholdConsent
:> Description "This returns 201 when a new conversation is created, and 200 when the conversation already existed"
:> ZLocalUser
:> ZOptClient
:> ZOptConn
:> "conversations"
:> ReqBody '[Servant.JSON] NewConv
Expand Down
6 changes: 4 additions & 2 deletions libs/wire-api/test/unit/Test/Wire/API/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ testRemoveProposalMessageSignature = withSystemTempDirectory "mls" $ \tmp -> do
usr <- flip Qualified (Domain "example.com") <$> (Id <$> UUID.nextRandom)
pure (userClientQid usr c)
void . liftIO $ spawn (cli qcid2 tmp ["init", qcid2]) Nothing
kp <- liftIO $ decodeMLSError <$> spawn (cli qcid2 tmp ["key-package", "create"]) Nothing
kp :: RawMLS KeyPackage <-
liftIO $
decodeMLSError <$> spawn (cli qcid2 tmp ["key-package", "create"]) Nothing
liftIO $ BS.writeFile (tmp </> qcid2) (rmRaw kp)

let groupFilename = "group"
Expand All @@ -132,7 +134,7 @@ testRemoveProposalMessageSignature = withSystemTempDirectory "mls" $ \tmp -> do

secretKey <- Ed25519.generateSecretKey
let publicKey = Ed25519.toPublic secretKey
let proposal = mkRemoveProposal (fromJust (kpRef' kp))
let proposal = mkRawMLS (RemoveProposal (error "TODO: remove proposal"))
let message =
mkSignedMessage
secretKey
Expand Down
2 changes: 1 addition & 1 deletion libs/wire-api/test/unit/Test/Wire/API/Roundtrip/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ newtype RemoveProposalPayload = RemoveProposalPayload {unRemoveProposalPayload :
deriving newtype (ParseMLS, SerialiseMLS, Eq, Show)

instance Arbitrary RemoveProposalPayload where
arbitrary = RemoveProposalPayload . FramedContentProposal . mkRemoveProposal <$> arbitrary
arbitrary = RemoveProposalPayload . FramedContentProposal . mkRawMLS . RemoveProposal <$> arbitrary

instance ArbitraryFramedContentData RemoveProposalPayload where
arbitraryFramedContentData = unRemoveProposalPayload <$> arbitrary
Expand Down
1 change: 1 addition & 0 deletions services/galley/galley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ executable galley-schema
V78_TeamFeatureOutlookCalIntegration
V79_TeamFeatureMlsE2EId
V80_MLSSubconversation
V81_MLSDraft17

hs-source-dirs: schema/src
default-extensions: TemplateHaskell
Expand Down
4 changes: 3 additions & 1 deletion services/galley/schema/src/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import qualified V77_MLSGroupMemberClient
import qualified V78_TeamFeatureOutlookCalIntegration
import qualified V79_TeamFeatureMlsE2EId
import qualified V80_MLSSubconversation
import qualified V81_MLSDraft17

main :: IO ()
main = do
Expand Down Expand Up @@ -151,7 +152,8 @@ main = do
V77_MLSGroupMemberClient.migration,
V78_TeamFeatureOutlookCalIntegration.migration,
V79_TeamFeatureMlsE2EId.migration,
V80_MLSSubconversation.migration
V80_MLSSubconversation.migration,
V81_MLSDraft17.migration
-- When adding migrations here, don't forget to update
-- 'schemaVersion' in Galley.Cassandra
-- (see also docs/developer/cassandra-interaction.md)
Expand Down
31 changes: 31 additions & 0 deletions services/galley/schema/src/V81_MLSDraft17.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module V81_MLSDraft17 (migration) where

import Cassandra.Schema
import Imports
import Text.RawString.QQ

migration :: Migration
migration =
Migration 81 "Upgrade to MLS draft 17 structures" $ do
schema'
[r| ALTER TABLE mls_group_member_client
ADD (leaf_node_index int
);
|]
4 changes: 0 additions & 4 deletions services/galley/src/Galley/API/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import Data.Singletons
import Data.Time.Clock
import Galley.API.Error
import Galley.API.MLS.Removal
import Galley.API.MLS.Types (cmAssocs)
import Galley.API.Util
import Galley.App
import Galley.Data.Conversation
Expand Down Expand Up @@ -342,9 +341,6 @@ performAction tag origUser lconv action = do
pure (mempty, action)
SConversationDeleteTag -> do
let deleteGroup groupId = do
cm <- E.lookupMLSClients groupId
let refs = cm & cmAssocs & map (snd . snd)
E.deleteKeyPackageRefs refs
E.removeAllMLSClients groupId
E.deleteAllProposals groupId

Expand Down
13 changes: 1 addition & 12 deletions services/galley/src/Galley/API/Create.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import Data.Time
import qualified Data.UUID.Tagged as U
import Galley.API.Error
import Galley.API.MLS
import Galley.API.MLS.KeyPackage (nullKeyPackageRef)
import Galley.API.MLS.Keys (getMLSRemovalKey)
import Galley.API.Mapping
import Galley.API.One2One
Expand Down Expand Up @@ -86,7 +85,6 @@ import Wire.API.Team.Permission hiding (self)
createGroupConversation ::
( Member BrigAccess r,
Member ConversationStore r,
Member MemberStore r,
Member (ErrorS 'ConvAccessDenied) r,
Member (Error InternalError) r,
Member (Error InvalidInput) r,
Expand All @@ -95,7 +93,6 @@ createGroupConversation ::
Member (ErrorS 'NotConnected) r,
Member (ErrorS 'MLSNotEnabled) r,
Member (ErrorS 'MLSNonEmptyMemberList) r,
Member (ErrorS 'MLSMissingSenderClient) r,
Member (ErrorS 'MissingLegalholdConsent) r,
Member FederatorAccess r,
Member GundeckAccess r,
Expand All @@ -107,11 +104,10 @@ createGroupConversation ::
Member P.TinyLog r
) =>
Local UserId ->
Maybe ClientId ->
Maybe ConnId ->
NewConv ->
Sem r ConversationResponse
createGroupConversation lusr mCreatorClient mConn newConv = do
createGroupConversation lusr mConn newConv = do
(nc, fromConvSize -> allUsers) <- newRegularConversation lusr newConv
let tinfo = newConvTeam newConv
checkCreateConvPermissions lusr newConv tinfo allUsers
Expand All @@ -132,13 +128,6 @@ createGroupConversation lusr mCreatorClient mConn newConv = do
-- conversation is already in the database.
conv <- E.createConversation lcnv nc

-- set creator client for MLS conversations
case (convProtocol conv, mCreatorClient) of
(ProtocolProteus, _) -> pure ()
(ProtocolMLS mlsMeta, Just c) ->
E.addMLSClients (cnvmlsGroupId mlsMeta) (tUntagged lusr) (Set.singleton (c, nullKeyPackageRef))
(ProtocolMLS _mlsMeta, Nothing) -> throwS @'MLSMissingSenderClient

now <- input
-- NOTE: We only send (conversation) events to members of the conversation
notifyCreatedConversation (Just now) lusr mConn conv
Expand Down
3 changes: 2 additions & 1 deletion services/galley/src/Galley/API/MLS/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ mkMLSConversation conv =
mcLocalMembers = Data.convLocalMembers conv,
mcRemoteMembers = Data.convRemoteMembers conv,
mcMLSData = mlsData,
mcMembers = cm
mcMembers = cm,
mcIndexMap = mempty -- TODO
}

mcConv :: MLSConversation -> Data.Conversation
Expand Down
Loading

0 comments on commit b79b7da

Please sign in to comment.