diff --git a/cabal.project b/cabal.project index cecdb7e0a..bdf53fde6 100644 --- a/cabal.project +++ b/cabal.project @@ -18,7 +18,7 @@ source-repository-package source-repository-package type: git location: https://github.com/kazu-yamamoto/http2.git - tag: 804fa283f067bd3fd89b8c5f8d25b3047813a517 + tag: f5525b755ff2418e6e6ecc69e877363b0d0bcaeb source-repository-package type: git diff --git a/package.yaml b/package.yaml index 428d7f8e6..387e4fd6b 100644 --- a/package.yaml +++ b/package.yaml @@ -43,7 +43,7 @@ dependencies: - filepath == 1.4.* - hourglass == 0.2.* - http-types == 0.12.* - - http2 >= 4.1.4 && < 4.2 + - http2 >= 4.2.2 && < 4.3 - ini == 0.4.1 - iproute == 1.7.* - iso8601-time == 0.1.* diff --git a/simplexmq.cabal b/simplexmq.cabal index 6a03b807d..ece876eee 100644 --- a/simplexmq.cabal +++ b/simplexmq.cabal @@ -168,7 +168,7 @@ library , filepath ==1.4.* , hourglass ==0.2.* , http-types ==0.12.* - , http2 >=4.1.4 && <4.2 + , http2 >=4.2.2 && <4.3 , ini ==0.4.1 , iproute ==1.7.* , iso8601-time ==0.1.* @@ -231,7 +231,7 @@ executable ntf-server , filepath ==1.4.* , hourglass ==0.2.* , http-types ==0.12.* - , http2 >=4.1.4 && <4.2 + , http2 >=4.2.2 && <4.3 , ini ==0.4.1 , iproute ==1.7.* , iso8601-time ==0.1.* @@ -295,7 +295,7 @@ executable smp-agent , filepath ==1.4.* , hourglass ==0.2.* , http-types ==0.12.* - , http2 >=4.1.4 && <4.2 + , http2 >=4.2.2 && <4.3 , ini ==0.4.1 , iproute ==1.7.* , iso8601-time ==0.1.* @@ -359,7 +359,7 @@ executable smp-server , filepath ==1.4.* , hourglass ==0.2.* , http-types ==0.12.* - , http2 >=4.1.4 && <4.2 + , http2 >=4.2.2 && <4.3 , ini ==0.4.1 , iproute ==1.7.* , iso8601-time ==0.1.* @@ -423,7 +423,7 @@ executable xftp , filepath ==1.4.* , hourglass ==0.2.* , http-types ==0.12.* - , http2 >=4.1.4 && <4.2 + , http2 >=4.2.2 && <4.3 , ini ==0.4.1 , iproute ==1.7.* , iso8601-time ==0.1.* @@ -487,7 +487,7 @@ executable xftp-server , filepath ==1.4.* , hourglass ==0.2.* , http-types ==0.12.* - , http2 >=4.1.4 && <4.2 + , http2 >=4.2.2 && <4.3 , ini ==0.4.1 , iproute ==1.7.* , iso8601-time ==0.1.* @@ -585,7 +585,7 @@ test-suite simplexmq-test , hspec ==2.7.* , hspec-core ==2.7.* , http-types ==0.12.* - , http2 >=4.1.4 && <4.2 + , http2 >=4.2.2 && <4.3 , ini ==0.4.1 , iproute ==1.7.* , iso8601-time ==0.1.* diff --git a/src/Simplex/FileTransfer/Agent.hs b/src/Simplex/FileTransfer/Agent.hs index 8c5b20052..aceeca6c7 100644 --- a/src/Simplex/FileTransfer/Agent.hs +++ b/src/Simplex/FileTransfer/Agent.hs @@ -102,7 +102,7 @@ closeXFTPAgent XFTPAgent {xftpRcvWorkers, xftpSndWorkers} = do xftpReceiveFile' :: AgentMonad m => AgentClient -> UserId -> ValidFileDescription 'FRecipient -> Maybe CryptoFileArgs -> m RcvFileId xftpReceiveFile' c userId (ValidFileDescription fd@FileDescription {chunks}) cfArgs = do - g <- asks idsDrg + g <- asks random prefixPath <- getPrefixPath "rcv.xftp" createDirectory prefixPath let relPrefixPath = takeFileName prefixPath @@ -281,7 +281,7 @@ notify c entId cmd = atomically $ writeTBQueue (subQ c) ("", entId, APC (sAEntit xftpSendFile' :: AgentMonad m => AgentClient -> UserId -> CryptoFile -> Int -> m SndFileId xftpSendFile' c userId file numRecipients = do - g <- asks idsDrg + g <- asks random prefixPath <- getPrefixPath "snd.xftp" createDirectory prefixPath let relPrefixPath = takeFileName prefixPath diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index cb6836b47..b0f9f93f5 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -470,7 +470,7 @@ newConnAsync c userId corrId enableNtfs cMode subMode = do newConnNoQueues :: AgentMonad m => AgentClient -> UserId -> ConnId -> Bool -> SConnectionMode c -> m ConnId newConnNoQueues c userId connId enableNtfs cMode = do - g <- asks idsDrg + g <- asks random connAgentVersion <- asks $ maxVersion . smpAgentVRange . config -- connection mode is determined by the accepting agent let cData = ConnData {userId, connId, connAgentVersion, enableNtfs, duplexHandshake = Nothing, lastExternalSndId = 0, deleted = False, ratchetSyncState = RSOk} @@ -482,7 +482,7 @@ joinConnAsync c userId corrId enableNtfs cReqUri@(CRInvitationUri ConnReqUriData aVRange <- asks $ smpAgentVRange . config case crAgentVRange `compatibleVersion` aVRange of Just (Compatible connAgentVersion) -> do - g <- asks idsDrg + g <- asks random let duplexHS = connAgentVersion /= 1 cData = ConnData {userId, connId = "", connAgentVersion, enableNtfs, duplexHandshake = Just duplexHS, lastExternalSndId = 0, deleted = False, ratchetSyncState = RSOk} connId <- withStore c $ \db -> createNewConn db g cData SCMInvitation @@ -616,7 +616,7 @@ joinConnSrv :: AgentMonad m => AgentClient -> UserId -> ConnId -> Bool -> Connec joinConnSrv c userId connId enableNtfs inv@CRInvitationUri {} cInfo subMode srv = withInvLock c (strEncode inv) "joinConnSrv" $ do (aVersion, cData@ConnData {connAgentVersion}, q, rc, e2eSndParams) <- startJoinInvitation userId connId enableNtfs inv - g <- asks idsDrg + g <- asks random connId' <- withStore c $ \db -> runExceptT $ do connId' <- ExceptT $ createSndConn db g cData q liftIO $ createRatchet db connId' rc @@ -2058,7 +2058,7 @@ processSMPTransmission c@AgentClient {smpClients, subQ} (tSess@(_, srv, _), v, s where processConf connInfo senderConf duplexHS = do let newConfirmation = NewConfirmation {connId, senderConf, ratchetState = rc'} - g <- asks idsDrg + g <- asks random confId <- withStore c $ \db -> do setHandshakeVersion db connId agentVersion duplexHS createConfirmation db g newConfirmation @@ -2235,7 +2235,7 @@ processSMPTransmission c@AgentClient {smpClients, subQ} (tSess@(_, srv, _), v, s logServer "<--" c srv rId "MSG " case conn' of ContactConnection {} -> do - g <- asks idsDrg + g <- asks random let newInv = NewInvitation {contactConnId = connId, connReq, recipientConnInfo = cInfo} invId <- withStore c $ \db -> createInvitation db g newInv let srvs = L.map qServer $ crSmpQueues crData diff --git a/src/Simplex/Messaging/Agent/Env/SQLite.hs b/src/Simplex/Messaging/Agent/Env/SQLite.hs index 3a818f250..cbdae289c 100644 --- a/src/Simplex/Messaging/Agent/Env/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Env/SQLite.hs @@ -178,7 +178,7 @@ defaultAgentConfig = data Env = Env { config :: AgentConfig, store :: SQLiteStore, - idsDrg :: TVar ChaChaDRG, + random :: TVar ChaChaDRG, clientCounter :: TVar Int, randomServer :: TVar StdGen, ntfSupervisor :: NtfSupervisor, @@ -187,12 +187,12 @@ data Env = Env newSMPAgentEnv :: AgentConfig -> SQLiteStore -> IO Env newSMPAgentEnv config@AgentConfig {initialClientId} store = do - idsDrg <- newTVarIO =<< liftIO drgNew + random <- newTVarIO =<< drgNew clientCounter <- newTVarIO initialClientId randomServer <- newTVarIO =<< liftIO newStdGen ntfSupervisor <- atomically . newNtfSubSupervisor $ tbqSize config xftpAgent <- atomically newXFTPAgent - pure Env {config, store, idsDrg, clientCounter, randomServer, ntfSupervisor, xftpAgent} + pure Env {config, store, random, clientCounter, randomServer, ntfSupervisor, xftpAgent} createAgentStore :: FilePath -> String -> MigrationConfirmation -> IO (Either MigrationError SQLiteStore) createAgentStore dbFilePath dbKey = createSQLiteStore dbFilePath dbKey Migrations.app diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index 684d2620d..d4f0bf7cc 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -214,7 +214,7 @@ module Simplex.Messaging.Agent.Store.SQLite where import Control.Monad.Except -import Crypto.Random (ChaChaDRG, randomBytesGenerate) +import Crypto.Random (ChaChaDRG) import qualified Data.Aeson.TH as J import qualified Data.Attoparsec.ByteString.Char8 as A import Data.Bifunctor (second) @@ -2084,7 +2084,7 @@ createWithRandomId gVar create = tryCreate 3 | otherwise -> pure . Left . SEInternal $ bshow e randomId :: TVar ChaChaDRG -> Int -> IO ByteString -randomId gVar n = U.encode <$> (atomically . stateTVar gVar $ randomBytesGenerate n) +randomId gVar n = atomically $ U.encode <$> C.pseudoRandomBytes n gVar ntfSubAndSMPAction :: NtfSubAction -> (Maybe NtfSubNTFAction, Maybe NtfSubSMPAction) ntfSubAndSMPAction (NtfSubNTFAction action) = (Just action, Nothing) diff --git a/src/Simplex/Messaging/Transport/HTTP2.hs b/src/Simplex/Messaging/Transport/HTTP2.hs index 1feccce88..511f5d322 100644 --- a/src/Simplex/Messaging/Transport/HTTP2.hs +++ b/src/Simplex/Messaging/Transport/HTTP2.hs @@ -13,6 +13,7 @@ import Network.HPACK (BufferSize) import Network.HTTP2.Client (Config (..), defaultPositionReadMaker, freeSimpleConfig) import qualified Network.HTTP2.Client as HC import qualified Network.HTTP2.Server as HS +import Network.Socket (SockAddr (..)) import qualified Network.TLS as T import qualified Network.TLS.Extra as TE import Simplex.Messaging.Transport (SessionId, TLS (tlsUniq), Transport (cGet, cPut)) @@ -36,7 +37,9 @@ allocHTTP2Config c sz = do confSendAll = cPut c, confReadN = cGet c, confPositionReadMaker = defaultPositionReadMaker, - confTimeoutManager = tm + confTimeoutManager = tm, + confMySockAddr = SockAddrInet 0 0, + confPeerSockAddr = SockAddrInet 0 0 } http2TLSParams :: T.Supported diff --git a/src/Simplex/Messaging/Transport/HTTP2/Client.hs b/src/Simplex/Messaging/Transport/HTTP2/Client.hs index 72400b22d..4230eb575 100644 --- a/src/Simplex/Messaging/Transport/HTTP2/Client.hs +++ b/src/Simplex/Messaging/Transport/HTTP2/Client.hs @@ -2,6 +2,7 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} module Simplex.Messaging.Transport.HTTP2.Client where @@ -162,4 +163,4 @@ runHTTP2ClientWith :: forall a. BufferSize -> TransportHost -> ((TLS -> IO a) -> runHTTP2ClientWith bufferSize host setup client = setup $ withHTTP2 bufferSize run where run :: H.Config -> SessionId -> IO a - run cfg = H.run (ClientConfig "https" (strEncode host) 20) cfg . client + run cfg sessId = H.run (ClientConfig "https" (strEncode host) 20) cfg $ client sessId diff --git a/stack.yaml b/stack.yaml index eefc49cf7..620299be9 100644 --- a/stack.yaml +++ b/stack.yaml @@ -49,7 +49,7 @@ extra-deps: - github: simplex-chat/aeson commit: aab7b5a14d6c5ea64c64dcaee418de1bb00dcc2b - github: kazu-yamamoto/http2 - commit: 804fa283f067bd3fd89b8c5f8d25b3047813a517 + commit: f5525b755ff2418e6e6ecc69e877363b0d0bcaeb # - ../direct-sqlcipher - github: simplex-chat/direct-sqlcipher commit: 34309410eb2069b029b8fc1872deb1e0db123294