OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "webrtc/p2p/base/constants.h" | 14 #include "webrtc/p2p/base/constants.h" |
15 #include "webrtc/p2p/base/transportdescription.h" | 15 #include "webrtc/p2p/base/transportdescription.h" |
16 #include "webrtc/p2p/base/transportdescriptionfactory.h" | 16 #include "webrtc/p2p/base/transportdescriptionfactory.h" |
17 #include "webrtc/base/fakesslidentity.h" | 17 #include "webrtc/base/fakesslidentity.h" |
18 #include "webrtc/base/gunit.h" | 18 #include "webrtc/base/gunit.h" |
19 #include "webrtc/base/ssladapter.h" | 19 #include "webrtc/base/ssladapter.h" |
20 | 20 |
21 using rtc::scoped_ptr; | 21 using rtc::scoped_ptr; |
22 using cricket::TransportDescriptionFactory; | 22 using cricket::TransportDescriptionFactory; |
23 using cricket::TransportDescription; | 23 using cricket::TransportDescription; |
24 using cricket::TransportOptions; | 24 using cricket::TransportOptions; |
25 | 25 |
26 class TransportDescriptionFactoryTest : public testing::Test { | 26 class TransportDescriptionFactoryTest : public testing::Test { |
27 public: | 27 public: |
28 TransportDescriptionFactoryTest() | 28 TransportDescriptionFactoryTest() |
29 : id1_(new rtc::FakeSSLIdentity("User1")), | 29 : cert1_(webrtc::DtlsCertificate::Create( |
30 id2_(new rtc::FakeSSLIdentity("User2")) { | 30 rtc::scoped_ptr<rtc::SSLIdentity>( |
| 31 new rtc::FakeSSLIdentity("User1")).Pass())), |
| 32 cert2_(webrtc::DtlsCertificate::Create( |
| 33 rtc::scoped_ptr<rtc::SSLIdentity>( |
| 34 new rtc::FakeSSLIdentity("User2")).Pass())) { |
31 } | 35 } |
32 | 36 |
33 void CheckDesc(const TransportDescription* desc, const std::string& type, | 37 void CheckDesc(const TransportDescription* desc, const std::string& type, |
34 const std::string& opt, const std::string& ice_ufrag, | 38 const std::string& opt, const std::string& ice_ufrag, |
35 const std::string& ice_pwd, const std::string& dtls_alg) { | 39 const std::string& ice_pwd, const std::string& dtls_alg) { |
36 ASSERT_TRUE(desc != NULL); | 40 ASSERT_TRUE(desc != NULL); |
37 EXPECT_EQ(type, desc->transport_type); | 41 EXPECT_EQ(type, desc->transport_type); |
38 EXPECT_EQ(!opt.empty(), desc->HasOption(opt)); | 42 EXPECT_EQ(!opt.empty(), desc->HasOption(opt)); |
39 if (ice_ufrag.empty() && ice_pwd.empty()) { | 43 if (ice_ufrag.empty() && ice_pwd.empty()) { |
40 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), | 44 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
(...skipping 14 matching lines...) Expand all Loading... |
55 } | 59 } |
56 | 60 |
57 // This test ice restart by doing two offer answer exchanges. On the second | 61 // This test ice restart by doing two offer answer exchanges. On the second |
58 // exchange ice is restarted. The test verifies that the ufrag and password | 62 // exchange ice is restarted. The test verifies that the ufrag and password |
59 // in the offer and answer is changed. | 63 // in the offer and answer is changed. |
60 // If |dtls| is true, the test verifies that the finger print is not changed. | 64 // If |dtls| is true, the test verifies that the finger print is not changed. |
61 void TestIceRestart(bool dtls) { | 65 void TestIceRestart(bool dtls) { |
62 if (dtls) { | 66 if (dtls) { |
63 f1_.set_secure(cricket::SEC_ENABLED); | 67 f1_.set_secure(cricket::SEC_ENABLED); |
64 f2_.set_secure(cricket::SEC_ENABLED); | 68 f2_.set_secure(cricket::SEC_ENABLED); |
65 f1_.set_identity(id1_.get()); | 69 f1_.set_certificate(cert1_.get()); |
66 f2_.set_identity(id2_.get()); | 70 f2_.set_certificate(cert2_.get()); |
67 } else { | 71 } else { |
68 f1_.set_secure(cricket::SEC_DISABLED); | 72 f1_.set_secure(cricket::SEC_DISABLED); |
69 f2_.set_secure(cricket::SEC_DISABLED); | 73 f2_.set_secure(cricket::SEC_DISABLED); |
70 } | 74 } |
71 | 75 |
72 cricket::TransportOptions options; | 76 cricket::TransportOptions options; |
73 // The initial offer / answer exchange. | 77 // The initial offer / answer exchange. |
74 rtc::scoped_ptr<TransportDescription> offer(f1_.CreateOffer( | 78 rtc::scoped_ptr<TransportDescription> offer(f1_.CreateOffer( |
75 options, NULL)); | 79 options, NULL)); |
76 rtc::scoped_ptr<TransportDescription> answer( | 80 rtc::scoped_ptr<TransportDescription> answer( |
(...skipping 30 matching lines...) Expand all Loading... |
107 EXPECT_FALSE( | 111 EXPECT_FALSE( |
108 org_desc->identity_fingerprint->GetRfc4572Fingerprint().empty()); | 112 org_desc->identity_fingerprint->GetRfc4572Fingerprint().empty()); |
109 EXPECT_EQ(org_desc->identity_fingerprint->GetRfc4572Fingerprint(), | 113 EXPECT_EQ(org_desc->identity_fingerprint->GetRfc4572Fingerprint(), |
110 restart_desc->identity_fingerprint->GetRfc4572Fingerprint()); | 114 restart_desc->identity_fingerprint->GetRfc4572Fingerprint()); |
111 } | 115 } |
112 } | 116 } |
113 | 117 |
114 protected: | 118 protected: |
115 TransportDescriptionFactory f1_; | 119 TransportDescriptionFactory f1_; |
116 TransportDescriptionFactory f2_; | 120 TransportDescriptionFactory f2_; |
117 scoped_ptr<rtc::SSLIdentity> id1_; | 121 rtc::scoped_refptr<webrtc::DtlsCertificate> cert1_; |
118 scoped_ptr<rtc::SSLIdentity> id2_; | 122 rtc::scoped_refptr<webrtc::DtlsCertificate> cert2_; |
119 }; | 123 }; |
120 | 124 |
121 // Test that in the default case, we generate the expected G-ICE offer. | 125 // Test that in the default case, we generate the expected G-ICE offer. |
122 TEST_F(TransportDescriptionFactoryTest, TestOfferGice) { | 126 TEST_F(TransportDescriptionFactoryTest, TestOfferGice) { |
123 f1_.set_protocol(cricket::ICEPROTO_GOOGLE); | 127 f1_.set_protocol(cricket::ICEPROTO_GOOGLE); |
124 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 128 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( |
125 TransportOptions(), NULL)); | 129 TransportOptions(), NULL)); |
126 CheckDesc(desc.get(), cricket::NS_GINGLE_P2P, "", "", "", ""); | 130 CheckDesc(desc.get(), cricket::NS_GINGLE_P2P, "", "", "", ""); |
127 } | 131 } |
128 | 132 |
(...skipping 10 matching lines...) Expand all Loading... |
139 f1_.set_protocol(cricket::ICEPROTO_RFC5245); | 143 f1_.set_protocol(cricket::ICEPROTO_RFC5245); |
140 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 144 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( |
141 TransportOptions(), NULL)); | 145 TransportOptions(), NULL)); |
142 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", ""); | 146 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", ""); |
143 } | 147 } |
144 | 148 |
145 // Test generating a hybrid offer with DTLS. | 149 // Test generating a hybrid offer with DTLS. |
146 TEST_F(TransportDescriptionFactoryTest, TestOfferHybridDtls) { | 150 TEST_F(TransportDescriptionFactoryTest, TestOfferHybridDtls) { |
147 f1_.set_protocol(cricket::ICEPROTO_HYBRID); | 151 f1_.set_protocol(cricket::ICEPROTO_HYBRID); |
148 f1_.set_secure(cricket::SEC_ENABLED); | 152 f1_.set_secure(cricket::SEC_ENABLED); |
149 f1_.set_identity(id1_.get()); | 153 f1_.set_certificate(cert1_.get()); |
150 std::string digest_alg; | 154 std::string digest_alg; |
151 ASSERT_TRUE(id1_->certificate().GetSignatureDigestAlgorithm(&digest_alg)); | 155 ASSERT_TRUE(cert1_->identity()->certificate().GetSignatureDigestAlgorithm( |
| 156 &digest_alg)); |
152 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 157 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( |
153 TransportOptions(), NULL)); | 158 TransportOptions(), NULL)); |
154 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "google-ice", "", "", | 159 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "google-ice", "", "", |
155 digest_alg); | 160 digest_alg); |
156 // Ensure it also works with SEC_REQUIRED. | 161 // Ensure it also works with SEC_REQUIRED. |
157 f1_.set_secure(cricket::SEC_REQUIRED); | 162 f1_.set_secure(cricket::SEC_REQUIRED); |
158 desc.reset(f1_.CreateOffer(TransportOptions(), NULL)); | 163 desc.reset(f1_.CreateOffer(TransportOptions(), NULL)); |
159 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "google-ice", "", "", | 164 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "google-ice", "", "", |
160 digest_alg); | 165 digest_alg); |
161 } | 166 } |
162 | 167 |
163 // Test generating a hybrid offer with DTLS fails with no identity. | 168 // Test generating a hybrid offer with DTLS fails with no identity. |
164 TEST_F(TransportDescriptionFactoryTest, TestOfferHybridDtlsWithNoIdentity) { | 169 TEST_F(TransportDescriptionFactoryTest, TestOfferHybridDtlsWithNoIdentity) { |
165 f1_.set_protocol(cricket::ICEPROTO_HYBRID); | 170 f1_.set_protocol(cricket::ICEPROTO_HYBRID); |
166 f1_.set_secure(cricket::SEC_ENABLED); | 171 f1_.set_secure(cricket::SEC_ENABLED); |
167 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 172 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( |
168 TransportOptions(), NULL)); | 173 TransportOptions(), NULL)); |
169 ASSERT_TRUE(desc.get() == NULL); | 174 ASSERT_TRUE(desc.get() == NULL); |
170 } | 175 } |
171 | 176 |
172 // Test updating a hybrid offer with DTLS to pick ICE. | 177 // Test updating a hybrid offer with DTLS to pick ICE. |
173 // The ICE credentials should stay the same in the new offer. | 178 // The ICE credentials should stay the same in the new offer. |
174 TEST_F(TransportDescriptionFactoryTest, TestOfferHybridDtlsReofferIceDtls) { | 179 TEST_F(TransportDescriptionFactoryTest, TestOfferHybridDtlsReofferIceDtls) { |
175 f1_.set_protocol(cricket::ICEPROTO_HYBRID); | 180 f1_.set_protocol(cricket::ICEPROTO_HYBRID); |
176 f1_.set_secure(cricket::SEC_ENABLED); | 181 f1_.set_secure(cricket::SEC_ENABLED); |
177 f1_.set_identity(id1_.get()); | 182 f1_.set_certificate(cert1_.get()); |
178 std::string digest_alg; | 183 std::string digest_alg; |
179 ASSERT_TRUE(id1_->certificate().GetSignatureDigestAlgorithm(&digest_alg)); | 184 ASSERT_TRUE(cert1_->identity()->certificate().GetSignatureDigestAlgorithm( |
| 185 &digest_alg)); |
180 scoped_ptr<TransportDescription> old_desc(f1_.CreateOffer( | 186 scoped_ptr<TransportDescription> old_desc(f1_.CreateOffer( |
181 TransportOptions(), NULL)); | 187 TransportOptions(), NULL)); |
182 ASSERT_TRUE(old_desc.get() != NULL); | 188 ASSERT_TRUE(old_desc.get() != NULL); |
183 f1_.set_protocol(cricket::ICEPROTO_RFC5245); | 189 f1_.set_protocol(cricket::ICEPROTO_RFC5245); |
184 scoped_ptr<TransportDescription> desc( | 190 scoped_ptr<TransportDescription> desc( |
185 f1_.CreateOffer(TransportOptions(), old_desc.get())); | 191 f1_.CreateOffer(TransportOptions(), old_desc.get())); |
186 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", | 192 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", |
187 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); | 193 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); |
188 } | 194 } |
189 | 195 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 old_desc.get())); | 295 old_desc.get())); |
290 ASSERT_TRUE(desc.get() != NULL); | 296 ASSERT_TRUE(desc.get() != NULL); |
291 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", | 297 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", |
292 old_desc->ice_ufrag, old_desc->ice_pwd, ""); | 298 old_desc->ice_ufrag, old_desc->ice_pwd, ""); |
293 } | 299 } |
294 | 300 |
295 // Test that we handle answering an offer with DTLS with no DTLS. | 301 // Test that we handle answering an offer with DTLS with no DTLS. |
296 TEST_F(TransportDescriptionFactoryTest, TestAnswerHybridToHybridDtls) { | 302 TEST_F(TransportDescriptionFactoryTest, TestAnswerHybridToHybridDtls) { |
297 f1_.set_protocol(cricket::ICEPROTO_HYBRID); | 303 f1_.set_protocol(cricket::ICEPROTO_HYBRID); |
298 f1_.set_secure(cricket::SEC_ENABLED); | 304 f1_.set_secure(cricket::SEC_ENABLED); |
299 f1_.set_identity(id1_.get()); | 305 f1_.set_certificate(cert1_.get()); |
300 f2_.set_protocol(cricket::ICEPROTO_HYBRID); | 306 f2_.set_protocol(cricket::ICEPROTO_HYBRID); |
301 scoped_ptr<TransportDescription> offer( | 307 scoped_ptr<TransportDescription> offer( |
302 f1_.CreateOffer(TransportOptions(), NULL)); | 308 f1_.CreateOffer(TransportOptions(), NULL)); |
303 ASSERT_TRUE(offer.get() != NULL); | 309 ASSERT_TRUE(offer.get() != NULL); |
304 scoped_ptr<TransportDescription> desc( | 310 scoped_ptr<TransportDescription> desc( |
305 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 311 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); |
306 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", ""); | 312 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", ""); |
307 } | 313 } |
308 | 314 |
309 // Test that we handle answering an offer without DTLS if we have DTLS enabled, | 315 // Test that we handle answering an offer without DTLS if we have DTLS enabled, |
310 // but fail if we require DTLS. | 316 // but fail if we require DTLS. |
311 TEST_F(TransportDescriptionFactoryTest, TestAnswerHybridDtlsToHybrid) { | 317 TEST_F(TransportDescriptionFactoryTest, TestAnswerHybridDtlsToHybrid) { |
312 f1_.set_protocol(cricket::ICEPROTO_HYBRID); | 318 f1_.set_protocol(cricket::ICEPROTO_HYBRID); |
313 f2_.set_protocol(cricket::ICEPROTO_HYBRID); | 319 f2_.set_protocol(cricket::ICEPROTO_HYBRID); |
314 f2_.set_secure(cricket::SEC_ENABLED); | 320 f2_.set_secure(cricket::SEC_ENABLED); |
315 f2_.set_identity(id2_.get()); | 321 f2_.set_certificate(cert2_.get()); |
316 scoped_ptr<TransportDescription> offer( | 322 scoped_ptr<TransportDescription> offer( |
317 f1_.CreateOffer(TransportOptions(), NULL)); | 323 f1_.CreateOffer(TransportOptions(), NULL)); |
318 ASSERT_TRUE(offer.get() != NULL); | 324 ASSERT_TRUE(offer.get() != NULL); |
319 scoped_ptr<TransportDescription> desc( | 325 scoped_ptr<TransportDescription> desc( |
320 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 326 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); |
321 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", ""); | 327 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", ""); |
322 f2_.set_secure(cricket::SEC_REQUIRED); | 328 f2_.set_secure(cricket::SEC_REQUIRED); |
323 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 329 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), |
324 NULL)); | 330 NULL)); |
325 ASSERT_TRUE(desc.get() == NULL); | 331 ASSERT_TRUE(desc.get() == NULL); |
326 } | 332 } |
327 | 333 |
328 // Test that we handle answering an DTLS offer with DTLS, both if we have | 334 // Test that we handle answering an DTLS offer with DTLS, both if we have |
329 // DTLS enabled and required. | 335 // DTLS enabled and required. |
330 TEST_F(TransportDescriptionFactoryTest, TestAnswerHybridDtlsToHybridDtls) { | 336 TEST_F(TransportDescriptionFactoryTest, TestAnswerHybridDtlsToHybridDtls) { |
331 f1_.set_protocol(cricket::ICEPROTO_HYBRID); | 337 f1_.set_protocol(cricket::ICEPROTO_HYBRID); |
332 f1_.set_secure(cricket::SEC_ENABLED); | 338 f1_.set_secure(cricket::SEC_ENABLED); |
333 f1_.set_identity(id1_.get()); | 339 f1_.set_certificate(cert1_.get()); |
334 | 340 |
335 f2_.set_protocol(cricket::ICEPROTO_HYBRID); | 341 f2_.set_protocol(cricket::ICEPROTO_HYBRID); |
336 f2_.set_secure(cricket::SEC_ENABLED); | 342 f2_.set_secure(cricket::SEC_ENABLED); |
337 f2_.set_identity(id2_.get()); | 343 f2_.set_certificate(cert2_.get()); |
338 // f2_ produces the answer that is being checked in this test, so the | 344 // f2_ produces the answer that is being checked in this test, so the |
339 // answer must contain fingerprint lines with id2_'s digest algorithm. | 345 // answer must contain fingerprint lines with cert2_'s digest algorithm. |
340 std::string digest_alg2; | 346 std::string digest_alg2; |
341 ASSERT_TRUE(id2_->certificate().GetSignatureDigestAlgorithm(&digest_alg2)); | 347 ASSERT_TRUE(cert2_->identity()->certificate().GetSignatureDigestAlgorithm( |
| 348 &digest_alg2)); |
342 | 349 |
343 scoped_ptr<TransportDescription> offer( | 350 scoped_ptr<TransportDescription> offer( |
344 f1_.CreateOffer(TransportOptions(), NULL)); | 351 f1_.CreateOffer(TransportOptions(), NULL)); |
345 ASSERT_TRUE(offer.get() != NULL); | 352 ASSERT_TRUE(offer.get() != NULL); |
346 scoped_ptr<TransportDescription> desc( | 353 scoped_ptr<TransportDescription> desc( |
347 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 354 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); |
348 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", digest_alg2); | 355 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", digest_alg2); |
349 f2_.set_secure(cricket::SEC_REQUIRED); | 356 f2_.set_secure(cricket::SEC_REQUIRED); |
350 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 357 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), |
351 NULL)); | 358 NULL)); |
352 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", digest_alg2); | 359 CheckDesc(desc.get(), cricket::NS_JINGLE_ICE_UDP, "", "", "", digest_alg2); |
353 } | 360 } |
354 | 361 |
355 // Test that ice ufrag and password is changed in an updated offer and answer | 362 // Test that ice ufrag and password is changed in an updated offer and answer |
356 // if |TransportDescriptionOptions::ice_restart| is true. | 363 // if |TransportDescriptionOptions::ice_restart| is true. |
357 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) { | 364 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) { |
358 TestIceRestart(false); | 365 TestIceRestart(false); |
359 } | 366 } |
360 | 367 |
361 // Test that ice ufrag and password is changed in an updated offer and answer | 368 // Test that ice ufrag and password is changed in an updated offer and answer |
362 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled. | 369 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled. |
363 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) { | 370 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) { |
364 TestIceRestart(true); | 371 TestIceRestart(true); |
365 } | 372 } |
OLD | NEW |