@@ -251,7 +251,6 @@ import Simplex.Messaging.Protocol
251
251
ErrorType ,
252
252
MsgFlags (.. ),
253
253
MsgId ,
254
- NtfPublicAuthKey ,
255
254
NtfServer ,
256
255
NtfServerWithAuth ,
257
256
ProtoServer ,
@@ -261,12 +260,14 @@ import Simplex.Messaging.Protocol
261
260
ProtocolType (.. ),
262
261
ProtocolTypeI (.. ),
263
262
QueueIdsKeys (.. ),
263
+ ServerNtfCreds (.. ),
264
264
RcvMessage (.. ),
265
265
RcvNtfPublicDhKey ,
266
266
SMPMsgMeta (.. ),
267
267
SProtocolType (.. ),
268
268
SndPublicAuthKey ,
269
269
SubscriptionMode (.. ),
270
+ NewNtfCreds (.. ),
270
271
QueueReqData (.. ),
271
272
QueueLinkData ,
272
273
UserProtocol ,
@@ -283,7 +284,7 @@ import Simplex.Messaging.Session
283
284
import Simplex.Messaging.Agent.Store.Entity
284
285
import Simplex.Messaging.TMap (TMap )
285
286
import qualified Simplex.Messaging.TMap as TM
286
- import Simplex.Messaging.Transport (SMPVersion , SessionId , THandleParams (sessionId , thVersion ), TransportError (.. ), TransportPeer (.. ), sndAuthKeySMPVersion , shortLinksSMPVersion )
287
+ import Simplex.Messaging.Transport (SMPVersion , SessionId , THandleParams (sessionId , thVersion ), TransportError (.. ), TransportPeer (.. ), sndAuthKeySMPVersion , shortLinksSMPVersion , newNtfCredsSMPVersion )
287
288
import Simplex.Messaging.Transport.Client (TransportHost (.. ))
288
289
import Simplex.Messaging.Util
289
290
import Simplex.Messaging.Version
@@ -1240,8 +1241,7 @@ runSMPServerTest c nm userId (ProtoServerWithAuth srv auth) = do
1240
1241
(sKey, spKey) <- atomically $ C. generateAuthKeyPair sa g
1241
1242
(dhKey, _) <- atomically $ C. generateKeyPair g
1242
1243
r <- runExceptT $ do
1243
- -- TODO [notifications]
1244
- SMP. QIK {rcvId, sndId, queueMode} <- liftError (testErr TSCreateQueue ) $ createSMPQueue smp nm Nothing rKeys dhKey auth SMSubscribe (QRMessaging Nothing ) -- Nothing
1244
+ SMP. QIK {rcvId, sndId, queueMode} <- liftError (testErr TSCreateQueue ) $ createSMPQueue smp nm Nothing rKeys dhKey auth SMSubscribe (QRMessaging Nothing ) Nothing
1245
1245
liftError (testErr TSSecureQueue ) $
1246
1246
case queueMode of
1247
1247
Just QMMessaging -> secureSndSMPQueue smp nm spKey sndId sKey
@@ -1352,12 +1352,11 @@ getSessionMode :: MonadIO m => AgentClient -> m TransportSessionMode
1352
1352
getSessionMode = fmap sessionMode . getNetworkConfig
1353
1353
{-# INLINE getSessionMode #-}
1354
1354
1355
- -- TODO [notifications]
1356
- newRcvQueue :: AgentClient -> NetworkRequestMode -> UserId -> ConnId -> SMPServerWithAuth -> VersionRangeSMPC -> SConnectionMode c -> SubscriptionMode -> AM (NewRcvQueue , SMPQueueUri , SMPTransportSession , SessionId )
1357
- newRcvQueue c nm userId connId srv vRange cMode subMode = do
1355
+ newRcvQueue :: AgentClient -> NetworkRequestMode -> UserId -> ConnId -> SMPServerWithAuth -> VersionRangeSMPC -> SConnectionMode c -> Bool -> SubscriptionMode -> AM (NewRcvQueue , SMPQueueUri , SMPTransportSession , SessionId )
1356
+ newRcvQueue c nm userId connId srv vRange cMode enableNtfs subMode = do
1358
1357
let qrd = case cMode of SCMInvitation -> CQRMessaging Nothing ; SCMContact -> CQRContact Nothing
1359
1358
e2eKeys <- atomically . C. generateKeyPair =<< asks random
1360
- newRcvQueue_ c nm userId connId srv vRange qrd subMode Nothing e2eKeys
1359
+ newRcvQueue_ c nm userId connId srv vRange qrd enableNtfs subMode Nothing e2eKeys
1361
1360
1362
1361
data ClntQueueReqData
1363
1362
= CQRMessaging (Maybe (CQRData (SMP. SenderId , QueueLinkData )))
@@ -1374,21 +1373,21 @@ queueReqData = \case
1374
1373
CQRMessaging d -> QRMessaging $ srvReq <$> d
1375
1374
CQRContact d -> QRContact $ srvReq <$> d
1376
1375
1377
- newRcvQueue_ :: AgentClient -> NetworkRequestMode -> UserId -> ConnId -> SMPServerWithAuth -> VersionRangeSMPC -> ClntQueueReqData -> SubscriptionMode -> Maybe C. CbNonce -> C. KeyPairX25519 -> AM (NewRcvQueue , SMPQueueUri , SMPTransportSession , SessionId )
1378
- newRcvQueue_ c nm userId connId (ProtoServerWithAuth srv auth) vRange cqrd subMode nonce_ (e2eDhKey, e2ePrivKey) = do
1376
+ newRcvQueue_ :: AgentClient -> NetworkRequestMode -> UserId -> ConnId -> SMPServerWithAuth -> VersionRangeSMPC -> ClntQueueReqData -> Bool -> SubscriptionMode -> Maybe C. CbNonce -> C. KeyPairX25519 -> AM (NewRcvQueue , SMPQueueUri , SMPTransportSession , SessionId )
1377
+ newRcvQueue_ c nm userId connId (ProtoServerWithAuth srv auth) vRange cqrd enableNtfs subMode nonce_ (e2eDhKey, e2ePrivKey) = do
1379
1378
C. AuthAlg a <- asks (rcvAuthAlg . config)
1380
1379
g <- asks random
1381
1380
rKeys@ (_, rcvPrivateKey) <- atomically $ C. generateAuthKeyPair a g
1382
1381
(dhKey, privDhKey) <- atomically $ C. generateKeyPair g
1383
1382
logServer " -->" c srv NoEntity " NEW"
1384
1383
tSess <- mkTransportSession c userId srv connId
1385
- -- TODO [notifications]
1386
- r @ (thParams', QIK {rcvId, sndId, rcvPublicDhKey, queueMode, serviceId}) <-
1387
- withClient c nm tSess $ \ ( SMPConnectedClient smp _) ->
1388
- (thParams smp,) <$> createSMPQueue smp nm nonce_ rKeys dhKey auth subMode (queueReqData cqrd)
1384
+ (thParams', ntfKeys, qik @ QIK {rcvId, sndId, rcvPublicDhKey, queueMode, serviceId, serverNtfCreds}) <-
1385
+ withClient c nm tSess $ \ ( SMPConnectedClient smp _) -> do
1386
+ (ntfKeys, ntfCreds) <- liftIO $ mkNtfCreds a g smp
1387
+ (thParams smp,ntfKeys, ) <$> createSMPQueue smp nm nonce_ rKeys dhKey auth subMode (queueReqData cqrd) ntfCreds
1389
1388
-- TODO [certs rcv] validate that serviceId is the same as in the client session
1390
1389
liftIO . logServer " <--" c srv NoEntity $ B. unwords [" IDS" , logSecret rcvId, logSecret sndId]
1391
- shortLink <- mkShortLinkCreds r
1390
+ shortLink <- mkShortLinkCreds thParams' qik
1392
1391
let rq =
1393
1392
RcvQueue
1394
1393
{ userId,
@@ -1409,14 +1408,26 @@ newRcvQueue_ c nm userId connId (ProtoServerWithAuth srv auth) vRange cqrd subMo
1409
1408
dbReplaceQueueId = Nothing ,
1410
1409
rcvSwchStatus = Nothing ,
1411
1410
smpClientVersion = maxVersion vRange,
1412
- clientNtfCreds = Nothing ,
1411
+ clientNtfCreds = mkClientNtfCreds ntfKeys serverNtfCreds ,
1413
1412
deleteErrors = 0
1414
1413
}
1415
1414
qUri = SMPQueueUri vRange $ SMPQueueAddress srv sndId e2eDhKey queueMode
1416
1415
pure (rq, qUri, tSess, sessionId thParams')
1417
1416
where
1418
- mkShortLinkCreds :: (THandleParams SMPVersion 'TClient, QueueIdsKeys ) -> AM (Maybe ShortLinkCreds )
1419
- mkShortLinkCreds (thParams', QIK {sndId, queueMode, linkId}) = case (cqrd, queueMode) of
1417
+ mkNtfCreds :: (C. AlgorithmI a , C. AuthAlgorithm a ) => C. SAlgorithm a -> TVar ChaChaDRG -> SMPClient -> IO (Maybe (C. AAuthKeyPair , C. PrivateKeyX25519 ), Maybe NewNtfCreds )
1418
+ mkNtfCreds a g smp
1419
+ | enableNtfs && thVersion (thParams smp) >= newNtfCredsSMPVersion = do
1420
+ authKeys@ (k, _) <- atomically $ C. generateAuthKeyPair a g
1421
+ (dhk, dhpk) <- atomically $ C. generateKeyPair g
1422
+ pure (Just (authKeys, dhpk), Just $ NewNtfCreds k dhk)
1423
+ | otherwise = pure (Nothing , Nothing )
1424
+ mkClientNtfCreds :: Maybe (C. AAuthKeyPair , C. PrivateKeyX25519 ) -> Maybe ServerNtfCreds -> Maybe ClientNtfCreds
1425
+ mkClientNtfCreds ntfKeys serverNtfCreds = case (ntfKeys, serverNtfCreds) of
1426
+ (Just ((ntfPublicKey, ntfPrivateKey), dhpk), Just (ServerNtfCreds notifierId dhk')) ->
1427
+ Just ClientNtfCreds {ntfPublicKey, ntfPrivateKey, notifierId, rcvNtfDhSecret = C. dh' dhk' dhpk}
1428
+ _ -> Nothing
1429
+ mkShortLinkCreds :: THandleParams SMPVersion 'TClient -> QueueIdsKeys -> AM (Maybe ShortLinkCreds )
1430
+ mkShortLinkCreds thParams' QIK {sndId, queueMode, linkId} = case (cqrd, queueMode) of
1420
1431
(CQRMessaging ld, Just QMMessaging ) ->
1421
1432
withLinkData ld $ \ lnkId CQRData {linkKey, privSigKey, srvReq = (sndId', d)} ->
1422
1433
if sndId == sndId'
@@ -1807,7 +1818,7 @@ getQueueInfo c nm rq@RcvQueue {server, rcvId, rcvPrivateKey, sndId, status, clie
1807
1818
where
1808
1819
enc = decodeLatin1 . B64. encode . unEntityId
1809
1820
1810
- agentNtfRegisterToken :: AgentClient -> NetworkRequestMode -> NtfToken -> NtfPublicAuthKey -> C. PublicKeyX25519 -> AM (NtfTokenId , C. PublicKeyX25519 )
1821
+ agentNtfRegisterToken :: AgentClient -> NetworkRequestMode -> NtfToken -> SMP. NtfPublicAuthKey -> C. PublicKeyX25519 -> AM (NtfTokenId , C. PublicKeyX25519 )
1811
1822
agentNtfRegisterToken c nm NtfToken {deviceToken, ntfServer, ntfPrivKey} ntfPubKey pubDhKey =
1812
1823
withClient c nm (0 , ntfServer, Nothing ) $ \ ntf -> ntfRegisterToken ntf nm ntfPrivKey (NewNtfTkn deviceToken ntfPubKey pubDhKey)
1813
1824
0 commit comments