mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-08-29 07:48:25 +00:00
all tests pass!
This commit is contained in:
@@ -253,7 +253,7 @@ newRcvQueue_ a c srv = do
|
||||
rcvSrvVerifyKey,
|
||||
rcvDhSecret,
|
||||
sndId = Just sndId,
|
||||
sndSrvVerifyKey = Just sndSrvVerifyKey,
|
||||
sndSrvVerifyKey = sndSrvVerifyKey,
|
||||
decryptKey,
|
||||
verifyKey = Nothing,
|
||||
status = New
|
||||
|
||||
@@ -87,7 +87,7 @@ data RcvQueue = RcvQueue
|
||||
-- | sender queue ID
|
||||
sndId :: Maybe SMP.SenderId,
|
||||
-- | key used by the sender to sign transmissions
|
||||
sndSrvVerifyKey :: Maybe SndPublicVerifyKey,
|
||||
sndSrvVerifyKey :: SndPublicVerifyKey,
|
||||
-- | TODO keys used for E2E encryption - these will change with double ratchet
|
||||
decryptKey :: C.APrivateDecryptKey,
|
||||
verifyKey :: Maybe C.APublicVerifyKey,
|
||||
|
||||
@@ -76,6 +76,7 @@ module Simplex.Messaging.Crypto
|
||||
|
||||
-- * DH derivation
|
||||
dh',
|
||||
dhSecret,
|
||||
|
||||
-- * AES256 AEAD-GCM scheme
|
||||
Key (..),
|
||||
@@ -372,14 +373,17 @@ class CryptoDhSecret s where
|
||||
strDhSecretP :: Parser s
|
||||
dhSecretP :: Parser s
|
||||
|
||||
instance AlgorithmI a => IsString (DhSecret a) where
|
||||
fromString = parseString $ dhSecret >=> dhSecret'
|
||||
|
||||
instance CryptoDhSecret ADhSecret where
|
||||
serializeDhSecret (ADhSecret _ s) = serializeDhSecret s
|
||||
dhSecretBytes (ADhSecret _ s) = dhSecretBytes s
|
||||
strDhSecretP = dhSecret_ <$?> base64P
|
||||
dhSecretP = dhSecret_ <$?> A.takeByteString
|
||||
strDhSecretP = dhSecret <$?> base64P
|
||||
dhSecretP = dhSecret <$?> A.takeByteString
|
||||
|
||||
dhSecret_ :: ByteString -> Either String ADhSecret
|
||||
dhSecret_ = cryptoPassed . secret
|
||||
dhSecret :: ByteString -> Either String ADhSecret
|
||||
dhSecret = cryptoPassed . secret
|
||||
where
|
||||
secret bs
|
||||
| B.length bs == x25519_size = ADhSecret SX25519 . DhSecretX25519 <$> X25519.dhSecret bs
|
||||
|
||||
@@ -271,7 +271,7 @@ client clnt@Client {subscriptions, ntfSubscriptions, rcvQ, sndQ = sndQ'} Server
|
||||
addQueueRetry n qik qRec = do
|
||||
ids@(rId, _) <- getIds
|
||||
-- create QueueRec record with these ids and keys
|
||||
atomically (addQueue' st $ qRec ids) >>= \case
|
||||
atomically (addQueue st $ qRec ids) >>= \case
|
||||
Left DUPLICATE_ -> addQueueRetry (n - 1) qik qRec
|
||||
Left e -> pure $ ERR e
|
||||
Right _ -> do
|
||||
|
||||
@@ -22,21 +22,9 @@ data QueueRec = QueueRec
|
||||
data QueueStatus = QueueActive | QueueOff deriving (Eq)
|
||||
|
||||
class MonadQueueStore s m where
|
||||
addQueue :: s -> RcvPublicVerifyKey -> (RecipientId, SenderId) -> m (Either ErrorType ())
|
||||
addQueue' :: s -> QueueRec -> m (Either ErrorType ())
|
||||
addQueue :: s -> QueueRec -> m (Either ErrorType ())
|
||||
getQueue :: s -> SParty (a :: Party) -> QueueId -> m (Either ErrorType QueueRec)
|
||||
secureQueue :: s -> RecipientId -> SndPublicVerifyKey -> m (Either ErrorType ())
|
||||
addQueueNotifier :: s -> RecipientId -> NotifierId -> NtfPublicVerifyKey -> m (Either ErrorType ())
|
||||
suspendQueue :: s -> RecipientId -> m (Either ErrorType ())
|
||||
deleteQueue :: s -> RecipientId -> m (Either ErrorType ())
|
||||
|
||||
mkQueueRec :: RcvPublicVerifyKey -> (RecipientId, SenderId) -> QueueRec
|
||||
mkQueueRec recipientKey (recipientId, senderId) =
|
||||
QueueRec
|
||||
{ recipientId,
|
||||
senderId,
|
||||
recipientKey,
|
||||
senderKey = Nothing,
|
||||
notifier = Nothing,
|
||||
status = QueueActive
|
||||
}
|
||||
|
||||
@@ -29,21 +29,8 @@ newQueueStore :: STM QueueStore
|
||||
newQueueStore = newTVar QueueStoreData {queues = M.empty, senders = M.empty, notifiers = M.empty}
|
||||
|
||||
instance MonadQueueStore QueueStore STM where
|
||||
addQueue :: QueueStore -> RcvPublicVerifyKey -> (RecipientId, SenderId) -> STM (Either ErrorType ())
|
||||
addQueue store rKey ids@(rId, sId) = do
|
||||
cs@QueueStoreData {queues, senders} <- readTVar store
|
||||
if M.member rId queues || M.member sId senders
|
||||
then return $ Left DUPLICATE_
|
||||
else do
|
||||
writeTVar store $
|
||||
cs
|
||||
{ queues = M.insert rId (mkQueueRec rKey ids) queues,
|
||||
senders = M.insert sId rId senders
|
||||
}
|
||||
return $ Right ()
|
||||
|
||||
addQueue' :: QueueStore -> QueueRec -> STM (Either ErrorType ())
|
||||
addQueue' store qRec@QueueRec {recipientId = rId, senderId = sId} = do
|
||||
addQueue :: QueueStore -> QueueRec -> STM (Either ErrorType ())
|
||||
addQueue store qRec@QueueRec {recipientId = rId, senderId = sId} = do
|
||||
cs@QueueStoreData {queues, senders} <- readTVar store
|
||||
if M.member rId queues || M.member sId senders
|
||||
then return $ Left DUPLICATE_
|
||||
|
||||
Reference in New Issue
Block a user