Skip to content

Commit 63789d0

Browse files
committed
deps: use tls-2.0
1 parent bb1d31e commit 63789d0

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ packages: .
44
-- packages: . ../http2
55
-- packages: . ../network-transport
66

7-
index-state: 2023-12-12T00:00:00Z
7+
index-state: 2024-06-01T00:00:00Z
88

99
package cryptostore
1010
flags: +use_crypton

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ dependencies:
6969
- temporary == 1.3.*
7070
- time == 1.12.*
7171
- time-manager == 0.0.*
72-
- tls >= 1.7.0 && < 1.8
72+
- tls >= 2.0.6 && < 2.1
7373
- transformers == 0.6.*
7474
- unliftio == 0.2.*
7575
- unliftio-core == 0.2.*

simplexmq.cabal

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ library
255255
, temporary ==1.3.*
256256
, time ==1.12.*
257257
, time-manager ==0.0.*
258-
, tls >=1.7.0 && <1.8
258+
, tls >=2.0.6 && <2.1
259259
, transformers ==0.6.*
260260
, unliftio ==0.2.*
261261
, unliftio-core ==0.2.*
@@ -330,7 +330,7 @@ executable ntf-server
330330
, temporary ==1.3.*
331331
, time ==1.12.*
332332
, time-manager ==0.0.*
333-
, tls >=1.7.0 && <1.8
333+
, tls >=2.0.6 && <2.1
334334
, transformers ==0.6.*
335335
, unliftio ==0.2.*
336336
, unliftio-core ==0.2.*
@@ -409,7 +409,7 @@ executable smp-server
409409
, temporary ==1.3.*
410410
, time ==1.12.*
411411
, time-manager ==0.0.*
412-
, tls >=1.7.0 && <1.8
412+
, tls >=2.0.6 && <2.1
413413
, transformers ==0.6.*
414414
, unliftio ==0.2.*
415415
, unliftio-core ==0.2.*
@@ -487,7 +487,7 @@ executable xftp
487487
, temporary ==1.3.*
488488
, time ==1.12.*
489489
, time-manager ==0.0.*
490-
, tls >=1.7.0 && <1.8
490+
, tls >=2.0.6 && <2.1
491491
, transformers ==0.6.*
492492
, unliftio ==0.2.*
493493
, unliftio-core ==0.2.*
@@ -562,7 +562,7 @@ executable xftp-server
562562
, temporary ==1.3.*
563563
, time ==1.12.*
564564
, time-manager ==0.0.*
565-
, tls >=1.7.0 && <1.8
565+
, tls >=2.0.6 && <2.1
566566
, transformers ==0.6.*
567567
, unliftio ==0.2.*
568568
, unliftio-core ==0.2.*
@@ -678,7 +678,7 @@ test-suite simplexmq-test
678678
, time ==1.12.*
679679
, time-manager ==0.0.*
680680
, timeit ==2.0.*
681-
, tls >=1.7.0 && <1.8
681+
, tls >=2.0.6 && <2.1
682682
, transformers ==0.6.*
683683
, unliftio ==0.2.*
684684
, unliftio-core ==0.2.*

src/Simplex/Messaging/Transport.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import Simplex.Messaging.Transport.Buffer
112112
import Simplex.Messaging.Util (bshow, catchAll, catchAll_, liftEitherWith)
113113
import Simplex.Messaging.Version
114114
import Simplex.Messaging.Version.Internal
115+
import System.IO.Error (isEOFError)
115116
import UnliftIO.Exception (Exception)
116117
import qualified UnliftIO.Exception as E
117118
import UnliftIO.STM
@@ -335,11 +336,12 @@ instance Transport TLS where
335336

336337
getLn :: TLS -> IO ByteString
337338
getLn TLS {tlsContext, tlsBuffer} = do
338-
getLnBuffered tlsBuffer (T.recvData tlsContext) `E.catch` handleEOF
339+
getLnBuffered tlsBuffer (T.recvData tlsContext) `E.catches` [E.Handler handleTlsEOF, E.Handler handleEOF]
339340
where
340-
handleEOF = \case
341-
T.Error_EOF -> E.throwIO TEBadBlock
341+
handleTlsEOF = \case
342+
T.PostHandshake T.Error_EOF -> E.throwIO TEBadBlock
342343
e -> E.throwIO e
344+
handleEOF e = if isEOFError e then E.throwIO TEBadBlock else E.throwIO e
343345

344346
-- * SMP transport
345347

src/Simplex/Messaging/Transport/WebSockets.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Simplex.Messaging.Transport
2525
withTlsUnique,
2626
)
2727
import Simplex.Messaging.Transport.Buffer (trimCR)
28+
import System.IO.Error (isEOFError)
2829

2930
data WS = WS
3031
{ wsPeer :: TransportPeer,
@@ -108,9 +109,11 @@ makeTLSContextStream cxt =
108109
S.makeStream readStream writeStream
109110
where
110111
readStream :: IO (Maybe ByteString)
111-
readStream =
112-
(Just <$> T.recvData cxt) `E.catch` \case
113-
T.Error_EOF -> pure Nothing
114-
e -> E.throwIO e
112+
readStream = (Just <$> T.recvData cxt) `E.catches` [E.Handler handleTlsEOF, E.Handler handleEOF]
113+
where
114+
handleTlsEOF = \case
115+
T.PostHandshake T.Error_EOF -> pure Nothing
116+
e -> E.throwIO e
117+
handleEOF e = if isEOFError e then pure Nothing else E.throwIO e
115118
writeStream :: Maybe LB.ByteString -> IO ()
116119
writeStream = maybe (closeTLS cxt) (T.sendData cxt)

src/Simplex/RemoteControl/Client.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,7 @@ connectRCCtrl_ drg pairing'@RCCtrlPairing {caKey, caCert} inv@RCInvitation {ca,
281281
TLS.Credentials (creds : _) -> pure $ Just creds
282282
_ -> throwE $ RCEInternal "genTLSCredentials must generate credentials"
283283
let clientConfig = defaultTransportClientConfig {clientCredentials}
284-
ExceptT . runTransportClient clientConfig Nothing host (show port) (Just ca) $ \tls@TLS {tlsBuffer, tlsContext} -> runExceptT $ do
285-
-- pump socket to detect connection problems
286-
liftIO $ peekBuffered tlsBuffer 100000 (TLS.recvData tlsContext) >>= logDebug . tshow -- should normally be ("", Nothing) here
284+
ExceptT . runTransportClient clientConfig Nothing host (show port) (Just ca) $ \tls -> runExceptT $ do
287285
logDebug "Got TLS connection"
288286
r' <- newEmptyTMVarIO
289287
whenM (atomically $ tryPutTMVar r $ Right (tlsUniq tls, tls, r')) $ do
@@ -305,7 +303,7 @@ connectRCCtrl_ drg pairing'@RCCtrlPairing {caKey, caCert} inv@RCInvitation {ca,
305303

306304
catchRCError :: ExceptT RCErrorType IO a -> (RCErrorType -> ExceptT RCErrorType IO a) -> ExceptT RCErrorType IO a
307305
catchRCError = catchAllErrors $ \e -> case fromException e of
308-
Just (TLS.Terminated _ _ (TLS.Error_Protocol (_, _, TLS.UnknownCa))) -> RCEIdentity
306+
Just (TLS.Terminated _ _ (TLS.Error_Protocol _ TLS.UnknownCa)) -> RCEIdentity
309307
_ -> RCEException $ show e
310308
{-# INLINE catchRCError #-}
311309

0 commit comments

Comments
 (0)