packages feed

tls 2.4.16 → 2.4.17

raw patch · 5 files changed

+84/−16 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Network.TLS: ValidationChecks :: Bool -> Maybe DateTime -> Bool -> Bool -> Bool -> Bool -> [ExtKeyUsageFlag] -> [ExtKeyUsagePurpose] -> Bool -> ValidationChecks
- Network.TLS: ValidationHooks :: (DistinguishedName -> Certificate -> Bool) -> (DateTime -> Certificate -> [FailedReason]) -> (HostName -> Certificate -> [FailedReason]) -> ([FailedReason] -> [FailedReason]) -> ValidationHooks
- Network.TLS: [checkAtTime] :: ValidationChecks -> Maybe DateTime
- Network.TLS: [checkCAConstraints] :: ValidationChecks -> Bool
- Network.TLS: [checkExhaustive] :: ValidationChecks -> Bool
- Network.TLS: [checkFQHN] :: ValidationChecks -> Bool
- Network.TLS: [checkLeafKeyPurpose] :: ValidationChecks -> [ExtKeyUsagePurpose]
- Network.TLS: [checkLeafKeyUsage] :: ValidationChecks -> [ExtKeyUsageFlag]
- Network.TLS: [checkLeafV3] :: ValidationChecks -> Bool
- Network.TLS: [checkStrictOrdering] :: ValidationChecks -> Bool
- Network.TLS: [checkTimeValidity] :: ValidationChecks -> Bool
- Network.TLS: [hookFilterReason] :: ValidationHooks -> [FailedReason] -> [FailedReason]
- Network.TLS: [hookMatchSubjectIssuer] :: ValidationHooks -> DistinguishedName -> Certificate -> Bool
- Network.TLS: [hookValidateName] :: ValidationHooks -> HostName -> Certificate -> [FailedReason]
- Network.TLS: [hookValidateTime] :: ValidationHooks -> DateTime -> Certificate -> [FailedReason]
+ Network.TLS: PrivKeyMLKEM1024 :: PrivKeyMLKEM MLKEM1024 -> PrivKey
+ Network.TLS: PrivKeyMLKEM512 :: PrivKeyMLKEM MLKEM512 -> PrivKey
+ Network.TLS: PrivKeyMLKEM768 :: PrivKeyMLKEM MLKEM768 -> PrivKey
+ Network.TLS: PrivKeyRSAPSS :: PrivateKey -> Maybe PSSParams -> PrivKey
+ Network.TLS: PubKeyMLKEM1024 :: EncapsulationKey MLKEM1024 -> PubKey
+ Network.TLS: PubKeyMLKEM512 :: EncapsulationKey MLKEM512 -> PubKey
+ Network.TLS: PubKeyMLKEM768 :: EncapsulationKey MLKEM768 -> PubKey
+ Network.TLS: PubKeyRSAPSS :: PublicKey -> Maybe PSSParams -> PubKey
- Network.TLS: PubKeyDH :: (Integer, Integer, Integer, Maybe Integer, ([Word8], Integer)) -> PubKey
+ Network.TLS: PubKeyDH :: PubKeyDH -> PubKey

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Change log for "tls" +## Version 2.4.17++* Use up a session for 0-RTT only after checking the ClientHello.+  [#655](https://github.com/haskell-tls/hs-tls/pull/655)+ ## Version 2.4.16  * Count milliseconds from the base without overflowing a 32-bit time_t.
Network/TLS/Handshake/Server/ClientHello13.hs view
@@ -156,21 +156,28 @@     -> 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 -> isJust <$> sessionResumeOnlyOnce mgr identity     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@@ -183,20 +190,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@@ -208,12 +210,16 @@                     let psk = sessionSecret sdata                     isFresh <- checkFreshness tinfo obfAge                     (isPSKvalid, is0RTTvalid) <- checkSessionEquality sdata+                    -- Early data is only with the first identity.+                    let m0RTT+                            | rtt0 && is0RTTvalid && n == 0 = Just identity+                            | otherwise = Nothing                     if isPSKvalid && isFresh                         then                             return                                 ( psk                                 , Just (bnd, n :: Int, len)-                                , is0RTTvalid && n == 0+                                , m0RTT                                 , sessionALPN sdata                                 )                         else tryPSK len rest
Network/TLS/Session.hs view
@@ -11,8 +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 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
@@ -203,6 +203,10 @@         it "rejects TLS 1.3 early data when ALPN changes" $             handshake13_0rtt_alpn         prop "can handshake with TLS 1.3 0RTT -> PSK" handshake13_0rtt_fallback+        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" $@@ -2690,6 +2694,55 @@         handshake ctx         _ <- recvData ctx         bye ctx++-- | '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)  -- The server has forgotten the session, so it answers 0-RTT with a full -- handshake, and the client must check its certificate.
tls.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.0 name:               tls-version:            2.4.16+version:            2.4.17 license:            BSD3 license-file:       LICENSE copyright:          Vincent Hanquez <vincent@snarc.org>@@ -125,11 +125,11 @@         bytestring >=0.10 && <0.13,         cereal >=0.5.3 && <0.6,         crypton >=2.1.9 && <2.3,-        crypton-asn1-encoding >= 0.10.0 && < 0.11,+        crypton-asn1-encoding >= 0.10.0 && < 0.12,         crypton-asn1-types >= 0.4.1 && < 0.5,-        crypton-x509 >=1.10 && <1.11,+        crypton-x509 >=1.10 && <1.12,         crypton-x509-store >=1.10 && <1.11,-        crypton-x509-validation >=1.10 && <1.11,+        crypton-x509-validation >=1.10 && <1.12,         data-default,         ech-config,         hpke >=0.4.0 && <0.5,