From 44991943015a862e2b1df0a898432bcd73cb7258 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Tue, 17 Sep 2024 22:03:25 +0800 Subject: [PATCH] chore: remove aes cbc for framecryptor. --- api/crypto/frame_crypto_transformer.cc | 47 ++----------------- .../api/org/webrtc/FrameCryptorAlgorithm.java | 1 - sdk/android/src/jni/pc/frame_cryptor.cc | 2 - sdk/objc/api/peerconnection/RTCFrameCryptor.h | 1 - .../api/peerconnection/RTCFrameCryptor.mm | 2 - 5 files changed, 3 insertions(+), 50 deletions(-) diff --git a/api/crypto/frame_crypto_transformer.cc b/api/crypto/frame_crypto_transformer.cc index 8c26080cb7..5f6ea55a60 100644 --- a/api/crypto/frame_crypto_transformer.cc +++ b/api/crypto/frame_crypto_transformer.cc @@ -250,46 +250,6 @@ int AesGcmEncryptDecrypt(EncryptOrDecrypt mode, return Success; } -int AesCbcEncryptDecrypt(EncryptOrDecrypt mode, - const std::vector& raw_key, - rtc::ArrayView iv, - const rtc::ArrayView input, - std::vector* output) { - const EVP_CIPHER* cipher = GetAesCbcAlgorithmFromKeySize(raw_key.size()); - if (!cipher) { - RTC_LOG(LS_ERROR) << "Invalid AES-CBC key size."; - return ErrorUnexpected; - } - RTC_DCHECK_EQ(EVP_CIPHER_iv_length(cipher), iv.size()); - RTC_DCHECK_EQ(EVP_CIPHER_key_length(cipher), raw_key.size()); - - bssl::ScopedEVP_CIPHER_CTX ctx; - if (!EVP_CipherInit_ex(ctx.get(), cipher, nullptr, - reinterpret_cast(raw_key.data()), - iv.data(), - mode == EncryptOrDecrypt::kEncrypt ? 1 : 0)) { - return OperationError; - } - - // Encrypting needs a block size of space to allow for any padding. - output->resize(input.size() + - (mode == EncryptOrDecrypt::kEncrypt ? iv.size() : 0)); - int out_len; - if (!EVP_CipherUpdate(ctx.get(), output->data(), &out_len, input.data(), - input.size())) - return OperationError; - - // Write out the final block plus padding (if any) to the end of the data - // just written. - int tail_len; - if (!EVP_CipherFinal_ex(ctx.get(), output->data() + out_len, &tail_len)) - return OperationError; - - out_len += tail_len; - RTC_CHECK_LE(out_len, static_cast(output->size())); - return Success; -} - int AesEncryptDecrypt(EncryptOrDecrypt mode, webrtc::FrameCryptorTransformer::Algorithm algorithm, const std::vector& raw_key, @@ -308,8 +268,9 @@ int AesEncryptDecrypt(EncryptOrDecrypt mode, return AesGcmEncryptDecrypt( mode, raw_key, data, tag_length_bits / 8, iv, additional_data, cipher, buffer); } - case webrtc::FrameCryptorTransformer::Algorithm::kAesCbc: - return AesCbcEncryptDecrypt(mode, raw_key, iv, data, buffer); + default: + RTC_LOG(LS_ERROR) << "Unsupported algorithm."; + return ErrorUnexpected; } } namespace webrtc { @@ -724,8 +685,6 @@ uint8_t FrameCryptorTransformer::getIvSize() { switch (algorithm_) { case Algorithm::kAesGcm: return 12; - case Algorithm::kAesCbc: - return 16; default: return 0; } diff --git a/sdk/android/api/org/webrtc/FrameCryptorAlgorithm.java b/sdk/android/api/org/webrtc/FrameCryptorAlgorithm.java index d0d4dc8374..121656cc99 100644 --- a/sdk/android/api/org/webrtc/FrameCryptorAlgorithm.java +++ b/sdk/android/api/org/webrtc/FrameCryptorAlgorithm.java @@ -18,5 +18,4 @@ public enum FrameCryptorAlgorithm { AES_GCM, - AES_CBC, } \ No newline at end of file diff --git a/sdk/android/src/jni/pc/frame_cryptor.cc b/sdk/android/src/jni/pc/frame_cryptor.cc index af2fd8f2b0..33b938f7f4 100644 --- a/sdk/android/src/jni/pc/frame_cryptor.cc +++ b/sdk/android/src/jni/pc/frame_cryptor.cc @@ -103,8 +103,6 @@ webrtc::FrameCryptorTransformer::Algorithm AlgorithmFromIndex(int index) { switch (index) { case 0: return webrtc::FrameCryptorTransformer::Algorithm::kAesGcm; - case 1: - return webrtc::FrameCryptorTransformer::Algorithm::kAesCbc; default: return webrtc::FrameCryptorTransformer::Algorithm::kAesGcm; } diff --git a/sdk/objc/api/peerconnection/RTCFrameCryptor.h b/sdk/objc/api/peerconnection/RTCFrameCryptor.h index 864e55be95..43719f35d8 100644 --- a/sdk/objc/api/peerconnection/RTCFrameCryptor.h +++ b/sdk/objc/api/peerconnection/RTCFrameCryptor.h @@ -28,7 +28,6 @@ NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(NSUInteger, RTCCryptorAlgorithm) { RTCCryptorAlgorithmAesGcm = 0, - RTCCryptorAlgorithmAesCbc, }; typedef NS_ENUM(NSInteger, FrameCryptionState) { diff --git a/sdk/objc/api/peerconnection/RTCFrameCryptor.mm b/sdk/objc/api/peerconnection/RTCFrameCryptor.mm index 7e6cd699d7..41893b086c 100644 --- a/sdk/objc/api/peerconnection/RTCFrameCryptor.mm +++ b/sdk/objc/api/peerconnection/RTCFrameCryptor.mm @@ -106,8 +106,6 @@ @implementation RTC_OBJC_TYPE (RTCFrameCryptor) { switch (algorithm) { case RTCCryptorAlgorithmAesGcm: return webrtc::FrameCryptorTransformer::Algorithm::kAesGcm; - case RTCCryptorAlgorithmAesCbc: - return webrtc::FrameCryptorTransformer::Algorithm::kAesCbc; default: return webrtc::FrameCryptorTransformer::Algorithm::kAesGcm; }