packages feed

tls 2.6.0 → 2.6.1

raw patch · 6 files changed

+88/−22 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Change log for "tls" +## Version 2.6.1++* Use up a session for 0-RTT only after checking the ClientHello.+  [#655](https://github.com/haskell-tls/hs-tls/pull/655)+ ## Version 2.6.0  The early data sizes are `Word32`, and `HasBackend` has a new method with a default.
Network/TLS/Handshake/Server/ClientHello13.hs view
@@ -157,21 +157,32 @@     -> IO (SecretPair EarlySecret, [ExtensionRaw], Bool, Bool, Maybe ByteString)     -- authenticated, is0RTTvalid, ticket ALPN pskAndEarlySecret sparams ctx (usedCipher, usedHash, rtt0) CH{..} = do-    (psk, binderInfo, is0RTTvalid, ticketALPN) <- choosePSK+    (psk, binderInfo, m0RTT, ticketALPN) <- choosePSK     earlyKey <- calculateEarlySecret ctx choice (Left psk)     let earlySecret = pairBase earlyKey         authenticated = isJust binderInfo     preSharedKeyExt <- checkBinder earlySecret binderInfo+    -- The session is used up for 0-RTT only now that the ClientHello is+    -- fresh and its binder is verified.  If it was used up already, only+    -- the early data is refused (RFC 9846 Section 8.3).+    is0RTTvalid <- case m0RTT of+        Nothing -> return False+        Just identity -> do+            msdata <- sessionResumeOnlyOnce mgr identity+            case msdata of+                Nothing -> return False+                Just sdata -> onAccept0RTT (serverHooks sparams) sdata     return (earlyKey, preSharedKeyExt, authenticated, is0RTTvalid, ticketALPN)   where     choice = makeCipherChoice TLS13 usedCipher+    mgr = sharedSessionManager $ serverShared sparams      choosePSK =         lookupAndDecodeAndDo             EID_PreSharedKey             MsgTClientHello             chExtensions-            (return (zero, Nothing, False, Nothing))+            (return (zero, Nothing, Nothing, Nothing))             selectPSK      selectPSK (PreSharedKeyClientHello ids bnds) = do@@ -184,20 +195,15 @@                 -- The first identity that can be resumed is chosen, each                 -- with its own age and binder.                 tryPSK len $ zip3 [0 ..] ids bnds-            else return (zero, Nothing, False, Nothing)-    selectPSK _ = return (zero, Nothing, False, Nothing)+            else return (zero, Nothing, Nothing, Nothing)+    selectPSK _ = return (zero, Nothing, Nothing, Nothing) -    tryPSK _ [] = return (zero, Nothing, False, Nothing)+    tryPSK _ [] = return (zero, Nothing, Nothing, Nothing)     tryPSK len ((n, PskIdentity identity obfAge, bnd) : rest) = do-        let mgr = sharedSessionManager $ serverShared sparams         -- sessionInvalidate is not used for TLS 1.3         -- because PSK is always changed.         -- So, identity is not stored in Context.-        -- Early data is only with the first identity.-        msdata <--            if rtt0 && n == 0-                then sessionResumeOnlyOnce mgr identity-                else sessionResume mgr identity+        msdata <- sessionResume mgr identity         case msdata of             -- RFC 8446 Section 4.6.1: only a TLS 1.3 session, which             -- has its ticket information, is resumed with a PSK.  A@@ -212,16 +218,14 @@                     if isPSKvalid && isFresh                         then do                             restoreClientCertificate ctx sdata-                            -- The application is asked only when 0-RTT is-                            -- otherwise possible.-                            accepted <--                                if rtt0 && is0RTTvalid && n == 0-                                    then onAccept0RTT (serverHooks sparams) sdata-                                    else return False+                            -- Early data is only with the first identity.+                            let m0RTT+                                    | rtt0 && is0RTTvalid && n == 0 = Just identity+                                    | otherwise = Nothing                             return                                 ( psk                                 , Just (bnd, n :: Int, len)-                                , accepted+                                , m0RTT                                 , sessionALPN sdata                                 )                         else tryPSK len rest
Network/TLS/Parameters.hs view
@@ -250,8 +250,9 @@     --     -- Early data can be replayed.  The server is to accept 0-RTT for the     -- same handshake at most once (RFC 9846 Section 8), which is left to-    -- 'sessionResumeOnlyOnce' of the session manager: the in-memory one of-    -- tls-session-manager does so, its session ticket one does not.+    -- 'sessionResumeOnlyOnce' of the session manager.  Both managers of+    -- tls-session-manager do so, the session ticket one since 0.1.3 and+    -- only within a process.     --     -- Default: 0     , serverTicketLifetime :: Int
Network/TLS/Session.hs view
@@ -11,9 +11,12 @@ data SessionManager = SessionManager     { sessionResume :: SessionIDorTicket -> IO (Maybe SessionData)     -- ^ Used on TLS 1.2\/1.3 servers to lookup 'SessionData' with 'SessionID' or to decrypt 'Ticket' to get 'SessionData'.+    -- It must not use up the session: it is also called first for 0RTT, before 'sessionResumeOnlyOnce'.     , sessionResumeOnlyOnce :: SessionIDorTicket -> IO (Maybe SessionData)     -- ^ Used for 0RTT on TLS 1.3 servers to lookup 'SessionData' with 'SessionID' or to decrypt 'Ticket' to get 'SessionData'.-    -- It is to return the 'SessionData' at most once for an identity, or early data can be replayed (RFC 9846 Section 8); a manager that keeps no state, as with tickets, cannot.+    -- It is called after 'sessionResume' has found the session and the ClientHello has passed the freshness and binder checks.+    -- It is to return the 'SessionData' at most once for an identity, or early data can be replayed (RFC 9846 Section 8).+    -- With 'Nothing', the early data is refused but the session is resumed.     , sessionEstablish :: SessionIDorTicket -> SessionData -> IO (Maybe Ticket)     -- ^ Used on TLS 1.2\/1.3 servers to store 'SessionData' with 'SessionID' or to encrypt 'SessionData' to get 'Ticket' ignoring 'SessionID'. Used on TLS 1.2\/1.3 clients to store 'SessionData' with 'SessionIDorTicket' and then return 'Nothing'. For clients, only this field should be set with 'noSessionManager'.     , sessionInvalidate :: SessionIDorTicket -> IO ()
test/HandshakeSpec.hs view
@@ -251,6 +251,10 @@             handshake13_0rtt_app_data True         it "refuses 0RTT, not the resumption, when the application says so" $             handshake13_0rtt_app_data False+        it "does not use up the session for a stale 0RTT ClientHello" $+            handshake13_0rtt_only_once True+        it "refuses 0RTT, not the resumption, when the session is used up" $+            handshake13_0rtt_only_once False         it "authenticates a server rejecting the PSK of 0RTT" $             handshake13_0rtt_psk_rejected False         it "authenticates a server rejecting the PSK of 0RTT, asking a cert" $@@ -2991,6 +2995,55 @@         mode = if accept then RTT0 else PreSharedKey     runTLS0RTT (pc{clientUseEarlyData = True}, ps') mode "early data"     readIORef seen `shouldReturn` Just "limits"++-- | 'sessionResumeOnlyOnce' is called only for a fresh 0RTT ClientHello+-- with a verified binder.  A stale one falls back to a full handshake+-- without it; a session it has used up already is resumed without 0RTT.+handshake13_0rtt_only_once :: Bool -> IO ()+handshake13_0rtt_only_once stale = do+    (cli, srv) <- generate arbitraryPairParams13+    let supported =+            defaultSupported+                { supportedCiphers = [cipher13_AES_128_GCM_SHA256]+                , supportedGroups = [X25519]+                , supportedGroupsTLS13 = [[X25519]]+                }+        params0 =+            ( cli{clientSupported = supported}+            , srv{serverSupported = supported, serverEarlyDataSize = 2048}+            )+    sessionRefs <- twoSessionRefs+    let (cmgr, smgr) = twoSessionManagers sessionRefs+        params = setPairParamsSessionManagers (cmgr, smgr) params0+    runTLSSimple13 params FullHandshake++    sessionParams <- readClientSessionRef sessionRefs+    expectJust "session param should be Just" sessionParams+    calls <- newIORef (0 :: Int)+    let -- an hour ago, far beyond the tolerance of the freshness check+        age sdata =+            sdata+                { sessionTicketInfo =+                    (\t -> t{txrxTime = txrxTime t - 3600000}) <$> sessionTicketInfo sdata+                }+        resume' f sid+            | stale = fmap age <$> f sid+            | otherwise = f sid+        smgr' =+            smgr+                { sessionResume = resume' (sessionResume smgr)+                , sessionResumeOnlyOnce = \sid -> do+                    modifyIORef' calls (+ 1)+                    if stale+                        then resume' (sessionResumeOnlyOnce smgr) sid+                        else return Nothing+                }+        (pc, ps) =+            setPairParamsSessionResuming (fromJust sessionParams) $+                setPairParamsSessionManagers (cmgr, smgr') params0+        mode = if stale then FullHandshake else PreSharedKey+    runTLS0RTT (pc{clientUseEarlyData = True}, ps) mode "early data"+    readIORef calls `shouldReturn` (if stale then 0 else 1)  handshake13_0rtt_fallback :: CSP13 -> IO () handshake13_0rtt_fallback (CSP13 (cli, srv)) = do
tls.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.0 name:               tls-version:            2.6.0+version:            2.6.1 license:            BSD3 license-file:       LICENSE copyright:          Vincent Hanquez <vincent@snarc.org>