agent: authorize sender commands with X25519 keys (#2054)

* agent: authorize sender commands with X25519 keys

* tests: check that new sender keys are X25519

* docs: sender command authorization in the crypto registry
This commit is contained in:
Evgeny @ SimpleX Chat authored and GitHub committed 2026-11-13 06:59:41 +00:00
1 parent 528479789c
commit e8c7b01d3f
5 files changed
+25 -9

No files matched your search

+3 -2
View File
@@ -40,6 +40,7 @@ Status values used below:
| Purpose | Default | Functions |
|---|---|---|
| Signature | Ed25519 | `C.sign'`, `C.verify'` with `C.SEd25519` |
| Sender command authorization | crypto_box authenticator over X25519 queue keys | `C.cbAuthenticate`, `C.cbVerify`; agent `sndAuthAlg` |
| Key agreement | X25519 | `C.generateKeyPair`, `C.dh'` |
| Post-quantum KEM | sntrup761 | `KEM.sntrup761Keypair`, `sntrup761Enc`, `sntrup761Dec` |
| Hybrid DH + KEM secret | HKDF-SHA512 over `dh \|\| kemSecret` with a new info string, as in `CR.rootKdf` | `C.hkdf` |
@@ -55,14 +56,14 @@ Status values used below:
| Primitive | Status | Purpose and protocol | Implementation | Lengths |
|---|---|---|---|---|
| Ed25519 | Default | SMP/NTF/XFTP queue and file keys (agent default `rcvAuthAlg`, `sndAuthAlg` in [Agent/Env/SQLite.hs](../src/Simplex/Messaging/Agent/Env/SQLite.hs)), short-link signatures and owner auth (`SL.encodeSign`, `SL.newOwnerAuth`), XRCP identity and session keys ([RemoteControl/Invitation.hs](../src/Simplex/RemoteControl/Invitation.hs)), agent service request signatures, client/service TLS certificates ([Transport/Credentials.hs](../src/Simplex/Messaging/Transport/Credentials.hs)) | crypton `Crypto.PubKey.Ed25519` via `C.sign'`/`C.verify'` | pub 32, priv 32, sig 64; X.509 SPKI 44 |
| Ed25519 | Default | SMP recipient and notifier keys, NTF token keys, XFTP file keys (agent default `rcvAuthAlg` in [Agent/Env/SQLite.hs](../src/Simplex/Messaging/Agent/Env/SQLite.hs)), short-link signatures and owner auth (`SL.encodeSign`, `SL.newOwnerAuth`), XRCP identity and session keys ([RemoteControl/Invitation.hs](../src/Simplex/RemoteControl/Invitation.hs)), agent service request signatures, client/service TLS certificates ([Transport/Credentials.hs](../src/Simplex/Messaging/Transport/Credentials.hs)) | crypton `Crypto.PubKey.Ed25519` via `C.sign'`/`C.verify'` | pub 32, priv 32, sig 64; X.509 SPKI 44 |
| Ed448 | Approved | Server CA and online certificates (default `signAlgorithm = ED448` in [Server/CLI.hs](../src/Simplex/Messaging/Server/CLI.hs)); accepted for SMP command signatures and TLS | crypton `Crypto.PubKey.Ed448`; server key generation by the `openssl genpkey` CLI | pub 57, priv 57, sig 114; SPKI 69 |
| X25519 | Default | Per-queue e2e and server-to-recipient `crypto_box` keys, SMP session DH, command authenticator (SMP v7+), proxy (PRXY/PFWD), notification tokens, XFTP chunk transport, XRCP hello and announcements | crypton `Crypto.PubKey.Curve25519` via `C.dh'` | pub 32, priv 32, secret 32; SPKI 44 |
| X448 | Restricted | E2E double ratchet only: X3DH and DH ratchet (`CR.RatchetX448`, E2E v3) | crypton `Crypto.PubKey.Curve448` | pub 56, priv 56, secret 56 |
| sntrup761 | Default | PQ KEM in double ratchet (E2E v3, agent v5+) and XRCP v1 hello | Vendored C [cbits/sntrup761.c](../cbits/sntrup761.c) via FFI; randomness from ChaChaDRG through `haskell_rng_func` ([Bindings/RNG.hs](../src/Simplex/Messaging/Crypto/SNTRUP761/Bindings/RNG.hs)) | pk 1158, sk 1763, ct 1039, shared 32 |
| XSalsa20-Poly1305, SimpleX crypto_box | Default | SMP message bodies (server to recipient), per-queue e2e envelope, confirmations, proxy forwarding, notifications, XRCP hello, XFTP chunk transport | crypton `Crypto.Cipher.XSalsa`, `Crypto.MAC.Poly1305`; `C.cryptoBox`, `LC.cbInit` | key 32 (DH secret), nonce 24, tag 16 |
| XSalsa20-Poly1305, SimpleX secretbox | Default | SMP transport block encryption (SMP v11+), short-link data (SMP v15+), XFTP file encryption, local file encryption ([Crypto/File.hs](../src/Simplex/Messaging/Crypto/File.hs)), XRCP session | same; `C.sbEncrypt`, `LC.sbEncryptTailTag`, `LC.sbInit` | key 32, nonce 24, tag 16 |
| crypto_box authenticator | Approved | Deniable sender command authorization with X25519 queue keys (SMP v7+); agent currently creates Ed25519 keys | `C.cbAuthenticate`, `C.cbVerify`: `crypto_box(sha512(msg))` | 80 = 64 + 16 |
| crypto_box authenticator | Default | Deniable sender command authorization with X25519 queue keys (SMP v7+, agent default `sndAuthAlg`) | `C.cbAuthenticate`, `C.cbVerify`: `crypto_box(sha512(msg))` | 80 = 64 + 16 |
| AES-256-GCM, 16-byte IV | Legacy-only | Double ratchet header and body (E2E v3, [pqdr.md](./pqdr.md)) | crypton `Crypto.Cipher.AES`, `Crypto.Cipher.Types`; `C.encryptAEAD`, `C.decryptAEAD`, `C.initAEAD`; J0 = GHASH(IV) as NIST SP 800-38D defines for non-96-bit IVs | key 32, IV 16, tag 16; padded header 88 (PQ off) or 2310 (PQ on), `CR.paddedHeaderLen` |
| AES-256-GCM, 12-byte IV | Restricted | WebRTC frame encryption in simplex-chat (`Simplex.Chat.Mobile.WebRTC`), for WebCrypto interoperability | `C.encryptAESNoPad`, `C.decryptAESNoPad`, `C.initAEADGCM`, `C.GCMIV` | key 32, IV 12, tag 16 |
| HKDF-SHA512 | Default | All KDFs listed in [Domain separation](#domain-separation-and-kdf-inputs) | crypton `Crypto.KDF.HKDF` with `SHA512`; `C.hkdf` (extract + expand) | output per use, at most 255 * 64 |
+1 -1
View File
@@ -392,7 +392,7 @@ Simplex messaging clients must cryptographically authorize commands for the foll
To authorize/verify transmissions clients and routers MUST use either signature algorithm Ed25519 algorithm defined in [RFC8709][15] or [deniable authentication scheme](#deniable-client-authentication-scheme) based on NaCL crypto_box.
It is recommended that clients use signature algorithm for the recipient commands and deniable authentication scheme for sender commands (to have non-repudiation quality in the whole protocol stack).
It is recommended that clients use signature algorithm for the recipient commands and deniable authentication scheme for sender commands (to have repudiation quality in the whole protocol stack).
To encrypt/decrypt message bodies delivered to the recipients, routers/clients MUST use NaCL crypto_box.
+2 -1
View File
@@ -1322,11 +1322,12 @@ getConnShortLink' :: forall c. AgentClient -> NetworkRequestMode -> UserId -> Co
getConnShortLink' c nm userId = \case
CSLInvitation _ srv linkId linkKey -> do
g <- asks random
C.AuthAlg a <- asks $ sndAuthAlg . config
invLink <- withStore' c $ \db -> do
getInvShortLink db srv linkId >>= \case
Just sl@InvShortLink {linkKey = lk} | linkKey == lk -> pure sl
_ -> do
sndPrivateKey <- atomically $ C.generatePrivateAuthKey C.SEd25519 g
sndPrivateKey <- atomically $ C.generatePrivateAuthKey a g
let sl = InvShortLink {server = srv, linkId, linkKey, sndPrivateKey, sndId = Nothing}
createInvShortLink db sl
pure sl
+1 -3
View File
@@ -222,10 +222,8 @@ defaultAgentConfig :: AgentConfig
defaultAgentConfig =
AgentConfig
{ tcpPort = Just "5224",
-- while the current client version supports X25519, it can only be enabled once support for SMP v6 is dropped,
-- and all servers are required to support v7 to be compatible.
rcvAuthAlg = C.AuthAlg C.SEd25519, -- this will stay as Ed25519
sndAuthAlg = C.AuthAlg C.SEd25519, -- TODO replace with X25519 when switching to v7
sndAuthAlg = C.AuthAlg C.SX25519,
connIdBytes = 12,
tbqSize = 128,
smpCfg = defaultSMPClientConfig,
+18 -2
View File
@@ -96,7 +96,7 @@ import Simplex.Messaging.Agent.Client (AgentOpState (..), ProtocolTestFailure (.
import Simplex.Messaging.Agent.Env.SQLite (AgentConfig (..), Env (..), InitialAgentServers (..), createAgentStore)
import Simplex.Messaging.Agent.Protocol hiding (CON, CONF, INFO, REQ, SENT)
import qualified Simplex.Messaging.Agent.Protocol as A
import Simplex.Messaging.Agent.Store (Connection' (..), SomeConn' (..), StoredRcvQueue (..))
import Simplex.Messaging.Agent.Store (Connection' (..), SomeConn' (..), StoredRcvQueue (..), StoredSndQueue (..))
import Simplex.Messaging.Agent.Store.AgentStore (deleteRatchetKeyHashesExpired, getConn, getConnIds, getRatchetX3dhKeys)
import Simplex.Messaging.Agent.Store.Common (DBStore (..), withTransaction)
import Simplex.Messaging.Agent.Store.Interface
@@ -347,6 +347,8 @@ functionalAPITests ps = do
withSmpServer ps testJoinUsedInvitation
it "should refuse confirmation with client version below the version of its agent" $
withSmpServer ps testConfClientVersionBelowAgentVersion
it "should create X25519 sender keys" $
withSmpServer ps testX25519SndKeys
describe "Duplex connection - delivery stress test" $ do
describe "one way (50)" $ testMatrix2Stress ps $ runAgentClientStressTestOneWay 50
xdescribe "one way (1000)" $ testMatrix2Stress ps $ runAgentClientStressTestOneWay 1000
@@ -961,6 +963,18 @@ testConfClientVersionBelowAgentVersion =
_ <- A.joinConnection bob NRMInteractive 1 aliceId True qInfo "bob's connInfo" PQSupportOn SMSubscribe
get alice =##> \case ("", c, ERR (AGENT A_VERSION)) -> c == bobId; _ -> False
testX25519SndKeys :: (HasCallStack, HasTestEnv) => IO ()
testX25519SndKeys =
withAgentClients2 $ \alice bob -> do
(aliceId, bobId) <- runRight $ makeConnection alice bob
checkX25519SndKey alice bobId
checkX25519SndKey bob aliceId
checkX25519SndKey :: AgentClient -> ConnId -> IO ()
checkX25519SndKey c connId = do
Right (SomeConn _ (DuplexConnection _ _ (SndQueue {sndPrivateKey = C.APrivateAuthKey C.SX25519 _} :| _))) <- withTransaction (store $ agentEnv c) (`getConn` connId)
pure ()
testEnablePQEncryption :: (HasCallStack, HasTestEnv) => IO ()
testEnablePQEncryption =
withAgentClients2 $ \ca cb -> runRight_ $ do
@@ -1898,6 +1912,7 @@ testJoinConn_ viaProxy sndSecure a bId b connReq = do
get a ##> ("", bId, CON)
get b ##> ("", aId, INFO "alice's connInfo")
get b ##> ("", aId, CON)
liftIO $ checkX25519SndKey b aId
exchangeGreetingsViaProxy viaProxy a bId b aId
testInvitationShortLinkAsync :: HasCallStack => Bool -> AgentClient -> AgentClient -> IO ()
@@ -4537,7 +4552,8 @@ testDeliveryReceiptsConcurrent (t, msType) =
appVersionsCfg :: HasTestEnv => (Word16, Word16) -> (Word16, Word16) -> (Word16, Word16) -> AgentConfig
appVersionsCfg (a1, a2) (c1, c2) (e1, e2) =
agentCfg
{ smpAgentVRange = mkVersionRange a1 a2,
{ sndAuthAlg = C.AuthAlg C.SEd25519,
smpAgentVRange = mkVersionRange a1 a2,
smpClientVRange = mkVersionRange c1 c2,
e2eEncryptVRange = mkVersionRange e1 e2
}