Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: webrtc/base/sslstreamadapter_unittest.cc

Issue 1416673006: Convert internal representation of Srtp cryptos from string to int. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: change srtp crypto name conversion Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/sslstreamadapter.cc ('k') | webrtc/p2p/base/dtlstransportchannel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 11 matching lines...) Expand all
22 #include "webrtc/base/sslstreamadapter.h" 22 #include "webrtc/base/sslstreamadapter.h"
23 #include "webrtc/base/stream.h" 23 #include "webrtc/base/stream.h"
24 #include "webrtc/test/testsupport/gtest_disable.h" 24 #include "webrtc/test/testsupport/gtest_disable.h"
25 25
26 using ::testing::WithParamInterface; 26 using ::testing::WithParamInterface;
27 using ::testing::Values; 27 using ::testing::Values;
28 using ::testing::Combine; 28 using ::testing::Combine;
29 using ::testing::tuple; 29 using ::testing::tuple;
30 30
31 static const int kBlockSize = 4096; 31 static const int kBlockSize = 4096;
32 static const char kAES_CM_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80";
33 static const char kAES_CM_HMAC_SHA1_32[] = "AES_CM_128_HMAC_SHA1_32";
34 static const char kExporterLabel[] = "label"; 32 static const char kExporterLabel[] = "label";
35 static const unsigned char kExporterContext[] = "context"; 33 static const unsigned char kExporterContext[] = "context";
36 static int kExporterContextLen = sizeof(kExporterContext); 34 static int kExporterContextLen = sizeof(kExporterContext);
37 35
38 static const char kRSA_PRIVATE_KEY_PEM[] = 36 static const char kRSA_PRIVATE_KEY_PEM[] =
39 "-----BEGIN RSA PRIVATE KEY-----\n" 37 "-----BEGIN RSA PRIVATE KEY-----\n"
40 "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMYRkbhmI7kVA/rM\n" 38 "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMYRkbhmI7kVA/rM\n"
41 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" 39 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n"
42 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" 40 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n"
43 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAECgYAvgOs4FJcgvp+TuREx7YtiYVsH\n" 41 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAECgYAvgOs4FJcgvp+TuREx7YtiYVsH\n"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 380 }
383 381
384 void SetMtu(size_t mtu) { 382 void SetMtu(size_t mtu) {
385 mtu_ = mtu; 383 mtu_ = mtu;
386 } 384 }
387 385
388 void SetHandshakeWait(int wait) { 386 void SetHandshakeWait(int wait) {
389 handshake_wait_ = wait; 387 handshake_wait_ = wait;
390 } 388 }
391 389
392 void SetDtlsSrtpCiphers(const std::vector<std::string> &ciphers, 390 void SetDtlsSrtpCryptoSuites(const std::vector<int>& ciphers, bool client) {
393 bool client) {
394 if (client) 391 if (client)
395 client_ssl_->SetDtlsSrtpCiphers(ciphers); 392 client_ssl_->SetDtlsSrtpCryptoSuites(ciphers);
396 else 393 else
397 server_ssl_->SetDtlsSrtpCiphers(ciphers); 394 server_ssl_->SetDtlsSrtpCryptoSuites(ciphers);
398 } 395 }
399 396
400 bool GetDtlsSrtpCipher(bool client, std::string *retval) { 397 bool GetDtlsSrtpCryptoSuite(bool client, int* retval) {
401 if (client) 398 if (client)
402 return client_ssl_->GetDtlsSrtpCipher(retval); 399 return client_ssl_->GetDtlsSrtpCryptoSuite(retval);
403 else 400 else
404 return server_ssl_->GetDtlsSrtpCipher(retval); 401 return server_ssl_->GetDtlsSrtpCryptoSuite(retval);
405 } 402 }
406 403
407 bool GetPeerCertificate(bool client, rtc::SSLCertificate** cert) { 404 bool GetPeerCertificate(bool client, rtc::SSLCertificate** cert) {
408 if (client) 405 if (client)
409 return client_ssl_->GetPeerCertificate(cert); 406 return client_ssl_->GetPeerCertificate(cert);
410 else 407 else
411 return server_ssl_->GetPeerCertificate(cert); 408 return server_ssl_->GetPeerCertificate(cert);
412 } 409 }
413 410
414 bool GetSslCipherSuite(bool client, int* retval) { 411 bool GetSslCipherSuite(bool client, int* retval) {
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 MAYBE_SKIP_TEST(HaveDtls); 799 MAYBE_SKIP_TEST(HaveDtls);
803 SetDamage(); // Must be called first because first packet 800 SetDamage(); // Must be called first because first packet
804 // write happens at end of handshake. 801 // write happens at end of handshake.
805 TestHandshake(); 802 TestHandshake();
806 TestTransfer(100); 803 TestTransfer(100);
807 }; 804 };
808 805
809 // Test DTLS-SRTP with all high ciphers 806 // Test DTLS-SRTP with all high ciphers
810 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpHigh) { 807 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpHigh) {
811 MAYBE_SKIP_TEST(HaveDtlsSrtp); 808 MAYBE_SKIP_TEST(HaveDtlsSrtp);
812 std::vector<std::string> high; 809 std::vector<int> high;
813 high.push_back(kAES_CM_HMAC_SHA1_80); 810 high.push_back(rtc::SRTP_AES128_CM_SHA1_80);
814 SetDtlsSrtpCiphers(high, true); 811 SetDtlsSrtpCryptoSuites(high, true);
815 SetDtlsSrtpCiphers(high, false); 812 SetDtlsSrtpCryptoSuites(high, false);
816 TestHandshake(); 813 TestHandshake();
817 814
818 std::string client_cipher; 815 int client_cipher;
819 ASSERT_TRUE(GetDtlsSrtpCipher(true, &client_cipher)); 816 ASSERT_TRUE(GetDtlsSrtpCryptoSuite(true, &client_cipher));
820 std::string server_cipher; 817 int server_cipher;
821 ASSERT_TRUE(GetDtlsSrtpCipher(false, &server_cipher)); 818 ASSERT_TRUE(GetDtlsSrtpCryptoSuite(false, &server_cipher));
822 819
823 ASSERT_EQ(client_cipher, server_cipher); 820 ASSERT_EQ(client_cipher, server_cipher);
824 ASSERT_EQ(client_cipher, kAES_CM_HMAC_SHA1_80); 821 ASSERT_EQ(client_cipher, rtc::SRTP_AES128_CM_SHA1_80);
825 }; 822 };
826 823
827 // Test DTLS-SRTP with all low ciphers 824 // Test DTLS-SRTP with all low ciphers
828 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpLow) { 825 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpLow) {
829 MAYBE_SKIP_TEST(HaveDtlsSrtp); 826 MAYBE_SKIP_TEST(HaveDtlsSrtp);
830 std::vector<std::string> low; 827 std::vector<int> low;
831 low.push_back(kAES_CM_HMAC_SHA1_32); 828 low.push_back(rtc::SRTP_AES128_CM_SHA1_32);
832 SetDtlsSrtpCiphers(low, true); 829 SetDtlsSrtpCryptoSuites(low, true);
833 SetDtlsSrtpCiphers(low, false); 830 SetDtlsSrtpCryptoSuites(low, false);
834 TestHandshake(); 831 TestHandshake();
835 832
836 std::string client_cipher; 833 int client_cipher;
837 ASSERT_TRUE(GetDtlsSrtpCipher(true, &client_cipher)); 834 ASSERT_TRUE(GetDtlsSrtpCryptoSuite(true, &client_cipher));
838 std::string server_cipher; 835 int server_cipher;
839 ASSERT_TRUE(GetDtlsSrtpCipher(false, &server_cipher)); 836 ASSERT_TRUE(GetDtlsSrtpCryptoSuite(false, &server_cipher));
840 837
841 ASSERT_EQ(client_cipher, server_cipher); 838 ASSERT_EQ(client_cipher, server_cipher);
842 ASSERT_EQ(client_cipher, kAES_CM_HMAC_SHA1_32); 839 ASSERT_EQ(client_cipher, rtc::SRTP_AES128_CM_SHA1_32);
843 }; 840 };
844 841
845 842
846 // Test DTLS-SRTP with a mismatch -- should not converge 843 // Test DTLS-SRTP with a mismatch -- should not converge
847 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpHighLow) { 844 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpHighLow) {
848 MAYBE_SKIP_TEST(HaveDtlsSrtp); 845 MAYBE_SKIP_TEST(HaveDtlsSrtp);
849 std::vector<std::string> high; 846 std::vector<int> high;
850 high.push_back(kAES_CM_HMAC_SHA1_80); 847 high.push_back(rtc::SRTP_AES128_CM_SHA1_80);
851 std::vector<std::string> low; 848 std::vector<int> low;
852 low.push_back(kAES_CM_HMAC_SHA1_32); 849 low.push_back(rtc::SRTP_AES128_CM_SHA1_32);
853 SetDtlsSrtpCiphers(high, true); 850 SetDtlsSrtpCryptoSuites(high, true);
854 SetDtlsSrtpCiphers(low, false); 851 SetDtlsSrtpCryptoSuites(low, false);
855 TestHandshake(); 852 TestHandshake();
856 853
857 std::string client_cipher; 854 int client_cipher;
858 ASSERT_FALSE(GetDtlsSrtpCipher(true, &client_cipher)); 855 ASSERT_FALSE(GetDtlsSrtpCryptoSuite(true, &client_cipher));
859 std::string server_cipher; 856 int server_cipher;
860 ASSERT_FALSE(GetDtlsSrtpCipher(false, &server_cipher)); 857 ASSERT_FALSE(GetDtlsSrtpCryptoSuite(false, &server_cipher));
861 }; 858 };
862 859
863 // Test DTLS-SRTP with each side being mixed -- should select high 860 // Test DTLS-SRTP with each side being mixed -- should select high
864 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpMixed) { 861 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpMixed) {
865 MAYBE_SKIP_TEST(HaveDtlsSrtp); 862 MAYBE_SKIP_TEST(HaveDtlsSrtp);
866 std::vector<std::string> mixed; 863 std::vector<int> mixed;
867 mixed.push_back(kAES_CM_HMAC_SHA1_80); 864 mixed.push_back(rtc::SRTP_AES128_CM_SHA1_80);
868 mixed.push_back(kAES_CM_HMAC_SHA1_32); 865 mixed.push_back(rtc::SRTP_AES128_CM_SHA1_32);
869 SetDtlsSrtpCiphers(mixed, true); 866 SetDtlsSrtpCryptoSuites(mixed, true);
870 SetDtlsSrtpCiphers(mixed, false); 867 SetDtlsSrtpCryptoSuites(mixed, false);
871 TestHandshake(); 868 TestHandshake();
872 869
873 std::string client_cipher; 870 int client_cipher;
874 ASSERT_TRUE(GetDtlsSrtpCipher(true, &client_cipher)); 871 ASSERT_TRUE(GetDtlsSrtpCryptoSuite(true, &client_cipher));
875 std::string server_cipher; 872 int server_cipher;
876 ASSERT_TRUE(GetDtlsSrtpCipher(false, &server_cipher)); 873 ASSERT_TRUE(GetDtlsSrtpCryptoSuite(false, &server_cipher));
877 874
878 ASSERT_EQ(client_cipher, server_cipher); 875 ASSERT_EQ(client_cipher, server_cipher);
879 ASSERT_EQ(client_cipher, kAES_CM_HMAC_SHA1_80); 876 ASSERT_EQ(client_cipher, rtc::SRTP_AES128_CM_SHA1_80);
880 }; 877 };
881 878
882 // Test an exporter 879 // Test an exporter
883 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSExporter) { 880 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSExporter) {
884 MAYBE_SKIP_TEST(HaveExporter); 881 MAYBE_SKIP_TEST(HaveExporter);
885 TestHandshake(); 882 TestHandshake();
886 unsigned char client_out[20]; 883 unsigned char client_out[20];
887 unsigned char server_out[20]; 884 unsigned char server_out[20];
888 885
889 bool result; 886 bool result;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); 1051 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256))));
1055 INSTANTIATE_TEST_CASE_P( 1052 INSTANTIATE_TEST_CASE_P(
1056 SSLStreamAdapterTestsDTLS, 1053 SSLStreamAdapterTestsDTLS,
1057 SSLStreamAdapterTestDTLS, 1054 SSLStreamAdapterTestDTLS,
1058 Combine(Values(rtc::KeyParams::RSA(1024, 65537), 1055 Combine(Values(rtc::KeyParams::RSA(1024, 65537),
1059 rtc::KeyParams::RSA(1152, 65537), 1056 rtc::KeyParams::RSA(1152, 65537),
1060 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)), 1057 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)),
1061 Values(rtc::KeyParams::RSA(1024, 65537), 1058 Values(rtc::KeyParams::RSA(1024, 65537),
1062 rtc::KeyParams::RSA(1152, 65537), 1059 rtc::KeyParams::RSA(1152, 65537),
1063 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); 1060 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256))));
OLDNEW
« no previous file with comments | « webrtc/base/sslstreamadapter.cc ('k') | webrtc/p2p/base/dtlstransportchannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698