From a78162e2985efd1c6c186deb86f8e7b006f97fa1 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Wed, 5 Jan 2011 09:20:33 +0000 Subject: [PATCH] add support for ciphers without encryption. --- Network/TLS/Receiving.hs | 12 +++++++++++- Network/TLS/Sending.hs | 2 +- Tests/Ciphers.hs | 2 ++ Tests/Common.hs | 4 +++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Network/TLS/Receiving.hs b/Network/TLS/Receiving.hs index f03281d..4c043e1 100644 --- a/Network/TLS/Receiving.hs +++ b/Network/TLS/Receiving.hs @@ -205,7 +205,17 @@ decryptData (EncryptedData econtent) = do let writekey = cstKey cst case cipherF cipher of - CipherNoneF -> fail "none decrypt" + CipherNoneF -> do + let contentlen = B.length econtent - digestSize + case partition3 econtent (contentlen, digestSize, 0) of + Nothing -> + throwError $ Error_Misc "partition3 failed" + Just (content, mac, _) -> + return $ CipherData + { cipherDataContent = content + , cipherDataMAC = Just mac + , cipherDataPadding = Nothing + } CipherBlockF _ decryptF -> do {- update IV -} let (iv, econtent') = diff --git a/Network/TLS/Sending.hs b/Network/TLS/Sending.hs index ab78fc3..638c17e 100644 --- a/Network/TLS/Sending.hs +++ b/Network/TLS/Sending.hs @@ -144,7 +144,7 @@ encryptData content = do let writekey = cstKey cst econtent <- case cipherF cipher of - CipherNoneF -> fail "none encrypt" + CipherNoneF -> return content CipherBlockF encrypt _ -> do let iv = cstIV cst let e = encrypt writekey iv (B.concat [ content, padding ]) diff --git a/Tests/Ciphers.hs b/Tests/Ciphers.hs index afb2f10..cab6a0f 100644 --- a/Tests/Ciphers.hs +++ b/Tests/Ciphers.hs @@ -33,6 +33,8 @@ cipher_test cipher = run_test n t key <- B.pack <$> arbitraryKey cipher t <- B.pack <$> arbitraryText cipher return $ stream ktoi enc dec key t + CipherNoneF -> do + return True block e d key iv t = (d key iv . e key iv) t == t stream ktoi e d key t = (fst . d iv . fst . e iv) t == t where iv = ktoi key diff --git a/Tests/Common.hs b/Tests/Common.hs index ee2727a..3fc63bf 100644 --- a/Tests/Common.hs +++ b/Tests/Common.hs @@ -11,7 +11,9 @@ supportedVersions = [SSL3, TLS10, TLS11] supportedCiphers :: [Cipher] supportedCiphers = - [ cipher_AES128_SHA1 + [ cipher_null_MD5 + , cipher_null_SHA1 + , cipher_AES128_SHA1 , cipher_AES256_SHA1 , cipher_RC4_128_MD5 , cipher_RC4_128_SHA1