Nagram/TMessagesProj/jni/voip/webrtc/pc/dtls_srtp_transport.h

106 lines
3.9 KiB
C
Raw Normal View History

2020-08-14 16:58:22 +00:00
/*
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef PC_DTLS_SRTP_TRANSPORT_H_
#define PC_DTLS_SRTP_TRANSPORT_H_
2021-06-25 00:43:10 +00:00
#include <string>
2020-08-14 16:58:22 +00:00
#include <vector>
#include "absl/types/optional.h"
#include "api/crypto_params.h"
2022-03-11 16:49:54 +00:00
#include "api/dtls_transport_interface.h"
2020-08-14 16:58:22 +00:00
#include "api/rtc_error.h"
#include "p2p/base/dtls_transport_internal.h"
#include "p2p/base/packet_transport_internal.h"
#include "pc/srtp_transport.h"
#include "rtc_base/buffer.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
namespace webrtc {
// The subclass of SrtpTransport is used for DTLS-SRTP. When the DTLS handshake
// is finished, it extracts the keying materials from DtlsTransport and
// configures the SrtpSessions in the base class.
class DtlsSrtpTransport : public SrtpTransport {
public:
explicit DtlsSrtpTransport(bool rtcp_mux_enabled);
// Set P2P layer RTP/RTCP DtlsTransports. When using RTCP-muxing,
2022-03-11 16:49:54 +00:00
// `rtcp_dtls_transport` is null.
2020-08-14 16:58:22 +00:00
void SetDtlsTransports(cricket::DtlsTransportInternal* rtp_dtls_transport,
cricket::DtlsTransportInternal* rtcp_dtls_transport);
void SetRtcpMuxEnabled(bool enable) override;
// Set the header extension ids that should be encrypted.
void UpdateSendEncryptedHeaderExtensionIds(
const std::vector<int>& send_extension_ids);
void UpdateRecvEncryptedHeaderExtensionIds(
const std::vector<int>& recv_extension_ids);
2021-06-25 00:43:10 +00:00
void SetOnDtlsStateChange(std::function<void(void)> callback);
2020-08-14 16:58:22 +00:00
RTCError SetSrtpSendKey(const cricket::CryptoParams& params) override {
return RTCError(RTCErrorType::UNSUPPORTED_OPERATION,
"Set SRTP keys for DTLS-SRTP is not supported.");
}
RTCError SetSrtpReceiveKey(const cricket::CryptoParams& params) override {
return RTCError(RTCErrorType::UNSUPPORTED_OPERATION,
"Set SRTP keys for DTLS-SRTP is not supported.");
}
2022-03-11 16:49:54 +00:00
// If `active_reset_srtp_params_` is set to be true, the SRTP parameters will
2020-08-14 16:58:22 +00:00
// be reset whenever the DtlsTransports are reset.
void SetActiveResetSrtpParams(bool active_reset_srtp_params) {
active_reset_srtp_params_ = active_reset_srtp_params;
}
private:
bool IsDtlsActive();
bool IsDtlsConnected();
bool IsDtlsWritable();
bool DtlsHandshakeCompleted();
void MaybeSetupDtlsSrtp();
void SetupRtpDtlsSrtp();
void SetupRtcpDtlsSrtp();
bool ExtractParams(cricket::DtlsTransportInternal* dtls_transport,
int* selected_crypto_suite,
rtc::ZeroOnFreeBuffer<unsigned char>* send_key,
rtc::ZeroOnFreeBuffer<unsigned char>* recv_key);
void SetDtlsTransport(cricket::DtlsTransportInternal* new_dtls_transport,
cricket::DtlsTransportInternal** old_dtls_transport);
void SetRtpDtlsTransport(cricket::DtlsTransportInternal* rtp_dtls_transport);
void SetRtcpDtlsTransport(
cricket::DtlsTransportInternal* rtcp_dtls_transport);
void OnDtlsState(cricket::DtlsTransportInternal* dtls_transport,
2022-03-11 16:49:54 +00:00
DtlsTransportState state);
2020-08-14 16:58:22 +00:00
// Override the SrtpTransport::OnWritableState.
void OnWritableState(rtc::PacketTransportInternal* packet_transport) override;
// Owned by the TransportController.
cricket::DtlsTransportInternal* rtp_dtls_transport_ = nullptr;
cricket::DtlsTransportInternal* rtcp_dtls_transport_ = nullptr;
// The encrypted header extension IDs.
absl::optional<std::vector<int>> send_extension_ids_;
absl::optional<std::vector<int>> recv_extension_ids_;
bool active_reset_srtp_params_ = false;
2021-06-25 00:43:10 +00:00
std::function<void(void)> on_dtls_state_change_;
2020-08-14 16:58:22 +00:00
};
} // namespace webrtc
#endif // PC_DTLS_SRTP_TRANSPORT_H_