zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "pc/srtptransport.h" |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 12 | |
| 13 | #include <string> |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 14 | #include <vector> |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "media/base/rtputils.h" |
| 17 | #include "pc/rtptransport.h" |
| 18 | #include "pc/srtpsession.h" |
| 19 | #include "rtc_base/asyncpacketsocket.h" |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 20 | #include "rtc_base/base64.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "rtc_base/copyonwritebuffer.h" |
| 22 | #include "rtc_base/ptr_util.h" |
| 23 | #include "rtc_base/trace_event.h" |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 27 | SrtpTransport::SrtpTransport(bool rtcp_mux_enabled) |
| 28 | : RtpTransportInternalAdapter(new RtpTransport(rtcp_mux_enabled)) { |
Zhi Huang | f2d7beb | 2017-11-20 14:35:11 -0800 | [diff] [blame] | 29 | // Own the raw pointer |transport| from the base class. |
| 30 | rtp_transport_.reset(transport_); |
| 31 | RTC_DCHECK(rtp_transport_); |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 32 | ConnectToRtpTransport(); |
| 33 | } |
| 34 | |
Zhi Huang | f2d7beb | 2017-11-20 14:35:11 -0800 | [diff] [blame] | 35 | SrtpTransport::SrtpTransport( |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 36 | std::unique_ptr<RtpTransportInternal> rtp_transport) |
Zhi Huang | f2d7beb | 2017-11-20 14:35:11 -0800 | [diff] [blame] | 37 | : RtpTransportInternalAdapter(rtp_transport.get()), |
Zhi Huang | f2d7beb | 2017-11-20 14:35:11 -0800 | [diff] [blame] | 38 | rtp_transport_(std::move(rtp_transport)) { |
| 39 | RTC_DCHECK(rtp_transport_); |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 40 | ConnectToRtpTransport(); |
| 41 | } |
| 42 | |
| 43 | void SrtpTransport::ConnectToRtpTransport() { |
| 44 | rtp_transport_->SignalPacketReceived.connect( |
| 45 | this, &SrtpTransport::OnPacketReceived); |
| 46 | rtp_transport_->SignalReadyToSend.connect(this, |
| 47 | &SrtpTransport::OnReadyToSend); |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 48 | rtp_transport_->SignalNetworkRouteChanged.connect( |
| 49 | this, &SrtpTransport::OnNetworkRouteChanged); |
Zhi Huang | cd3fc5d | 2017-11-29 10:41:57 -0800 | [diff] [blame] | 50 | rtp_transport_->SignalWritableState.connect(this, |
| 51 | &SrtpTransport::OnWritableState); |
| 52 | rtp_transport_->SignalSentPacket.connect(this, &SrtpTransport::OnSentPacket); |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 55 | bool SrtpTransport::SendRtpPacket(rtc::CopyOnWriteBuffer* packet, |
| 56 | const rtc::PacketOptions& options, |
| 57 | int flags) { |
| 58 | return SendPacket(false, packet, options, flags); |
| 59 | } |
| 60 | |
| 61 | bool SrtpTransport::SendRtcpPacket(rtc::CopyOnWriteBuffer* packet, |
| 62 | const rtc::PacketOptions& options, |
| 63 | int flags) { |
| 64 | return SendPacket(true, packet, options, flags); |
| 65 | } |
| 66 | |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 67 | bool SrtpTransport::SendPacket(bool rtcp, |
| 68 | rtc::CopyOnWriteBuffer* packet, |
| 69 | const rtc::PacketOptions& options, |
| 70 | int flags) { |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 71 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 72 | RTC_LOG(LS_ERROR) |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 73 | << "Failed to send the packet because SRTP transport is inactive."; |
| 74 | return false; |
| 75 | } |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 76 | |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 77 | rtc::PacketOptions updated_options = options; |
| 78 | rtc::CopyOnWriteBuffer cp = *packet; |
| 79 | TRACE_EVENT0("webrtc", "SRTP Encode"); |
| 80 | bool res; |
| 81 | uint8_t* data = packet->data(); |
| 82 | int len = static_cast<int>(packet->size()); |
| 83 | if (!rtcp) { |
| 84 | // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done |
| 85 | // inside libsrtp for a RTP packet. A external HMAC module will be writing |
| 86 | // a fake HMAC value. This is ONLY done for a RTP packet. |
| 87 | // Socket layer will update rtp sendtime extension header if present in |
| 88 | // packet with current time before updating the HMAC. |
| 89 | #if !defined(ENABLE_EXTERNAL_AUTH) |
| 90 | res = ProtectRtp(data, len, static_cast<int>(packet->capacity()), &len); |
| 91 | #else |
| 92 | if (!IsExternalAuthActive()) { |
| 93 | res = ProtectRtp(data, len, static_cast<int>(packet->capacity()), &len); |
| 94 | } else { |
| 95 | updated_options.packet_time_params.rtp_sendtime_extension_id = |
| 96 | rtp_abs_sendtime_extn_id_; |
| 97 | res = ProtectRtp(data, len, static_cast<int>(packet->capacity()), &len, |
| 98 | &updated_options.packet_time_params.srtp_packet_index); |
| 99 | // If protection succeeds, let's get auth params from srtp. |
| 100 | if (res) { |
| 101 | uint8_t* auth_key = NULL; |
| 102 | int key_len; |
| 103 | res = GetRtpAuthParams( |
| 104 | &auth_key, &key_len, |
| 105 | &updated_options.packet_time_params.srtp_auth_tag_len); |
| 106 | if (res) { |
| 107 | updated_options.packet_time_params.srtp_auth_key.resize(key_len); |
| 108 | updated_options.packet_time_params.srtp_auth_key.assign( |
| 109 | auth_key, auth_key + key_len); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | #endif |
| 114 | if (!res) { |
| 115 | int seq_num = -1; |
| 116 | uint32_t ssrc = 0; |
| 117 | cricket::GetRtpSeqNum(data, len, &seq_num); |
| 118 | cricket::GetRtpSsrc(data, len, &ssrc); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 119 | RTC_LOG(LS_ERROR) << "Failed to protect RTP packet: size=" << len |
| 120 | << ", seqnum=" << seq_num << ", SSRC=" << ssrc; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 121 | return false; |
| 122 | } |
| 123 | } else { |
| 124 | res = ProtectRtcp(data, len, static_cast<int>(packet->capacity()), &len); |
| 125 | if (!res) { |
| 126 | int type = -1; |
| 127 | cricket::GetRtcpType(data, len, &type); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 128 | RTC_LOG(LS_ERROR) << "Failed to protect RTCP packet: size=" << len |
| 129 | << ", type=" << type; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 130 | return false; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // Update the length of the packet now that we've added the auth tag. |
| 135 | packet->SetSize(len); |
| 136 | return rtcp ? rtp_transport_->SendRtcpPacket(packet, updated_options, flags) |
| 137 | : rtp_transport_->SendRtpPacket(packet, updated_options, flags); |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void SrtpTransport::OnPacketReceived(bool rtcp, |
| 141 | rtc::CopyOnWriteBuffer* packet, |
| 142 | const rtc::PacketTime& packet_time) { |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 143 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 144 | RTC_LOG(LS_WARNING) |
| 145 | << "Inactive SRTP transport received a packet. Drop it."; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 146 | return; |
| 147 | } |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 148 | |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 149 | TRACE_EVENT0("webrtc", "SRTP Decode"); |
| 150 | char* data = packet->data<char>(); |
| 151 | int len = static_cast<int>(packet->size()); |
| 152 | bool res; |
| 153 | if (!rtcp) { |
| 154 | res = UnprotectRtp(data, len, &len); |
| 155 | if (!res) { |
| 156 | int seq_num = -1; |
| 157 | uint32_t ssrc = 0; |
| 158 | cricket::GetRtpSeqNum(data, len, &seq_num); |
| 159 | cricket::GetRtpSsrc(data, len, &ssrc); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 160 | RTC_LOG(LS_ERROR) << "Failed to unprotect RTP packet: size=" << len |
| 161 | << ", seqnum=" << seq_num << ", SSRC=" << ssrc; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 162 | return; |
| 163 | } |
| 164 | } else { |
| 165 | res = UnprotectRtcp(data, len, &len); |
| 166 | if (!res) { |
| 167 | int type = -1; |
| 168 | cricket::GetRtcpType(data, len, &type); |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 169 | RTC_LOG(LS_ERROR) << "Failed to unprotect RTCP packet: size=" << len |
| 170 | << ", type=" << type; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 171 | return; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | packet->SetSize(len); |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 176 | SignalPacketReceived(rtcp, packet, packet_time); |
| 177 | } |
| 178 | |
Zhi Huang | 942bc2e | 2017-11-13 13:26:07 -0800 | [diff] [blame] | 179 | void SrtpTransport::OnNetworkRouteChanged( |
| 180 | |
| 181 | rtc::Optional<rtc::NetworkRoute> network_route) { |
| 182 | // Only append the SRTP overhead when there is a selected network route. |
| 183 | if (network_route) { |
| 184 | int srtp_overhead = 0; |
| 185 | if (IsActive()) { |
| 186 | GetSrtpOverhead(&srtp_overhead); |
| 187 | } |
| 188 | network_route->packet_overhead += srtp_overhead; |
| 189 | } |
| 190 | SignalNetworkRouteChanged(network_route); |
| 191 | } |
| 192 | |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 193 | bool SrtpTransport::SetRtpParams(int send_cs, |
| 194 | const uint8_t* send_key, |
| 195 | int send_key_len, |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 196 | const std::vector<int>& send_extension_ids, |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 197 | int recv_cs, |
| 198 | const uint8_t* recv_key, |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 199 | int recv_key_len, |
| 200 | const std::vector<int>& recv_extension_ids) { |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 201 | // If parameters are being set for the first time, we should create new SRTP |
| 202 | // sessions and call "SetSend/SetRecv". Otherwise we should call |
| 203 | // "UpdateSend"/"UpdateRecv" on the existing sessions, which will internally |
| 204 | // call "srtp_update". |
| 205 | bool new_sessions = false; |
| 206 | if (!send_session_) { |
| 207 | RTC_DCHECK(!recv_session_); |
| 208 | CreateSrtpSessions(); |
| 209 | new_sessions = true; |
| 210 | } |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 211 | bool ret = new_sessions |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 212 | ? send_session_->SetSend(send_cs, send_key, send_key_len, |
| 213 | send_extension_ids) |
| 214 | : send_session_->UpdateSend(send_cs, send_key, send_key_len, |
| 215 | send_extension_ids); |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 216 | if (!ret) { |
| 217 | ResetParams(); |
| 218 | return false; |
| 219 | } |
| 220 | |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 221 | ret = new_sessions ? recv_session_->SetRecv(recv_cs, recv_key, recv_key_len, |
| 222 | recv_extension_ids) |
| 223 | : recv_session_->UpdateRecv( |
| 224 | recv_cs, recv_key, recv_key_len, recv_extension_ids); |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 225 | if (!ret) { |
| 226 | ResetParams(); |
| 227 | return false; |
| 228 | } |
| 229 | |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 230 | RTC_LOG(LS_INFO) << "SRTP " << (new_sessions ? "activated" : "updated") |
Jonas Olsson | 45cc890 | 2018-02-13 10:37:07 +0100 | [diff] [blame] | 231 | << " with negotiated parameters: send cipher_suite " |
| 232 | << send_cs << " recv cipher_suite " << recv_cs; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 233 | return true; |
| 234 | } |
| 235 | |
| 236 | bool SrtpTransport::SetRtcpParams(int send_cs, |
| 237 | const uint8_t* send_key, |
| 238 | int send_key_len, |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 239 | const std::vector<int>& send_extension_ids, |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 240 | int recv_cs, |
| 241 | const uint8_t* recv_key, |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 242 | int recv_key_len, |
| 243 | const std::vector<int>& recv_extension_ids) { |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 244 | // This can only be called once, but can be safely called after |
| 245 | // SetRtpParams |
| 246 | if (send_rtcp_session_ || recv_rtcp_session_) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 247 | RTC_LOG(LS_ERROR) << "Tried to set SRTCP Params when filter already active"; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 248 | return false; |
| 249 | } |
| 250 | |
| 251 | send_rtcp_session_.reset(new cricket::SrtpSession()); |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 252 | if (!send_rtcp_session_->SetSend(send_cs, send_key, send_key_len, |
| 253 | send_extension_ids)) { |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 254 | return false; |
| 255 | } |
| 256 | |
| 257 | recv_rtcp_session_.reset(new cricket::SrtpSession()); |
Zhi Huang | c99b6c7 | 2017-11-10 16:44:46 -0800 | [diff] [blame] | 258 | if (!recv_rtcp_session_->SetRecv(recv_cs, recv_key, recv_key_len, |
| 259 | recv_extension_ids)) { |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 260 | return false; |
| 261 | } |
| 262 | |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 263 | RTC_LOG(LS_INFO) << "SRTCP activated with negotiated parameters:" |
Jonas Olsson | 45cc890 | 2018-02-13 10:37:07 +0100 | [diff] [blame] | 264 | " send cipher_suite " |
| 265 | << send_cs << " recv cipher_suite " << recv_cs; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 266 | |
| 267 | return true; |
| 268 | } |
| 269 | |
| 270 | bool SrtpTransport::IsActive() const { |
| 271 | return send_session_ && recv_session_; |
| 272 | } |
| 273 | |
| 274 | void SrtpTransport::ResetParams() { |
| 275 | send_session_ = nullptr; |
| 276 | recv_session_ = nullptr; |
| 277 | send_rtcp_session_ = nullptr; |
| 278 | recv_rtcp_session_ = nullptr; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 279 | RTC_LOG(LS_INFO) << "The params in SRTP transport are reset."; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 282 | void SrtpTransport::CreateSrtpSessions() { |
| 283 | send_session_.reset(new cricket::SrtpSession()); |
| 284 | recv_session_.reset(new cricket::SrtpSession()); |
| 285 | |
| 286 | if (external_auth_enabled_) { |
| 287 | send_session_->EnableExternalAuth(); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | bool SrtpTransport::ProtectRtp(void* p, int in_len, int max_len, int* out_len) { |
| 292 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 293 | RTC_LOG(LS_WARNING) << "Failed to ProtectRtp: SRTP not active"; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 294 | return false; |
| 295 | } |
| 296 | RTC_CHECK(send_session_); |
| 297 | return send_session_->ProtectRtp(p, in_len, max_len, out_len); |
| 298 | } |
| 299 | |
| 300 | bool SrtpTransport::ProtectRtp(void* p, |
| 301 | int in_len, |
| 302 | int max_len, |
| 303 | int* out_len, |
| 304 | int64_t* index) { |
| 305 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 306 | RTC_LOG(LS_WARNING) << "Failed to ProtectRtp: SRTP not active"; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 307 | return false; |
| 308 | } |
| 309 | RTC_CHECK(send_session_); |
| 310 | return send_session_->ProtectRtp(p, in_len, max_len, out_len, index); |
| 311 | } |
| 312 | |
| 313 | bool SrtpTransport::ProtectRtcp(void* p, |
| 314 | int in_len, |
| 315 | int max_len, |
| 316 | int* out_len) { |
| 317 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 318 | RTC_LOG(LS_WARNING) << "Failed to ProtectRtcp: SRTP not active"; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 319 | return false; |
| 320 | } |
| 321 | if (send_rtcp_session_) { |
| 322 | return send_rtcp_session_->ProtectRtcp(p, in_len, max_len, out_len); |
| 323 | } else { |
| 324 | RTC_CHECK(send_session_); |
| 325 | return send_session_->ProtectRtcp(p, in_len, max_len, out_len); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | bool SrtpTransport::UnprotectRtp(void* p, int in_len, int* out_len) { |
| 330 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 331 | RTC_LOG(LS_WARNING) << "Failed to UnprotectRtp: SRTP not active"; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 332 | return false; |
| 333 | } |
| 334 | RTC_CHECK(recv_session_); |
| 335 | return recv_session_->UnprotectRtp(p, in_len, out_len); |
| 336 | } |
| 337 | |
| 338 | bool SrtpTransport::UnprotectRtcp(void* p, int in_len, int* out_len) { |
| 339 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 340 | RTC_LOG(LS_WARNING) << "Failed to UnprotectRtcp: SRTP not active"; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 341 | return false; |
| 342 | } |
| 343 | if (recv_rtcp_session_) { |
| 344 | return recv_rtcp_session_->UnprotectRtcp(p, in_len, out_len); |
| 345 | } else { |
| 346 | RTC_CHECK(recv_session_); |
| 347 | return recv_session_->UnprotectRtcp(p, in_len, out_len); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | bool SrtpTransport::GetRtpAuthParams(uint8_t** key, |
| 352 | int* key_len, |
| 353 | int* tag_len) { |
| 354 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 355 | RTC_LOG(LS_WARNING) << "Failed to GetRtpAuthParams: SRTP not active"; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 356 | return false; |
| 357 | } |
| 358 | |
| 359 | RTC_CHECK(send_session_); |
| 360 | return send_session_->GetRtpAuthParams(key, key_len, tag_len); |
| 361 | } |
| 362 | |
| 363 | bool SrtpTransport::GetSrtpOverhead(int* srtp_overhead) const { |
| 364 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 365 | RTC_LOG(LS_WARNING) << "Failed to GetSrtpOverhead: SRTP not active"; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 366 | return false; |
| 367 | } |
| 368 | |
| 369 | RTC_CHECK(send_session_); |
| 370 | *srtp_overhead = send_session_->GetSrtpOverhead(); |
| 371 | return true; |
| 372 | } |
| 373 | |
| 374 | void SrtpTransport::EnableExternalAuth() { |
| 375 | RTC_DCHECK(!IsActive()); |
| 376 | external_auth_enabled_ = true; |
| 377 | } |
| 378 | |
| 379 | bool SrtpTransport::IsExternalAuthEnabled() const { |
| 380 | return external_auth_enabled_; |
| 381 | } |
| 382 | |
| 383 | bool SrtpTransport::IsExternalAuthActive() const { |
| 384 | if (!IsActive()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 385 | RTC_LOG(LS_WARNING) |
| 386 | << "Failed to check IsExternalAuthActive: SRTP not active"; |
Zhi Huang | cf990f5 | 2017-09-22 12:12:30 -0700 | [diff] [blame] | 387 | return false; |
| 388 | } |
| 389 | |
| 390 | RTC_CHECK(send_session_); |
| 391 | return send_session_->IsExternalAuthActive(); |
| 392 | } |
| 393 | |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 394 | } // namespace webrtc |