tls 2.6.4 → 2.6.5
raw patch · 11 files changed
+185/−35 lines, 11 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Network.TLS: VerifyData :: ByteString -> VerifyData
+ Network.TLS: newtype VerifyData
Files
- CHANGELOG.md +9/−0
- Network/TLS.hs +2/−0
- Network/TLS/Context.hs +2/−2
- Network/TLS/Core.hs +12/−2
- Network/TLS/Handshake/Client.hs +0/−2
- Network/TLS/Handshake/Client/ClientHello.hs +15/−8
- Network/TLS/Handshake/Client/TLS13.hs +33/−19
- Network/TLS/IO.hs +8/−0
- Network/TLS/Struct.hs +3/−0
- test/HandshakeSpec.hs +100/−1
- tls.cabal +1/−1
CHANGELOG.md view
@@ -1,5 +1,14 @@ # Change log for "tls" +## Version 2.6.5++* Throw a late alert of client authentication failure on the next receive.+ [#703](https://github.com/haskell-tls/hs-tls/pull/703)+* Send TLS 1.3 ChangeCipherSpec of the client in one write with the next message.+ [#704](https://github.com/haskell-tls/hs-tls/pull/704)+* Export VerifyData, which getFinished and getPeerFinished return.+ [#705](https://github.com/haskell-tls/hs-tls/pull/705)+ ## Version 2.6.4 * An interrupted receive breaks the receive side and wakes PHA waiters.
Network/TLS.hs view
@@ -281,6 +281,7 @@ getTLSServerEndPoint, getFinished, getPeerFinished,+ VerifyData (..), -- ** Modifying hooks in context Hooks,@@ -381,6 +382,7 @@ ServerRandom (..), TLSError (..), TLSException (..),+ VerifyData (..), signatureSchemesForTLS13, supportedSignatureSchemes, )
Network/TLS/Context.hs view
@@ -269,13 +269,13 @@ contextHookSetLogging context loggingCallbacks = contextModifyHooks context (\hooks -> hooks{hookLogging = loggingCallbacks}) -{-# DEPRECATED getFinished "Use getTLSUnique instead" #-}+{-# DEPRECATED getFinished "Use getTLSUnique (TLS 1.2) or getTLSExporter (TLS 1.3) for channel binding" #-} -- | Getting TLS Finished sent to peer. getFinished :: Context -> IO (Maybe VerifyData) getFinished ctx = usingState_ ctx getMyVerifyData -{-# DEPRECATED getPeerFinished "Use getTLSUnique instead" #-}+{-# DEPRECATED getPeerFinished "Use getTLSUnique (TLS 1.2) or getTLSExporter (TLS 1.3) for channel binding" #-} -- | Getting TLS Finished received from peer. getPeerFinished :: Context -> IO (Maybe VerifyData)
Network/TLS/Core.hs view
@@ -453,7 +453,7 @@ recvData ctx = liftIO $ do tls13 <- tls13orLater ctx withReadLock ctx $ do- checkValid ctx+ checkValidOrPending ctx -- We protect with a read lock both reception and processing of the -- packet, because don't want another thread to receive a new packet -- before this one has been fully processed.@@ -476,10 +476,20 @@ tls13 <- tls13orLater ctx (giveUp', given) <- recording giveUp fmap join $ withReadLockGivingUp ctx giveUp $ do- checkValid ctx+ checkValidOrPending ctx withRxGiveUp ctx (GiveUp giveUp' giveUp') $ (Right <$> if tls13 then recvData13 ctx else recvData12 ctx) `E.catch` \GaveUp -> given >>= maybe (E.throwIO GaveUp) (return . Left)++-- | 'checkValid', except that an error of the receive in the thread of+-- 'waitAuthFailure', such as an alert which also set EOF, is left for+-- 'recvData13' to throw.+checkValidOrPending :: Context -> IO ()+checkValidOrPending ctx = do+ pending <- tls13stPendingRecv <$> getTLS13State ctx+ case pending of+ PendingRecvError _ -> return ()+ _ -> checkValid ctx recvData12 :: Context -> IO ByteString recvData12 ctx = do
Network/TLS/Handshake/Client.hs view
@@ -18,7 +18,6 @@ import Network.TLS.Handshake.Common13 import Network.TLS.Handshake.State import Network.TLS.Handshake.State13-import Network.TLS.IO import Network.TLS.Imports import Network.TLS.Measurement import Network.TLS.Parameters@@ -171,7 +170,6 @@ usingHState ctx $ setTLS13HandshakeMode HelloRetryRequest clearTxRecordState ctx let cparams' = cparams{clientUseEarlyData = False}- runPacketFlight ctx $ sendChangeCipherSpec13 ctx clientSession <- tls13stSession <$> getTLS13State ctx -- RFC 8446 Sec 4.1.2: the second ClientHello MUST be identical -- to the first except for the specific listed changes.
Network/TLS/Handshake/Client/ClientHello.hs view
@@ -9,6 +9,7 @@ ) where import qualified Control.Exception as E+import Control.Monad.IO.Class (liftIO) import Crypto.HPKE hiding (CipherText, PlainText) import Data.ByteArray (convert) import qualified Data.ByteArray as BA@@ -167,10 +168,15 @@ -- encodeUpdateTranscriptHash12 usingHState ctx $ setClientHello ch0 [] return ch0- sendPacket12 ctx $ Handshake [ClientHello ch] []- mEarlySecInfo <- case rtt0info of- Nothing -> return Nothing- Just info -> Just <$> getEarlySecretInfo info+ -- One write with ChangeCipherSpec: a second one could wait for the+ -- server's delayed ACK of the first.+ mEarlySecInfo <- runPacketFlight ctx $ do+ -- After HelloRetryRequest, it precedes the second ClientHello.+ when (hrr && not (ctxQUICMode ctx)) $ sendChangeCipherSpec13 ctx+ loadPacket12 ctx $ Handshake [ClientHello ch] []+ case rtt0info of+ Nothing -> return Nothing+ Just info -> Just <$> getEarlySecretInfo info unless hrr $ contextSync ctx $ SendClientHello mEarlySecInfo let sentExtensions = map (\(ExtensionRaw i _) -> i) extensions modifyTLS13State ctx $ \st -> st{tls13stSentExtensions = sentExtensions}@@ -383,12 +389,13 @@ usedHash = cHash choice -- Early data is protected with the first PSK. earlySecret : _ <- usingHState ctx getTLS13EarlySecrets- earlyKey <- calculateEarlySecret ctx choice (Right earlySecret)+ earlyKey <- liftIO $ calculateEarlySecret ctx choice (Right earlySecret) let clientEarlySecret = pairClient earlyKey unless (ctxQUICMode ctx) $ do- runPacketFlight ctx $ sendChangeCipherSpec13 ctx- setTxRecordState ctx usedHash usedCipher clientEarlySecret- setEstablished ctx EarlyDataSending+ sendChangeCipherSpec13 ctx+ liftIO $ do+ setTxRecordState ctx usedHash usedCipher clientEarlySecret+ setEstablished ctx EarlyDataSending -- We set RTT0Sent even in quicMode usingHState ctx $ setTLS13RTT0Status RTT0Sent return $ EarlySecretInfo usedCipher clientEarlySecret
Network/TLS/Handshake/Client/TLS13.hs view
@@ -327,14 +327,17 @@ -> IO () sendClientSecondFlight13' cparams ctx choice hkey rtt0accepted eexts = do hChSf <- transcriptHash ctx "CH..SF"- unless (ctxQUICMode ctx) $- runPacketFlight ctx $- sendChangeCipherSpec13 ctx- when (rtt0accepted && not (ctxQUICMode ctx)) $- sendPacket13 ctx (Handshake13 [EndOfEarlyData13] [])+ mcc <- clientChain cparams ctx let clientHandshakeSecret = triClient hkey- setTxRecordState ctx usedHash usedCipher clientHandshakeSecret- sendClientFlight13 cparams ctx usedHash clientHandshakeSecret+ -- One write: a second one could wait for the server's delayed ACK of+ -- the first, longer than the client waits for an alert of failure.+ runPacketFlight ctx $ do+ unless (ctxQUICMode ctx) $ do+ sendChangeCipherSpec13 ctx+ when rtt0accepted $+ loadPacket13 ctx (Handshake13 [EndOfEarlyData13] [])+ liftIO $ setTxRecordState ctx usedHash usedCipher clientHandshakeSecret+ loadClientFlight13 ctx usedHash clientHandshakeSecret mcc appKey <- switchToApplicationSecret hChSf let applicationSecret = triBase appKey setResumptionSecret applicationSecret@@ -375,20 +378,31 @@ sendClientFlight13 :: ClientParams -> Context -> Hash -> ClientTrafficSecret a -> IO ()-sendClientFlight13 cparams ctx usedHash (ClientTrafficSecret baseKey) = do+sendClientFlight13 cparams ctx usedHash secret = do mcc <- clientChain cparams ctx- runPacketFlight ctx $ do- case mcc of- Nothing -> return ()- Just cc -> do- reqtoken <- usingHState ctx getCertReqToken- certComp <- usingHState ctx getTLS13CertComp- loadClientData13 cc reqtoken certComp- rawFinished <- makeFinished ctx usedHash baseKey- loadPacket13 ctx $ Handshake13 [rawFinished] []+ runPacketFlight ctx $ loadClientFlight13 ctx usedHash secret mcc++-- | Certificate, CertificateVerify if any, and Finished.+loadClientFlight13+ :: Monoid b+ => Context+ -> Hash+ -> ClientTrafficSecret a+ -> Maybe CertificateChain+ -> PacketFlightM b ()+loadClientFlight13 ctx usedHash (ClientTrafficSecret baseKey) mcc = do+ case mcc of+ Nothing -> return ()+ Just cc -> do+ reqtoken <- usingHState ctx getCertReqToken+ certComp <- usingHState ctx getTLS13CertComp+ loadClientData13 cc reqtoken certComp+ rawFinished <- makeFinished ctx usedHash baseKey+ loadPacket13 ctx $ Handshake13 [rawFinished] [] when (isJust mcc) $- modifyTLS13State ctx $- \st -> st{tls13stSentClientCert = True}+ liftIO $+ modifyTLS13State ctx $+ \st -> st{tls13stSentClientCert = True} where loadClientData13 chain (Just token) certComp = do let (CertificateChain certs) = chain
Network/TLS/IO.hs view
@@ -13,6 +13,7 @@ -- * Grouping multiple packets in the same flight PacketFlightM, runPacketFlight,+ loadPacket12, loadPacket13, ) where @@ -252,6 +253,13 @@ build <- readIORef ref let bss = build [] unless (null bss) $ recordSendBytes recordLayer ctx $ mconcat bss++loadPacket12 :: Monoid b => Context -> Packet -> PacketFlightM b ()+loadPacket12 ctx pkt = PacketFlightM $ do+ (recordLayer, ref) <- ask+ liftIO $ do+ bs <- writePacketBytes12 ctx recordLayer pkt+ modifyIORef' ref (. (bs :)) loadPacket13 :: Monoid b => Context -> Packet13 -> PacketFlightM b () loadPacket13 ctx pkt = PacketFlightM $ do
Network/TLS/Struct.hs view
@@ -275,6 +275,9 @@ {-# DEPRECATED FinishedData "use VerifyData" #-} type FinishedData = ByteString +-- | The verify_data of a Finished message.+--+-- Exported from "Network.TLS" since 2.6.5. newtype VerifyData = VerifyData ByteString deriving (Eq) instance Show VerifyData where show (VerifyData bs) = showBytesHex bs
test/HandshakeSpec.hs view
@@ -10,7 +10,7 @@ takeMVar, threadDelay, )-import Control.Concurrent.Async (concurrently_)+import Control.Concurrent.Async (concurrently_, withAsync) import qualified Control.Exception as E import Control.Monad import Crypto.Cipher.AES (AES128)@@ -180,6 +180,8 @@ it "refuses a custom DH prime outside the bounds of its size" $ handshake_dh_prime_size prop "can receive client authentication failure" handshake_client_auth_fail+ it "reports a late TLS 1.3 client authentication failure on receive" $+ handshake13_client_auth_late_fail it "accepts an empty TLS 1.2 client certificate when the hook does" $ handshake_client_auth_empty TLS12 it "accepts an empty TLS 1.3 client certificate when the hook does" $@@ -485,6 +487,8 @@ [P256] it "rejects a two-byte TLS 1.3 ChangeCipherSpec" $ malformed_ccs_unexpected TLS13 cipher13_AES_128_GCM_SHA256 [X25519] [X25519]+ it "sends ChangeCipherSpec of TLS 1.3 with the next message" $+ handshake13_ccs_not_alone it "rejects a two-byte TLS 1.3 ChangeCipherSpec after HelloRetryRequest" $ malformed_ccs_unexpected TLS13@@ -2000,6 +2004,42 @@ where validateChain _ _ = return (CertificateUsageReject CertificateRejectUnknownCA) +-- The rejection arrives after the client has stopped waiting for it, so+-- the client's handshake succeeds and the next receive gets the alert.+handshake13_client_auth_late_fail :: IO ()+handshake13_client_auth_late_fail = do+ let cipher = cipher13_AES_128_GCM_SHA256+ (clientParam, serverParam) <-+ generate $+ arbitraryPairParamsWithVersionsAndCiphers+ ([TLS13], [TLS13])+ ([cipher], [cipher])+ cred <- generate $ arbitraryClientCredential TLS13+ let clientParam' =+ clientParam+ { clientHooks =+ (clientHooks clientParam)+ { onCertificateRequest = \_ -> return $ Just cred+ }+ }+ serverParam' =+ serverParam+ { serverWantClientCert = True+ , serverHooks =+ (serverHooks serverParam)+ { onClientCertificate = \_ -> do+ threadDelay 300000+ return (CertificateUsageReject CertificateRejectUnknownCA)+ }+ }+ withPairContext (clientParam', serverParam') $ \(cCtx, sCtx) ->+ withAsync (E.try (handshake sCtx) :: IO (Either TLSException ())) $ \_ -> do+ timeout 5000000 (handshake cCtx) `shouldReturn` Just ()+ r <- timeout 5000000 $ E.try $ recvData cCtx+ case r of+ Just (Left (Terminated _ _ (Error_Protocol _ UnknownCa))) -> return ()+ _ -> expectationFailure $ "unexpected: " ++ show r+ -------------------------------------------------------------- handshake_ems :: (EMSMode, EMSMode) -> IO ()@@ -2904,6 +2944,65 @@ params2 = (pc{clientUseEarlyData = True}, ps) runTLS0RTT params2 RTT0 earlyData++-- A ChangeCipherSpec written alone makes the next write wait for the+-- peer's delayed ACK. The client sends it after HelloRetryRequest, with+-- its certificate, and with early data.+handshake13_ccs_not_alone :: IO ()+handshake13_ccs_not_alone = do+ (cli, srv) <- generate arbitraryPairParams13+ cred <- generate $ arbitraryClientCredential TLS13+ let cliSupported =+ defaultSupported+ { supportedCiphers = [cipher13_AES_128_GCM_SHA256]+ , supportedGroups = [P256, X25519]+ }+ svrSupported =+ defaultSupported+ { supportedCiphers = [cipher13_AES_128_GCM_SHA256]+ , supportedGroups = [X25519]+ , supportedGroupsTLS13 = [[X25519]]+ }+ params0 =+ ( cli+ { clientSupported = cliSupported+ , clientHooks =+ (clientHooks cli){onCertificateRequest = \_ -> return $ Just cred}+ }+ , srv+ { serverSupported = svrSupported+ , serverWantClientCert = True+ , serverHooks =+ (serverHooks srv)+ { onClientCertificate = \_ -> return CertificateUsageAccept+ }+ , serverEarlyDataSize = 2048+ }+ )+ sessionRefs <- twoSessionRefs+ let params = setPairParamsSessionManagers (twoSessionManagers sessionRefs) params0+ sent1 <- recordingClientSends params $ \(cCtx, sCtx) -> do+ concurrently_ (handshake cCtx) (handshake sCtx)+ concurrently_ (sendData sCtx "x") (recvDataAssert cCtx "x")+ mmode <- (>>= infoTLS13HandshakeMode) <$> contextGetInformation cCtx+ mmode `shouldBe` Just HelloRetryRequest+ filter (== ccs) sent1 `shouldBe` []+ Just sessionParams <- readClientSessionRef sessionRefs+ let (pc, ps) = setPairParamsSessionResuming sessionParams params+ sent2 <- recordingClientSends (pc{clientUseEarlyData = True}, ps) $ \(cCtx, sCtx) -> do+ concurrently_+ (handshake cCtx >> sendData cCtx "y" >> recvDataAssert cCtx "z")+ (handshake sCtx >> recvDataAssert sCtx "y" >> sendData sCtx "z")+ mmode <- (>>= infoTLS13HandshakeMode) <$> contextGetInformation cCtx+ mmode `shouldBe` Just RTT0+ filter (== ccs) sent2 `shouldBe` []+ where+ ccs = B.pack [20, 3, 3, 0, 1, 1]+ recordingClientSends params body = do+ ref <- newIORef []+ let wrap be = be{backendSend = \bs -> modifyIORef ref (bs :) >> backendSend be bs}+ _ <- withPairContextWith (wrap, id) params body+ reverse <$> readIORef ref handshake13_0rtt_alpn :: IO () handshake13_0rtt_alpn = do
tls.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.0 name: tls-version: 2.6.4+version: 2.6.5 license: BSD3 license-file: LICENSE copyright: Vincent Hanquez <vincent@snarc.org>