36 Commits

Author SHA1 Message Date
Evgeny Poberezkin
091fbdd0e9 rename simplexmq-legacy into simplexmq-v0 (#270)
* rename simplexmq-legacy into simplexmq-v0

* split UnliftIO instance of ExceptT
2022-01-11 07:27:30 +00:00
Evgeny Poberezkin
04c65d98da support permanent connection link ("contact") in SMP agent protocols (#143)
* open/public queue extension for SMP and SMP agent protocols

* add connection mode - invitation or contact

* use ConnectionMode with REQ and ACPT agent notification/command

* parameterize ConnectionRequest with ConnectionMode

* implement Contact connection mode for permanent connection links

* tests for contact connections
2021-12-04 18:42:08 +00:00
Evgeny Poberezkin
dd5137c336 asynchronous message sending to allow accepting messages when agent (or server) is offline (#179)
* asynchronous message sending to allow accepting messages when agent (or server) is offline

* send pending messages after agent restart; test for pending messages delivery when server restarted

* test pending message delivery after agent restart

* message delivery process per server

* test layout
2021-08-12 22:15:55 +01:00
Evgeny Poberezkin
3829479a21 Remove introductions, rename CONF/LET to REQ/ACPT (#175)
* remove intros and functions in Reader monad

* rename CONF/LET to REQ/ACPT, allowConnection to acceptConnection
2021-08-05 08:27:44 +01:00
Efim Poberezkin
3d9ceff691 ask client for confirmation of sender; make establishment of connection asynchronous (#163)
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
2021-07-04 04:48:24 +10:00
Evgeny Poberezkin
daad3315eb upgrade stack resolver to lts-18.0 (#165)
* upgrade stack resolver to lts-18.0

* fix random package version
2021-06-30 10:35:50 +01:00
Evgeny Poberezkin
e4d9b481ec refactor message meta to MsgMeta type (#164) 2021-06-30 10:29:45 +01:00
Evgeny Poberezkin
7af7272635 SQLiteStore connection pool (#162)
* SQLiteStore connection pool

* move SQLiteStore to agent env - single store instance is used for all clients
2021-06-25 18:17:11 +01:00
Evgeny Poberezkin
09c6adeabc pass migration as parameter (to use in simplex-chat) (#161)
* pass migration as parameter (to use in simplex-chat)

* add connId parameter to create/joinConnection
2021-06-24 18:39:59 +01:00
Evgeny Poberezkin
ab89963f45 introduction protocol (#156)
* commands to support introduction

* agent messages / envelopes to support introductions

* introductions and invitations table; insert record with random unique ID

* store class methods and types for introductions

* process INTRO and ACPT commands for connection introductions

* fix tests: add MonadFail constraint, remove OK response to JOIN

* process agent messages for introductions

* ICON notification when introduction is completed

* replace multiway if with case

* correction

* support random connection IDs

* save additional connection fields, refactor create connection funcs

* refactor

* refactor

* test duplex connection with random IDs

* store methods for introductions

* test introduction

* fix parsing of CON agent message

* test introduction with random connection IDs

* broadcast with random connection and broadcast IDs

* clean up sql
2021-06-11 21:33:13 +01:00
Efim Poberezkin
8bd42035aa reorganize sqlite store test suite (#138) 2021-05-10 15:10:32 +04:00
Evgeny Poberezkin
5d59e4b2bd package and module docs, remove Simplex.Markdown (moved to simplex-chat), rename Agent.Transmission to Agent.Protocol (#133)
* package and module docs, remove Simplex.Markdown (moved to simplex-chat), rename Agent.Transmission to Agent.Protocol

* move errors.md to haddock comments, Transport docs

* add CHANGELOG.md, add missing package versions

* changelog, copyright

* docs for Simplex.Messaging.Crypto

* consistent punctuation

* use absolute URLs in readme

* correction
2021-05-09 09:36:08 +01:00
Efim Poberezkin
ad87442811 sqlite busy stress test (#131)
* sqlite busy stress test

* refactor withStore2

* refactor withStore2

* pragmas

* swith to IMMEDIATE sqlite transactions and add retry on ErrorBusy

* refactor

* increase timeout, print errors and results

* remove logging errors/results

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
2021-05-08 16:30:40 +01:00
Evgeny Poberezkin
7aacee405e agent: send CON to user when the 1st party responds HELLO; fix REPLY vulnerability (#130)
* agent: send CON to user when the 1st party responds HELLO; fix REPLY vulnerability

* test for getRcvConn

* add commented OK response to JOIN command

* store: use Only newtype to select one field
2021-05-07 06:57:53 +01:00
Efim Poberezkin
b7902ee4c8 agent sqlite: store msg hashes and integrity (#118, #119, #120)
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
2021-05-02 10:48:31 +04:00
Efim Poberezkin
6be4839703 agent: verify msg integrity based on previous msg hash and id (#110)
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
2021-05-02 00:38:32 +04:00
Evgeny Poberezkin
6ceeb2c9db save keys as binary to db, remove legacy encoding (#114)
* save keys as binary to db, remove legacy encoding

* import list
2021-04-30 09:13:18 +01:00
Efim Poberezkin
40ad6db51a return error on creation of duplicate connection (#102)
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
2021-04-19 00:46:01 +04:00
Evgeny Poberezkin
5e3bc7ee6c improve error handling (#101)
* inventory of error handling problems and types

* Change SMP protocol errors syntax

* connection errors in agent protocol (ERR CONN), STORE error -> AGENT error

* include exception in SEInternal error

* add MESSAGE errors, remove CRYPTO and SIZE errors

* agent protocol SYNTAX and AGENT errors

* BROKER errors

* group all client command (and agent response) errors

* BROKER TRANSPORT error

* simplify Client

* clean up

* transport errors

* simplify client

* parse / serialize agent errors

* differentiate crypto errors

* update errors.md

* make agent and SMP protocol errors consistent, simplify

* update doc

* test: parse / serialize protocol errors with QuickCheck

* add String to internal error

* exponential back-off when retrying to send HELLO

* refactor Client.hs

* replace fold with recursion in startTCPClient

* fail test if server did not start, refactor

* test: wait till TCP server stops

* test: refactor waiting for server to stop

* test: fail with error if server did not start/stop
2021-04-18 18:37:54 +01:00
Evgeny Poberezkin
326050651a Merge branch 'master' into v2 2021-04-14 21:30:30 +01:00
Evgeny Poberezkin
0028939155 standard X509/PKCS8 encoding for RSA keys (#98)
* key encoding primitives (WIP)

* use X509/PKCS8 to read/write server key files

* make PrivateKey type class

* clean up

* remove separate public key file

* specific import
2021-04-14 21:20:08 +01:00
Efim Poberezkin
2eb5ce24ec tests: block on tcp server creation (#99)
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
2021-04-14 02:25:57 +04:00
Evgeny Poberezkin
0fbf406800 transport encryption (#65)
* transport encryption (WIP - using fixed key, parsing/serialization works, SMP tests fail)

* transport encryption

* transport encryption: separate keys to receive and to send, counter-based IVs

* docs: update transport encryption and handshake

* transport encryption handshake (TODO: validate key hash, welcome block, move keys to system environment)

* change KeyHash type to newtype of Digest SHA256

* transport encryption: validate public key hash

* send and receive welcome block with SMP version

* refactor: parsing SMPServer

* remove unused function

* verify that client version is compatible with server version (major version is not smaller)

* update (fix) SMP server tests
2021-04-05 13:10:16 +01:00
Efim Poberezkin
08171e987d agent sqlite: initialize database in home directory by default (#74) 2021-03-29 19:18:54 +04:00
Efim Poberezkin
b9943c359d chat: subscribe to all connections on startup (#70) 2021-03-06 15:39:00 +04:00
Efim Poberezkin
11c8bee836 agent store: make newtypes for msg internal Ids (#68) 2021-03-04 23:19:12 +04:00
Efim Poberezkin
93e782b874 agent store: organize sender and broker fields into tuples (#67) 2021-03-04 23:00:00 +04:00
Efim Poberezkin
660e35d1d1 check that sqlite library is compiled with threadsafe code (#63) 2021-03-02 22:30:59 +04:00
Evgeny Poberezkin
927ff230da Separate db connection for each TCP client connection (#60)
* use separate db connections for each TCP client connection

* refactor atomically, increast delay in tests

* increase test delay for SMP server to start

* increase SMP ping frequency

* remove comment

* separate SQLite connection per thread, to support multi-threaded mode

* remove redundant import
2021-02-28 14:59:29 +00:00
Efim Poberezkin
3af34dea8b agent store: accept internal ts and return internal id (#58) 2021-02-27 15:06:51 +04:00
Efim Poberezkin
8134bb0eb9 agent store: settle naming of Rcv and Snd entities (#55) 2021-02-26 18:17:56 +04:00
Efim Poberezkin
0f60c53a66 agent: save messages (#45) 2021-02-25 19:02:27 +04:00
Efim Poberezkin
469f84bb74 use cryptographic key pairs for encryption keys (#39)
* use cryptographic key pairs for encryption keys

* use speaking key types

* fix key types

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
2021-02-26 18:14:22 +04:00
Evgeny Poberezkin
0fe41dbf16 Sign / verify SMP commands (#37)
* generate key pair

* crypto: sign/verify functions

* remove extension

* parse/serialize keys

* use RSA recipient/sender keys (TODO sign/verify)

* make PublicKey newtype, assign 0s to private_p & private_q

* replace SMP command parsing with Attoparsec

* rename types: Signed->Transmission, Transmission->SignedTransmission

* sign and verify commands (server tests skipped, agent tests pass)

* SMP client: avoid seralizing transmission twice when sending commands

* update SMP server tests to use command signatures

* remove support for "SEND :msg" syntax from SMP server protocol

* rename RSA module name to R to avoid confusion with C used for S.M.Crypto

* update key sizes to use bits `div` 8

* tidy up
2021-02-26 18:14:22 +04:00
Efim Poberezkin
7e9cfcce8c agent sqlite: rework schema, make methods transactional, enable foreign keys (#34)
* agent sqlite: rework schema

* agent sqlite: explicitly mark primary keys as NOT NULL

* agent sqlite: adjust connections and queues fkeys

* agent sqlite: remove ack_mode from queues tables

* [WIP] agent sqlite: refactor methods

* agent sqlite: implement transactional createRcvConn

* add comment

* agent sqlite: remove ConnAlias from createRcvConn signature

* agent sqlite: implement transactional createSndConn

* agent sqlite: remove monadic stack from store util methods

* agent sqlite: refactor getConn

* agent sqlite: rename conn -> dbConn

* agent sqlite: move transactional logic to utils

* agent sqlite: remove addServer from store interface

* fix comment

* agent sqlite: refactor getRcvQueue

* agent sqlite: refactor deleteConn

* agent sqlite: remove old deleteConn

* agent sqlite: enable FKs

* agent sqlite: refactor methods upgrading connection to duplex

* agent sqlite: uncomment not implemented methods

* agent sqlite: rename methods upgrading connection to duplex

* use liftEither

* agent sqlite: refactor update queue status methods

* agent sqlite: refactor createMsg

* clean up

* fix compilation errors in src

* fix existing tests

* clean up tests

* agent sqlite: test that foreign keys are enabled

* change private members naming

* tests: expect specific error code

* clean up

* agent sqlite: consistently separate lifts from logic to their own lines
2021-02-04 19:23:43 +04:00
Efim Poberezkin
e09d3bae99 agent store: move SQLite Types -> Util (#30) 2021-01-25 20:14:33 +04:00