| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 #include "webrtc/base/sslidentity.h" | 21 #include "webrtc/base/sslidentity.h" |
| 22 #include "webrtc/base/sslstreamadapter.h" | 22 #include "webrtc/base/sslstreamadapter.h" |
| 23 #include "webrtc/base/stringutils.h" | 23 #include "webrtc/base/stringutils.h" |
| 24 | 24 |
| 25 #define MAYBE_SKIP_TEST(feature) \ | 25 #define MAYBE_SKIP_TEST(feature) \ |
| 26 if (!(rtc::SSLStreamAdapter::feature())) { \ | 26 if (!(rtc::SSLStreamAdapter::feature())) { \ |
| 27 LOG(LS_INFO) << "Feature disabled... skipping"; \ | 27 LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 28 return; \ | 28 return; \ |
| 29 } | 29 } |
| 30 | 30 |
| 31 static const char AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; | |
| 32 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; | 31 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
| 33 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; | 32 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
| 34 static const size_t kPacketNumOffset = 8; | 33 static const size_t kPacketNumOffset = 8; |
| 35 static const size_t kPacketHeaderLen = 12; | 34 static const size_t kPacketHeaderLen = 12; |
| 36 static const int kFakePacketId = 0x1234; | 35 static const int kFakePacketId = 0x1234; |
| 37 | 36 |
| 38 static bool IsRtpLeadByte(uint8_t b) { | 37 static bool IsRtpLeadByte(uint8_t b) { |
| 39 return ((b & 0xC0) == 0x80); | 38 return ((b & 0xC0) == 0x80); |
| 40 } | 39 } |
| 41 | 40 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 remote_fingerprint.reset(rtc::SSLFingerprint::Create( | 142 remote_fingerprint.reset(rtc::SSLFingerprint::Create( |
| 144 digest_algorithm, remote_cert->identity())); | 143 digest_algorithm, remote_cert->identity())); |
| 145 ASSERT_TRUE(remote_fingerprint.get() != NULL); | 144 ASSERT_TRUE(remote_fingerprint.get() != NULL); |
| 146 EXPECT_EQ(rtc::DIGEST_SHA_256, digest_algorithm); | 145 EXPECT_EQ(rtc::DIGEST_SHA_256, digest_algorithm); |
| 147 } | 146 } |
| 148 | 147 |
| 149 if (use_dtls_srtp_ && !(flags & NF_REOFFER)) { | 148 if (use_dtls_srtp_ && !(flags & NF_REOFFER)) { |
| 150 // SRTP ciphers will be set only in the beginning. | 149 // SRTP ciphers will be set only in the beginning. |
| 151 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = | 150 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = |
| 152 channels_.begin(); it != channels_.end(); ++it) { | 151 channels_.begin(); it != channels_.end(); ++it) { |
| 153 std::vector<std::string> ciphers; | 152 std::vector<int> ciphers; |
| 154 ciphers.push_back(AES_CM_128_HMAC_SHA1_80); | 153 ciphers.push_back(rtc::SRTP_AES128_CM_SHA1_80); |
| 155 ASSERT_TRUE((*it)->SetSrtpCiphers(ciphers)); | 154 ASSERT_TRUE((*it)->SetSrtpCryptoSuites(ciphers)); |
| 156 } | 155 } |
| 157 } | 156 } |
| 158 | 157 |
| 159 cricket::TransportDescription local_desc( | 158 cricket::TransportDescription local_desc( |
| 160 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL, | 159 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL, |
| 161 local_role, | 160 local_role, |
| 162 // If remote if the offerer and has no DTLS support, answer will be | 161 // If remote if the offerer and has no DTLS support, answer will be |
| 163 // without any fingerprint. | 162 // without any fingerprint. |
| 164 (action == cricket::CA_ANSWER && !remote_cert) | 163 (action == cricket::CA_ANSWER && !remote_cert) |
| 165 ? nullptr | 164 ? nullptr |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 void CheckRole(rtc::SSLRole role) { | 207 void CheckRole(rtc::SSLRole role) { |
| 209 if (role == rtc::SSL_CLIENT) { | 208 if (role == rtc::SSL_CLIENT) { |
| 210 ASSERT_FALSE(received_dtls_client_hello_); | 209 ASSERT_FALSE(received_dtls_client_hello_); |
| 211 ASSERT_TRUE(received_dtls_server_hello_); | 210 ASSERT_TRUE(received_dtls_server_hello_); |
| 212 } else { | 211 } else { |
| 213 ASSERT_TRUE(received_dtls_client_hello_); | 212 ASSERT_TRUE(received_dtls_client_hello_); |
| 214 ASSERT_FALSE(received_dtls_server_hello_); | 213 ASSERT_FALSE(received_dtls_server_hello_); |
| 215 } | 214 } |
| 216 } | 215 } |
| 217 | 216 |
| 218 void CheckSrtp(const std::string& expected_cipher) { | 217 void CheckSrtp(int expected_crypto_suite) { |
| 219 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = | 218 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = |
| 220 channels_.begin(); it != channels_.end(); ++it) { | 219 channels_.begin(); it != channels_.end(); ++it) { |
| 221 std::string cipher; | 220 int crypto_suite; |
| 222 | 221 |
| 223 bool rv = (*it)->GetSrtpCryptoSuite(&cipher); | 222 bool rv = (*it)->GetSrtpCryptoSuite(&crypto_suite); |
| 224 if (negotiated_dtls_ && !expected_cipher.empty()) { | 223 if (negotiated_dtls_ && expected_crypto_suite) { |
| 225 ASSERT_TRUE(rv); | 224 ASSERT_TRUE(rv); |
| 226 | 225 |
| 227 ASSERT_EQ(cipher, expected_cipher); | 226 ASSERT_EQ(crypto_suite, expected_crypto_suite); |
| 228 } else { | 227 } else { |
| 229 ASSERT_FALSE(rv); | 228 ASSERT_FALSE(rv); |
| 230 } | 229 } |
| 231 } | 230 } |
| 232 } | 231 } |
| 233 | 232 |
| 234 void CheckSsl(int expected_cipher) { | 233 void CheckSsl(int expected_cipher) { |
| 235 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = | 234 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = |
| 236 channels_.begin(); it != channels_.end(); ++it) { | 235 channels_.begin(); it != channels_.end(); ++it) { |
| 237 int cipher; | 236 int cipher; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 (client1_role == cricket::CONNECTIONROLE_PASSIVE && | 461 (client1_role == cricket::CONNECTIONROLE_PASSIVE && |
| 463 client2_role == cricket::CONNECTIONROLE_ACTPASS)) ? | 462 client2_role == cricket::CONNECTIONROLE_ACTPASS)) ? |
| 464 rtc::SSL_CLIENT : rtc::SSL_SERVER; | 463 rtc::SSL_CLIENT : rtc::SSL_SERVER; |
| 465 | 464 |
| 466 client1_.CheckRole(client1_ssl_role); | 465 client1_.CheckRole(client1_ssl_role); |
| 467 client2_.CheckRole(client2_ssl_role); | 466 client2_.CheckRole(client2_ssl_role); |
| 468 } | 467 } |
| 469 | 468 |
| 470 // Check that we negotiated the right ciphers. | 469 // Check that we negotiated the right ciphers. |
| 471 if (use_dtls_srtp_) { | 470 if (use_dtls_srtp_) { |
| 472 client1_.CheckSrtp(AES_CM_128_HMAC_SHA1_80); | 471 client1_.CheckSrtp(rtc::SRTP_AES128_CM_SHA1_80); |
| 473 client2_.CheckSrtp(AES_CM_128_HMAC_SHA1_80); | 472 client2_.CheckSrtp(rtc::SRTP_AES128_CM_SHA1_80); |
| 474 } else { | 473 } else { |
| 475 client1_.CheckSrtp(""); | 474 client1_.CheckSrtp(rtc::SRTP_INVALID_CRYPTO_SUITE); |
| 476 client2_.CheckSrtp(""); | 475 client2_.CheckSrtp(rtc::SRTP_INVALID_CRYPTO_SUITE); |
| 477 } | 476 } |
| 478 client1_.CheckSsl(rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | 477 client1_.CheckSsl(rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 479 ssl_expected_version_, rtc::KT_DEFAULT)); | 478 ssl_expected_version_, rtc::KT_DEFAULT)); |
| 480 client2_.CheckSsl(rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( | 479 client2_.CheckSsl(rtc::SSLStreamAdapter::GetDefaultSslCipherForTest( |
| 481 ssl_expected_version_, rtc::KT_DEFAULT)); | 480 ssl_expected_version_, rtc::KT_DEFAULT)); |
| 482 | 481 |
| 483 return true; | 482 return true; |
| 484 } | 483 } |
| 485 | 484 |
| 486 bool Connect() { | 485 bool Connect() { |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 // Each side's remote certificate is the other side's local certificate. | 884 // Each side's remote certificate is the other side's local certificate. |
| 886 ASSERT_TRUE( | 885 ASSERT_TRUE( |
| 887 client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept())); | 886 client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept())); |
| 888 ASSERT_EQ(remote_cert1->ToPEMString(), | 887 ASSERT_EQ(remote_cert1->ToPEMString(), |
| 889 certificate2->ssl_certificate().ToPEMString()); | 888 certificate2->ssl_certificate().ToPEMString()); |
| 890 ASSERT_TRUE( | 889 ASSERT_TRUE( |
| 891 client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept())); | 890 client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept())); |
| 892 ASSERT_EQ(remote_cert2->ToPEMString(), | 891 ASSERT_EQ(remote_cert2->ToPEMString(), |
| 893 certificate1->ssl_certificate().ToPEMString()); | 892 certificate1->ssl_certificate().ToPEMString()); |
| 894 } | 893 } |
| OLD | NEW |