OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 using cricket::NS_JINGLE_RTP; | 79 using cricket::NS_JINGLE_RTP; |
80 using cricket::MEDIA_TYPE_AUDIO; | 80 using cricket::MEDIA_TYPE_AUDIO; |
81 using cricket::MEDIA_TYPE_VIDEO; | 81 using cricket::MEDIA_TYPE_VIDEO; |
82 using cricket::MEDIA_TYPE_DATA; | 82 using cricket::MEDIA_TYPE_DATA; |
83 using cricket::RtpHeaderExtension; | 83 using cricket::RtpHeaderExtension; |
84 using cricket::SEC_DISABLED; | 84 using cricket::SEC_DISABLED; |
85 using cricket::SEC_ENABLED; | 85 using cricket::SEC_ENABLED; |
86 using cricket::SEC_REQUIRED; | 86 using cricket::SEC_REQUIRED; |
87 using rtc::CS_AES_CM_128_HMAC_SHA1_32; | 87 using rtc::CS_AES_CM_128_HMAC_SHA1_32; |
88 using rtc::CS_AES_CM_128_HMAC_SHA1_80; | 88 using rtc::CS_AES_CM_128_HMAC_SHA1_80; |
| 89 using rtc::CS_AEAD_AES_128_GCM; |
| 90 using rtc::CS_AEAD_AES_256_GCM; |
89 | 91 |
90 static const AudioCodec kAudioCodecs1[] = { | 92 static const AudioCodec kAudioCodecs1[] = { |
91 AudioCodec(103, "ISAC", 16000, -1, 1, 6), | 93 AudioCodec(103, "ISAC", 16000, -1, 1, 6), |
92 AudioCodec(102, "iLBC", 8000, 13300, 1, 5), | 94 AudioCodec(102, "iLBC", 8000, 13300, 1, 5), |
93 AudioCodec(0, "PCMU", 8000, 64000, 1, 4), | 95 AudioCodec(0, "PCMU", 8000, 64000, 1, 4), |
94 AudioCodec(8, "PCMA", 8000, 64000, 1, 3), | 96 AudioCodec(8, "PCMA", 8000, 64000, 1, 3), |
95 AudioCodec(117, "red", 8000, 0, 1, 2), | 97 AudioCodec(117, "red", 8000, 0, 1, 2), |
96 AudioCodec(107, "CN", 48000, 0, 1, 1) | 98 AudioCodec(107, "CN", 48000, 0, 1, 1) |
97 }; | 99 }; |
98 | 100 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 const cricket::AudioContentDescription* audio_content_desc = | 465 const cricket::AudioContentDescription* audio_content_desc = |
464 static_cast<const cricket::AudioContentDescription*>(description); | 466 static_cast<const cricket::AudioContentDescription*>(description); |
465 ASSERT(audio_content_desc != NULL); | 467 ASSERT(audio_content_desc != NULL); |
466 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { | 468 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
467 if (audio_content_desc->codecs()[i].name == "CN") | 469 if (audio_content_desc->codecs()[i].name == "CN") |
468 return false; | 470 return false; |
469 } | 471 } |
470 return true; | 472 return true; |
471 } | 473 } |
472 | 474 |
| 475 void TestVideoGcmCipher(bool gcm_offer, bool gcm_answer) { |
| 476 MediaSessionOptions offer_opts; |
| 477 offer_opts.recv_video = true; |
| 478 offer_opts.enable_gcm_ciphers = gcm_offer; |
| 479 MediaSessionOptions answer_opts; |
| 480 answer_opts.recv_video = true; |
| 481 answer_opts.enable_gcm_ciphers = gcm_answer; |
| 482 f1_.set_secure(SEC_ENABLED); |
| 483 f2_.set_secure(SEC_ENABLED); |
| 484 rtc::scoped_ptr<SessionDescription> offer( |
| 485 f1_.CreateOffer(offer_opts, NULL)); |
| 486 ASSERT_TRUE(offer.get() != NULL); |
| 487 rtc::scoped_ptr<SessionDescription> answer( |
| 488 f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 489 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 490 const ContentInfo* vc = answer->GetContentByName("video"); |
| 491 ASSERT_TRUE(ac != NULL); |
| 492 ASSERT_TRUE(vc != NULL); |
| 493 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 494 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); |
| 495 const AudioContentDescription* acd = |
| 496 static_cast<const AudioContentDescription*>(ac->description); |
| 497 const VideoContentDescription* vcd = |
| 498 static_cast<const VideoContentDescription*>(vc->description); |
| 499 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 500 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 501 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 502 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc |
| 503 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 504 if (gcm_offer && gcm_answer) { |
| 505 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); |
| 506 } else { |
| 507 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
| 508 } |
| 509 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
| 510 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); |
| 511 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc |
| 512 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
| 513 if (gcm_offer && gcm_answer) { |
| 514 ASSERT_CRYPTO(vcd, 1U, CS_AEAD_AES_256_GCM); |
| 515 } else { |
| 516 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 517 } |
| 518 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 519 } |
| 520 |
473 protected: | 521 protected: |
474 MediaSessionDescriptionFactory f1_; | 522 MediaSessionDescriptionFactory f1_; |
475 MediaSessionDescriptionFactory f2_; | 523 MediaSessionDescriptionFactory f2_; |
476 TransportDescriptionFactory tdf1_; | 524 TransportDescriptionFactory tdf1_; |
477 TransportDescriptionFactory tdf2_; | 525 TransportDescriptionFactory tdf2_; |
478 }; | 526 }; |
479 | 527 |
480 // Create a typical audio offer, and ensure it matches what we expect. | 528 // Create a typical audio offer, and ensure it matches what we expect. |
481 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { | 529 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { |
482 f1_.set_secure(SEC_ENABLED); | 530 f1_.set_secure(SEC_ENABLED); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 static_cast<const AudioContentDescription*>(ac->description); | 827 static_cast<const AudioContentDescription*>(ac->description); |
780 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 828 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
781 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 829 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
782 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 830 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc |
783 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw | 831 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
784 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 832 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
785 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 833 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
786 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); | 834 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
787 } | 835 } |
788 | 836 |
| 837 // Create a typical audio answer with GCM ciphers enabled, and ensure it |
| 838 // matches what we expect. |
| 839 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) { |
| 840 f1_.set_secure(SEC_ENABLED); |
| 841 f2_.set_secure(SEC_ENABLED); |
| 842 MediaSessionOptions options; |
| 843 options.enable_gcm_ciphers = true; |
| 844 rtc::scoped_ptr<SessionDescription> offer( |
| 845 f1_.CreateOffer(options, NULL)); |
| 846 ASSERT_TRUE(offer.get() != NULL); |
| 847 rtc::scoped_ptr<SessionDescription> answer( |
| 848 f2_.CreateAnswer(offer.get(), options, NULL)); |
| 849 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 850 const ContentInfo* vc = answer->GetContentByName("video"); |
| 851 ASSERT_TRUE(ac != NULL); |
| 852 ASSERT_TRUE(vc == NULL); |
| 853 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 854 const AudioContentDescription* acd = |
| 855 static_cast<const AudioContentDescription*>(ac->description); |
| 856 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 857 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 858 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc |
| 859 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 860 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 861 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); |
| 862 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
| 863 } |
| 864 |
789 // Create a typical video answer, and ensure it matches what we expect. | 865 // Create a typical video answer, and ensure it matches what we expect. |
790 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { | 866 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { |
791 MediaSessionOptions opts; | 867 MediaSessionOptions opts; |
792 opts.recv_video = true; | 868 opts.recv_video = true; |
793 f1_.set_secure(SEC_ENABLED); | 869 f1_.set_secure(SEC_ENABLED); |
794 f2_.set_secure(SEC_ENABLED); | 870 f2_.set_secure(SEC_ENABLED); |
795 rtc::scoped_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 871 rtc::scoped_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
796 ASSERT_TRUE(offer.get() != NULL); | 872 ASSERT_TRUE(offer.get() != NULL); |
797 rtc::scoped_ptr<SessionDescription> answer( | 873 rtc::scoped_ptr<SessionDescription> answer( |
798 f2_.CreateAnswer(offer.get(), opts, NULL)); | 874 f2_.CreateAnswer(offer.get(), opts, NULL)); |
(...skipping 14 matching lines...) Expand all Loading... |
813 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 889 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
814 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 890 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
815 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); | 891 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
816 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); | 892 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); |
817 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc | 893 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc |
818 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux | 894 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
819 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 895 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
820 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); | 896 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
821 } | 897 } |
822 | 898 |
| 899 // Create a typical video answer with GCM ciphers enabled, and ensure it |
| 900 // matches what we expect. |
| 901 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcm) { |
| 902 TestVideoGcmCipher(true, true); |
| 903 } |
| 904 |
| 905 // Create a typical video answer with GCM ciphers enabled for the offer only, |
| 906 // and ensure it matches what we expect. |
| 907 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmOffer) { |
| 908 TestVideoGcmCipher(true, false); |
| 909 } |
| 910 |
| 911 // Create a typical video answer with GCM ciphers enabled for the answer only, |
| 912 // and ensure it matches what we expect. |
| 913 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmAnswer) { |
| 914 TestVideoGcmCipher(false, true); |
| 915 } |
| 916 |
823 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswer) { | 917 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswer) { |
824 MediaSessionOptions opts; | 918 MediaSessionOptions opts; |
825 opts.data_channel_type = cricket::DCT_RTP; | 919 opts.data_channel_type = cricket::DCT_RTP; |
826 f1_.set_secure(SEC_ENABLED); | 920 f1_.set_secure(SEC_ENABLED); |
827 f2_.set_secure(SEC_ENABLED); | 921 f2_.set_secure(SEC_ENABLED); |
828 rtc::scoped_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 922 rtc::scoped_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
829 ASSERT_TRUE(offer.get() != NULL); | 923 ASSERT_TRUE(offer.get() != NULL); |
830 rtc::scoped_ptr<SessionDescription> answer( | 924 rtc::scoped_ptr<SessionDescription> answer( |
831 f2_.CreateAnswer(offer.get(), opts, NULL)); | 925 f2_.CreateAnswer(offer.get(), opts, NULL)); |
832 const ContentInfo* ac = answer->GetContentByName("audio"); | 926 const ContentInfo* ac = answer->GetContentByName("audio"); |
(...skipping 13 matching lines...) Expand all Loading... |
846 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 940 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
847 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 941 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
848 EXPECT_EQ(MEDIA_TYPE_DATA, vcd->type()); | 942 EXPECT_EQ(MEDIA_TYPE_DATA, vcd->type()); |
849 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), vcd->codecs()); | 943 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), vcd->codecs()); |
850 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc | 944 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc |
851 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux | 945 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
852 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 946 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
853 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); | 947 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
854 } | 948 } |
855 | 949 |
| 950 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerGcm) { |
| 951 MediaSessionOptions opts; |
| 952 opts.data_channel_type = cricket::DCT_RTP; |
| 953 opts.enable_gcm_ciphers = true; |
| 954 f1_.set_secure(SEC_ENABLED); |
| 955 f2_.set_secure(SEC_ENABLED); |
| 956 rtc::scoped_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 957 ASSERT_TRUE(offer.get() != NULL); |
| 958 rtc::scoped_ptr<SessionDescription> answer( |
| 959 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 960 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 961 const ContentInfo* vc = answer->GetContentByName("data"); |
| 962 ASSERT_TRUE(ac != NULL); |
| 963 ASSERT_TRUE(vc != NULL); |
| 964 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 965 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); |
| 966 const AudioContentDescription* acd = |
| 967 static_cast<const AudioContentDescription*>(ac->description); |
| 968 const DataContentDescription* vcd = |
| 969 static_cast<const DataContentDescription*>(vc->description); |
| 970 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 971 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 972 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 973 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc |
| 974 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 975 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); |
| 976 EXPECT_EQ(MEDIA_TYPE_DATA, vcd->type()); |
| 977 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), vcd->codecs()); |
| 978 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc |
| 979 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
| 980 ASSERT_CRYPTO(vcd, 1U, CS_AEAD_AES_256_GCM); |
| 981 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 982 } |
| 983 |
856 // Verifies that the order of the media contents in the offer is preserved in | 984 // Verifies that the order of the media contents in the offer is preserved in |
857 // the answer. | 985 // the answer. |
858 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { | 986 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { |
859 MediaSessionOptions opts; | 987 MediaSessionOptions opts; |
860 | 988 |
861 // Creates a data only offer. | 989 // Creates a data only offer. |
862 opts.recv_audio = false; | 990 opts.recv_audio = false; |
863 opts.data_channel_type = cricket::DCT_SCTP; | 991 opts.data_channel_type = cricket::DCT_SCTP; |
864 rtc::scoped_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); | 992 rtc::scoped_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
865 ASSERT_TRUE(offer1.get() != NULL); | 993 ASSERT_TRUE(offer1.get() != NULL); |
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 offer.reset(f1_.CreateOffer(options, NULL)); | 2434 offer.reset(f1_.CreateOffer(options, NULL)); |
2307 ASSERT_TRUE(offer.get() != NULL); | 2435 ASSERT_TRUE(offer.get() != NULL); |
2308 audio_content = offer->GetContentByName("audio"); | 2436 audio_content = offer->GetContentByName("audio"); |
2309 EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); | 2437 EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
2310 rtc::scoped_ptr<SessionDescription> answer( | 2438 rtc::scoped_ptr<SessionDescription> answer( |
2311 f1_.CreateAnswer(offer.get(), options, NULL)); | 2439 f1_.CreateAnswer(offer.get(), options, NULL)); |
2312 ASSERT_TRUE(answer.get() != NULL); | 2440 ASSERT_TRUE(answer.get() != NULL); |
2313 audio_content = answer->GetContentByName("audio"); | 2441 audio_content = answer->GetContentByName("audio"); |
2314 EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); | 2442 EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
2315 } | 2443 } |
OLD | NEW |