| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2009 Google Inc. | 3 * Copyright 2009 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 extern "C" debug_module_t mod_aes_icm; | 66 extern "C" debug_module_t mod_aes_icm; |
| 67 extern "C" debug_module_t mod_aes_hmac; | 67 extern "C" debug_module_t mod_aes_hmac; |
| 68 #endif | 68 #endif |
| 69 #else | 69 #else |
| 70 // SrtpFilter needs that constant. | 70 // SrtpFilter needs that constant. |
| 71 #define SRTP_MASTER_KEY_LEN 30 | 71 #define SRTP_MASTER_KEY_LEN 30 |
| 72 #endif // HAVE_SRTP | 72 #endif // HAVE_SRTP |
| 73 | 73 |
| 74 namespace cricket { | 74 namespace cricket { |
| 75 | 75 |
| 76 const int SRTP_MASTER_KEY_BASE64_LEN = SRTP_MASTER_KEY_LEN * 4 / 3; | |
| 77 const int SRTP_MASTER_KEY_KEY_LEN = 16; | |
| 78 const int SRTP_MASTER_KEY_SALT_LEN = 14; | |
| 79 | |
| 80 #ifndef HAVE_SRTP | 76 #ifndef HAVE_SRTP |
| 81 | 77 |
| 82 // This helper function is used on systems that don't (yet) have SRTP, | 78 // This helper function is used on systems that don't (yet) have SRTP, |
| 83 // to log that the functions that require it won't do anything. | 79 // to log that the functions that require it won't do anything. |
| 84 namespace { | 80 namespace { |
| 85 bool SrtpNotAvailable(const char *func) { | 81 bool SrtpNotAvailable(const char *func) { |
| 86 LOG(LS_ERROR) << func << ": SRTP is not available on your system."; | 82 LOG(LS_ERROR) << func << ": SRTP is not available on your system."; |
| 87 return false; | 83 return false; |
| 88 } | 84 } |
| 89 } // anonymous namespace | 85 } // anonymous namespace |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 << "SRTP session already created"; | 666 << "SRTP session already created"; |
| 671 return false; | 667 return false; |
| 672 } | 668 } |
| 673 | 669 |
| 674 if (!Init()) { | 670 if (!Init()) { |
| 675 return false; | 671 return false; |
| 676 } | 672 } |
| 677 | 673 |
| 678 srtp_policy_t policy; | 674 srtp_policy_t policy; |
| 679 memset(&policy, 0, sizeof(policy)); | 675 memset(&policy, 0, sizeof(policy)); |
| 680 | |
| 681 if (cs == rtc::SRTP_AES128_CM_SHA1_80) { | 676 if (cs == rtc::SRTP_AES128_CM_SHA1_80) { |
| 682 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp); | 677 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp); |
| 683 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); | 678 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); |
| 684 } else if (cs == rtc::SRTP_AES128_CM_SHA1_32) { | 679 } else if (cs == rtc::SRTP_AES128_CM_SHA1_32) { |
| 685 crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp); // rtp is 32, | 680 crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp); // rtp is 32, |
| 686 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // rtcp still 80 | 681 crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // rtcp still 80 |
| 682 } else if (cs == rtc::SRTP_AEAD_AES_128_GCM) { |
| 683 crypto_policy_set_aes_gcm_128_16_auth(&policy.rtp); |
| 684 crypto_policy_set_aes_gcm_128_16_auth(&policy.rtcp); |
| 685 } else if (cs == rtc::SRTP_AEAD_AES_256_GCM) { |
| 686 crypto_policy_set_aes_gcm_256_16_auth(&policy.rtp); |
| 687 crypto_policy_set_aes_gcm_256_16_auth(&policy.rtcp); |
| 687 } else { | 688 } else { |
| 688 LOG(LS_WARNING) << "Failed to create SRTP session: unsupported" | 689 LOG(LS_WARNING) << "Failed to create SRTP session: unsupported" |
| 689 << " cipher_suite " << cs; | 690 << " cipher_suite " << cs; |
| 690 return false; | 691 return false; |
| 691 } | 692 } |
| 692 | 693 |
| 693 if (!key || len != SRTP_MASTER_KEY_LEN) { | 694 int expected_key_len; |
| 695 int expected_salt_len; |
| 696 if (!rtc::GetSrtpKeyAndSaltLengths(cs, &expected_key_len, |
| 697 &expected_salt_len)) { |
| 698 // This should never happen. |
| 699 LOG(LS_WARNING) << "Failed to create SRTP session: unsupported" |
| 700 << " cipher_suite without length information" << cs; |
| 701 return false; |
| 702 } |
| 703 |
| 704 if (!key || len != (expected_key_len + expected_salt_len)) { |
| 694 LOG(LS_WARNING) << "Failed to create SRTP session: invalid key"; | 705 LOG(LS_WARNING) << "Failed to create SRTP session: invalid key"; |
| 695 return false; | 706 return false; |
| 696 } | 707 } |
| 697 | 708 |
| 698 policy.ssrc.type = static_cast<ssrc_type_t>(type); | 709 policy.ssrc.type = static_cast<ssrc_type_t>(type); |
| 699 policy.ssrc.value = 0; | 710 policy.ssrc.value = 0; |
| 700 policy.key = const_cast<uint8_t*>(key); | 711 policy.key = const_cast<uint8_t*>(key); |
| 701 // TODO(astor) parse window size from WSH session-param | 712 // TODO(astor) parse window size from WSH session-param |
| 702 policy.window_size = 1024; | 713 policy.window_size = 1024; |
| 703 policy.allow_repeat_tx = 1; | 714 policy.allow_repeat_tx = 1; |
| 704 // If external authentication option is enabled, supply custom auth module | 715 // If external authentication option is enabled, supply custom auth module |
| 705 // id EXTERNAL_HMAC_SHA1 in the policy structure. | 716 // id EXTERNAL_HMAC_SHA1 in the policy structure. |
| 706 // We want to set this option only for rtp packets. | 717 // We want to set this option only for rtp packets. |
| 707 // By default policy structure is initialized to HMAC_SHA1. | 718 // By default policy structure is initialized to HMAC_SHA1. |
| 708 #if defined(ENABLE_EXTERNAL_AUTH) | 719 #if defined(ENABLE_EXTERNAL_AUTH) |
| 709 // Enable external HMAC authentication only for outgoing streams. | 720 // Enable external HMAC authentication only for outgoing streams. |
| 710 if (type == ssrc_any_outbound) { | 721 if (type == ssrc_any_outbound) { |
| 711 policy.rtp.auth_type = EXTERNAL_HMAC_SHA1; | 722 policy.rtp.auth_type = EXTERNAL_HMAC_SHA1; |
| 712 } | 723 } |
| 713 #endif | 724 #endif |
| 714 policy.next = NULL; | 725 policy.next = NULL; |
| 715 | 726 |
| 716 int err = srtp_create(&session_, &policy); | 727 int err = srtp_create(&session_, &policy); |
| 717 if (err != err_status_ok) { | 728 if (err != err_status_ok) { |
| 718 session_ = NULL; | 729 session_ = NULL; |
| 719 LOG(LS_ERROR) << "Failed to create SRTP session, err=" << err; | 730 LOG(LS_ERROR) << "Failed to create SRTP session, err=" << err; |
| 720 return false; | 731 return false; |
| 721 } | 732 } |
| 722 | 733 |
| 723 | |
| 724 rtp_auth_tag_len_ = policy.rtp.auth_tag_len; | 734 rtp_auth_tag_len_ = policy.rtp.auth_tag_len; |
| 725 rtcp_auth_tag_len_ = policy.rtcp.auth_tag_len; | 735 rtcp_auth_tag_len_ = policy.rtcp.auth_tag_len; |
| 726 return true; | 736 return true; |
| 727 } | 737 } |
| 728 | 738 |
| 729 bool SrtpSession::Init() { | 739 bool SrtpSession::Init() { |
| 730 rtc::GlobalLockScope ls(&lock_); | 740 rtc::GlobalLockScope ls(&lock_); |
| 731 | 741 |
| 732 if (!inited_) { | 742 if (!inited_) { |
| 733 int err; | 743 int err; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 SrtpNotAvailable(__FUNCTION__); | 955 SrtpNotAvailable(__FUNCTION__); |
| 946 } | 956 } |
| 947 | 957 |
| 948 void SrtpStat::HandleSrtpResult(const SrtpStat::FailureKey& key) { | 958 void SrtpStat::HandleSrtpResult(const SrtpStat::FailureKey& key) { |
| 949 SrtpNotAvailable(__FUNCTION__); | 959 SrtpNotAvailable(__FUNCTION__); |
| 950 } | 960 } |
| 951 | 961 |
| 952 #endif // HAVE_SRTP | 962 #endif // HAVE_SRTP |
| 953 | 963 |
| 954 } // namespace cricket | 964 } // namespace cricket |
| OLD | NEW |