Skip to content

Commit

Permalink
adding the KeyUpdateRequest argument to keyUpdate.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Nov 23, 2018
1 parent 0c300f9 commit 549eb76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/Network/TLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ module Network.TLS
, recvData
, recvData'
, updateKey
, KeyUpdateRequest(..)

-- * Crypto Key
, PubKey(..)
Expand Down
15 changes: 12 additions & 3 deletions core/Network/TLS/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Network.TLS.Core
, recvData
, recvData'
, updateKey
, KeyUpdateRequest(..)
) where

import Network.TLS.Cipher
Expand Down Expand Up @@ -241,13 +242,21 @@ keyUpdate ctx getState setState = do
let applicationTrafficSecretN1 = hkdfExpandLabel usedHash applicationTrafficSecretN "traffic upd" "" $ hashDigestSize usedHash
setState ctx usedHash usedCipher applicationTrafficSecretN1

-- | How to update keys in TLS 1.3
data KeyUpdateRequest = OneWay -- ^ Unidirectional key update
| TwoWay -- ^ Bidirectional key update (normal case)
deriving (Eq, Show)

-- | Updating appication traffic secrets for TLS 1.3.
-- If this API is called for TLS 1.3, 'True' is returned.
-- Otherwise, 'False' is returned.
updateKey :: Context -> IO Bool
updateKey ctx = do
updateKey :: Context -> KeyUpdateRequest -> IO Bool
updateKey ctx way = do
tls13 <- tls13orLater ctx
when tls13 $ do
sendPacket13 ctx $ Handshake13 [KeyUpdate13 UpdateRequested]
let req = case way of
OneWay -> UpdateNotRequested
TwoWay -> UpdateRequested
sendPacket13 ctx $ Handshake13 [KeyUpdate13 req]
keyUpdate ctx getTxState setTxState
return tls13
6 changes: 4 additions & 2 deletions core/Tests/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ runTLSPipeSimpleKeyUpdate params = runTLSPipeN 3 params tlsServer tlsClient
where tlsServer ctx queue = do
handshake ctx
d0 <- recvDataNonNull ctx
_ <- updateKey ctx
req <- generate $ elements [OneWay, TwoWay]
_ <- updateKey ctx req
d1 <- recvDataNonNull ctx
d2 <- recvDataNonNull ctx
writeChan queue [d0,d1,d2]
Expand All @@ -133,7 +134,8 @@ runTLSPipeSimpleKeyUpdate params = runTLSPipeN 3 params tlsServer tlsClient
sendData ctx (L.fromChunks [d0])
d1 <- readChan queue
sendData ctx (L.fromChunks [d1])
_ <- updateKey ctx
req <- generate $ elements [OneWay, TwoWay]
_ <- updateKey ctx req
d2 <- readChan queue
sendData ctx (L.fromChunks [d2])
bye ctx
Expand Down

0 comments on commit 549eb76

Please sign in to comment.