tls 2.5.3 → 2.5.4
raw patch · 6 files changed
+91/−25 lines, 6 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 +5/−0
- Network/TLS/Handshake/Server/ClientHello13.hs +22/−18
- Network/TLS/Parameters.hs +3/−2
- Network/TLS/Session.hs +4/−1
- test/HandshakeSpec.hs +53/−0
- tls.cabal +4/−4
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Change log for "tls" +## Version 2.5.4++* Use up a session for 0-RTT only after checking the ClientHello.+ [#655](https://github.com/haskell-tls/hs-tls/pull/655)+ ## Version 2.5.3 * Count milliseconds from the base without overflowing a 32-bit time_t.
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
@@ -247,8 +247,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.5.3+version: 2.5.4 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 >=0.0.2, hpke >=0.4.0 && <0.5,