Skip to content

Commit 1834ad4

Browse files
committed
fix connection request when queue data and sender ID are created for old servers
1 parent 7dd82bf commit 1834ad4

3 files changed

Lines changed: 44 additions & 19 deletions

File tree

src/Simplex/Messaging/Agent.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ newRcvConnSrv c userId connId enableNtfs cMode userData_ clientData pqInitKeys s
986986
in pure $ CCLink cReq (Just link)
987987
| otherwise -> throwE $ INTERNAL "different rcv queue address"
988988
Nothing ->
989-
let updated (ConnReqUriData _ vr _ _) = (ConnReqUriData SSSimplex vr [qUri] clientData)
989+
let updated (ConnReqUriData _ vr _ _) = (ConnReqUriData SSSimplex vr [qUri'] clientData)
990990
cReq' = case cReq of
991991
CRContactUri crData -> CRContactUri (updated crData)
992992
CRInvitationUri crData e2eParams -> CRInvitationUri (updated crData) e2eParams

src/Simplex/Messaging/Agent/Protocol.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ import UnliftIO.Exception (Exception)
255255
-- 4 - delivery receipts (7/13/2023)
256256
-- 5 - post-quantum double ratchet (3/14/2024)
257257
-- 6 - secure reply queues with provided keys (6/14/2024)
258+
-- 7 - initialize ratchet on processing confirmation (7/18/2024)
258259

259260
data SMPAgentVersion
260261

tests/AgentTests/FunctionalAPITests.hs

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import Data.Type.Equality (testEquality, (:~:) (Refl))
7878
import Data.Word (Word16)
7979
import GHC.Stack (withFrozenCallStack)
8080
import SMPAgentClient
81-
import SMPClient (cfgMS, cfgJ2QS, prevRange, prevVersion, testPort, testPort2, testStoreLogFile, withSmpServer, withSmpServers2, withSmpServerConfigOn, withSmpServerProxy, withSmpServersProxy2, withSmpServerStoreLogOn, withSmpServerStoreMsgLogOn)
81+
import SMPClient (cfgJ2QS, cfgMS, prevRange, prevVersion, proxyCfgJ2QS, proxyCfgMS, testPort, testPort2, testStoreLogFile, withSmpServer, withSmpServers2, withSmpServerConfigOn, withSmpServerProxy, withSmpServersProxy2, withSmpServerStoreLogOn, withSmpServerStoreMsgLogOn)
8282
import Simplex.Messaging.Agent hiding (createConnection, joinConnection, sendMessage)
8383
import qualified Simplex.Messaging.Agent as A
8484
import Simplex.Messaging.Agent.Client (ProtocolTestFailure (..), ProtocolTestStep (..), ServerQueueInfo (..), UserNetworkInfo (..), UserNetworkType (..), waitForUserNetwork)
@@ -102,7 +102,7 @@ import Simplex.Messaging.Server.Env.STM (AServerStoreCfg (..), AStoreType (..),
102102
import Simplex.Messaging.Server.Expiration
103103
import Simplex.Messaging.Server.MsgStore.Types (SMSType (..), SQSType (..))
104104
import Simplex.Messaging.Server.QueueStore.QueueInfo
105-
import Simplex.Messaging.Transport (ATransport (..), SMPVersion, VersionSMP, authCmdsSMPVersion, currentServerSMPRelayVersion, minClientSMPRelayVersion, minServerSMPRelayVersion, sendingProxySMPVersion, sndAuthKeySMPVersion, supportedSMPHandshakes)
105+
import Simplex.Messaging.Transport (ATransport (..), SMPVersion, VersionSMP, authCmdsSMPVersion, currentServerSMPRelayVersion, minClientSMPRelayVersion, minServerSMPRelayVersion, sendingProxySMPVersion, sndAuthKeySMPVersion, supportedSMPHandshakes, supportedServerSMPRelayVRange)
106106
import Simplex.Messaging.Util (bshow, diffToMicroseconds)
107107
import Simplex.Messaging.Version (VersionRange (..))
108108
import qualified Simplex.Messaging.Version as V
@@ -315,6 +315,7 @@ functionalAPITests ps = do
315315
describe "should connect via 1-time short link with async join" $ testProxyMatrix ps testInviationShortLinkAsync
316316
describe "should connect via contact short link" $ testProxyMatrix ps testContactShortLink
317317
describe "should add short link to existing contact and connect" $ testProxyMatrix ps testAddContactShortLink
318+
describe "try to create 1-time short link with prev versions" $ testProxyMatrixWithPrev ps testInviationShortLinkPrev
318319
describe "server restart" $ do
319320
it "should get 1-time link data after restart" $ testInviationShortLinkRestart ps
320321
it "should connect via contact short link after restart" $ testContactShortLinkRestart ps
@@ -547,8 +548,21 @@ testServerMatrix2 ps runTest = do
547548

548549
testProxyMatrix :: HasCallStack => (ATransport, AStoreType) -> (Bool -> AgentClient -> AgentClient -> IO ()) -> Spec
549550
testProxyMatrix ps runTest = do
550-
it "2 servers, directly" $ withSmpServers2 ps $ withAgentClientsServers2 initAgentServers initAgentServers2 $ runTest False
551-
it "2 servers, via proxy" $ withSmpServersProxy2 ps $ withAgentClientsServers2 initAgentServersProxy initAgentServersProxy2 $ runTest True
551+
it "2 servers, directly" $ withSmpServers2 ps $ withAgentClientsServers2 (agentCfg, initAgentServers) (agentCfg, initAgentServers2) $ runTest False
552+
it "2 servers, via proxy" $ withSmpServersProxy2 ps $ withAgentClientsServers2 (agentCfg, initAgentServersProxy) (agentCfg, initAgentServersProxy2) $ runTest True
553+
554+
testProxyMatrixWithPrev :: HasCallStack => (ATransport, AStoreType) -> (Bool -> Bool -> AgentClient -> AgentClient -> IO ()) -> Spec
555+
testProxyMatrixWithPrev ps@(t, msType@(ASType qs _ms)) runTest = do
556+
it "2 servers, directly, curr clients, prev servers" $ withSmpServers2Prev $ withAgentClientsServers2 (agentCfg, initAgentServers) (agentCfg, initAgentServers2) $ runTest False True
557+
it "2 servers, via proxy, curr clients, prev servers" $ withSmpServersProxy2Prev $ withAgentClientsServers2 (agentCfg, initAgentServersProxy) (agentCfg, initAgentServersProxy2) $ runTest True True
558+
it "2 servers, directly, prev clients, curr servers" $ withSmpServers2 ps $ withAgentClientsServers2 (agentCfgVPrevPQ, initAgentServers) (agentCfgVPrevPQ, initAgentServers2) $ runTest False False
559+
it "2 servers, via proxy, prev clients, curr servers" $ withSmpServersProxy2 ps $ withAgentClientsServers2 (agentCfgVPrevPQ, initAgentServersProxy) (agentCfgVPrevPQ, initAgentServersProxy2) $ runTest True False
560+
where
561+
prev cfg' = cfg' {smpServerVRange = prevRange supportedServerSMPRelayVRange}
562+
withSmpServers2Prev a = withServers2 (prev $ cfgMS msType) (prev $ cfgJ2QS qs) a
563+
withSmpServersProxy2Prev a = withServers2 (prev $ proxyCfgMS msType) (prev $ proxyCfgJ2QS qs) a
564+
withServers2 cfg1 cfg2 a =
565+
withSmpServerConfigOn t cfg1 testPort $ \_ -> withSmpServerConfigOn t cfg2 testPort2 $ \_ -> a
552566

553567
testPQMatrix2 :: HasCallStack => (ATransport, AStoreType) -> (HasCallStack => (AgentClient, InitialKeys) -> (AgentClient, PQSupport) -> AgentMsgId -> IO ()) -> Spec
554568
testPQMatrix2 = pqMatrix2_ True
@@ -604,10 +618,10 @@ withAgentClientsCfgServers2 aCfg bCfg servers runTest =
604618
withAgent 2 bCfg servers testDB2 $ \b ->
605619
runTest a b
606620

607-
withAgentClientsServers2 :: HasCallStack => InitialAgentServers -> InitialAgentServers -> (HasCallStack => AgentClient -> AgentClient -> IO a) -> IO a
608-
withAgentClientsServers2 aServers bServers runTest =
609-
withAgent 1 agentCfg aServers testDB $ \a ->
610-
withAgent 2 agentCfg bServers testDB2 $ \b ->
621+
withAgentClientsServers2 :: HasCallStack => (AgentConfig, InitialAgentServers) -> (AgentConfig, InitialAgentServers) -> (HasCallStack => AgentClient -> AgentClient -> IO a) -> IO a
622+
withAgentClientsServers2 (aCfg, aServers) (bCfg, bServers) runTest =
623+
withAgent 1 aCfg aServers testDB $ \a ->
624+
withAgent 2 bCfg bServers testDB2 $ \b ->
611625
runTest a b
612626

613627
withAgentClientsCfg2 :: HasCallStack => AgentConfig -> AgentConfig -> (HasCallStack => AgentClient -> AgentClient -> IO a) -> IO a
@@ -1114,16 +1128,26 @@ testInviationShortLink viaProxy a b =
11141128
runExceptT (getConnShortLink c 1 shortLink) >>= \case
11151129
Left (SMP _ AUTH) -> pure ()
11161130
r -> liftIO $ expectationFailure ("unexpected result " <> show r)
1117-
runRight $ do
1118-
aId <- A.prepareConnectionToJoin b 1 True connReq PQSupportOn
1119-
sndSecure <- A.joinConnection b 1 aId True connReq "bob's connInfo" PQSupportOn SMSubscribe
1120-
liftIO $ sndSecure `shouldBe` True
1121-
("", _, CONF confId _ "bob's connInfo") <- get a
1122-
allowConnection a bId confId "alice's connInfo"
1123-
get a ##> ("", bId, CON)
1124-
get b ##> ("", aId, INFO "alice's connInfo")
1125-
get b ##> ("", aId, CON)
1126-
exchangeGreetingsViaProxy viaProxy a bId b aId
1131+
runRight $ testJoinConn_ viaProxy True a bId b connReq
1132+
1133+
testJoinConn_ :: Bool -> Bool -> AgentClient -> ConnId -> AgentClient -> ConnectionRequestUri c -> ExceptT AgentErrorType IO ()
1134+
testJoinConn_ viaProxy sndSecure a bId b connReq = do
1135+
aId <- A.prepareConnectionToJoin b 1 True connReq PQSupportOn
1136+
sndSecure' <- A.joinConnection b 1 aId True connReq "bob's connInfo" PQSupportOn SMSubscribe
1137+
liftIO $ sndSecure' `shouldBe` sndSecure
1138+
("", _, CONF confId _ "bob's connInfo") <- get a
1139+
allowConnection a bId confId "alice's connInfo"
1140+
get a ##> ("", bId, CON)
1141+
get b ##> ("", aId, INFO "alice's connInfo")
1142+
get b ##> ("", aId, CON)
1143+
exchangeGreetingsViaProxy viaProxy a bId b aId
1144+
1145+
testInviationShortLinkPrev :: HasCallStack => Bool -> Bool -> AgentClient -> AgentClient -> IO ()
1146+
testInviationShortLinkPrev viaProxy sndSecure a b = runRight_ $ do
1147+
let userData = "some user data"
1148+
-- can't create short link with previous version
1149+
(bId, CCLink connReq Nothing) <- A.createConnection a 1 True SCMInvitation (Just userData) Nothing CR.IKPQOn SMSubscribe
1150+
testJoinConn_ viaProxy sndSecure a bId b connReq
11271151

11281152
testInviationShortLinkAsync :: HasCallStack => Bool -> AgentClient -> AgentClient -> IO ()
11291153
testInviationShortLinkAsync viaProxy a b = do

0 commit comments

Comments
 (0)