| 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 |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <memory> |
| 13 #include <set> | 14 #include <set> |
| 14 #include <string> | 15 #include <string> |
| 15 | 16 |
| 16 #include "webrtc/base/bufferqueue.h" | 17 #include "webrtc/base/bufferqueue.h" |
| 17 #include "webrtc/base/gunit.h" | 18 #include "webrtc/base/gunit.h" |
| 18 #include "webrtc/base/helpers.h" | 19 #include "webrtc/base/helpers.h" |
| 19 #include "webrtc/base/scoped_ptr.h" | |
| 20 #include "webrtc/base/ssladapter.h" | 20 #include "webrtc/base/ssladapter.h" |
| 21 #include "webrtc/base/sslconfig.h" | 21 #include "webrtc/base/sslconfig.h" |
| 22 #include "webrtc/base/sslidentity.h" | 22 #include "webrtc/base/sslidentity.h" |
| 23 #include "webrtc/base/sslstreamadapter.h" | 23 #include "webrtc/base/sslstreamadapter.h" |
| 24 #include "webrtc/base/stream.h" | 24 #include "webrtc/base/stream.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; |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 server_ssl_->SetDtlsSrtpCryptoSuites(ciphers); | 467 server_ssl_->SetDtlsSrtpCryptoSuites(ciphers); |
| 468 } | 468 } |
| 469 | 469 |
| 470 bool GetDtlsSrtpCryptoSuite(bool client, int* retval) { | 470 bool GetDtlsSrtpCryptoSuite(bool client, int* retval) { |
| 471 if (client) | 471 if (client) |
| 472 return client_ssl_->GetDtlsSrtpCryptoSuite(retval); | 472 return client_ssl_->GetDtlsSrtpCryptoSuite(retval); |
| 473 else | 473 else |
| 474 return server_ssl_->GetDtlsSrtpCryptoSuite(retval); | 474 return server_ssl_->GetDtlsSrtpCryptoSuite(retval); |
| 475 } | 475 } |
| 476 | 476 |
| 477 rtc::scoped_ptr<rtc::SSLCertificate> GetPeerCertificate(bool client) { | 477 std::unique_ptr<rtc::SSLCertificate> GetPeerCertificate(bool client) { |
| 478 if (client) | 478 if (client) |
| 479 return client_ssl_->GetPeerCertificate(); | 479 return client_ssl_->GetPeerCertificate(); |
| 480 else | 480 else |
| 481 return server_ssl_->GetPeerCertificate(); | 481 return server_ssl_->GetPeerCertificate(); |
| 482 } | 482 } |
| 483 | 483 |
| 484 bool GetSslCipherSuite(bool client, int* retval) { | 484 bool GetSslCipherSuite(bool client, int* retval) { |
| 485 if (client) | 485 if (client) |
| 486 return client_ssl_->GetSslCipherSuite(retval); | 486 return client_ssl_->GetSslCipherSuite(retval); |
| 487 else | 487 else |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 virtual void ReadData(rtc::StreamInterface *stream) = 0; | 519 virtual void ReadData(rtc::StreamInterface *stream) = 0; |
| 520 virtual void TestTransfer(int size) = 0; | 520 virtual void TestTransfer(int size) = 0; |
| 521 | 521 |
| 522 protected: | 522 protected: |
| 523 std::string client_cert_pem_; | 523 std::string client_cert_pem_; |
| 524 std::string client_private_key_pem_; | 524 std::string client_private_key_pem_; |
| 525 rtc::KeyParams client_key_type_; | 525 rtc::KeyParams client_key_type_; |
| 526 rtc::KeyParams server_key_type_; | 526 rtc::KeyParams server_key_type_; |
| 527 SSLDummyStreamBase *client_stream_; // freed by client_ssl_ destructor | 527 SSLDummyStreamBase *client_stream_; // freed by client_ssl_ destructor |
| 528 SSLDummyStreamBase *server_stream_; // freed by server_ssl_ destructor | 528 SSLDummyStreamBase *server_stream_; // freed by server_ssl_ destructor |
| 529 rtc::scoped_ptr<rtc::SSLStreamAdapter> client_ssl_; | 529 std::unique_ptr<rtc::SSLStreamAdapter> client_ssl_; |
| 530 rtc::scoped_ptr<rtc::SSLStreamAdapter> server_ssl_; | 530 std::unique_ptr<rtc::SSLStreamAdapter> server_ssl_; |
| 531 rtc::SSLIdentity *client_identity_; // freed by client_ssl_ destructor | 531 rtc::SSLIdentity *client_identity_; // freed by client_ssl_ destructor |
| 532 rtc::SSLIdentity *server_identity_; // freed by server_ssl_ destructor | 532 rtc::SSLIdentity *server_identity_; // freed by server_ssl_ destructor |
| 533 int delay_; | 533 int delay_; |
| 534 size_t mtu_; | 534 size_t mtu_; |
| 535 int loss_; | 535 int loss_; |
| 536 bool lose_first_packet_; | 536 bool lose_first_packet_; |
| 537 bool damage_; | 537 bool damage_; |
| 538 bool dtls_; | 538 bool dtls_; |
| 539 int handshake_wait_; | 539 int handshake_wait_; |
| 540 bool identities_set_; | 540 bool identities_set_; |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 TEST_F(SSLStreamAdapterTestDTLSFromPEMStrings, TestDTLSGetPeerCertificate) { | 1036 TEST_F(SSLStreamAdapterTestDTLSFromPEMStrings, TestDTLSGetPeerCertificate) { |
| 1037 MAYBE_SKIP_TEST(HaveDtls); | 1037 MAYBE_SKIP_TEST(HaveDtls); |
| 1038 | 1038 |
| 1039 // Peer certificates haven't been received yet. | 1039 // Peer certificates haven't been received yet. |
| 1040 ASSERT_FALSE(GetPeerCertificate(true)); | 1040 ASSERT_FALSE(GetPeerCertificate(true)); |
| 1041 ASSERT_FALSE(GetPeerCertificate(false)); | 1041 ASSERT_FALSE(GetPeerCertificate(false)); |
| 1042 | 1042 |
| 1043 TestHandshake(); | 1043 TestHandshake(); |
| 1044 | 1044 |
| 1045 // The client should have a peer certificate after the handshake. | 1045 // The client should have a peer certificate after the handshake. |
| 1046 rtc::scoped_ptr<rtc::SSLCertificate> client_peer_cert = | 1046 std::unique_ptr<rtc::SSLCertificate> client_peer_cert = |
| 1047 GetPeerCertificate(true); | 1047 GetPeerCertificate(true); |
| 1048 ASSERT_TRUE(client_peer_cert); | 1048 ASSERT_TRUE(client_peer_cert); |
| 1049 | 1049 |
| 1050 // It's not kCERT_PEM. | 1050 // It's not kCERT_PEM. |
| 1051 std::string client_peer_string = client_peer_cert->ToPEMString(); | 1051 std::string client_peer_string = client_peer_cert->ToPEMString(); |
| 1052 ASSERT_NE(kCERT_PEM, client_peer_string); | 1052 ASSERT_NE(kCERT_PEM, client_peer_string); |
| 1053 | 1053 |
| 1054 // It must not have a chain, because the test certs are self-signed. | 1054 // It must not have a chain, because the test certs are self-signed. |
| 1055 ASSERT_FALSE(client_peer_cert->GetChain()); | 1055 ASSERT_FALSE(client_peer_cert->GetChain()); |
| 1056 | 1056 |
| 1057 // The server should have a peer certificate after the handshake. | 1057 // The server should have a peer certificate after the handshake. |
| 1058 rtc::scoped_ptr<rtc::SSLCertificate> server_peer_cert = | 1058 std::unique_ptr<rtc::SSLCertificate> server_peer_cert = |
| 1059 GetPeerCertificate(false); | 1059 GetPeerCertificate(false); |
| 1060 ASSERT_TRUE(server_peer_cert); | 1060 ASSERT_TRUE(server_peer_cert); |
| 1061 | 1061 |
| 1062 // It's kCERT_PEM | 1062 // It's kCERT_PEM |
| 1063 ASSERT_EQ(kCERT_PEM, server_peer_cert->ToPEMString()); | 1063 ASSERT_EQ(kCERT_PEM, server_peer_cert->ToPEMString()); |
| 1064 | 1064 |
| 1065 // It must not have a chain, because the test certs are self-signed. | 1065 // It must not have a chain, because the test certs are self-signed. |
| 1066 ASSERT_FALSE(server_peer_cert->GetChain()); | 1066 ASSERT_FALSE(server_peer_cert->GetChain()); |
| 1067 } | 1067 } |
| 1068 | 1068 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); | 1158 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); |
| 1159 INSTANTIATE_TEST_CASE_P( | 1159 INSTANTIATE_TEST_CASE_P( |
| 1160 SSLStreamAdapterTestsDTLS, | 1160 SSLStreamAdapterTestsDTLS, |
| 1161 SSLStreamAdapterTestDTLS, | 1161 SSLStreamAdapterTestDTLS, |
| 1162 Combine(Values(rtc::KeyParams::RSA(1024, 65537), | 1162 Combine(Values(rtc::KeyParams::RSA(1024, 65537), |
| 1163 rtc::KeyParams::RSA(1152, 65537), | 1163 rtc::KeyParams::RSA(1152, 65537), |
| 1164 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)), | 1164 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)), |
| 1165 Values(rtc::KeyParams::RSA(1024, 65537), | 1165 Values(rtc::KeyParams::RSA(1024, 65537), |
| 1166 rtc::KeyParams::RSA(1152, 65537), | 1166 rtc::KeyParams::RSA(1152, 65537), |
| 1167 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); | 1167 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); |
| OLD | NEW |