mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-08-28 02:54:51 +00:00
all tests pass!
This commit is contained in:
@@ -11,8 +11,11 @@ CREATE TABLE IF NOT EXISTS rcv_queues(
|
||||
rcv_id BLOB NOT NULL,
|
||||
conn_alias BLOB NOT NULL,
|
||||
rcv_private_key BLOB NOT NULL,
|
||||
snd_id BLOB,
|
||||
rcv_srv_verify_key BLOB NOT NULL,
|
||||
rcv_dh_secret BLOB NOT NULL,
|
||||
snd_id BLOB NOT NULL,
|
||||
snd_key BLOB,
|
||||
snd_srv_verify_key BLOB NOT NULL,
|
||||
decrypt_key BLOB NOT NULL,
|
||||
verify_key BLOB,
|
||||
status TEXT NOT NULL,
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
ALTER TABLE rcv_queues ADD rcv_srv_verify_key BLOB NOT NULL;
|
||||
ALTER TABLE rcv_queues ADD rcv_dh_secret BLOB NOT NULL;
|
||||
ALTER TABLE rcv_queues ADD snd_srv_verify_key BLOB NOT NULL;
|
||||
@@ -30,7 +30,6 @@ extra-source-files:
|
||||
migrations/20210624_confirmations.sql
|
||||
migrations/20210809_snd_messages.sql
|
||||
migrations/20211202_connection_mode.sql
|
||||
migrations/20211212_rcv_queue_keys.sql
|
||||
migrations/README.md
|
||||
|
||||
library
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -152,11 +152,20 @@ cData1 = ConnData {connId = "conn1"}
|
||||
testPrivateSignKey :: C.APrivateSignKey
|
||||
testPrivateSignKey = C.APrivateSignKey C.SRSA testPrivateKey
|
||||
|
||||
testPublicVerifyKey :: C.APublicVerifyKey
|
||||
testPublicVerifyKey = C.APublicVerifyKey C.SRSA testPublicKey
|
||||
|
||||
testPrivateDecryptKey :: C.APrivateDecryptKey
|
||||
testPrivateDecryptKey = C.APrivateDecryptKey C.SRSA testPrivateKey
|
||||
|
||||
testPublicEncryptKey :: C.APublicEncryptKey
|
||||
testPublicEncryptKey = C.APublicEncryptKey C.SRSA $ C.PublicKeyRSA $ R.PublicKey 1 2 3
|
||||
testPublicEncryptKey = C.APublicEncryptKey C.SRSA testPublicKey
|
||||
|
||||
testPublicKey :: C.PublicKey 'C.RSA
|
||||
testPublicKey = C.PublicKeyRSA $ R.PublicKey 1 2 3
|
||||
|
||||
testDhSecret :: C.DhSecret 'C.X25519
|
||||
testDhSecret = "01234567890123456789012345678901"
|
||||
|
||||
testPrivateKey :: C.PrivateKey 'C.RSA
|
||||
testPrivateKey =
|
||||
@@ -182,7 +191,10 @@ rcvQueue1 =
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") testKeyHash,
|
||||
rcvId = "1234",
|
||||
rcvPrivateKey = testPrivateSignKey,
|
||||
rcvSrvVerifyKey = testPublicVerifyKey,
|
||||
rcvDhSecret = testDhSecret,
|
||||
sndId = Just "2345",
|
||||
sndSrvVerifyKey = testPublicVerifyKey,
|
||||
decryptKey = testPrivateDecryptKey,
|
||||
verifyKey = Nothing,
|
||||
status = New
|
||||
@@ -354,7 +366,10 @@ testUpgradeSndConnToDuplex =
|
||||
{ server = SMPServer "smp.simplex.im" (Just "5223") testKeyHash,
|
||||
rcvId = "3456",
|
||||
rcvPrivateKey = testPrivateSignKey,
|
||||
rcvSrvVerifyKey = testPublicVerifyKey,
|
||||
rcvDhSecret = testDhSecret,
|
||||
sndId = Just "4567",
|
||||
sndSrvVerifyKey = testPublicVerifyKey,
|
||||
decryptKey = testPrivateDecryptKey,
|
||||
verifyKey = Nothing,
|
||||
status = New
|
||||
|
||||
+1
-1
@@ -15,5 +15,5 @@ main = do
|
||||
describe "Protocol errors" protocolErrorTests
|
||||
describe "SMP server via TCP" $ serverTests (transport @TCP)
|
||||
describe "SMP server via WebSockets" $ serverTests (transport @WS)
|
||||
xdescribe "SMP client agent" $ agentTests (transport @TCP)
|
||||
describe "SMP client agent" $ agentTests (transport @TCP)
|
||||
removeDirectoryRecursive "tests/tmp"
|
||||
|
||||
Reference in New Issue
Block a user