mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-11-12 00:48:04 +00:00
* crypto: Ethereum primitives for SimpleX names secp256k1 (vendored libsecp256k1 v0.8.0, recoverable ECDSA), BIP-39 mnemonics, BIP-32 derivation, Keccak-256, EIP-55 addresses and EIP-712 typed data hashing. Client-side signing only: no RLP, no transaction construction, no chain writes. The resolver path stays read-only. Verified against published vectors — the 24 official BIP-39 English vectors, BIP-32 spec vectors 1 and 2, the EIP-55 spec addresses and the EIP-712 Mail example. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * tiny fixes * plan update * expose what's necessary for stealth addresses too" * add string encoding * streamline hex encoding * core: ethereumPath takes the address index The BIP-44 path is the same for every address under an account, so the caller that wants one names it, rather than rebuilding the path around the one this hard-coded. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rvc3HbiWBTqbAvRT45G5oX * core: embed the BIP-39 wordlist as the upstream file The list was transcoded into Haskell, which can only be audited by reading 2048 words against the source. The upstream english.txt is vendored instead and embedded at compile time, so auditing it is one sha256sum, and a test pins that checksum so the copy cannot drift. file-embed moves into the library, where it was already a dependency of the executables and the test suite. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rvc3HbiWBTqbAvRT45G5oX * review fixes * fix review findings iterate self-reviews with /goal * next review round * cut to the min * cut comments * streamline * Update src/Simplex/Messaging/Crypto/BIP32.hs Co-authored-by: Evgeny <evgeny@poberezkin.com> * Update CHANGELOG.md Co-authored-by: Evgeny <evgeny@poberezkin.com> * Update src/Simplex/Messaging/Crypto/BIP32.hs Co-authored-by: Evgeny <evgeny@poberezkin.com> * Update src/Simplex/Messaging/Crypto/Secp256k1.hs Co-authored-by: Evgeny <evgeny@poberezkin.com> * Update src/Simplex/Messaging/Crypto/Secp256k1.hs Co-authored-by: Evgeny <evgeny@poberezkin.com> * opus 5.5 /goal iterations * self-review rounds * self-review iteration 2 * self-review iteration 3 * self-review iteration 3ff * self-review iteration 3fff * self-review iteration 5 * more doc tweaks * self-review iteration 9 * self-review iteration 10 * wip * rng preserve * finish wip and factor in test vectors * make wallet creation and account derivation infallible like trezor does * review iterations * limit derivation retries to 3 * remove unnecessary export * random * security, simplify, imports * use static context * fix test * restore public api to use rng * back to IO --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> Co-authored-by: Evgeny <evgeny@poberezkin.com>
208 lines
9.4 KiB
Haskell
208 lines
9.4 KiB
Haskell
{-# LANGUAGE CPP #-}
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
{-# LANGUAGE TypeApplications #-}
|
|
|
|
import AgentTests (agentCoreTests, agentTests)
|
|
import CLITests
|
|
import Control.Concurrent (threadDelay)
|
|
import qualified Control.Exception as E
|
|
import Control.Logger.Simple
|
|
import CoreTests.BatchingTests
|
|
import CoreTests.CryptoFileTests
|
|
import CoreTests.CryptoTests
|
|
import CoreTests.EncodingTests
|
|
import CoreTests.EthCryptoTests
|
|
import CoreTests.MsgStoreTests
|
|
import CoreTests.RetryIntervalTests
|
|
import CoreTests.SOCKSSettings
|
|
import CoreTests.StoreLogTests
|
|
import CoreTests.TSessionSubs
|
|
import CoreTests.UtilTests
|
|
import CoreTests.VersionRangeTests
|
|
import FileDescriptionTests (fileDescriptionTests)
|
|
import GHC.IO.Exception (IOException (..))
|
|
import qualified GHC.IO.Exception as IOException
|
|
import RSLVTests (rslvTests)
|
|
import RemoteControl (remoteControlTests)
|
|
import SMPNamesTests (smpNamesTests)
|
|
import SMPProxyTests (smpProxyTests)
|
|
import ServerTests
|
|
import Simplex.Messaging.Server.Env.STM (AStoreType (..))
|
|
import Simplex.Messaging.Server.MsgStore.Types (SMSType (..), SQSType (..))
|
|
import Simplex.Messaging.Transport (TLS, Transport (..))
|
|
-- import Simplex.Messaging.Transport.WebSockets (WS)
|
|
import System.Directory (createDirectoryIfMissing, removeDirectoryRecursive)
|
|
import System.Environment (setEnv)
|
|
import Test.Hspec hiding (fit, it)
|
|
import Util
|
|
import XFTPAgent
|
|
import XFTPCLI (xftpCLIFileTests)
|
|
import Simplex.FileTransfer.Server.Env (AFStoreType (..))
|
|
import Simplex.FileTransfer.Server.Store (SFSType (..))
|
|
import XFTPServerTests (xftpServerTests)
|
|
import WebTests (webTests)
|
|
import XFTPWebTests (xftpWebTests)
|
|
|
|
#if defined(dbPostgres)
|
|
import Fixtures
|
|
import SMPAgentClient (testDB)
|
|
import Simplex.Messaging.Agent.Store.Postgres.Migrations.App
|
|
import Simplex.Messaging.Agent.Store.Postgres.Util (dropAllSchemasExceptSystem)
|
|
#else
|
|
import AgentTests.SchemaDump (schemaDumpTest)
|
|
#endif
|
|
|
|
#if defined(dbServerPostgres)
|
|
import CoreTests.XFTPStoreTests (xftpStoreTests, xftpMigrationTests)
|
|
import NtfServerTests (ntfServerTests)
|
|
import NtfClient (ntfTestServerDBConnectInfo, ntfTestStoreDBOpts)
|
|
import SMPClient (testServerDBConnectInfo, testStoreDBOpts)
|
|
import Simplex.Messaging.Notifications.Server.Store.Migrations (ntfServerMigrations)
|
|
import Simplex.Messaging.Server.QueueStore.Postgres.Migrations (serverMigrations)
|
|
import XFTPClient (testXFTPDBConnectInfo)
|
|
#endif
|
|
|
|
#if defined(dbPostgres) || defined(dbServerPostgres)
|
|
import PostgresSchemaDump (postgresSchemaDumpTest)
|
|
import SMPClient (postgressBracket)
|
|
#endif
|
|
|
|
logCfg :: LogConfig
|
|
logCfg = LogConfig {lc_file = Nothing, lc_stderr = True}
|
|
|
|
main :: IO ()
|
|
main = do
|
|
setLogLevel testLogLevel
|
|
withGlobalLogging logCfg $ do
|
|
setEnv "APNS_KEY_ID" "H82WD9K9AQ"
|
|
setEnv "APNS_KEY_FILE" "./tests/fixtures/AuthKey_H82WD9K9AQ.p8"
|
|
hspec
|
|
#if defined(dbPostgres)
|
|
. aroundAll_ (postgressBracket testDBConnectInfo)
|
|
#endif
|
|
. before_ (createDirectoryIfMissing False "tests/tmp")
|
|
. after_ (eventuallyRemove "tests/tmp" 3)
|
|
$ do
|
|
describe "Core tests" $ do
|
|
describe "Batching tests" batchingTests
|
|
describe "Encoding tests" encodingTests
|
|
describe "Version range" versionRangeTests
|
|
describe "Encryption tests" cryptoTests
|
|
describe "Ethereum crypto tests" ethCryptoTests
|
|
describe "Encrypted files tests" cryptoFileTests
|
|
describe "Message store tests" msgStoreTests
|
|
describe "Retry interval tests" retryIntervalTests
|
|
describe "SOCKS settings tests" socksSettingsTests
|
|
#if defined(dbServerPostgres)
|
|
around_ (postgressBracket testServerDBConnectInfo) $
|
|
describe "Store log tests" storeLogTests
|
|
#else
|
|
describe "Store log tests" storeLogTests
|
|
#endif
|
|
describe "XFTP store log tests" fileStoreLogTests
|
|
fileExpirationTests
|
|
describe "TSessionSubs tests" tSessionSubsTests
|
|
describe "Util tests" utilTests
|
|
describe "Names resolver tests" smpNamesTests
|
|
describe "RSLV functional API tests" rslvTests
|
|
describe "Agent core tests" agentCoreTests
|
|
#if defined(dbServerPostgres)
|
|
around_ (postgressBracket testServerDBConnectInfo) $
|
|
describe "SMP server schema dump" $
|
|
postgresSchemaDumpTest
|
|
serverMigrations
|
|
[ "20250320_short_links" -- snd_secure moves to the bottom on down migration
|
|
] -- skipComparisonForDownMigrations
|
|
testStoreDBOpts
|
|
"src/Simplex/Messaging/Server/QueueStore/Postgres/server_schema.sql"
|
|
around_ (postgressBracket testServerDBConnectInfo) $ do
|
|
-- xdescribe "SMP server via TLS, postgres+jornal message store" $
|
|
-- before (pure (transport @TLS, ASType SQSPostgres SMSJournal)) serverTests
|
|
describe "SMP server via TLS, postgres-only message store" $
|
|
before (pure (transport @TLS, ASType SQSPostgres SMSPostgres)) serverTests
|
|
#endif
|
|
describe "SMP server via TLS, jornal message store" $ do
|
|
describe "SMP syntax" $ serverSyntaxTests (transport @TLS)
|
|
before (pure (transport @TLS, ASType SQSMemory SMSJournal)) serverTests
|
|
describe "SMP server via TLS, memory message store" $
|
|
before (pure (transport @TLS, ASType SQSMemory SMSMemory)) serverTests
|
|
-- xdescribe "SMP server via WebSockets" $ do
|
|
-- describe "SMP syntax" $ serverSyntaxTests (transport @WS)
|
|
-- before (pure (transport @WS, ASType SQSMemory SMSJournal)) serverTests
|
|
#if defined(dbServerPostgres)
|
|
around_ (postgressBracket ntfTestServerDBConnectInfo) $
|
|
describe "Ntf server schema dump" $
|
|
postgresSchemaDumpTest
|
|
ntfServerMigrations
|
|
[] -- skipComparisonForDownMigrations
|
|
ntfTestStoreDBOpts
|
|
"src/Simplex/Messaging/Notifications/Server/Store/ntf_server_schema.sql"
|
|
around_ (postgressBracket ntfTestServerDBConnectInfo) $ do
|
|
describe "Notifications server (SMP server: memory store)" $
|
|
ntfServerTests (transport @TLS, ASType SQSMemory SMSMemory)
|
|
around_ (postgressBracket testServerDBConnectInfo) $ do
|
|
-- xdescribe "Notifications server (SMP server: postgres+jornal store)" $
|
|
-- ntfServerTests (transport @TLS, ASType SQSPostgres SMSJournal)
|
|
describe "Notifications server (SMP server: postgres-only store)" $
|
|
ntfServerTests (transport @TLS, ASType SQSPostgres SMSPostgres)
|
|
around_ (postgressBracket testServerDBConnectInfo) $ do
|
|
-- xdescribe "SMP client agent, postgres+jornal message store" $ agentTests (transport @TLS, ASType SQSPostgres SMSJournal)
|
|
describe "SMP client agent, server postgres-only message store" $ agentTests (transport @TLS, ASType SQSPostgres SMSPostgres)
|
|
-- xdescribe "SMP proxy, postgres+jornal message store" $
|
|
-- before (pure $ ASType SQSPostgres SMSJournal) smpProxyTests
|
|
describe "SMP proxy, postgres-only message store" $
|
|
before (pure $ ASType SQSPostgres SMSPostgres) smpProxyTests
|
|
#endif
|
|
-- xdescribe "SMP client agent, server jornal message store" $ agentTests (transport @TLS, ASType SQSMemory SMSJournal)
|
|
describe "SMP client agent, server memory message store" $ agentTests (transport @TLS, ASType SQSMemory SMSMemory)
|
|
describe "SMP proxy, jornal message store" $
|
|
before (pure $ ASType SQSMemory SMSJournal) smpProxyTests
|
|
describe "XFTP" $ do
|
|
describe "XFTP server" $
|
|
before (pure $ AFSType SFSMemory) xftpServerTests
|
|
describe "XFTP file description" fileDescriptionTests
|
|
describe "XFTP CLI (memory)" $
|
|
before (pure $ AFSType SFSMemory) xftpCLIFileTests
|
|
describe "XFTP agent" $
|
|
before (pure $ AFSType SFSMemory) xftpAgentTests
|
|
#if defined(dbServerPostgres)
|
|
around_ (postgressBracket testXFTPDBConnectInfo) $ do
|
|
describe "XFTP Postgres store operations" xftpStoreTests
|
|
describe "XFTP migration round-trip" xftpMigrationTests
|
|
describe "XFTP server (PostgreSQL)" $
|
|
before (pure $ AFSType SFSPostgres) xftpServerTests
|
|
describe "XFTP agent (PostgreSQL)" $
|
|
before (pure $ AFSType SFSPostgres) xftpAgentTests
|
|
describe "XFTP CLI (PostgreSQL)" $
|
|
before (pure $ AFSType SFSPostgres) xftpCLIFileTests
|
|
#endif
|
|
#if defined(dbPostgres)
|
|
describe "XFTP Web Client" $ xftpWebTests (dropAllSchemasExceptSystem testDBConnectInfo)
|
|
#else
|
|
describe "XFTP Web Client" $ xftpWebTests (pure ())
|
|
#endif
|
|
describe "XRCP" remoteControlTests
|
|
describe "Web" webTests
|
|
describe "Server CLIs" cliTests
|
|
#if defined(dbPostgres)
|
|
around_ (postgressBracket testDBConnectInfo) $
|
|
describe "Agent PostgreSQL schema dump" $
|
|
postgresSchemaDumpTest
|
|
appMigrations
|
|
["20250322_short_links"] -- snd_secure and last_broker_ts columns swap order on down migration
|
|
(testDBOpts testDB)
|
|
"src/Simplex/Messaging/Agent/Store/Postgres/Migrations/agent_postgres_schema.sql"
|
|
#else
|
|
describe "Agent SQLite schema dump" schemaDumpTest
|
|
#endif
|
|
|
|
eventuallyRemove :: FilePath -> Int -> IO ()
|
|
eventuallyRemove path retries = case retries of
|
|
0 -> action
|
|
n ->
|
|
action `E.catch` \ioe@IOError {ioe_type, ioe_filename} -> case ioe_type of
|
|
IOException.UnsatisfiedConstraints | ioe_filename == Just path -> threadDelay 1000000 >> eventuallyRemove path (n - 1)
|
|
_ -> E.throwIO ioe
|
|
where
|
|
action = removeDirectoryRecursive path
|