core: WebRTC frames encryption (#1942)

* core: WebRTC frames encryption

* test
This commit is contained in:
Evgeny Poberezkin
2023-02-19 23:51:50 +00:00
committed by GitHub
parent 07ad3edbc2
commit 0ebf1da05d
8 changed files with 71 additions and 14 deletions

View File

@@ -8,6 +8,7 @@ import ProtocolTests
import SchemaDump
import Test.Hspec
import UnliftIO.Temporary (withTempDirectory)
import WebRTCTests
main :: IO ()
main = do
@@ -15,6 +16,7 @@ main = do
withGlobalLogging logCfg . hspec $ do
describe "SimpleX chat markdown" markdownTests
describe "SimpleX chat protocol" protocolTests
describe "WebRTC encryption" webRTCTests
describe "Schema dump" schemaDumpTest
around testBracket $ do
describe "Mobile API Tests" mobileTests

18
tests/WebRTCTests.hs Normal file
View File

@@ -0,0 +1,18 @@
module WebRTCTests where
import Crypto.Random (getRandomBytes)
import qualified Data.ByteString.Base64.URL as U
import qualified Data.ByteString.Char8 as B
import Simplex.Chat.Mobile.WebRTC
import Test.Hspec
webRTCTests :: Spec
webRTCTests = describe "WebRTC crypto" $ do
it "encrypts and decrypts media" $ do
key <- U.encode <$> getRandomBytes 32
frame <- getRandomBytes 1000
let reservedSize = authTagSize + ivSize
frame' <- chatEncryptMedia key $ frame <> B.replicate reservedSize '\NUL'
B.length frame' `shouldBe` B.length frame + reservedSize
frame'' <- chatDecryptMedia key frame'
frame'' `shouldBe` frame <> B.replicate reservedSize '\NUL'