| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "webrtc/p2p/base/constants.h" | 43 #include "webrtc/p2p/base/constants.h" |
| 44 | 44 |
| 45 #ifdef HAVE_SCTP | 45 #ifdef HAVE_SCTP |
| 46 #include "talk/media/sctp/sctpdataengine.h" | 46 #include "talk/media/sctp/sctpdataengine.h" |
| 47 #else | 47 #else |
| 48 static const uint32_t kMaxSctpSid = 1023; | 48 static const uint32_t kMaxSctpSid = 1023; |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 namespace { | 51 namespace { |
| 52 const char kInline[] = "inline:"; | 52 const char kInline[] = "inline:"; |
| 53 |
| 54 void GetSupportedCryptoSuiteNames(void (*func)(std::vector<int>*), |
| 55 std::vector<std::string>* names) { |
| 56 #ifdef HAVE_SRTP |
| 57 std::vector<int> crypto_suites; |
| 58 func(&crypto_suites); |
| 59 for (const auto crypto : crypto_suites) { |
| 60 names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); |
| 61 } |
| 62 #endif |
| 63 } |
| 53 } | 64 } |
| 54 | 65 |
| 55 namespace cricket { | 66 namespace cricket { |
| 56 | 67 |
| 57 using rtc::scoped_ptr; | 68 using rtc::scoped_ptr; |
| 58 | 69 |
| 59 // RTP Profile names | 70 // RTP Profile names |
| 60 // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml | 71 // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml |
| 61 // RFC4585 | 72 // RFC4585 |
| 62 const char kMediaProtocolAvpf[] = "RTP/AVPF"; | 73 const char kMediaProtocolAvpf[] = "RTP/AVPF"; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 it != cryptos.end(); ++it) { | 156 it != cryptos.end(); ++it) { |
| 146 if (crypto.Matches(*it)) { | 157 if (crypto.Matches(*it)) { |
| 147 *out = *it; | 158 *out = *it; |
| 148 return true; | 159 return true; |
| 149 } | 160 } |
| 150 } | 161 } |
| 151 return false; | 162 return false; |
| 152 } | 163 } |
| 153 | 164 |
| 154 // For audio, HMAC 32 is prefered because of the low overhead. | 165 // For audio, HMAC 32 is prefered because of the low overhead. |
| 155 void GetSupportedAudioCryptoSuites( | 166 void GetSupportedAudioCryptoSuites(std::vector<int>* crypto_suites) { |
| 156 std::vector<std::string>* crypto_suites) { | |
| 157 #ifdef HAVE_SRTP | 167 #ifdef HAVE_SRTP |
| 158 crypto_suites->push_back(rtc::CS_AES_CM_128_HMAC_SHA1_32); | 168 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_32); |
| 159 crypto_suites->push_back(rtc::CS_AES_CM_128_HMAC_SHA1_80); | 169 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); |
| 160 #endif | 170 #endif |
| 161 } | 171 } |
| 162 | 172 |
| 163 void GetSupportedVideoCryptoSuites( | 173 void GetSupportedAudioCryptoSuiteNames( |
| 164 std::vector<std::string>* crypto_suites) { | 174 std::vector<std::string>* crypto_suite_names) { |
| 165 GetDefaultSrtpCryptoSuiteNames(crypto_suites); | 175 GetSupportedCryptoSuiteNames(GetSupportedAudioCryptoSuites, |
| 176 crypto_suite_names); |
| 166 } | 177 } |
| 167 | 178 |
| 168 void GetSupportedDataCryptoSuites( | 179 void GetSupportedVideoCryptoSuites(std::vector<int>* crypto_suites) { |
| 169 std::vector<std::string>* crypto_suites) { | 180 GetDefaultSrtpCryptoSuites(crypto_suites); |
| 170 GetDefaultSrtpCryptoSuiteNames(crypto_suites); | |
| 171 } | 181 } |
| 172 | 182 |
| 173 void GetDefaultSrtpCryptoSuiteNames(std::vector<std::string>* crypto_suites) { | 183 void GetSupportedVideoCryptoSuiteNames( |
| 184 std::vector<std::string>* crypto_suite_names) { |
| 185 GetSupportedCryptoSuiteNames(GetSupportedVideoCryptoSuites, |
| 186 crypto_suite_names); |
| 187 } |
| 188 |
| 189 void GetSupportedDataCryptoSuites(std::vector<int>* crypto_suites) { |
| 190 GetDefaultSrtpCryptoSuites(crypto_suites); |
| 191 } |
| 192 |
| 193 void GetSupportedDataCryptoSuiteNames( |
| 194 std::vector<std::string>* crypto_suite_names) { |
| 195 GetSupportedCryptoSuiteNames(GetSupportedDataCryptoSuites, |
| 196 crypto_suite_names); |
| 197 } |
| 198 |
| 199 void GetDefaultSrtpCryptoSuites(std::vector<int>* crypto_suites) { |
| 174 #ifdef HAVE_SRTP | 200 #ifdef HAVE_SRTP |
| 175 crypto_suites->push_back(rtc::CS_AES_CM_128_HMAC_SHA1_80); | 201 crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); |
| 176 #endif | 202 #endif |
| 177 } | 203 } |
| 178 | 204 |
| 205 void GetDefaultSrtpCryptoSuiteNames( |
| 206 std::vector<std::string>* crypto_suite_names) { |
| 207 GetSupportedCryptoSuiteNames(GetDefaultSrtpCryptoSuites, crypto_suite_names); |
| 208 } |
| 209 |
| 179 // For video support only 80-bit SHA1 HMAC. For audio 32-bit HMAC is | 210 // For video support only 80-bit SHA1 HMAC. For audio 32-bit HMAC is |
| 180 // tolerated unless bundle is enabled because it is low overhead. Pick the | 211 // tolerated unless bundle is enabled because it is low overhead. Pick the |
| 181 // crypto in the list that is supported. | 212 // crypto in the list that is supported. |
| 182 static bool SelectCrypto(const MediaContentDescription* offer, | 213 static bool SelectCrypto(const MediaContentDescription* offer, |
| 183 bool bundle, | 214 bool bundle, |
| 184 CryptoParams *crypto) { | 215 CryptoParams *crypto) { |
| 185 bool audio = offer->type() == MEDIA_TYPE_AUDIO; | 216 bool audio = offer->type() == MEDIA_TYPE_AUDIO; |
| 186 const CryptoParamsVec& cryptos = offer->cryptos(); | 217 const CryptoParamsVec& cryptos = offer->cryptos(); |
| 187 | 218 |
| 188 for (CryptoParamsVec::const_iterator i = cryptos.begin(); | 219 for (CryptoParamsVec::const_iterator i = cryptos.begin(); |
| (...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1507 const RtpHeaderExtensions& audio_rtp_extensions, | 1538 const RtpHeaderExtensions& audio_rtp_extensions, |
| 1508 const AudioCodecs& audio_codecs, | 1539 const AudioCodecs& audio_codecs, |
| 1509 StreamParamsVec* current_streams, | 1540 StreamParamsVec* current_streams, |
| 1510 SessionDescription* desc) const { | 1541 SessionDescription* desc) const { |
| 1511 cricket::SecurePolicy sdes_policy = | 1542 cricket::SecurePolicy sdes_policy = |
| 1512 IsDtlsActive(CN_AUDIO, current_description) ? | 1543 IsDtlsActive(CN_AUDIO, current_description) ? |
| 1513 cricket::SEC_DISABLED : secure(); | 1544 cricket::SEC_DISABLED : secure(); |
| 1514 | 1545 |
| 1515 scoped_ptr<AudioContentDescription> audio(new AudioContentDescription()); | 1546 scoped_ptr<AudioContentDescription> audio(new AudioContentDescription()); |
| 1516 std::vector<std::string> crypto_suites; | 1547 std::vector<std::string> crypto_suites; |
| 1517 GetSupportedAudioCryptoSuites(&crypto_suites); | 1548 GetSupportedAudioCryptoSuiteNames(&crypto_suites); |
| 1518 if (!CreateMediaContentOffer( | 1549 if (!CreateMediaContentOffer( |
| 1519 options, | 1550 options, |
| 1520 audio_codecs, | 1551 audio_codecs, |
| 1521 sdes_policy, | 1552 sdes_policy, |
| 1522 GetCryptos(GetFirstAudioContentDescription(current_description)), | 1553 GetCryptos(GetFirstAudioContentDescription(current_description)), |
| 1523 crypto_suites, | 1554 crypto_suites, |
| 1524 audio_rtp_extensions, | 1555 audio_rtp_extensions, |
| 1525 add_legacy_, | 1556 add_legacy_, |
| 1526 current_streams, | 1557 current_streams, |
| 1527 audio.get())) { | 1558 audio.get())) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1561 const RtpHeaderExtensions& video_rtp_extensions, | 1592 const RtpHeaderExtensions& video_rtp_extensions, |
| 1562 const VideoCodecs& video_codecs, | 1593 const VideoCodecs& video_codecs, |
| 1563 StreamParamsVec* current_streams, | 1594 StreamParamsVec* current_streams, |
| 1564 SessionDescription* desc) const { | 1595 SessionDescription* desc) const { |
| 1565 cricket::SecurePolicy sdes_policy = | 1596 cricket::SecurePolicy sdes_policy = |
| 1566 IsDtlsActive(CN_VIDEO, current_description) ? | 1597 IsDtlsActive(CN_VIDEO, current_description) ? |
| 1567 cricket::SEC_DISABLED : secure(); | 1598 cricket::SEC_DISABLED : secure(); |
| 1568 | 1599 |
| 1569 scoped_ptr<VideoContentDescription> video(new VideoContentDescription()); | 1600 scoped_ptr<VideoContentDescription> video(new VideoContentDescription()); |
| 1570 std::vector<std::string> crypto_suites; | 1601 std::vector<std::string> crypto_suites; |
| 1571 GetSupportedVideoCryptoSuites(&crypto_suites); | 1602 GetSupportedVideoCryptoSuiteNames(&crypto_suites); |
| 1572 if (!CreateMediaContentOffer( | 1603 if (!CreateMediaContentOffer( |
| 1573 options, | 1604 options, |
| 1574 video_codecs, | 1605 video_codecs, |
| 1575 sdes_policy, | 1606 sdes_policy, |
| 1576 GetCryptos(GetFirstVideoContentDescription(current_description)), | 1607 GetCryptos(GetFirstVideoContentDescription(current_description)), |
| 1577 crypto_suites, | 1608 crypto_suites, |
| 1578 video_rtp_extensions, | 1609 video_rtp_extensions, |
| 1579 add_legacy_, | 1610 add_legacy_, |
| 1580 current_streams, | 1611 current_streams, |
| 1581 video.get())) { | 1612 video.get())) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1631 // SDES doesn't make sense for SCTP, so we disable it, and we only | 1662 // SDES doesn't make sense for SCTP, so we disable it, and we only |
| 1632 // get SDES crypto suites for RTP-based data channels. | 1663 // get SDES crypto suites for RTP-based data channels. |
| 1633 sdes_policy = cricket::SEC_DISABLED; | 1664 sdes_policy = cricket::SEC_DISABLED; |
| 1634 // Unlike SetMediaProtocol below, we need to set the protocol | 1665 // Unlike SetMediaProtocol below, we need to set the protocol |
| 1635 // before we call CreateMediaContentOffer. Otherwise, | 1666 // before we call CreateMediaContentOffer. Otherwise, |
| 1636 // CreateMediaContentOffer won't know this is SCTP and will | 1667 // CreateMediaContentOffer won't know this is SCTP and will |
| 1637 // generate SSRCs rather than SIDs. | 1668 // generate SSRCs rather than SIDs. |
| 1638 data->set_protocol( | 1669 data->set_protocol( |
| 1639 secure_transport ? kMediaProtocolDtlsSctp : kMediaProtocolSctp); | 1670 secure_transport ? kMediaProtocolDtlsSctp : kMediaProtocolSctp); |
| 1640 } else { | 1671 } else { |
| 1641 GetSupportedDataCryptoSuites(&crypto_suites); | 1672 GetSupportedDataCryptoSuiteNames(&crypto_suites); |
| 1642 } | 1673 } |
| 1643 | 1674 |
| 1644 if (!CreateMediaContentOffer( | 1675 if (!CreateMediaContentOffer( |
| 1645 options, | 1676 options, |
| 1646 *data_codecs, | 1677 *data_codecs, |
| 1647 sdes_policy, | 1678 sdes_policy, |
| 1648 GetCryptos(GetFirstDataContentDescription(current_description)), | 1679 GetCryptos(GetFirstDataContentDescription(current_description)), |
| 1649 crypto_suites, | 1680 crypto_suites, |
| 1650 RtpHeaderExtensions(), | 1681 RtpHeaderExtensions(), |
| 1651 add_legacy_, | 1682 add_legacy_, |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1924 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); | 1955 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
| 1925 } | 1956 } |
| 1926 | 1957 |
| 1927 const DataContentDescription* GetFirstDataContentDescription( | 1958 const DataContentDescription* GetFirstDataContentDescription( |
| 1928 const SessionDescription* sdesc) { | 1959 const SessionDescription* sdesc) { |
| 1929 return static_cast<const DataContentDescription*>( | 1960 return static_cast<const DataContentDescription*>( |
| 1930 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 1961 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
| 1931 } | 1962 } |
| 1932 | 1963 |
| 1933 } // namespace cricket | 1964 } // namespace cricket |
| OLD | NEW |