From 5ad6e5f2f33ff7c26122bb53435bdfccbc99b707 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 18 Aug 2024 13:55:12 +0100 Subject: [PATCH] deps: upgrade tls to 1.9 (#1265) * deps: use tls-2.0 * roll back RCP "cleanup" * use tls 1.9 --------- Co-authored-by: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> --- package.yaml | 2 +- simplexmq.cabal | 12 ++++++------ src/Simplex/Messaging/Transport.hs | 8 +++++--- src/Simplex/Messaging/Transport/WebSockets.hs | 11 +++++++---- src/Simplex/RemoteControl/Client.hs | 2 +- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/package.yaml b/package.yaml index 26cdcc51a..ceff0afb9 100644 --- a/package.yaml +++ b/package.yaml @@ -69,7 +69,7 @@ dependencies: - temporary == 1.3.* - time == 1.12.* - time-manager == 0.0.* - - tls >= 1.7.0 && < 1.8 + - tls >= 1.9.0 && < 1.10 - transformers == 0.6.* - unliftio == 0.2.* - unliftio-core == 0.2.* diff --git a/simplexmq.cabal b/simplexmq.cabal index d557ac509..44e39c8ae 100644 --- a/simplexmq.cabal +++ b/simplexmq.cabal @@ -258,7 +258,7 @@ library , temporary ==1.3.* , time ==1.12.* , time-manager ==0.0.* - , tls >=1.7.0 && <1.8 + , tls >=1.9.0 && <1.10 , transformers ==0.6.* , unliftio ==0.2.* , unliftio-core ==0.2.* @@ -333,7 +333,7 @@ executable ntf-server , temporary ==1.3.* , time ==1.12.* , time-manager ==0.0.* - , tls >=1.7.0 && <1.8 + , tls >=1.9.0 && <1.10 , transformers ==0.6.* , unliftio ==0.2.* , unliftio-core ==0.2.* @@ -412,7 +412,7 @@ executable smp-server , temporary ==1.3.* , time ==1.12.* , time-manager ==0.0.* - , tls >=1.7.0 && <1.8 + , tls >=1.9.0 && <1.10 , transformers ==0.6.* , unliftio ==0.2.* , unliftio-core ==0.2.* @@ -490,7 +490,7 @@ executable xftp , temporary ==1.3.* , time ==1.12.* , time-manager ==0.0.* - , tls >=1.7.0 && <1.8 + , tls >=1.9.0 && <1.10 , transformers ==0.6.* , unliftio ==0.2.* , unliftio-core ==0.2.* @@ -565,7 +565,7 @@ executable xftp-server , temporary ==1.3.* , time ==1.12.* , time-manager ==0.0.* - , tls >=1.7.0 && <1.8 + , tls >=1.9.0 && <1.10 , transformers ==0.6.* , unliftio ==0.2.* , unliftio-core ==0.2.* @@ -681,7 +681,7 @@ test-suite simplexmq-test , time ==1.12.* , time-manager ==0.0.* , timeit ==2.0.* - , tls >=1.7.0 && <1.8 + , tls >=1.9.0 && <1.10 , transformers ==0.6.* , unliftio ==0.2.* , unliftio-core ==0.2.* diff --git a/src/Simplex/Messaging/Transport.hs b/src/Simplex/Messaging/Transport.hs index 58843b7f5..3386f82f3 100644 --- a/src/Simplex/Messaging/Transport.hs +++ b/src/Simplex/Messaging/Transport.hs @@ -113,6 +113,7 @@ import Simplex.Messaging.Transport.Buffer import Simplex.Messaging.Util (bshow, catchAll, catchAll_, liftEitherWith) import Simplex.Messaging.Version import Simplex.Messaging.Version.Internal +import System.IO.Error (isEOFError) import UnliftIO.Exception (Exception) import qualified UnliftIO.Exception as E import UnliftIO.STM @@ -339,11 +340,12 @@ instance Transport TLS where getLn :: TLS -> IO ByteString getLn TLS {tlsContext, tlsBuffer} = do - getLnBuffered tlsBuffer (T.recvData tlsContext) `E.catch` handleEOF + getLnBuffered tlsBuffer (T.recvData tlsContext) `E.catches` [E.Handler handleTlsEOF, E.Handler handleEOF] where - handleEOF = \case - T.Error_EOF -> E.throwIO TEBadBlock + handleTlsEOF = \case + T.PostHandshake T.Error_EOF -> E.throwIO TEBadBlock e -> E.throwIO e + handleEOF e = if isEOFError e then E.throwIO TEBadBlock else E.throwIO e -- * SMP transport diff --git a/src/Simplex/Messaging/Transport/WebSockets.hs b/src/Simplex/Messaging/Transport/WebSockets.hs index 0883fcc28..866d0d197 100644 --- a/src/Simplex/Messaging/Transport/WebSockets.hs +++ b/src/Simplex/Messaging/Transport/WebSockets.hs @@ -25,6 +25,7 @@ import Simplex.Messaging.Transport withTlsUnique, ) import Simplex.Messaging.Transport.Buffer (trimCR) +import System.IO.Error (isEOFError) data WS = WS { wsPeer :: TransportPeer, @@ -108,9 +109,11 @@ makeTLSContextStream cxt = S.makeStream readStream writeStream where readStream :: IO (Maybe ByteString) - readStream = - (Just <$> T.recvData cxt) `E.catch` \case - T.Error_EOF -> pure Nothing - e -> E.throwIO e + readStream = (Just <$> T.recvData cxt) `E.catches` [E.Handler handleTlsEOF, E.Handler handleEOF] + where + handleTlsEOF = \case + T.PostHandshake T.Error_EOF -> pure Nothing + e -> E.throwIO e + handleEOF e = if isEOFError e then pure Nothing else E.throwIO e writeStream :: Maybe LB.ByteString -> IO () writeStream = maybe (closeTLS cxt) (T.sendData cxt) diff --git a/src/Simplex/RemoteControl/Client.hs b/src/Simplex/RemoteControl/Client.hs index de0cbce3b..381397c6e 100644 --- a/src/Simplex/RemoteControl/Client.hs +++ b/src/Simplex/RemoteControl/Client.hs @@ -305,7 +305,7 @@ connectRCCtrl_ drg pairing'@RCCtrlPairing {caKey, caCert} inv@RCInvitation {ca, catchRCError :: ExceptT RCErrorType IO a -> (RCErrorType -> ExceptT RCErrorType IO a) -> ExceptT RCErrorType IO a catchRCError = catchAllErrors $ \e -> case fromException e of - Just (TLS.Terminated _ _ (TLS.Error_Protocol (_, _, TLS.UnknownCa))) -> RCEIdentity + Just (TLS.Terminated _ _ (TLS.Error_Protocol _ TLS.UnknownCa)) -> RCEIdentity _ -> RCEException $ show e {-# INLINE catchRCError #-}