ntf server: fix repeat token registration when it became invalid (regression) (#1539)

This commit is contained in:
Evgeny
2025-05-15 19:56:48 +01:00
committed by GitHub
parent cf4b9f669d
commit b90e25a3a5
3 changed files with 27 additions and 10 deletions

View File

@@ -536,6 +536,15 @@ data NtfTknStatus
NTExpired
deriving (Eq, Show)
allowTokenVerification :: NtfTknStatus -> Bool
allowTokenVerification = \case
NTNew -> False
NTRegistered -> True
NTInvalid _ -> False
NTConfirmed -> True
NTActive -> True
NTExpired -> False
allowNtfSubCommands :: NtfTknStatus -> Bool
allowNtfSubCommands = \case
NTNew -> False

View File

@@ -5,6 +5,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedLists #-}
@@ -729,14 +730,17 @@ client NtfServerClient {rcvQ, sndQ} NtfSubscriber {newSubQ, smpAgent = ca} NtfPu
logDebug "TNEW - registered token"
let dhSecret = C.dh' dhPubKey tknDhPrivKey
-- it is required that DH secret is the same, to avoid failed verifications if notification is delaying
if tknDhSecret == dhSecret
then do
if
| tknDhSecret /= dhSecret -> pure $ NRErr AUTH
| allowTokenVerification tknStatus -> sendVerification
| otherwise -> withNtfStore (\st -> updateTknStatus st tkn NTRegistered) $ \_ -> sendVerification
where
sendVerification = do
atomically $ writeTBQueue pushQ (tkn, PNVerification tknRegCode)
incNtfStatT token ntfVrfQueued
pure $ NRTknId ntfTknId $ C.publicKey tknDhPrivKey
else pure $ NRErr AUTH
TVFY code -- this allows repeated verification for cases when client connection dropped before server response
| (tknStatus == NTRegistered || tknStatus == NTConfirmed || tknStatus == NTActive) && tknRegCode == code -> do
| allowTokenVerification tknStatus && tknRegCode == code -> do
logDebug "TVFY - token verified"
withNtfStore (`setTokenActive` tkn) $ \_ -> NROk <$ incNtfStatT token tknVerified
| otherwise -> do