Skip to content

Commit c5b7d3c

Browse files
authored
agent: use flexible (small/large) string encoding for contact link data, for backward/forward compatibility (#1569)
* agent: use large string encoding for contact link data * size-dependent user link data encoding * tag large user data encoding with \255
1 parent d950012 commit c5b7d3c

File tree

7 files changed

+58
-37
lines changed

7 files changed

+58
-37
lines changed

src/Simplex/Messaging/Agent.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,12 @@ deleteConnectionsAsync c waitDelivery = withAgentEnv c . deleteConnectionsAsync'
368368
{-# INLINE deleteConnectionsAsync #-}
369369

370370
-- | Create SMP agent connection (NEW command)
371-
createConnection :: ConnectionModeI c => AgentClient -> UserId -> Bool -> SConnectionMode c -> Maybe ConnInfo -> Maybe CRClientData -> CR.InitialKeys -> SubscriptionMode -> AE (ConnId, (CreatedConnLink c, Maybe ClientServiceId))
371+
createConnection :: ConnectionModeI c => AgentClient -> UserId -> Bool -> SConnectionMode c -> Maybe UserLinkData -> Maybe CRClientData -> CR.InitialKeys -> SubscriptionMode -> AE (ConnId, (CreatedConnLink c, Maybe ClientServiceId))
372372
createConnection c userId enableNtfs = withAgentEnv c .::. newConn c userId enableNtfs
373373
{-# INLINE createConnection #-}
374374

375375
-- | Create or update user's contact connection short link
376-
setConnShortLink :: AgentClient -> ConnId -> SConnectionMode c -> ConnInfo -> Maybe CRClientData -> AE (ConnShortLink c)
376+
setConnShortLink :: AgentClient -> ConnId -> SConnectionMode c -> UserLinkData -> Maybe CRClientData -> AE (ConnShortLink c)
377377
setConnShortLink c = withAgentEnv c .:: setConnShortLink' c
378378
{-# INLINE setConnShortLink #-}
379379

@@ -832,14 +832,14 @@ switchConnectionAsync' c corrId connId =
832832
pure . connectionStats $ DuplexConnection cData rqs' sqs
833833
_ -> throwE $ CMD PROHIBITED "switchConnectionAsync: not duplex"
834834

835-
newConn :: ConnectionModeI c => AgentClient -> UserId -> Bool -> SConnectionMode c -> Maybe ConnInfo -> Maybe CRClientData -> CR.InitialKeys -> SubscriptionMode -> AM (ConnId, (CreatedConnLink c, Maybe ClientServiceId))
835+
newConn :: ConnectionModeI c => AgentClient -> UserId -> Bool -> SConnectionMode c -> Maybe UserLinkData -> Maybe CRClientData -> CR.InitialKeys -> SubscriptionMode -> AM (ConnId, (CreatedConnLink c, Maybe ClientServiceId))
836836
newConn c userId enableNtfs cMode userData_ clientData pqInitKeys subMode = do
837837
srv <- getSMPServer c userId
838838
connId <- newConnNoQueues c userId enableNtfs cMode (CR.connPQEncryption pqInitKeys)
839839
(connId,) <$> newRcvConnSrv c userId connId enableNtfs cMode userData_ clientData pqInitKeys subMode srv
840840
`catchE` \e -> withStore' c (`deleteConnRecord` connId) >> throwE e
841841

842-
setConnShortLink' :: AgentClient -> ConnId -> SConnectionMode c -> ConnInfo -> Maybe CRClientData -> AM (ConnShortLink c)
842+
setConnShortLink' :: AgentClient -> ConnId -> SConnectionMode c -> UserLinkData -> Maybe CRClientData -> AM (ConnShortLink c)
843843
setConnShortLink' c connId cMode userData clientData =
844844
withConnLock c connId "setConnShortLink" $ do
845845
SomeConn _ conn <- withStore c (`getConn` connId)
@@ -935,7 +935,7 @@ changeConnectionUser' c oldUserId connId newUserId = do
935935
where
936936
updateConn = withStore' c $ \db -> setConnUserId db oldUserId connId newUserId
937937

938-
newRcvConnSrv :: forall c. ConnectionModeI c => AgentClient -> UserId -> ConnId -> Bool -> SConnectionMode c -> Maybe ConnInfo -> Maybe CRClientData -> CR.InitialKeys -> SubscriptionMode -> SMPServerWithAuth -> AM (CreatedConnLink c, Maybe ClientServiceId)
938+
newRcvConnSrv :: forall c. ConnectionModeI c => AgentClient -> UserId -> ConnId -> Bool -> SConnectionMode c -> Maybe UserLinkData -> Maybe CRClientData -> CR.InitialKeys -> SubscriptionMode -> SMPServerWithAuth -> AM (CreatedConnLink c, Maybe ClientServiceId)
939939
newRcvConnSrv c userId connId enableNtfs cMode userData_ clientData pqInitKeys subMode srvWithAuth@(ProtoServerWithAuth srv _) = do
940940
case (cMode, pqInitKeys) of
941941
(SCMContact, CR.IKUsePQ) -> throwE $ CMD PROHIBITED "newRcvConnSrv"
@@ -978,7 +978,7 @@ newRcvConnSrv c userId connId enableNtfs cMode userData_ clientData pqInitKeys s
978978
(pk1, pk2, pKem, e2eRcvParams) <- liftIO $ CR.generateRcvE2EParams g (maxVersion e2eEncryptVRange) pqEnc
979979
withStore' c $ \db -> createRatchetX3dhKeys db connId pk1 pk2 pKem
980980
pure $ CRInvitationUri crData $ toVersionRangeT e2eRcvParams e2eEncryptVRange
981-
prepareLinkData :: ConnInfo -> C.PublicKeyX25519 -> AM (C.CbNonce, SMPQueueUri, ConnectionRequestUri c, ClntQueueReqData)
981+
prepareLinkData :: UserLinkData -> C.PublicKeyX25519 -> AM (C.CbNonce, SMPQueueUri, ConnectionRequestUri c, ClntQueueReqData)
982982
prepareLinkData userData e2eDhKey = do
983983
g <- asks random
984984
nonce@(C.CbNonce corrId) <- atomically $ C.randomCbNonce g

src/Simplex/Messaging/Agent/Protocol.hs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module Simplex.Messaging.Agent.Protocol
111111
ServiceScheme,
112112
FixedLinkData (..),
113113
ConnLinkData (..),
114+
UserLinkData (..),
114115
OwnerAuth (..),
115116
OwnerId,
116117
ConnectionLink (..),
@@ -167,6 +168,7 @@ module Simplex.Messaging.Agent.Protocol
167168
shortenShortLink,
168169
restoreShortLink,
169170
linkUserData,
171+
linkUserData',
170172
)
171173
where
172174

@@ -1633,7 +1635,7 @@ data FixedLinkData c = FixedLinkData
16331635
}
16341636

16351637
data ConnLinkData c where
1636-
InvitationLinkData :: VersionRangeSMPA -> ConnInfo -> ConnLinkData 'CMInvitation
1638+
InvitationLinkData :: VersionRangeSMPA -> UserLinkData -> ConnLinkData 'CMInvitation
16371639
ContactLinkData ::
16381640
{ agentVRange :: VersionRangeSMPA,
16391641
-- direct connection via connReq in fixed data is allowed.
@@ -1642,15 +1644,22 @@ data ConnLinkData c where
16421644
owners :: [OwnerAuth],
16431645
-- alternative addresses of chat relays that receive requests for this contact address.
16441646
relays :: [ConnShortLink 'CMContact],
1645-
userData :: ConnInfo
1647+
userData :: UserLinkData
16461648
} -> ConnLinkData 'CMContact
16471649

1650+
newtype UserLinkData = UserLinkData ByteString
1651+
16481652
data AConnLinkData = forall m. ConnectionModeI m => ACLD (SConnectionMode m) (ConnLinkData m)
16491653

1650-
linkUserData :: ConnLinkData c -> ConnInfo
1654+
linkUserData :: ConnLinkData c -> UserLinkData
16511655
linkUserData = \case
16521656
InvitationLinkData _ d -> d
16531657
ContactLinkData {userData} -> userData
1658+
{-# INLINE linkUserData #-}
1659+
1660+
linkUserData' :: ConnLinkData c -> ByteString
1661+
linkUserData' d = let UserLinkData s = linkUserData d in s
1662+
{-# INLINE linkUserData' #-}
16541663

16551664
type OwnerId = ByteString
16561665

@@ -1706,6 +1715,12 @@ instance Encoding AConnLinkData where
17061715
userData <- smpP <* A.takeByteString -- ignoring tail for forward compatibility with the future link data encoding
17071716
pure $ ACLD SCMContact ContactLinkData {agentVRange, direct, owners, relays, userData}
17081717

1718+
instance Encoding UserLinkData where
1719+
smpEncode (UserLinkData s) = if B.length s <= 254 then smpEncode s else smpEncode ('\255', Large s)
1720+
{-# INLINE smpEncode #-}
1721+
smpP = UserLinkData <$> ((A.char '\255' *> (unLarge <$> smpP)) <|> smpP)
1722+
{-# INLINE smpP #-}
1723+
17091724
data StoredClientService (s :: DBStored) = ClientService
17101725
{ dbServiceId :: DBEntityId' s,
17111726
serviceId :: SMP.ServiceId

src/Simplex/Messaging/Crypto/ShortLink.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ contactShortLinkKdf (LinkKey k) =
4848
invShortLinkKdf :: LinkKey -> C.SbKey
4949
invShortLinkKdf (LinkKey k) = C.unsafeSbKey $ C.hkdf "" k "SimpleXInvLink" 32
5050

51-
encodeSignLinkData :: forall c. ConnectionModeI c => C.KeyPairEd25519 -> VersionRangeSMPA -> ConnectionRequestUri c -> ConnInfo -> (LinkKey, (ByteString, ByteString))
51+
encodeSignLinkData :: forall c. ConnectionModeI c => C.KeyPairEd25519 -> VersionRangeSMPA -> ConnectionRequestUri c -> UserLinkData -> (LinkKey, (ByteString, ByteString))
5252
encodeSignLinkData (rootKey, pk) agentVRange connReq userData =
5353
let fd = smpEncode FixedLinkData {agentVRange, rootKey, connReq}
5454
md = smpEncode $ connLinkData @c agentVRange userData
5555
in (LinkKey (C.sha3_256 fd), (encodeSign pk fd, encodeSign pk md))
5656

57-
encodeSignUserData :: forall c. ConnectionModeI c => SConnectionMode c -> C.PrivateKeyEd25519 -> VersionRangeSMPA -> ConnInfo -> ByteString
57+
encodeSignUserData :: forall c. ConnectionModeI c => SConnectionMode c -> C.PrivateKeyEd25519 -> VersionRangeSMPA -> UserLinkData -> ByteString
5858
encodeSignUserData _ pk agentVRange userData =
5959
encodeSign pk $ smpEncode $ connLinkData @c agentVRange userData
6060

61-
connLinkData :: forall c. ConnectionModeI c => VersionRangeSMPA -> ConnInfo -> ConnLinkData c
61+
connLinkData :: forall c. ConnectionModeI c => VersionRangeSMPA -> UserLinkData -> ConnLinkData c
6262
connLinkData agentVRange userData = case sConnectionMode @c of
6363
SCMInvitation -> InvitationLinkData agentVRange userData
6464
SCMContact -> ContactLinkData {agentVRange, direct = True, owners = [], relays = [], userData}

src/Simplex/Messaging/Util.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,11 @@ atomicModifyIORef'_ r f = atomicModifyIORef' r (\v -> (f v, ()))
265265

266266
encodeJSON :: ToJSON a => a -> Text
267267
encodeJSON = safeDecodeUtf8 . LB.toStrict . J.encode
268+
{-# INLINE encodeJSON #-}
268269

269270
decodeJSON :: FromJSON a => Text -> Maybe a
270-
decodeJSON = J.decode . LB.fromStrict . encodeUtf8
271+
decodeJSON = J.decodeStrict . encodeUtf8
272+
{-# INLINE decodeJSON #-}
271273

272274
traverseWithKey_ :: Monad m => (k -> v -> m ()) -> Map k v -> m ()
273275
traverseWithKey_ f = M.foldrWithKey (\k v -> (f k v >>)) (pure ())

tests/AgentTests/EqInstances.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module AgentTests.EqInstances where
66

77
import Data.Type.Equality
8-
import Simplex.Messaging.Agent.Protocol (ConnLinkData (..), OwnerAuth (..))
8+
import Simplex.Messaging.Agent.Protocol (ConnLinkData (..), OwnerAuth (..), UserLinkData (..))
99
import Simplex.Messaging.Agent.Store
1010
import Simplex.Messaging.Client (ProxiedRelay (..))
1111

@@ -30,6 +30,10 @@ deriving instance Show (ConnLinkData c)
3030

3131
deriving instance Eq (ConnLinkData c)
3232

33+
deriving instance Show UserLinkData
34+
35+
deriving instance Eq UserLinkData
36+
3337
deriving instance Show OwnerAuth
3438

3539
deriving instance Eq OwnerAuth

tests/AgentTests/FunctionalAPITests.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ testAllowConnectionClientRestart ps@(t, ASType qsType _) = do
11371137
testInviationShortLink :: HasCallStack => Bool -> AgentClient -> AgentClient -> IO ()
11381138
testInviationShortLink viaProxy a b =
11391139
withAgent 3 agentCfg initAgentServers testDB3 $ \c -> do
1140-
let userData = "some user data"
1140+
let userData = UserLinkData "some user data"
11411141
(bId, (CCLink connReq (Just shortLink), Nothing)) <- runRight $ A.createConnection a 1 True SCMInvitation (Just userData) Nothing CR.IKUsePQ SMSubscribe
11421142
(connReq', connData') <- runRight $ getConnShortLink b 1 shortLink
11431143
strDecode (strEncode shortLink) `shouldBe` Right shortLink
@@ -1171,14 +1171,14 @@ testJoinConn_ viaProxy sndSecure a bId b connReq = do
11711171

11721172
testInviationShortLinkPrev :: HasCallStack => Bool -> Bool -> AgentClient -> AgentClient -> IO ()
11731173
testInviationShortLinkPrev viaProxy sndSecure a b = runRight_ $ do
1174-
let userData = "some user data"
1174+
let userData = UserLinkData "some user data"
11751175
-- can't create short link with previous version
11761176
(bId, (CCLink connReq Nothing, Nothing)) <- A.createConnection a 1 True SCMInvitation (Just userData) Nothing CR.IKPQOn SMSubscribe
11771177
testJoinConn_ viaProxy sndSecure a bId b connReq
11781178

11791179
testInviationShortLinkAsync :: HasCallStack => Bool -> AgentClient -> AgentClient -> IO ()
11801180
testInviationShortLinkAsync viaProxy a b = do
1181-
let userData = "some user data"
1181+
let userData = UserLinkData "some user data"
11821182
(bId, (CCLink connReq (Just shortLink), Nothing)) <- runRight $ A.createConnection a 1 True SCMInvitation (Just userData) Nothing CR.IKUsePQ SMSubscribe
11831183
(connReq', connData') <- runRight $ getConnShortLink b 1 shortLink
11841184
strDecode (strEncode shortLink) `shouldBe` Right shortLink
@@ -1197,7 +1197,7 @@ testInviationShortLinkAsync viaProxy a b = do
11971197
testContactShortLink :: HasCallStack => Bool -> AgentClient -> AgentClient -> IO ()
11981198
testContactShortLink viaProxy a b =
11991199
withAgent 3 agentCfg initAgentServers testDB3 $ \c -> do
1200-
let userData = "some user data"
1200+
let userData = UserLinkData "some user data"
12011201
(contactId, (CCLink connReq0 (Just shortLink), Nothing)) <- runRight $ A.createConnection a 1 True SCMContact (Just userData) Nothing CR.IKPQOn SMSubscribe
12021202
Right connReq <- pure $ smpDecode (smpEncode connReq0)
12031203
(connReq', connData') <- runRight $ getConnShortLink b 1 shortLink
@@ -1226,7 +1226,7 @@ testContactShortLink viaProxy a b =
12261226
get b ##> ("", aId, CON)
12271227
exchangeGreetingsViaProxy viaProxy a bId b aId
12281228
-- update user data
1229-
let updatedData = "updated user data"
1229+
let updatedData = UserLinkData "updated user data"
12301230
shortLink' <- runRight $ setConnShortLink a contactId SCMContact updatedData Nothing
12311231
shortLink' `shouldBe` shortLink
12321232
(connReq4, updatedConnData') <- runRight $ getConnShortLink c 1 shortLink
@@ -1245,7 +1245,7 @@ testAddContactShortLink viaProxy a b =
12451245
withAgent 3 agentCfg initAgentServers testDB3 $ \c -> do
12461246
(contactId, (CCLink connReq0 Nothing, Nothing)) <- runRight $ A.createConnection a 1 True SCMContact Nothing Nothing CR.IKPQOn SMSubscribe
12471247
Right connReq <- pure $ smpDecode (smpEncode connReq0) --
1248-
let userData = "some user data"
1248+
let userData = UserLinkData "some user data"
12491249
shortLink <- runRight $ setConnShortLink a contactId SCMContact userData Nothing
12501250
(connReq', connData') <- runRight $ getConnShortLink b 1 shortLink
12511251
strDecode (strEncode shortLink) `shouldBe` Right shortLink
@@ -1273,7 +1273,7 @@ testAddContactShortLink viaProxy a b =
12731273
get b ##> ("", aId, CON)
12741274
exchangeGreetingsViaProxy viaProxy a bId b aId
12751275
-- update user data
1276-
let updatedData = "updated user data"
1276+
let updatedData = UserLinkData "updated user data"
12771277
shortLink' <- runRight $ setConnShortLink a contactId SCMContact updatedData Nothing
12781278
shortLink' `shouldBe` shortLink
12791279
(connReq4, updatedConnData') <- runRight $ getConnShortLink c 1 shortLink
@@ -1282,7 +1282,7 @@ testAddContactShortLink viaProxy a b =
12821282

12831283
testInviationShortLinkRestart :: HasCallStack => (ASrvTransport, AStoreType) -> IO ()
12841284
testInviationShortLinkRestart ps = withAgentClients2 $ \a b -> do
1285-
let userData = "some user data"
1285+
let userData = UserLinkData "some user data"
12861286
(bId, (CCLink connReq (Just shortLink), Nothing)) <- withSmpServer ps $
12871287
runRight $ A.createConnection a 1 True SCMInvitation (Just userData) Nothing CR.IKUsePQ SMOnlyCreate
12881288
withSmpServer ps $ do
@@ -1294,11 +1294,11 @@ testInviationShortLinkRestart ps = withAgentClients2 $ \a b -> do
12941294

12951295
testContactShortLinkRestart :: HasCallStack => (ASrvTransport, AStoreType) -> IO ()
12961296
testContactShortLinkRestart ps = withAgentClients2 $ \a b -> do
1297-
let userData = "some user data"
1297+
let userData = UserLinkData "some user data"
12981298
(contactId, (CCLink connReq0 (Just shortLink), Nothing)) <- withSmpServer ps $
12991299
runRight $ A.createConnection a 1 True SCMContact (Just userData) Nothing CR.IKPQOn SMOnlyCreate
13001300
Right connReq <- pure $ smpDecode (smpEncode connReq0)
1301-
let updatedData = "updated user data"
1301+
let updatedData = UserLinkData "updated user data"
13021302
withSmpServer ps $ do
13031303
(connReq', connData') <- runRight $ getConnShortLink b 1 shortLink
13041304
strDecode (strEncode shortLink) `shouldBe` Right shortLink
@@ -1314,12 +1314,12 @@ testContactShortLinkRestart ps = withAgentClients2 $ \a b -> do
13141314

13151315
testAddContactShortLinkRestart :: HasCallStack => (ASrvTransport, AStoreType) -> IO ()
13161316
testAddContactShortLinkRestart ps = withAgentClients2 $ \a b -> do
1317-
let userData = "some user data"
1317+
let userData = UserLinkData "some user data"
13181318
((contactId, (CCLink connReq0 Nothing, Nothing)), shortLink) <- withSmpServer ps $ runRight $ do
13191319
r@(contactId, _) <- A.createConnection a 1 True SCMContact Nothing Nothing CR.IKPQOn SMOnlyCreate
13201320
(r,) <$> setConnShortLink a contactId SCMContact userData Nothing
13211321
Right connReq <- pure $ smpDecode (smpEncode connReq0)
1322-
let updatedData = "updated user data"
1322+
let updatedData = UserLinkData "updated user data"
13231323
withSmpServer ps $ do
13241324
(connReq', connData') <- runRight $ getConnShortLink b 1 shortLink
13251325
strDecode (strEncode shortLink) `shouldBe` Right shortLink
@@ -1355,14 +1355,14 @@ testOldContactQueueShortLink ps@(_, msType) = withAgentClients2 $ \a b -> do
13551355
_ -> pure ()
13561356

13571357
withSmpServer ps $ do
1358-
let userData = "some user data"
1358+
let userData = UserLinkData "some user data"
13591359
shortLink <- runRight $ setConnShortLink a contactId SCMContact userData Nothing
13601360
(connReq', connData') <- runRight $ getConnShortLink b 1 shortLink
13611361
strDecode (strEncode shortLink) `shouldBe` Right shortLink
13621362
connReq' `shouldBe` connReq
13631363
linkUserData connData' `shouldBe` userData
13641364
-- update user data
1365-
let updatedData = "updated user data"
1365+
let updatedData = UserLinkData "updated user data"
13661366
shortLink' <- runRight $ setConnShortLink a contactId SCMContact updatedData Nothing
13671367
shortLink' `shouldBe` shortLink
13681368
-- check updated

tests/AgentTests/ShortLinkTests.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import AgentTests.ConnectionRequestTests (contactConnRequest, invConnRequest)
88
import AgentTests.EqInstances ()
99
import Control.Concurrent.STM
1010
import Control.Monad.Except
11-
import Simplex.Messaging.Agent.Protocol (AgentErrorType (..), ConnectionMode (..), LinkKey (..), SConnectionMode (..), SMPAgentError (..), linkUserData, supportedSMPAgentVRange)
11+
import Simplex.Messaging.Agent.Protocol (AgentErrorType (..), ConnectionMode (..), LinkKey (..), SConnectionMode (..), SMPAgentError (..), UserLinkData (..), linkUserData, supportedSMPAgentVRange)
1212
import qualified Simplex.Messaging.Crypto as C
1313
import qualified Simplex.Messaging.Crypto.ShortLink as SL
1414
import Test.Hspec hiding (fit, it)
@@ -30,7 +30,7 @@ testInvShortLink = do
3030
-- encrypt
3131
g <- C.newRandom
3232
sigKeys <- atomically $ C.generateKeyPair @'C.Ed25519 g
33-
let userData = "some user data"
33+
let userData = UserLinkData "some user data"
3434
(linkKey, linkData) = SL.encodeSignLinkData sigKeys supportedSMPAgentVRange invConnRequest userData
3535
k = SL.invShortLinkKdf linkKey
3636
Right srvData <- runExceptT $ SL.encryptLinkData g k linkData
@@ -44,7 +44,7 @@ testInvShortLinkBadDataHash = do
4444
-- encrypt
4545
g <- C.newRandom
4646
sigKeys <- atomically $ C.generateKeyPair @'C.Ed25519 g
47-
let userData = "some user data"
47+
let userData = UserLinkData "some user data"
4848
(_linkKey, linkData) = SL.encodeSignLinkData sigKeys supportedSMPAgentVRange invConnRequest userData
4949
-- different key
5050
linkKey <- LinkKey <$> atomically (C.randomBytes 32 g)
@@ -59,7 +59,7 @@ testContactShortLink = do
5959
-- encrypt
6060
g <- C.newRandom
6161
sigKeys <- atomically $ C.generateKeyPair @'C.Ed25519 g
62-
let userData = "some user data"
62+
let userData = UserLinkData "some user data"
6363
(linkKey, linkData) = SL.encodeSignLinkData sigKeys supportedSMPAgentVRange contactConnRequest userData
6464
(_linkId, k) = SL.contactShortLinkKdf linkKey
6565
Right srvData <- runExceptT $ SL.encryptLinkData g k linkData
@@ -73,12 +73,12 @@ testUpdateContactShortLink = do
7373
-- encrypt
7474
g <- C.newRandom
7575
sigKeys <- atomically $ C.generateKeyPair @'C.Ed25519 g
76-
let userData = "some user data"
76+
let userData = UserLinkData "some user data"
7777
(linkKey, linkData) = SL.encodeSignLinkData sigKeys supportedSMPAgentVRange contactConnRequest userData
7878
(_linkId, k) = SL.contactShortLinkKdf linkKey
7979
Right (fd, _ud) <- runExceptT $ SL.encryptLinkData g k linkData
8080
-- encrypt updated user data
81-
let updatedUserData = "updated user data"
81+
let updatedUserData = UserLinkData "updated user data"
8282
signed = SL.encodeSignUserData SCMContact (snd sigKeys) supportedSMPAgentVRange updatedUserData
8383
Right ud' <- runExceptT $ SL.encryptUserData g k signed
8484
-- decrypt
@@ -91,7 +91,7 @@ testContactShortLinkBadDataHash = do
9191
-- encrypt
9292
g <- C.newRandom
9393
sigKeys <- atomically $ C.generateKeyPair @'C.Ed25519 g
94-
let userData = "some user data"
94+
let userData = UserLinkData "some user data"
9595
(_linkKey, linkData) = SL.encodeSignLinkData sigKeys supportedSMPAgentVRange contactConnRequest userData
9696
-- different key
9797
linkKey <- LinkKey <$> atomically (C.randomBytes 32 g)
@@ -106,12 +106,12 @@ testContactShortLinkBadSignature = do
106106
-- encrypt
107107
g <- C.newRandom
108108
sigKeys <- atomically $ C.generateKeyPair @'C.Ed25519 g
109-
let userData = "some user data"
109+
let userData = UserLinkData "some user data"
110110
(linkKey, linkData) = SL.encodeSignLinkData sigKeys supportedSMPAgentVRange contactConnRequest userData
111111
(_linkId, k) = SL.contactShortLinkKdf linkKey
112112
Right (fd, _ud) <- runExceptT $ SL.encryptLinkData g k linkData
113113
-- encrypt updated user data
114-
let updatedUserData = "updated user data"
114+
let updatedUserData = UserLinkData "updated user data"
115115
-- another signature key
116116
(_, pk) <- atomically $ C.generateKeyPair @'C.Ed25519 g
117117
let signed = SL.encodeSignUserData SCMContact pk supportedSMPAgentVRange updatedUserData

0 commit comments

Comments
 (0)