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

Unified Diff: webrtc/p2p/base/dtlstransportchannel_unittest.cc

Issue 1269843005: Added DtlsCertificate, a ref counted object owning an SSLIdentity (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Cleanup Created 5 years, 4 months 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/dtlstransportchannel_unittest.cc
diff --git a/webrtc/p2p/base/dtlstransportchannel_unittest.cc b/webrtc/p2p/base/dtlstransportchannel_unittest.cc
index 8c1c21cd1e365928e12f6211334da7a00af521ad..8b4354433dbedfeb1a543609b0eb7dd72666c334 100644
--- a/webrtc/p2p/base/dtlstransportchannel_unittest.cc
+++ b/webrtc/p2p/base/dtlstransportchannel_unittest.cc
@@ -63,11 +63,15 @@ class DtlsTestClient : public sigslot::has_slots<> {
protocol_ = proto;
}
void CreateIdentity() {
- identity_.reset(rtc::SSLIdentity::Generate(name_));
+ certificate_ = webrtc::DtlsCertificate::Create(
+ rtc::scoped_ptr<rtc::SSLIdentity>(
+ rtc::SSLIdentity::Generate(name_)).Pass());
+ }
+ rtc::scoped_refptr<webrtc::DtlsCertificate> certificate() {
+ return certificate_;
}
- rtc::SSLIdentity* identity() { return identity_.get(); }
void SetupSrtp() {
- ASSERT(identity_.get() != NULL);
+ ASSERT(certificate_);
use_dtls_srtp_ = true;
}
void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) {
@@ -77,7 +81,7 @@ class DtlsTestClient : public sigslot::has_slots<> {
void SetupChannels(int count, cricket::IceRole role) {
transport_.reset(new cricket::DtlsTransport<cricket::FakeTransport>(
signaling_thread_, worker_thread_, "dtls content name", NULL,
- identity_.get()));
+ certificate_));
transport_->SetAsync(true);
transport_->SetIceRole(role);
transport_->SetIceTiebreaker(
@@ -118,8 +122,14 @@ class DtlsTestClient : public sigslot::has_slots<> {
void Negotiate(DtlsTestClient* peer, cricket::ContentAction action,
ConnectionRole local_role, ConnectionRole remote_role,
int flags) {
- Negotiate(identity_.get(), (identity_) ? peer->identity_.get() : NULL,
- action, local_role, remote_role, flags);
+ if (certificate_) {
+ Negotiate(certificate_->identity(),
+ peer->certificate_ ? peer->certificate_->identity() : nullptr,
+ action, local_role, remote_role, flags);
+ } else {
+ Negotiate(nullptr, nullptr,
+ action, local_role, remote_role, flags);
+ }
}
// Allow any DTLS configuration to be specified (including invalid ones).
@@ -258,7 +268,7 @@ class DtlsTestClient : public sigslot::has_slots<> {
static_cast<uint32>(sent));
// Only set the bypass flag if we've activated DTLS.
- int flags = (identity_.get() && srtp) ? cricket::PF_SRTP_BYPASS : 0;
+ int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0;
rtc::PacketOptions packet_options;
int rv = channels_[channel]->SendPacket(
packet.get(), size, packet_options, flags);
@@ -339,7 +349,7 @@ class DtlsTestClient : public sigslot::has_slots<> {
ASSERT_TRUE(VerifyPacket(data, size, &packet_num));
received_.insert(packet_num);
// Only DTLS-SRTP packets should have the bypass flag set.
- int expected_flags = (identity_.get() && IsRtpLeadByte(data[0])) ?
+ int expected_flags = (certificate_ && IsRtpLeadByte(data[0])) ?
cricket::PF_SRTP_BYPASS : 0;
ASSERT_EQ(expected_flags, flags);
}
@@ -377,7 +387,7 @@ class DtlsTestClient : public sigslot::has_slots<> {
rtc::Thread* signaling_thread_;
rtc::Thread* worker_thread_;
cricket::TransportProtocol protocol_;
- rtc::scoped_ptr<rtc::SSLIdentity> identity_;
+ rtc::scoped_refptr<webrtc::DtlsCertificate> certificate_;
rtc::scoped_ptr<cricket::FakeTransport> transport_;
std::vector<cricket::DtlsTransportChannelWrapper*> channels_;
size_t packet_size_;
@@ -856,17 +866,17 @@ TEST_F(DtlsTransportChannelTest, TestCertificatesBeforeConnect) {
PrepareDtls(true, true);
Negotiate();
- rtc::scoped_ptr<rtc::SSLIdentity> identity1;
- rtc::scoped_ptr<rtc::SSLIdentity> identity2;
+ rtc::scoped_refptr<webrtc::DtlsCertificate> dtlscert1;
+ rtc::scoped_refptr<webrtc::DtlsCertificate> dtlscert2;
rtc::scoped_ptr<rtc::SSLCertificate> remote_cert1;
rtc::scoped_ptr<rtc::SSLCertificate> remote_cert2;
// After negotiation, each side has a distinct local certificate, but still no
// remote certificate, because connection has not yet occurred.
- ASSERT_TRUE(client1_.transport()->GetIdentity(identity1.accept()));
- ASSERT_TRUE(client2_.transport()->GetIdentity(identity2.accept()));
- ASSERT_NE(identity1->certificate().ToPEMString(),
- identity2->certificate().ToPEMString());
+ ASSERT_TRUE(client1_.transport()->GetCertificate(&dtlscert1));
+ ASSERT_TRUE(client2_.transport()->GetCertificate(&dtlscert2));
+ ASSERT_NE(dtlscert1->identity()->certificate().ToPEMString(),
+ dtlscert2->identity()->certificate().ToPEMString());
ASSERT_FALSE(
client1_.transport()->GetRemoteCertificate(remote_cert1.accept()));
ASSERT_FALSE(remote_cert1 != NULL);
@@ -881,24 +891,24 @@ TEST_F(DtlsTransportChannelTest, TestCertificatesAfterConnect) {
PrepareDtls(true, true);
ASSERT_TRUE(Connect());
- rtc::scoped_ptr<rtc::SSLIdentity> identity1;
- rtc::scoped_ptr<rtc::SSLIdentity> identity2;
+ rtc::scoped_refptr<webrtc::DtlsCertificate> dtlscert1;
+ rtc::scoped_refptr<webrtc::DtlsCertificate> dtlscert2;
rtc::scoped_ptr<rtc::SSLCertificate> remote_cert1;
rtc::scoped_ptr<rtc::SSLCertificate> remote_cert2;
// After connection, each side has a distinct local certificate.
- ASSERT_TRUE(client1_.transport()->GetIdentity(identity1.accept()));
- ASSERT_TRUE(client2_.transport()->GetIdentity(identity2.accept()));
- ASSERT_NE(identity1->certificate().ToPEMString(),
- identity2->certificate().ToPEMString());
+ ASSERT_TRUE(client1_.transport()->GetCertificate(&dtlscert1));
+ ASSERT_TRUE(client2_.transport()->GetCertificate(&dtlscert2));
+ ASSERT_NE(dtlscert1->identity()->certificate().ToPEMString(),
+ dtlscert2->identity()->certificate().ToPEMString());
// Each side's remote certificate is the other side's local certificate.
ASSERT_TRUE(
client1_.transport()->GetRemoteCertificate(remote_cert1.accept()));
ASSERT_EQ(remote_cert1->ToPEMString(),
- identity2->certificate().ToPEMString());
+ dtlscert2->identity()->certificate().ToPEMString());
ASSERT_TRUE(
client2_.transport()->GetRemoteCertificate(remote_cert2.accept()));
ASSERT_EQ(remote_cert2->ToPEMString(),
- identity1->certificate().ToPEMString());
+ dtlscert1->identity()->certificate().ToPEMString());
}

Powered by Google App Engine
This is Rietveld 408576698