From 0ccde5871c84d1885c9060a2e15aa532c4d37807 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 5 Apr 2021 13:10:16 +0100 Subject: [PATCH] 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 --- ChatOptions.hs | 4 ++-- Main.hs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ChatOptions.hs b/ChatOptions.hs index 0a7ff89f09..0940c34b8f 100644 --- a/ChatOptions.hs +++ b/ChatOptions.hs @@ -2,10 +2,10 @@ module ChatOptions (getChatOpts, ChatOpts (..)) where -import qualified Data.Attoparsec.ByteString.Char8 as A import qualified Data.ByteString.Char8 as B import Options.Applicative import Simplex.Messaging.Agent.Transmission (SMPServer (..), smpServerP) +import Simplex.Messaging.Parsers (parseAll) import System.FilePath (combine) import System.Info (os) import Types @@ -58,7 +58,7 @@ chatOpts appDir = | otherwise = TermModeEditor parseSMPServer :: ReadM SMPServer -parseSMPServer = eitherReader $ A.parseOnly (smpServerP <* A.endOfInput) . B.pack +parseSMPServer = eitherReader $ parseAll smpServerP . B.pack parseTermMode :: ReadM TermMode parseTermMode = maybeReader $ \case diff --git a/Main.hs b/Main.hs index ac33b81e50..bc2c1c198f 100644 --- a/Main.hs +++ b/Main.hs @@ -26,6 +26,7 @@ import Simplex.Messaging.Agent.Client (AgentClient (..)) import Simplex.Messaging.Agent.Env.SQLite import Simplex.Messaging.Agent.Transmission import Simplex.Messaging.Client (smpDefaultConfig) +import Simplex.Messaging.Parsers (parseAll) import Simplex.Messaging.Util (bshow, raceAny_) import System.Directory (getAppUserDataDirectory) import System.Exit (exitFailure) @@ -124,7 +125,7 @@ main = do t <- getChatClient smpServer user ct <- newChatTerminal (tbqSize cfg) user termMode -- setLogLevel LogInfo -- LogError - -- withGlobalLogging logCfg $ + -- withGlobalLogging logCfg $ do env <- newSMPAgentEnv cfg {dbFile = dbFileName} dogFoodChat t ct env @@ -172,7 +173,7 @@ newChatClient qSize smpServer name = do receiveFromChatTerm :: ChatClient -> ChatTerminal -> IO () receiveFromChatTerm t ct = forever $ do atomically (readTBQueue $ inputQ ct) - >>= processOrError . A.parseOnly (chatCommandP <* A.endOfInput) + >>= processOrError . parseAll chatCommandP where processOrError = \case Left err -> atomically . writeTBQueue (outQ t) . ErrorInput $ B.pack err