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

Side by Side Diff: talk/session/media/srtpfilter_unittest.cc

Issue 1416673006: Convert internal representation of Srtp cryptos from string to int. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: change srtp crypto name conversion Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « talk/session/media/srtpfilter.cc ('k') | webrtc/base/opensslstreamadapter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // Complete the negotiation. 501 // Complete the negotiation.
502 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL)); 502 EXPECT_TRUE(f2_.SetAnswer(answer, CS_LOCAL));
503 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE)); 503 EXPECT_TRUE(f1_.SetAnswer(answer, CS_REMOTE));
504 504
505 EXPECT_FALSE(f1_.IsActive()); 505 EXPECT_FALSE(f1_.IsActive());
506 EXPECT_FALSE(f2_.IsActive()); 506 EXPECT_FALSE(f2_.IsActive());
507 } 507 }
508 508
509 // Test directly setting the params with AES_CM_128_HMAC_SHA1_80 509 // Test directly setting the params with AES_CM_128_HMAC_SHA1_80
510 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_80) { 510 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_80) {
511 EXPECT_TRUE(f1_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_80, 511 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
512 kTestKey1, kTestKeyLen, 512 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80,
513 CS_AES_CM_128_HMAC_SHA1_80,
514 kTestKey2, kTestKeyLen)); 513 kTestKey2, kTestKeyLen));
515 EXPECT_TRUE(f2_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_80, 514 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2,
516 kTestKey2, kTestKeyLen, 515 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80,
517 CS_AES_CM_128_HMAC_SHA1_80,
518 kTestKey1, kTestKeyLen)); 516 kTestKey1, kTestKeyLen));
519 EXPECT_TRUE(f1_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_80, 517 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
520 kTestKey1, kTestKeyLen, 518 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80,
521 CS_AES_CM_128_HMAC_SHA1_80,
522 kTestKey2, kTestKeyLen)); 519 kTestKey2, kTestKeyLen));
523 EXPECT_TRUE(f2_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_80, 520 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2,
524 kTestKey2, kTestKeyLen, 521 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_80,
525 CS_AES_CM_128_HMAC_SHA1_80,
526 kTestKey1, kTestKeyLen)); 522 kTestKey1, kTestKeyLen));
527 EXPECT_TRUE(f1_.IsActive()); 523 EXPECT_TRUE(f1_.IsActive());
528 EXPECT_TRUE(f2_.IsActive()); 524 EXPECT_TRUE(f2_.IsActive());
529 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80); 525 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_80, CS_AES_CM_128_HMAC_SHA1_80);
530 } 526 }
531 527
532 // Test directly setting the params with AES_CM_128_HMAC_SHA1_32 528 // Test directly setting the params with AES_CM_128_HMAC_SHA1_32
533 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_32) { 529 TEST_F(SrtpFilterTest, TestProtect_SetParamsDirect_AES_CM_128_HMAC_SHA1_32) {
534 EXPECT_TRUE(f1_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_32, 530 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
535 kTestKey1, kTestKeyLen, 531 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
536 CS_AES_CM_128_HMAC_SHA1_32,
537 kTestKey2, kTestKeyLen)); 532 kTestKey2, kTestKeyLen));
538 EXPECT_TRUE(f2_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_32, 533 EXPECT_TRUE(f2_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey2,
539 kTestKey2, kTestKeyLen, 534 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
540 CS_AES_CM_128_HMAC_SHA1_32,
541 kTestKey1, kTestKeyLen)); 535 kTestKey1, kTestKeyLen));
542 EXPECT_TRUE(f1_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_32, 536 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
543 kTestKey1, kTestKeyLen, 537 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
544 CS_AES_CM_128_HMAC_SHA1_32,
545 kTestKey2, kTestKeyLen)); 538 kTestKey2, kTestKeyLen));
546 EXPECT_TRUE(f2_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_32, 539 EXPECT_TRUE(f2_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey2,
547 kTestKey2, kTestKeyLen, 540 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
548 CS_AES_CM_128_HMAC_SHA1_32,
549 kTestKey1, kTestKeyLen)); 541 kTestKey1, kTestKeyLen));
550 EXPECT_TRUE(f1_.IsActive()); 542 EXPECT_TRUE(f1_.IsActive());
551 EXPECT_TRUE(f2_.IsActive()); 543 EXPECT_TRUE(f2_.IsActive());
552 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_32, CS_AES_CM_128_HMAC_SHA1_32); 544 TestProtectUnprotect(CS_AES_CM_128_HMAC_SHA1_32, CS_AES_CM_128_HMAC_SHA1_32);
553 } 545 }
554 546
555 // Test directly setting the params with bogus keys 547 // Test directly setting the params with bogus keys
556 TEST_F(SrtpFilterTest, TestSetParamsKeyTooShort) { 548 TEST_F(SrtpFilterTest, TestSetParamsKeyTooShort) {
557 EXPECT_FALSE(f1_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_80, 549 EXPECT_FALSE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
558 kTestKey1, kTestKeyLen - 1, 550 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80,
559 CS_AES_CM_128_HMAC_SHA1_80,
560 kTestKey1, kTestKeyLen - 1)); 551 kTestKey1, kTestKeyLen - 1));
561 EXPECT_FALSE(f1_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_80, 552 EXPECT_FALSE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1,
562 kTestKey1, kTestKeyLen - 1, 553 kTestKeyLen - 1, rtc::SRTP_AES128_CM_SHA1_80,
563 CS_AES_CM_128_HMAC_SHA1_80,
564 kTestKey1, kTestKeyLen - 1)); 554 kTestKey1, kTestKeyLen - 1));
565 } 555 }
566 556
567 #if defined(ENABLE_EXTERNAL_AUTH) 557 #if defined(ENABLE_EXTERNAL_AUTH)
568 TEST_F(SrtpFilterTest, TestGetSendAuthParams) { 558 TEST_F(SrtpFilterTest, TestGetSendAuthParams) {
569 EXPECT_TRUE(f1_.SetRtpParams(CS_AES_CM_128_HMAC_SHA1_32, 559 EXPECT_TRUE(f1_.SetRtpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
570 kTestKey1, kTestKeyLen, 560 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
571 CS_AES_CM_128_HMAC_SHA1_32,
572 kTestKey2, kTestKeyLen)); 561 kTestKey2, kTestKeyLen));
573 EXPECT_TRUE(f1_.SetRtcpParams(CS_AES_CM_128_HMAC_SHA1_32, 562 EXPECT_TRUE(f1_.SetRtcpParams(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1,
574 kTestKey1, kTestKeyLen, 563 kTestKeyLen, rtc::SRTP_AES128_CM_SHA1_32,
575 CS_AES_CM_128_HMAC_SHA1_32,
576 kTestKey2, kTestKeyLen)); 564 kTestKey2, kTestKeyLen));
577 uint8_t* auth_key = NULL; 565 uint8_t* auth_key = NULL;
578 int auth_key_len = 0, auth_tag_len = 0; 566 int auth_key_len = 0, auth_tag_len = 0;
579 EXPECT_TRUE(f1_.GetRtpAuthParams(&auth_key, &auth_key_len, &auth_tag_len)); 567 EXPECT_TRUE(f1_.GetRtpAuthParams(&auth_key, &auth_key_len, &auth_tag_len));
580 EXPECT_TRUE(auth_key != NULL); 568 EXPECT_TRUE(auth_key != NULL);
581 EXPECT_EQ(20, auth_key_len); 569 EXPECT_EQ(20, auth_key_len);
582 EXPECT_EQ(4, auth_tag_len); 570 EXPECT_EQ(4, auth_tag_len);
583 } 571 }
584 #endif 572 #endif
585 573
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 cricket::SrtpSession s1_; 610 cricket::SrtpSession s1_;
623 cricket::SrtpSession s2_; 611 cricket::SrtpSession s2_;
624 char rtp_packet_[sizeof(kPcmuFrame) + 10]; 612 char rtp_packet_[sizeof(kPcmuFrame) + 10];
625 char rtcp_packet_[sizeof(kRtcpReport) + 4 + 10]; 613 char rtcp_packet_[sizeof(kRtcpReport) + 4 + 10];
626 int rtp_len_; 614 int rtp_len_;
627 int rtcp_len_; 615 int rtcp_len_;
628 }; 616 };
629 617
630 // Test that we can set up the session and keys properly. 618 // Test that we can set up the session and keys properly.
631 TEST_F(SrtpSessionTest, TestGoodSetup) { 619 TEST_F(SrtpSessionTest, TestGoodSetup) {
632 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 620 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
633 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 621 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
634 } 622 }
635 623
636 // Test that we can't change the keys once set. 624 // Test that we can't change the keys once set.
637 TEST_F(SrtpSessionTest, TestBadSetup) { 625 TEST_F(SrtpSessionTest, TestBadSetup) {
638 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 626 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
639 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 627 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
640 EXPECT_FALSE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey2, kTestKeyLen)); 628 EXPECT_FALSE(
641 EXPECT_FALSE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey2, kTestKeyLen)); 629 s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2, kTestKeyLen));
630 EXPECT_FALSE(
631 s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey2, kTestKeyLen));
642 } 632 }
643 633
644 // Test that we fail keys of the wrong length. 634 // Test that we fail keys of the wrong length.
645 TEST_F(SrtpSessionTest, TestKeysTooShort) { 635 TEST_F(SrtpSessionTest, TestKeysTooShort) {
646 EXPECT_FALSE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, 1)); 636 EXPECT_FALSE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 1));
647 EXPECT_FALSE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, 1)); 637 EXPECT_FALSE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, 1));
648 } 638 }
649 639
650 // Test that we can encrypt and decrypt RTP/RTCP using AES_CM_128_HMAC_SHA1_80. 640 // Test that we can encrypt and decrypt RTP/RTCP using AES_CM_128_HMAC_SHA1_80.
651 TEST_F(SrtpSessionTest, TestProtect_AES_CM_128_HMAC_SHA1_80) { 641 TEST_F(SrtpSessionTest, TestProtect_AES_CM_128_HMAC_SHA1_80) {
652 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 642 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
653 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 643 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
654 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_80); 644 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_80);
655 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_80); 645 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_80);
656 TestUnprotectRtp(CS_AES_CM_128_HMAC_SHA1_80); 646 TestUnprotectRtp(CS_AES_CM_128_HMAC_SHA1_80);
657 TestUnprotectRtcp(CS_AES_CM_128_HMAC_SHA1_80); 647 TestUnprotectRtcp(CS_AES_CM_128_HMAC_SHA1_80);
658 } 648 }
659 649
660 // Test that we can encrypt and decrypt RTP/RTCP using AES_CM_128_HMAC_SHA1_32. 650 // Test that we can encrypt and decrypt RTP/RTCP using AES_CM_128_HMAC_SHA1_32.
661 TEST_F(SrtpSessionTest, TestProtect_AES_CM_128_HMAC_SHA1_32) { 651 TEST_F(SrtpSessionTest, TestProtect_AES_CM_128_HMAC_SHA1_32) {
662 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_32, kTestKey1, kTestKeyLen)); 652 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, kTestKeyLen));
663 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_32, kTestKey1, kTestKeyLen)); 653 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, kTestKeyLen));
664 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_32); 654 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_32);
665 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_32); 655 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_32);
666 TestUnprotectRtp(CS_AES_CM_128_HMAC_SHA1_32); 656 TestUnprotectRtp(CS_AES_CM_128_HMAC_SHA1_32);
667 TestUnprotectRtcp(CS_AES_CM_128_HMAC_SHA1_32); 657 TestUnprotectRtcp(CS_AES_CM_128_HMAC_SHA1_32);
668 } 658 }
669 659
670 TEST_F(SrtpSessionTest, TestGetSendStreamPacketIndex) { 660 TEST_F(SrtpSessionTest, TestGetSendStreamPacketIndex) {
671 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_32, kTestKey1, kTestKeyLen)); 661 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_32, kTestKey1, kTestKeyLen));
672 int64_t index; 662 int64_t index;
673 int out_len = 0; 663 int out_len = 0;
674 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, 664 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_,
675 sizeof(rtp_packet_), &out_len, &index)); 665 sizeof(rtp_packet_), &out_len, &index));
676 // |index| will be shifted by 16. 666 // |index| will be shifted by 16.
677 int64_t be64_index = static_cast<int64_t>(rtc::NetworkToHost64(1 << 16)); 667 int64_t be64_index = static_cast<int64_t>(rtc::NetworkToHost64(1 << 16));
678 EXPECT_EQ(be64_index, index); 668 EXPECT_EQ(be64_index, index);
679 } 669 }
680 670
681 // Test that we fail to unprotect if someone tampers with the RTP/RTCP paylaods. 671 // Test that we fail to unprotect if someone tampers with the RTP/RTCP paylaods.
682 TEST_F(SrtpSessionTest, TestTamperReject) { 672 TEST_F(SrtpSessionTest, TestTamperReject) {
683 int out_len; 673 int out_len;
684 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 674 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
685 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 675 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
686 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_80); 676 TestProtectRtp(CS_AES_CM_128_HMAC_SHA1_80);
687 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_80); 677 TestProtectRtcp(CS_AES_CM_128_HMAC_SHA1_80);
688 rtp_packet_[0] = 0x12; 678 rtp_packet_[0] = 0x12;
689 rtcp_packet_[1] = 0x34; 679 rtcp_packet_[1] = 0x34;
690 EXPECT_FALSE(s2_.UnprotectRtp(rtp_packet_, rtp_len_, &out_len)); 680 EXPECT_FALSE(s2_.UnprotectRtp(rtp_packet_, rtp_len_, &out_len));
691 EXPECT_FALSE(s2_.UnprotectRtcp(rtcp_packet_, rtcp_len_, &out_len)); 681 EXPECT_FALSE(s2_.UnprotectRtcp(rtcp_packet_, rtcp_len_, &out_len));
692 } 682 }
693 683
694 // Test that we fail to unprotect if the payloads are not authenticated. 684 // Test that we fail to unprotect if the payloads are not authenticated.
695 TEST_F(SrtpSessionTest, TestUnencryptReject) { 685 TEST_F(SrtpSessionTest, TestUnencryptReject) {
696 int out_len; 686 int out_len;
697 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 687 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
698 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 688 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
699 EXPECT_FALSE(s2_.UnprotectRtp(rtp_packet_, rtp_len_, &out_len)); 689 EXPECT_FALSE(s2_.UnprotectRtp(rtp_packet_, rtp_len_, &out_len));
700 EXPECT_FALSE(s2_.UnprotectRtcp(rtcp_packet_, rtcp_len_, &out_len)); 690 EXPECT_FALSE(s2_.UnprotectRtcp(rtcp_packet_, rtcp_len_, &out_len));
701 } 691 }
702 692
703 // Test that we fail when using buffers that are too small. 693 // Test that we fail when using buffers that are too small.
704 TEST_F(SrtpSessionTest, TestBuffersTooSmall) { 694 TEST_F(SrtpSessionTest, TestBuffersTooSmall) {
705 int out_len; 695 int out_len;
706 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 696 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
707 EXPECT_FALSE(s1_.ProtectRtp(rtp_packet_, rtp_len_, 697 EXPECT_FALSE(s1_.ProtectRtp(rtp_packet_, rtp_len_,
708 sizeof(rtp_packet_) - 10, &out_len)); 698 sizeof(rtp_packet_) - 10, &out_len));
709 EXPECT_FALSE(s1_.ProtectRtcp(rtcp_packet_, rtcp_len_, 699 EXPECT_FALSE(s1_.ProtectRtcp(rtcp_packet_, rtcp_len_,
710 sizeof(rtcp_packet_) - 14, &out_len)); 700 sizeof(rtcp_packet_) - 14, &out_len));
711 } 701 }
712 702
713 TEST_F(SrtpSessionTest, TestReplay) { 703 TEST_F(SrtpSessionTest, TestReplay) {
714 static const uint16_t kMaxSeqnum = static_cast<uint16_t>(-1); 704 static const uint16_t kMaxSeqnum = static_cast<uint16_t>(-1);
715 static const uint16_t seqnum_big = 62275; 705 static const uint16_t seqnum_big = 62275;
716 static const uint16_t seqnum_small = 10; 706 static const uint16_t seqnum_small = 10;
717 static const uint16_t replay_window = 1024; 707 static const uint16_t replay_window = 1024;
718 int out_len; 708 int out_len;
719 709
720 EXPECT_TRUE(s1_.SetSend(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 710 EXPECT_TRUE(s1_.SetSend(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
721 EXPECT_TRUE(s2_.SetRecv(CS_AES_CM_128_HMAC_SHA1_80, kTestKey1, kTestKeyLen)); 711 EXPECT_TRUE(s2_.SetRecv(rtc::SRTP_AES128_CM_SHA1_80, kTestKey1, kTestKeyLen));
722 712
723 // Initial sequence number. 713 // Initial sequence number.
724 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2, seqnum_big); 714 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2, seqnum_big);
725 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_), 715 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_),
726 &out_len)); 716 &out_len));
727 717
728 // Replay within the 1024 window should succeed. 718 // Replay within the 1024 window should succeed.
729 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2, 719 rtc::SetBE16(reinterpret_cast<uint8_t*>(rtp_packet_) + 2,
730 seqnum_big - replay_window + 1); 720 seqnum_big - replay_window + 1);
731 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_), 721 EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_),
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 srtp_stat_.AddUnprotectRtcpResult(err_status_fail); 916 srtp_stat_.AddUnprotectRtcpResult(err_status_fail);
927 EXPECT_EQ(-1, mode_); 917 EXPECT_EQ(-1, mode_);
928 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); 918 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_);
929 // Now the error will be triggered again. 919 // Now the error will be triggered again.
930 Reset(); 920 Reset();
931 rtc::Thread::Current()->SleepMs(210); 921 rtc::Thread::Current()->SleepMs(210);
932 srtp_stat_.AddUnprotectRtcpResult(err_status_fail); 922 srtp_stat_.AddUnprotectRtcpResult(err_status_fail);
933 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); 923 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_);
934 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); 924 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_);
935 } 925 }
OLDNEW
« no previous file with comments | « talk/session/media/srtpfilter.cc ('k') | webrtc/base/opensslstreamadapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698