dtls_srtp_transport.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef PC_DTLS_SRTP_TRANSPORT_H_
  11. #define PC_DTLS_SRTP_TRANSPORT_H_
  12. #include <vector>
  13. #include "absl/types/optional.h"
  14. #include "api/crypto_params.h"
  15. #include "api/rtc_error.h"
  16. #include "p2p/base/dtls_transport_internal.h"
  17. #include "p2p/base/packet_transport_internal.h"
  18. #include "pc/srtp_transport.h"
  19. #include "rtc_base/buffer.h"
  20. #include "rtc_base/third_party/sigslot/sigslot.h"
  21. namespace webrtc {
  22. // The subclass of SrtpTransport is used for DTLS-SRTP. When the DTLS handshake
  23. // is finished, it extracts the keying materials from DtlsTransport and
  24. // configures the SrtpSessions in the base class.
  25. class DtlsSrtpTransport : public SrtpTransport {
  26. public:
  27. explicit DtlsSrtpTransport(bool rtcp_mux_enabled);
  28. // Set P2P layer RTP/RTCP DtlsTransports. When using RTCP-muxing,
  29. // |rtcp_dtls_transport| is null.
  30. void SetDtlsTransports(cricket::DtlsTransportInternal* rtp_dtls_transport,
  31. cricket::DtlsTransportInternal* rtcp_dtls_transport);
  32. void SetRtcpMuxEnabled(bool enable) override;
  33. // Set the header extension ids that should be encrypted.
  34. void UpdateSendEncryptedHeaderExtensionIds(
  35. const std::vector<int>& send_extension_ids);
  36. void UpdateRecvEncryptedHeaderExtensionIds(
  37. const std::vector<int>& recv_extension_ids);
  38. sigslot::signal<DtlsSrtpTransport*, bool> SignalDtlsSrtpSetupFailure;
  39. sigslot::signal<> SignalDtlsStateChange;
  40. RTCError SetSrtpSendKey(const cricket::CryptoParams& params) override {
  41. return RTCError(RTCErrorType::UNSUPPORTED_OPERATION,
  42. "Set SRTP keys for DTLS-SRTP is not supported.");
  43. }
  44. RTCError SetSrtpReceiveKey(const cricket::CryptoParams& params) override {
  45. return RTCError(RTCErrorType::UNSUPPORTED_OPERATION,
  46. "Set SRTP keys for DTLS-SRTP is not supported.");
  47. }
  48. // If |active_reset_srtp_params_| is set to be true, the SRTP parameters will
  49. // be reset whenever the DtlsTransports are reset.
  50. void SetActiveResetSrtpParams(bool active_reset_srtp_params) {
  51. active_reset_srtp_params_ = active_reset_srtp_params;
  52. }
  53. private:
  54. bool IsDtlsActive();
  55. bool IsDtlsConnected();
  56. bool IsDtlsWritable();
  57. bool DtlsHandshakeCompleted();
  58. void MaybeSetupDtlsSrtp();
  59. void SetupRtpDtlsSrtp();
  60. void SetupRtcpDtlsSrtp();
  61. bool ExtractParams(cricket::DtlsTransportInternal* dtls_transport,
  62. int* selected_crypto_suite,
  63. rtc::ZeroOnFreeBuffer<unsigned char>* send_key,
  64. rtc::ZeroOnFreeBuffer<unsigned char>* recv_key);
  65. void SetDtlsTransport(cricket::DtlsTransportInternal* new_dtls_transport,
  66. cricket::DtlsTransportInternal** old_dtls_transport);
  67. void SetRtpDtlsTransport(cricket::DtlsTransportInternal* rtp_dtls_transport);
  68. void SetRtcpDtlsTransport(
  69. cricket::DtlsTransportInternal* rtcp_dtls_transport);
  70. void OnDtlsState(cricket::DtlsTransportInternal* dtls_transport,
  71. cricket::DtlsTransportState state);
  72. // Override the SrtpTransport::OnWritableState.
  73. void OnWritableState(rtc::PacketTransportInternal* packet_transport) override;
  74. // Owned by the TransportController.
  75. cricket::DtlsTransportInternal* rtp_dtls_transport_ = nullptr;
  76. cricket::DtlsTransportInternal* rtcp_dtls_transport_ = nullptr;
  77. // The encrypted header extension IDs.
  78. absl::optional<std::vector<int>> send_extension_ids_;
  79. absl::optional<std::vector<int>> recv_extension_ids_;
  80. bool active_reset_srtp_params_ = false;
  81. };
  82. } // namespace webrtc
  83. #endif // PC_DTLS_SRTP_TRANSPORT_H_