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
This commit is contained in:
parent
010a4e8f0b
commit
1b1a39fdef
@ -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_);
|
||||
}
|
@ -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
|
||||
|
||||
|
@ -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() :
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user