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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 return DoSetAnswer(answer_params, source, true); | 142 return DoSetAnswer(answer_params, source, true); |
143 } | 143 } |
144 | 144 |
145 bool SrtpFilter::SetProvisionalAnswer( | 145 bool SrtpFilter::SetProvisionalAnswer( |
146 const std::vector<CryptoParams>& answer_params, | 146 const std::vector<CryptoParams>& answer_params, |
147 ContentSource source) { | 147 ContentSource source) { |
148 return DoSetAnswer(answer_params, source, false); | 148 return DoSetAnswer(answer_params, source, false); |
149 } | 149 } |
150 | 150 |
151 bool SrtpFilter::SetRtpParams(const std::string& send_cs, | 151 bool SrtpFilter::SetRtpParams(const std::string& send_cs, |
152 const uint8* send_key, int send_key_len, | 152 const uint8_t* send_key, |
| 153 int send_key_len, |
153 const std::string& recv_cs, | 154 const std::string& recv_cs, |
154 const uint8* recv_key, int recv_key_len) { | 155 const uint8_t* recv_key, |
| 156 int recv_key_len) { |
155 if (IsActive()) { | 157 if (IsActive()) { |
156 LOG(LS_ERROR) << "Tried to set SRTP Params when filter already active"; | 158 LOG(LS_ERROR) << "Tried to set SRTP Params when filter already active"; |
157 return false; | 159 return false; |
158 } | 160 } |
159 CreateSrtpSessions(); | 161 CreateSrtpSessions(); |
160 if (!send_session_->SetSend(send_cs, send_key, send_key_len)) | 162 if (!send_session_->SetSend(send_cs, send_key, send_key_len)) |
161 return false; | 163 return false; |
162 | 164 |
163 if (!recv_session_->SetRecv(recv_cs, recv_key, recv_key_len)) | 165 if (!recv_session_->SetRecv(recv_cs, recv_key, recv_key_len)) |
164 return false; | 166 return false; |
165 | 167 |
166 state_ = ST_ACTIVE; | 168 state_ = ST_ACTIVE; |
167 | 169 |
168 LOG(LS_INFO) << "SRTP activated with negotiated parameters:" | 170 LOG(LS_INFO) << "SRTP activated with negotiated parameters:" |
169 << " send cipher_suite " << send_cs | 171 << " send cipher_suite " << send_cs |
170 << " recv cipher_suite " << recv_cs; | 172 << " recv cipher_suite " << recv_cs; |
171 return true; | 173 return true; |
172 } | 174 } |
173 | 175 |
174 // This function is provided separately because DTLS-SRTP behaves | 176 // This function is provided separately because DTLS-SRTP behaves |
175 // differently in RTP/RTCP mux and non-mux modes. | 177 // differently in RTP/RTCP mux and non-mux modes. |
176 // | 178 // |
177 // - In the non-muxed case, RTP and RTCP are keyed with different | 179 // - In the non-muxed case, RTP and RTCP are keyed with different |
178 // keys (from different DTLS handshakes), and so we need a new | 180 // keys (from different DTLS handshakes), and so we need a new |
179 // SrtpSession. | 181 // SrtpSession. |
180 // - In the muxed case, they are keyed with the same keys, so | 182 // - In the muxed case, they are keyed with the same keys, so |
181 // this function is not needed | 183 // this function is not needed |
182 bool SrtpFilter::SetRtcpParams(const std::string& send_cs, | 184 bool SrtpFilter::SetRtcpParams(const std::string& send_cs, |
183 const uint8* send_key, int send_key_len, | 185 const uint8_t* send_key, |
| 186 int send_key_len, |
184 const std::string& recv_cs, | 187 const std::string& recv_cs, |
185 const uint8* recv_key, int recv_key_len) { | 188 const uint8_t* recv_key, |
| 189 int recv_key_len) { |
186 // This can only be called once, but can be safely called after | 190 // This can only be called once, but can be safely called after |
187 // SetRtpParams | 191 // SetRtpParams |
188 if (send_rtcp_session_ || recv_rtcp_session_) { | 192 if (send_rtcp_session_ || recv_rtcp_session_) { |
189 LOG(LS_ERROR) << "Tried to set SRTCP Params when filter already active"; | 193 LOG(LS_ERROR) << "Tried to set SRTCP Params when filter already active"; |
190 return false; | 194 return false; |
191 } | 195 } |
192 | 196 |
193 send_rtcp_session_.reset(new SrtpSession()); | 197 send_rtcp_session_.reset(new SrtpSession()); |
194 SignalSrtpError.repeat(send_rtcp_session_->SignalSrtpError); | 198 SignalSrtpError.repeat(send_rtcp_session_->SignalSrtpError); |
195 send_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms_); | 199 send_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms_); |
(...skipping 15 matching lines...) Expand all Loading... |
211 | 215 |
212 bool SrtpFilter::ProtectRtp(void* p, int in_len, int max_len, int* out_len) { | 216 bool SrtpFilter::ProtectRtp(void* p, int in_len, int max_len, int* out_len) { |
213 if (!IsActive()) { | 217 if (!IsActive()) { |
214 LOG(LS_WARNING) << "Failed to ProtectRtp: SRTP not active"; | 218 LOG(LS_WARNING) << "Failed to ProtectRtp: SRTP not active"; |
215 return false; | 219 return false; |
216 } | 220 } |
217 ASSERT(send_session_ != NULL); | 221 ASSERT(send_session_ != NULL); |
218 return send_session_->ProtectRtp(p, in_len, max_len, out_len); | 222 return send_session_->ProtectRtp(p, in_len, max_len, out_len); |
219 } | 223 } |
220 | 224 |
221 bool SrtpFilter::ProtectRtp(void* p, int in_len, int max_len, int* out_len, | 225 bool SrtpFilter::ProtectRtp(void* p, |
222 int64* index) { | 226 int in_len, |
| 227 int max_len, |
| 228 int* out_len, |
| 229 int64_t* index) { |
223 if (!IsActive()) { | 230 if (!IsActive()) { |
224 LOG(LS_WARNING) << "Failed to ProtectRtp: SRTP not active"; | 231 LOG(LS_WARNING) << "Failed to ProtectRtp: SRTP not active"; |
225 return false; | 232 return false; |
226 } | 233 } |
227 ASSERT(send_session_ != NULL); | 234 ASSERT(send_session_ != NULL); |
228 return send_session_->ProtectRtp(p, in_len, max_len, out_len, index); | 235 return send_session_->ProtectRtp(p, in_len, max_len, out_len, index); |
229 } | 236 } |
230 | 237 |
231 bool SrtpFilter::ProtectRtcp(void* p, int in_len, int max_len, int* out_len) { | 238 bool SrtpFilter::ProtectRtcp(void* p, int in_len, int max_len, int* out_len) { |
232 if (!IsActive()) { | 239 if (!IsActive()) { |
(...skipping 23 matching lines...) Expand all Loading... |
256 return false; | 263 return false; |
257 } | 264 } |
258 if (recv_rtcp_session_) { | 265 if (recv_rtcp_session_) { |
259 return recv_rtcp_session_->UnprotectRtcp(p, in_len, out_len); | 266 return recv_rtcp_session_->UnprotectRtcp(p, in_len, out_len); |
260 } else { | 267 } else { |
261 ASSERT(recv_session_ != NULL); | 268 ASSERT(recv_session_ != NULL); |
262 return recv_session_->UnprotectRtcp(p, in_len, out_len); | 269 return recv_session_->UnprotectRtcp(p, in_len, out_len); |
263 } | 270 } |
264 } | 271 } |
265 | 272 |
266 bool SrtpFilter::GetRtpAuthParams(uint8** key, int* key_len, int* tag_len) { | 273 bool SrtpFilter::GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len) { |
267 if (!IsActive()) { | 274 if (!IsActive()) { |
268 LOG(LS_WARNING) << "Failed to GetRtpAuthParams: SRTP not active"; | 275 LOG(LS_WARNING) << "Failed to GetRtpAuthParams: SRTP not active"; |
269 return false; | 276 return false; |
270 } | 277 } |
271 | 278 |
272 ASSERT(send_session_ != NULL); | 279 ASSERT(send_session_ != NULL); |
273 return send_session_->GetRtpAuthParams(key, key_len, tag_len); | 280 return send_session_->GetRtpAuthParams(key, key_len, tag_len); |
274 } | 281 } |
275 | 282 |
276 void SrtpFilter::set_signal_silent_time(uint32 signal_silent_time_in_ms) { | 283 void SrtpFilter::set_signal_silent_time(uint32_t signal_silent_time_in_ms) { |
277 signal_silent_time_in_ms_ = signal_silent_time_in_ms; | 284 signal_silent_time_in_ms_ = signal_silent_time_in_ms; |
278 if (IsActive()) { | 285 if (IsActive()) { |
279 ASSERT(send_session_ != NULL); | 286 ASSERT(send_session_ != NULL); |
280 send_session_->set_signal_silent_time(signal_silent_time_in_ms); | 287 send_session_->set_signal_silent_time(signal_silent_time_in_ms); |
281 ASSERT(recv_session_ != NULL); | 288 ASSERT(recv_session_ != NULL); |
282 recv_session_->set_signal_silent_time(signal_silent_time_in_ms); | 289 recv_session_->set_signal_silent_time(signal_silent_time_in_ms); |
283 if (send_rtcp_session_) | 290 if (send_rtcp_session_) |
284 send_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms); | 291 send_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms); |
285 if (recv_rtcp_session_) | 292 if (recv_rtcp_session_) |
286 recv_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms); | 293 recv_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 applied_send_params_.key_params == send_params.key_params && | 418 applied_send_params_.key_params == send_params.key_params && |
412 applied_recv_params_.cipher_suite == recv_params.cipher_suite && | 419 applied_recv_params_.cipher_suite == recv_params.cipher_suite && |
413 applied_recv_params_.key_params == recv_params.key_params) { | 420 applied_recv_params_.key_params == recv_params.key_params) { |
414 LOG(LS_INFO) << "Applying the same SRTP parameters again. No-op."; | 421 LOG(LS_INFO) << "Applying the same SRTP parameters again. No-op."; |
415 | 422 |
416 // We do not want to reset the ROC if the keys are the same. So just return. | 423 // We do not want to reset the ROC if the keys are the same. So just return. |
417 return true; | 424 return true; |
418 } | 425 } |
419 // TODO(juberti): Zero these buffers after use. | 426 // TODO(juberti): Zero these buffers after use. |
420 bool ret; | 427 bool ret; |
421 uint8 send_key[SRTP_MASTER_KEY_LEN], recv_key[SRTP_MASTER_KEY_LEN]; | 428 uint8_t send_key[SRTP_MASTER_KEY_LEN], recv_key[SRTP_MASTER_KEY_LEN]; |
422 ret = (ParseKeyParams(send_params.key_params, send_key, sizeof(send_key)) && | 429 ret = (ParseKeyParams(send_params.key_params, send_key, sizeof(send_key)) && |
423 ParseKeyParams(recv_params.key_params, recv_key, sizeof(recv_key))); | 430 ParseKeyParams(recv_params.key_params, recv_key, sizeof(recv_key))); |
424 if (ret) { | 431 if (ret) { |
425 CreateSrtpSessions(); | 432 CreateSrtpSessions(); |
426 ret = (send_session_->SetSend(send_params.cipher_suite, | 433 ret = (send_session_->SetSend(send_params.cipher_suite, |
427 send_key, sizeof(send_key)) && | 434 send_key, sizeof(send_key)) && |
428 recv_session_->SetRecv(recv_params.cipher_suite, | 435 recv_session_->SetRecv(recv_params.cipher_suite, |
429 recv_key, sizeof(recv_key))); | 436 recv_key, sizeof(recv_key))); |
430 } | 437 } |
431 if (ret) { | 438 if (ret) { |
432 LOG(LS_INFO) << "SRTP activated with negotiated parameters:" | 439 LOG(LS_INFO) << "SRTP activated with negotiated parameters:" |
433 << " send cipher_suite " << send_params.cipher_suite | 440 << " send cipher_suite " << send_params.cipher_suite |
434 << " recv cipher_suite " << recv_params.cipher_suite; | 441 << " recv cipher_suite " << recv_params.cipher_suite; |
435 applied_send_params_ = send_params; | 442 applied_send_params_ = send_params; |
436 applied_recv_params_ = recv_params; | 443 applied_recv_params_ = recv_params; |
437 } else { | 444 } else { |
438 LOG(LS_WARNING) << "Failed to apply negotiated SRTP parameters"; | 445 LOG(LS_WARNING) << "Failed to apply negotiated SRTP parameters"; |
439 } | 446 } |
440 return ret; | 447 return ret; |
441 } | 448 } |
442 | 449 |
443 bool SrtpFilter::ResetParams() { | 450 bool SrtpFilter::ResetParams() { |
444 offer_params_.clear(); | 451 offer_params_.clear(); |
445 state_ = ST_INIT; | 452 state_ = ST_INIT; |
446 LOG(LS_INFO) << "SRTP reset to init state"; | 453 LOG(LS_INFO) << "SRTP reset to init state"; |
447 return true; | 454 return true; |
448 } | 455 } |
449 | 456 |
450 bool SrtpFilter::ParseKeyParams(const std::string& key_params, | 457 bool SrtpFilter::ParseKeyParams(const std::string& key_params, |
451 uint8* key, int len) { | 458 uint8_t* key, |
| 459 int len) { |
452 // example key_params: "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2" | 460 // example key_params: "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2" |
453 | 461 |
454 // Fail if key-method is wrong. | 462 // Fail if key-method is wrong. |
455 if (key_params.find("inline:") != 0) { | 463 if (key_params.find("inline:") != 0) { |
456 return false; | 464 return false; |
457 } | 465 } |
458 | 466 |
459 // Fail if base64 decode fails, or the key is the wrong size. | 467 // Fail if base64 decode fails, or the key is the wrong size. |
460 std::string key_b64(key_params.substr(7)), key_str; | 468 std::string key_b64(key_params.substr(7)), key_str; |
461 if (!rtc::Base64::Decode(key_b64, rtc::Base64::DO_STRICT, | 469 if (!rtc::Base64::Decode(key_b64, rtc::Base64::DO_STRICT, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 SrtpSession::~SrtpSession() { | 502 SrtpSession::~SrtpSession() { |
495 { | 503 { |
496 rtc::GlobalLockScope ls(&lock_); | 504 rtc::GlobalLockScope ls(&lock_); |
497 sessions()->erase(std::find(sessions()->begin(), sessions()->end(), this)); | 505 sessions()->erase(std::find(sessions()->begin(), sessions()->end(), this)); |
498 } | 506 } |
499 if (session_) { | 507 if (session_) { |
500 srtp_dealloc(session_); | 508 srtp_dealloc(session_); |
501 } | 509 } |
502 } | 510 } |
503 | 511 |
504 bool SrtpSession::SetSend(const std::string& cs, const uint8* key, int len) { | 512 bool SrtpSession::SetSend(const std::string& cs, const uint8_t* key, int len) { |
505 return SetKey(ssrc_any_outbound, cs, key, len); | 513 return SetKey(ssrc_any_outbound, cs, key, len); |
506 } | 514 } |
507 | 515 |
508 bool SrtpSession::SetRecv(const std::string& cs, const uint8* key, int len) { | 516 bool SrtpSession::SetRecv(const std::string& cs, const uint8_t* key, int len) { |
509 return SetKey(ssrc_any_inbound, cs, key, len); | 517 return SetKey(ssrc_any_inbound, cs, key, len); |
510 } | 518 } |
511 | 519 |
512 bool SrtpSession::ProtectRtp(void* p, int in_len, int max_len, int* out_len) { | 520 bool SrtpSession::ProtectRtp(void* p, int in_len, int max_len, int* out_len) { |
513 if (!session_) { | 521 if (!session_) { |
514 LOG(LS_WARNING) << "Failed to protect SRTP packet: no SRTP Session"; | 522 LOG(LS_WARNING) << "Failed to protect SRTP packet: no SRTP Session"; |
515 return false; | 523 return false; |
516 } | 524 } |
517 | 525 |
518 int need_len = in_len + rtp_auth_tag_len_; // NOLINT | 526 int need_len = in_len + rtp_auth_tag_len_; // NOLINT |
519 if (max_len < need_len) { | 527 if (max_len < need_len) { |
520 LOG(LS_WARNING) << "Failed to protect SRTP packet: The buffer length " | 528 LOG(LS_WARNING) << "Failed to protect SRTP packet: The buffer length " |
521 << max_len << " is less than the needed " << need_len; | 529 << max_len << " is less than the needed " << need_len; |
522 return false; | 530 return false; |
523 } | 531 } |
524 | 532 |
525 *out_len = in_len; | 533 *out_len = in_len; |
526 int err = srtp_protect(session_, p, out_len); | 534 int err = srtp_protect(session_, p, out_len); |
527 uint32 ssrc; | 535 uint32_t ssrc; |
528 if (GetRtpSsrc(p, in_len, &ssrc)) { | 536 if (GetRtpSsrc(p, in_len, &ssrc)) { |
529 srtp_stat_->AddProtectRtpResult(ssrc, err); | 537 srtp_stat_->AddProtectRtpResult(ssrc, err); |
530 } | 538 } |
531 int seq_num; | 539 int seq_num; |
532 GetRtpSeqNum(p, in_len, &seq_num); | 540 GetRtpSeqNum(p, in_len, &seq_num); |
533 if (err != err_status_ok) { | 541 if (err != err_status_ok) { |
534 LOG(LS_WARNING) << "Failed to protect SRTP packet, seqnum=" | 542 LOG(LS_WARNING) << "Failed to protect SRTP packet, seqnum=" |
535 << seq_num << ", err=" << err << ", last seqnum=" | 543 << seq_num << ", err=" << err << ", last seqnum=" |
536 << last_send_seq_num_; | 544 << last_send_seq_num_; |
537 return false; | 545 return false; |
538 } | 546 } |
539 last_send_seq_num_ = seq_num; | 547 last_send_seq_num_ = seq_num; |
540 return true; | 548 return true; |
541 } | 549 } |
542 | 550 |
543 bool SrtpSession::ProtectRtp(void* p, int in_len, int max_len, int* out_len, | 551 bool SrtpSession::ProtectRtp(void* p, |
544 int64* index) { | 552 int in_len, |
| 553 int max_len, |
| 554 int* out_len, |
| 555 int64_t* index) { |
545 if (!ProtectRtp(p, in_len, max_len, out_len)) { | 556 if (!ProtectRtp(p, in_len, max_len, out_len)) { |
546 return false; | 557 return false; |
547 } | 558 } |
548 return (index) ? GetSendStreamPacketIndex(p, in_len, index) : true; | 559 return (index) ? GetSendStreamPacketIndex(p, in_len, index) : true; |
549 } | 560 } |
550 | 561 |
551 bool SrtpSession::ProtectRtcp(void* p, int in_len, int max_len, int* out_len) { | 562 bool SrtpSession::ProtectRtcp(void* p, int in_len, int max_len, int* out_len) { |
552 if (!session_) { | 563 if (!session_) { |
553 LOG(LS_WARNING) << "Failed to protect SRTCP packet: no SRTP Session"; | 564 LOG(LS_WARNING) << "Failed to protect SRTCP packet: no SRTP Session"; |
554 return false; | 565 return false; |
555 } | 566 } |
556 | 567 |
557 int need_len = in_len + sizeof(uint32) + rtcp_auth_tag_len_; // NOLINT | 568 int need_len = in_len + sizeof(uint32_t) + rtcp_auth_tag_len_; // NOLINT |
558 if (max_len < need_len) { | 569 if (max_len < need_len) { |
559 LOG(LS_WARNING) << "Failed to protect SRTCP packet: The buffer length " | 570 LOG(LS_WARNING) << "Failed to protect SRTCP packet: The buffer length " |
560 << max_len << " is less than the needed " << need_len; | 571 << max_len << " is less than the needed " << need_len; |
561 return false; | 572 return false; |
562 } | 573 } |
563 | 574 |
564 *out_len = in_len; | 575 *out_len = in_len; |
565 int err = srtp_protect_rtcp(session_, p, out_len); | 576 int err = srtp_protect_rtcp(session_, p, out_len); |
566 srtp_stat_->AddProtectRtcpResult(err); | 577 srtp_stat_->AddProtectRtcpResult(err); |
567 if (err != err_status_ok) { | 578 if (err != err_status_ok) { |
568 LOG(LS_WARNING) << "Failed to protect SRTCP packet, err=" << err; | 579 LOG(LS_WARNING) << "Failed to protect SRTCP packet, err=" << err; |
569 return false; | 580 return false; |
570 } | 581 } |
571 return true; | 582 return true; |
572 } | 583 } |
573 | 584 |
574 bool SrtpSession::UnprotectRtp(void* p, int in_len, int* out_len) { | 585 bool SrtpSession::UnprotectRtp(void* p, int in_len, int* out_len) { |
575 if (!session_) { | 586 if (!session_) { |
576 LOG(LS_WARNING) << "Failed to unprotect SRTP packet: no SRTP Session"; | 587 LOG(LS_WARNING) << "Failed to unprotect SRTP packet: no SRTP Session"; |
577 return false; | 588 return false; |
578 } | 589 } |
579 | 590 |
580 *out_len = in_len; | 591 *out_len = in_len; |
581 int err = srtp_unprotect(session_, p, out_len); | 592 int err = srtp_unprotect(session_, p, out_len); |
582 uint32 ssrc; | 593 uint32_t ssrc; |
583 if (GetRtpSsrc(p, in_len, &ssrc)) { | 594 if (GetRtpSsrc(p, in_len, &ssrc)) { |
584 srtp_stat_->AddUnprotectRtpResult(ssrc, err); | 595 srtp_stat_->AddUnprotectRtpResult(ssrc, err); |
585 } | 596 } |
586 if (err != err_status_ok) { | 597 if (err != err_status_ok) { |
587 LOG(LS_WARNING) << "Failed to unprotect SRTP packet, err=" << err; | 598 LOG(LS_WARNING) << "Failed to unprotect SRTP packet, err=" << err; |
588 return false; | 599 return false; |
589 } | 600 } |
590 return true; | 601 return true; |
591 } | 602 } |
592 | 603 |
593 bool SrtpSession::UnprotectRtcp(void* p, int in_len, int* out_len) { | 604 bool SrtpSession::UnprotectRtcp(void* p, int in_len, int* out_len) { |
594 if (!session_) { | 605 if (!session_) { |
595 LOG(LS_WARNING) << "Failed to unprotect SRTCP packet: no SRTP Session"; | 606 LOG(LS_WARNING) << "Failed to unprotect SRTCP packet: no SRTP Session"; |
596 return false; | 607 return false; |
597 } | 608 } |
598 | 609 |
599 *out_len = in_len; | 610 *out_len = in_len; |
600 int err = srtp_unprotect_rtcp(session_, p, out_len); | 611 int err = srtp_unprotect_rtcp(session_, p, out_len); |
601 srtp_stat_->AddUnprotectRtcpResult(err); | 612 srtp_stat_->AddUnprotectRtcpResult(err); |
602 if (err != err_status_ok) { | 613 if (err != err_status_ok) { |
603 LOG(LS_WARNING) << "Failed to unprotect SRTCP packet, err=" << err; | 614 LOG(LS_WARNING) << "Failed to unprotect SRTCP packet, err=" << err; |
604 return false; | 615 return false; |
605 } | 616 } |
606 return true; | 617 return true; |
607 } | 618 } |
608 | 619 |
609 bool SrtpSession::GetRtpAuthParams(uint8** key, int* key_len, | 620 bool SrtpSession::GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len) { |
610 int* tag_len) { | |
611 #if defined(ENABLE_EXTERNAL_AUTH) | 621 #if defined(ENABLE_EXTERNAL_AUTH) |
612 ExternalHmacContext* external_hmac = NULL; | 622 ExternalHmacContext* external_hmac = NULL; |
613 // stream_template will be the reference context for other streams. | 623 // stream_template will be the reference context for other streams. |
614 // Let's use it for getting the keys. | 624 // Let's use it for getting the keys. |
615 srtp_stream_ctx_t* srtp_context = session_->stream_template; | 625 srtp_stream_ctx_t* srtp_context = session_->stream_template; |
616 if (srtp_context && srtp_context->rtp_auth) { | 626 if (srtp_context && srtp_context->rtp_auth) { |
617 external_hmac = reinterpret_cast<ExternalHmacContext*>( | 627 external_hmac = reinterpret_cast<ExternalHmacContext*>( |
618 srtp_context->rtp_auth->state); | 628 srtp_context->rtp_auth->state); |
619 } | 629 } |
620 | 630 |
621 if (!external_hmac) { | 631 if (!external_hmac) { |
622 LOG(LS_ERROR) << "Failed to get auth keys from libsrtp!."; | 632 LOG(LS_ERROR) << "Failed to get auth keys from libsrtp!."; |
623 return false; | 633 return false; |
624 } | 634 } |
625 | 635 |
626 *key = external_hmac->key; | 636 *key = external_hmac->key; |
627 *key_len = external_hmac->key_length; | 637 *key_len = external_hmac->key_length; |
628 *tag_len = rtp_auth_tag_len_; | 638 *tag_len = rtp_auth_tag_len_; |
629 return true; | 639 return true; |
630 #else | 640 #else |
631 return false; | 641 return false; |
632 #endif | 642 #endif |
633 } | 643 } |
634 | 644 |
635 bool SrtpSession::GetSendStreamPacketIndex(void* p, int in_len, int64* index) { | 645 bool SrtpSession::GetSendStreamPacketIndex(void* p, |
| 646 int in_len, |
| 647 int64_t* index) { |
636 srtp_hdr_t* hdr = reinterpret_cast<srtp_hdr_t*>(p); | 648 srtp_hdr_t* hdr = reinterpret_cast<srtp_hdr_t*>(p); |
637 srtp_stream_ctx_t* stream = srtp_get_stream(session_, hdr->ssrc); | 649 srtp_stream_ctx_t* stream = srtp_get_stream(session_, hdr->ssrc); |
638 if (stream == NULL) | 650 if (stream == NULL) |
639 return false; | 651 return false; |
640 | 652 |
641 // Shift packet index, put into network byte order | 653 // Shift packet index, put into network byte order |
642 *index = static_cast<int64>( | 654 *index = static_cast<int64_t>( |
643 rtc::NetworkToHost64(rdbx_get_packet_index(&stream->rtp_rdbx) << 16)); | 655 rtc::NetworkToHost64(rdbx_get_packet_index(&stream->rtp_rdbx) << 16)); |
644 return true; | 656 return true; |
645 } | 657 } |
646 | 658 |
647 void SrtpSession::set_signal_silent_time(uint32 signal_silent_time_in_ms) { | 659 void SrtpSession::set_signal_silent_time(uint32_t signal_silent_time_in_ms) { |
648 srtp_stat_->set_signal_silent_time(signal_silent_time_in_ms); | 660 srtp_stat_->set_signal_silent_time(signal_silent_time_in_ms); |
649 } | 661 } |
650 | 662 |
651 bool SrtpSession::SetKey(int type, const std::string& cs, | 663 bool SrtpSession::SetKey(int type, |
652 const uint8* key, int len) { | 664 const std::string& cs, |
| 665 const uint8_t* key, |
| 666 int len) { |
653 if (session_) { | 667 if (session_) { |
654 LOG(LS_ERROR) << "Failed to create SRTP session: " | 668 LOG(LS_ERROR) << "Failed to create SRTP session: " |
655 << "SRTP session already created"; | 669 << "SRTP session already created"; |
656 return false; | 670 return false; |
657 } | 671 } |
658 | 672 |
659 if (!Init()) { | 673 if (!Init()) { |
660 return false; | 674 return false; |
661 } | 675 } |
662 | 676 |
(...skipping 12 matching lines...) Expand all Loading... |
675 return false; | 689 return false; |
676 } | 690 } |
677 | 691 |
678 if (!key || len != SRTP_MASTER_KEY_LEN) { | 692 if (!key || len != SRTP_MASTER_KEY_LEN) { |
679 LOG(LS_WARNING) << "Failed to create SRTP session: invalid key"; | 693 LOG(LS_WARNING) << "Failed to create SRTP session: invalid key"; |
680 return false; | 694 return false; |
681 } | 695 } |
682 | 696 |
683 policy.ssrc.type = static_cast<ssrc_type_t>(type); | 697 policy.ssrc.type = static_cast<ssrc_type_t>(type); |
684 policy.ssrc.value = 0; | 698 policy.ssrc.value = 0; |
685 policy.key = const_cast<uint8*>(key); | 699 policy.key = const_cast<uint8_t*>(key); |
686 // TODO(astor) parse window size from WSH session-param | 700 // TODO(astor) parse window size from WSH session-param |
687 policy.window_size = 1024; | 701 policy.window_size = 1024; |
688 policy.allow_repeat_tx = 1; | 702 policy.allow_repeat_tx = 1; |
689 // If external authentication option is enabled, supply custom auth module | 703 // If external authentication option is enabled, supply custom auth module |
690 // id EXTERNAL_HMAC_SHA1 in the policy structure. | 704 // id EXTERNAL_HMAC_SHA1 in the policy structure. |
691 // We want to set this option only for rtp packets. | 705 // We want to set this option only for rtp packets. |
692 // By default policy structure is initialized to HMAC_SHA1. | 706 // By default policy structure is initialized to HMAC_SHA1. |
693 #if defined(ENABLE_EXTERNAL_AUTH) | 707 #if defined(ENABLE_EXTERNAL_AUTH) |
694 // Enable external HMAC authentication only for outgoing streams. | 708 // Enable external HMAC authentication only for outgoing streams. |
695 if (type == ssrc_any_outbound) { | 709 if (type == ssrc_any_outbound) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 | 808 |
795 // On some systems, SRTP is not (yet) available. | 809 // On some systems, SRTP is not (yet) available. |
796 | 810 |
797 SrtpSession::SrtpSession() { | 811 SrtpSession::SrtpSession() { |
798 LOG(WARNING) << "SRTP implementation is missing."; | 812 LOG(WARNING) << "SRTP implementation is missing."; |
799 } | 813 } |
800 | 814 |
801 SrtpSession::~SrtpSession() { | 815 SrtpSession::~SrtpSession() { |
802 } | 816 } |
803 | 817 |
804 bool SrtpSession::SetSend(const std::string& cs, const uint8* key, int len) { | 818 bool SrtpSession::SetSend(const std::string& cs, const uint8_t* key, int len) { |
805 return SrtpNotAvailable(__FUNCTION__); | 819 return SrtpNotAvailable(__FUNCTION__); |
806 } | 820 } |
807 | 821 |
808 bool SrtpSession::SetRecv(const std::string& cs, const uint8* key, int len) { | 822 bool SrtpSession::SetRecv(const std::string& cs, const uint8_t* key, int len) { |
809 return SrtpNotAvailable(__FUNCTION__); | 823 return SrtpNotAvailable(__FUNCTION__); |
810 } | 824 } |
811 | 825 |
812 bool SrtpSession::ProtectRtp(void* data, int in_len, int max_len, | 826 bool SrtpSession::ProtectRtp(void* data, int in_len, int max_len, |
813 int* out_len) { | 827 int* out_len) { |
814 return SrtpNotAvailable(__FUNCTION__); | 828 return SrtpNotAvailable(__FUNCTION__); |
815 } | 829 } |
816 | 830 |
817 bool SrtpSession::ProtectRtcp(void* data, int in_len, int max_len, | 831 bool SrtpSession::ProtectRtcp(void* data, int in_len, int max_len, |
818 int* out_len) { | 832 int* out_len) { |
819 return SrtpNotAvailable(__FUNCTION__); | 833 return SrtpNotAvailable(__FUNCTION__); |
820 } | 834 } |
821 | 835 |
822 bool SrtpSession::UnprotectRtp(void* data, int in_len, int* out_len) { | 836 bool SrtpSession::UnprotectRtp(void* data, int in_len, int* out_len) { |
823 return SrtpNotAvailable(__FUNCTION__); | 837 return SrtpNotAvailable(__FUNCTION__); |
824 } | 838 } |
825 | 839 |
826 bool SrtpSession::UnprotectRtcp(void* data, int in_len, int* out_len) { | 840 bool SrtpSession::UnprotectRtcp(void* data, int in_len, int* out_len) { |
827 return SrtpNotAvailable(__FUNCTION__); | 841 return SrtpNotAvailable(__FUNCTION__); |
828 } | 842 } |
829 | 843 |
830 void SrtpSession::set_signal_silent_time(uint32 signal_silent_time) { | 844 void SrtpSession::set_signal_silent_time(uint32_t signal_silent_time) { |
831 // Do nothing. | 845 // Do nothing. |
832 } | 846 } |
833 | 847 |
834 #endif // HAVE_SRTP | 848 #endif // HAVE_SRTP |
835 | 849 |
836 /////////////////////////////////////////////////////////////////////////////// | 850 /////////////////////////////////////////////////////////////////////////////// |
837 // SrtpStat | 851 // SrtpStat |
838 | 852 |
839 #ifdef HAVE_SRTP | 853 #ifdef HAVE_SRTP |
840 | 854 |
841 SrtpStat::SrtpStat() | 855 SrtpStat::SrtpStat() |
842 : signal_silent_time_(1000) { | 856 : signal_silent_time_(1000) { |
843 } | 857 } |
844 | 858 |
845 void SrtpStat::AddProtectRtpResult(uint32 ssrc, int result) { | 859 void SrtpStat::AddProtectRtpResult(uint32_t ssrc, int result) { |
846 FailureKey key; | 860 FailureKey key; |
847 key.ssrc = ssrc; | 861 key.ssrc = ssrc; |
848 key.mode = SrtpFilter::PROTECT; | 862 key.mode = SrtpFilter::PROTECT; |
849 switch (result) { | 863 switch (result) { |
850 case err_status_ok: | 864 case err_status_ok: |
851 key.error = SrtpFilter::ERROR_NONE; | 865 key.error = SrtpFilter::ERROR_NONE; |
852 break; | 866 break; |
853 case err_status_auth_fail: | 867 case err_status_auth_fail: |
854 key.error = SrtpFilter::ERROR_AUTH; | 868 key.error = SrtpFilter::ERROR_AUTH; |
855 break; | 869 break; |
856 default: | 870 default: |
857 key.error = SrtpFilter::ERROR_FAIL; | 871 key.error = SrtpFilter::ERROR_FAIL; |
858 } | 872 } |
859 HandleSrtpResult(key); | 873 HandleSrtpResult(key); |
860 } | 874 } |
861 | 875 |
862 void SrtpStat::AddUnprotectRtpResult(uint32 ssrc, int result) { | 876 void SrtpStat::AddUnprotectRtpResult(uint32_t ssrc, int result) { |
863 FailureKey key; | 877 FailureKey key; |
864 key.ssrc = ssrc; | 878 key.ssrc = ssrc; |
865 key.mode = SrtpFilter::UNPROTECT; | 879 key.mode = SrtpFilter::UNPROTECT; |
866 switch (result) { | 880 switch (result) { |
867 case err_status_ok: | 881 case err_status_ok: |
868 key.error = SrtpFilter::ERROR_NONE; | 882 key.error = SrtpFilter::ERROR_NONE; |
869 break; | 883 break; |
870 case err_status_auth_fail: | 884 case err_status_auth_fail: |
871 key.error = SrtpFilter::ERROR_AUTH; | 885 key.error = SrtpFilter::ERROR_AUTH; |
872 break; | 886 break; |
(...skipping 15 matching lines...) Expand all Loading... |
888 AddUnprotectRtpResult(0U, result); | 902 AddUnprotectRtpResult(0U, result); |
889 } | 903 } |
890 | 904 |
891 void SrtpStat::HandleSrtpResult(const SrtpStat::FailureKey& key) { | 905 void SrtpStat::HandleSrtpResult(const SrtpStat::FailureKey& key) { |
892 // Handle some cases where error should be signalled right away. For other | 906 // Handle some cases where error should be signalled right away. For other |
893 // errors, trigger error for the first time seeing it. After that, silent | 907 // errors, trigger error for the first time seeing it. After that, silent |
894 // the same error for a certain amount of time (default 1 sec). | 908 // the same error for a certain amount of time (default 1 sec). |
895 if (key.error != SrtpFilter::ERROR_NONE) { | 909 if (key.error != SrtpFilter::ERROR_NONE) { |
896 // For errors, signal first time and wait for 1 sec. | 910 // For errors, signal first time and wait for 1 sec. |
897 FailureStat* stat = &(failures_[key]); | 911 FailureStat* stat = &(failures_[key]); |
898 uint32 current_time = rtc::Time(); | 912 uint32_t current_time = rtc::Time(); |
899 if (stat->last_signal_time == 0 || | 913 if (stat->last_signal_time == 0 || |
900 rtc::TimeDiff(current_time, stat->last_signal_time) > | 914 rtc::TimeDiff(current_time, stat->last_signal_time) > |
901 static_cast<int>(signal_silent_time_)) { | 915 static_cast<int>(signal_silent_time_)) { |
902 SignalSrtpError(key.ssrc, key.mode, key.error); | 916 SignalSrtpError(key.ssrc, key.mode, key.error); |
903 stat->last_signal_time = current_time; | 917 stat->last_signal_time = current_time; |
904 } | 918 } |
905 } | 919 } |
906 } | 920 } |
907 | 921 |
908 #else // !HAVE_SRTP | 922 #else // !HAVE_SRTP |
909 | 923 |
910 // On some systems, SRTP is not (yet) available. | 924 // On some systems, SRTP is not (yet) available. |
911 | 925 |
912 SrtpStat::SrtpStat() | 926 SrtpStat::SrtpStat() |
913 : signal_silent_time_(1000) { | 927 : signal_silent_time_(1000) { |
914 LOG(WARNING) << "SRTP implementation is missing."; | 928 LOG(WARNING) << "SRTP implementation is missing."; |
915 } | 929 } |
916 | 930 |
917 void SrtpStat::AddProtectRtpResult(uint32 ssrc, int result) { | 931 void SrtpStat::AddProtectRtpResult(uint32_t ssrc, int result) { |
918 SrtpNotAvailable(__FUNCTION__); | 932 SrtpNotAvailable(__FUNCTION__); |
919 } | 933 } |
920 | 934 |
921 void SrtpStat::AddUnprotectRtpResult(uint32 ssrc, int result) { | 935 void SrtpStat::AddUnprotectRtpResult(uint32_t ssrc, int result) { |
922 SrtpNotAvailable(__FUNCTION__); | 936 SrtpNotAvailable(__FUNCTION__); |
923 } | 937 } |
924 | 938 |
925 void SrtpStat::AddProtectRtcpResult(int result) { | 939 void SrtpStat::AddProtectRtcpResult(int result) { |
926 SrtpNotAvailable(__FUNCTION__); | 940 SrtpNotAvailable(__FUNCTION__); |
927 } | 941 } |
928 | 942 |
929 void SrtpStat::AddUnprotectRtcpResult(int result) { | 943 void SrtpStat::AddUnprotectRtcpResult(int result) { |
930 SrtpNotAvailable(__FUNCTION__); | 944 SrtpNotAvailable(__FUNCTION__); |
931 } | 945 } |
932 | 946 |
933 void SrtpStat::HandleSrtpResult(const SrtpStat::FailureKey& key) { | 947 void SrtpStat::HandleSrtpResult(const SrtpStat::FailureKey& key) { |
934 SrtpNotAvailable(__FUNCTION__); | 948 SrtpNotAvailable(__FUNCTION__); |
935 } | 949 } |
936 | 950 |
937 #endif // HAVE_SRTP | 951 #endif // HAVE_SRTP |
938 | 952 |
939 } // namespace cricket | 953 } // namespace cricket |
OLD | NEW |