From 1b1a39fdefd5d3f7fc5377453411bfcd09e24292 Mon Sep 17 00:00:00 2001 From: "phoglund@webrtc.org" Date: Thu, 29 Mar 2012 16:58:35 +0000 Subject: [PATCH] Rewrote external encryption test. BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/456009 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1959 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../auto_test/standard/encryption_test.cc | 74 +++++++++++ .../main/test/auto_test/voe_standard_test.cc | 123 ------------------ .../main/test/auto_test/voe_standard_test.h | 13 +- .../main/test/voice_engine_tests.gypi | 1 + 4 files changed, 76 insertions(+), 135 deletions(-) create mode 100644 src/voice_engine/main/test/auto_test/standard/encryption_test.cc diff --git a/src/voice_engine/main/test/auto_test/standard/encryption_test.cc b/src/voice_engine/main/test/auto_test/standard/encryption_test.cc new file mode 100644 index 0000000000..fba5f9a49e --- /dev/null +++ b/src/voice_engine/main/test/auto_test/standard/encryption_test.cc @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "voice_engine/main/interface/voe_encryption.h" +#include "voice_engine/main/test/auto_test/fixtures/after_streaming_fixture.h" + +class BasicBitInverseEncryption : public webrtc::Encryption { + void encrypt(int channel_no, unsigned char* in_data, + unsigned char* out_data, int bytes_in, int* bytes_out); + void decrypt(int channel_no, unsigned char* in_data, + unsigned char* out_data, int bytes_in, int* bytes_out); + void encrypt_rtcp(int channel_no, unsigned char* in_data, + unsigned char* out_data, int bytes_in, int* bytes_out); + void decrypt_rtcp(int channel_no, unsigned char* in_data, + unsigned char* out_data, int bytes_in, int* bytes_out); +}; + +void BasicBitInverseEncryption::encrypt(int, unsigned char* in_data, + unsigned char* out_data, + int bytes_in, int* bytes_out) { + int i; + for (i = 0; i < bytes_in; i++) + out_data[i] = ~in_data[i]; + *bytes_out = bytes_in + 2; +} + +void BasicBitInverseEncryption::decrypt(int, unsigned char* in_data, + unsigned char* out_data, + int bytes_in, int* bytes_out) { + int i; + for (i = 0; i < bytes_in; i++) + out_data[i] = ~in_data[i]; + *bytes_out = bytes_in - 2; +} + +void BasicBitInverseEncryption::encrypt_rtcp(int, unsigned char* in_data, + unsigned char* out_data, + int bytes_in, int* bytes_out) { + int i; + for (i = 0; i < bytes_in; i++) + out_data[i] = ~in_data[i]; + *bytes_out = bytes_in + 2; +} + +void BasicBitInverseEncryption::decrypt_rtcp(int, unsigned char* in_data, + unsigned char* out_data, + int bytes_in, int* bytes_out) { + int i; + for (i = 0; i < bytes_in; i++) + out_data[i] = ~in_data[i]; + *bytes_out = bytes_in + 2; +} + + +class EncryptionTest : public AfterStreamingFixture { +}; + +TEST_F(EncryptionTest, ManualBasicCorrectExternalEncryptionHasNoEffectOnVoice) { + BasicBitInverseEncryption basic_encryption; + + voe_encrypt_->RegisterExternalEncryption(channel_, basic_encryption); + + TEST_LOG("Registered external encryption, should still hear good audio."); + Sleep(3000); + + voe_encrypt_->DeRegisterExternalEncryption(channel_); +} diff --git a/src/voice_engine/main/test/auto_test/voe_standard_test.cc b/src/voice_engine/main/test/auto_test/voe_standard_test.cc index ff8e531be0..771932b587 100644 --- a/src/voice_engine/main/test/auto_test/voe_standard_test.cc +++ b/src/voice_engine/main/test/auto_test/voe_standard_test.cc @@ -332,47 +332,6 @@ void RtcpAppHandler::Reset() { name_ = 0; } -void my_encryption::encrypt(int, unsigned char * in_data, - unsigned char * out_data, - int bytes_in, - int * bytes_out) { - int i; - for (i = 0; i < bytes_in; i++) - out_data[i] = ~in_data[i]; - *bytes_out = bytes_in + 2; // length is increased by 2 -} - -void my_encryption::decrypt(int, unsigned char * in_data, - unsigned char * out_data, - int bytes_in, - int * bytes_out) { - int i; - for (i = 0; i < bytes_in; i++) - out_data[i] = ~in_data[i]; - *bytes_out = bytes_in - 2; // length is decreased by 2 -} - -void my_encryption::encrypt_rtcp(int, - unsigned char * in_data, - unsigned char * out_data, - int bytes_in, - int * bytes_out) { - int i; - for (i = 0; i < bytes_in; i++) - out_data[i] = ~in_data[i]; - *bytes_out = bytes_in + 2; -} - -void my_encryption::decrypt_rtcp(int, unsigned char * in_data, - unsigned char * out_data, - int bytes_in, - int * bytes_out) { - int i; - for (i = 0; i < bytes_in; i++) - out_data[i] = ~in_data[i]; - *bytes_out = bytes_in + 2; -} - void SubAPIManager::DisplayStatus() const { TEST_LOG("Supported sub APIs:\n\n"); if (_base) @@ -1051,89 +1010,7 @@ int VoETestManager::DoStandardTest() { #else TEST_LOG("\n\n+++ Video sync tests NOT ENABLED +++\n"); #endif // #ifdef _TEST_VIDEO_SYNC_ - ////////////// - // Encryption -#ifdef _TEST_ENCRYPT_ - TEST_LOG("\n\n+++ Encryption tests +++\n\n"); - -#ifdef WEBRTC_SRTP - TEST_LOG("SRTP tests:\n"); - - unsigned char encrKey[30] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; - - TEST_LOG("Enable SRTP encryption and decryption, you should still hear" - " the voice\n"); - TEST_MUSTPASS(voe_encrypt_->EnableSRTPSend(0, - kCipherAes128CounterMode, - 30, - kAuthHmacSha1, - 20, 4, kEncryptionAndAuthentication, encrKey)); - TEST_MUSTPASS(voe_encrypt_->EnableSRTPReceive(0, - kCipherAes128CounterMode, - 30, - kAuthHmacSha1, - 20, 4, kEncryptionAndAuthentication, encrKey)); - SLEEP(2000); - - TEST_LOG("Disabling decryption, you should hear nothing or garbage\n"); - TEST_MUSTPASS(voe_encrypt_->DisableSRTPReceive(0)); - SLEEP(2000); - - TEST_LOG("Enable decryption again, you should hear the voice again\n"); - TEST_MUSTPASS(voe_encrypt_->EnableSRTPReceive(0, - kCipherAes128CounterMode, - 30, - kAuthHmacSha1, - 20, 4, kEncryptionAndAuthentication, encrKey)); - SLEEP(2000); - - TEST_LOG("Disabling encryption and enabling decryption, you should" - " hear nothing\n"); - TEST_MUSTPASS(voe_encrypt_->DisableSRTPSend(0)); - SLEEP(2000); - - TEST_LOG("Back to normal\n"); - // both SRTP sides are now inactive - TEST_MUSTPASS(voe_encrypt_->DisableSRTPReceive(0)); - SLEEP(2000); - - TEST_LOG("Enable SRTP and SRTCP encryption and decryption," - " you should still hear the voice\n"); - TEST_MUSTPASS(voe_encrypt_->EnableSRTPSend(0, - kCipherAes128CounterMode, - 30, - kAuthHmacSha1, - 20, 4, kEncryptionAndAuthentication, encrKey, true)); - TEST_MUSTPASS(voe_encrypt_->EnableSRTPReceive(0, - kCipherAes128CounterMode, - 30, - kAuthHmacSha1, - 20, 4, kEncryptionAndAuthentication, encrKey, true)); - SLEEP(2000); - - TEST_LOG("Back to normal\n"); - TEST_MUSTPASS(voe_encrypt_->DisableSRTPSend(0)); - // both SRTP sides are now inactive - TEST_MUSTPASS(voe_encrypt_->DisableSRTPReceive(0)); - SLEEP(2000); - -#else - TEST_LOG("Skipping SRTP tests - WEBRTC_SRTP not defined \n"); -#endif // #ifdef WEBRTC_SRTP - TEST_LOG("\nExternal encryption tests:\n"); - my_encryption * encObj = new my_encryption; - TEST_MUSTPASS(voe_encrypt_->RegisterExternalEncryption(0, *encObj)); - TEST_LOG("Encryption enabled but you should still hear the voice\n"); - SLEEP(2000); - TEST_LOG("Removing encryption object and deleting it\n"); - TEST_MUSTPASS(voe_encrypt_->DeRegisterExternalEncryption(0)); - delete encObj; - SLEEP(2000); -#else - TEST_LOG("\n\n+++ Encryption tests NOT ENABLED +++\n"); -#endif // #ifdef _TEST_ENCRYPT_ ////////////////// // External media diff --git a/src/voice_engine/main/test/auto_test/voe_standard_test.h b/src/voice_engine/main/test/auto_test/voe_standard_test.h index ae0fb24315..4512e5dc58 100644 --- a/src/voice_engine/main/test/auto_test/voe_standard_test.h +++ b/src/voice_engine/main/test/auto_test/voe_standard_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -150,17 +150,6 @@ class DtmfCallback : public VoETelephoneEventObserver { } }; -class my_encryption : public Encryption { - void encrypt(int channel_no, unsigned char * in_data, - unsigned char * out_data, int bytes_in, int * bytes_out); - void decrypt(int channel_no, unsigned char * in_data, - unsigned char * out_data, int bytes_in, int * bytes_out); - void encrypt_rtcp(int channel_no, unsigned char * in_data, - unsigned char * out_data, int bytes_in, int * bytes_out); - void decrypt_rtcp(int channel_no, unsigned char * in_data, - unsigned char * out_data, int bytes_in, int * bytes_out); -}; - class RxCallback : public VoERxVadCallback { public: RxCallback() : diff --git a/src/voice_engine/main/test/voice_engine_tests.gypi b/src/voice_engine/main/test/voice_engine_tests.gypi index db108babfd..d41809881e 100644 --- a/src/voice_engine/main/test/voice_engine_tests.gypi +++ b/src/voice_engine/main/test/voice_engine_tests.gypi @@ -41,6 +41,7 @@ 'auto_test/standard/codec_before_streaming_test.cc', 'auto_test/standard/codec_test.cc', 'auto_test/standard/dtmf_test.cc', + 'auto_test/standard/encryption_test.cc', 'auto_test/standard/file_test.cc', 'auto_test/standard/hardware_before_initializing_test.cc', 'auto_test/standard/hardware_before_streaming_test.cc',