2017-07-19 13:38:02 -07: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef PC_SRTPTRANSPORT_H_
|
|
|
|
|
#define PC_SRTPTRANSPORT_H_
|
2017-07-19 13:38:02 -07:00
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
2017-10-30 09:57:42 -07:00
|
|
|
#include <vector>
|
2017-07-19 13:38:02 -07:00
|
|
|
|
2017-11-13 13:26:07 -08:00
|
|
|
#include "p2p/base/icetransportinternal.h"
|
2017-11-20 14:35:11 -08:00
|
|
|
#include "pc/rtptransportinternaladapter.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "pc/srtpfilter.h"
|
2017-09-22 12:12:30 -07:00
|
|
|
#include "pc/srtpsession.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2017-07-19 13:38:02 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// This class will eventually be a wrapper around RtpTransportInternal
|
2017-09-22 12:12:30 -07:00
|
|
|
// that protects and unprotects sent and received RTP packets.
|
2017-11-20 14:35:11 -08:00
|
|
|
class SrtpTransport : public RtpTransportInternalAdapter {
|
2017-07-19 13:38:02 -07:00
|
|
|
public:
|
|
|
|
|
SrtpTransport(bool rtcp_mux_enabled, const std::string& content_name);
|
|
|
|
|
|
2017-11-20 14:35:11 -08:00
|
|
|
SrtpTransport(std::unique_ptr<RtpTransportInternal> rtp_transport,
|
2017-07-19 13:38:02 -07:00
|
|
|
const std::string& content_name);
|
|
|
|
|
|
2017-09-22 12:12:30 -07:00
|
|
|
bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet,
|
|
|
|
|
const rtc::PacketOptions& options,
|
|
|
|
|
int flags) override;
|
|
|
|
|
|
|
|
|
|
bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet,
|
|
|
|
|
const rtc::PacketOptions& options,
|
|
|
|
|
int flags) override;
|
|
|
|
|
|
|
|
|
|
// The transport becomes active if the send_session_ and recv_session_ are
|
|
|
|
|
// created.
|
|
|
|
|
bool IsActive() const;
|
2017-07-19 13:38:02 -07:00
|
|
|
|
|
|
|
|
// TODO(zstein): Remove this when we remove RtpTransportAdapter.
|
|
|
|
|
RtpTransportAdapter* GetInternal() override { return nullptr; }
|
|
|
|
|
|
2017-09-22 12:12:30 -07:00
|
|
|
// Create new send/recv sessions and set the negotiated crypto keys for RTP
|
|
|
|
|
// packet encryption. The keys can either come from SDES negotiation or DTLS
|
|
|
|
|
// handshake.
|
|
|
|
|
bool SetRtpParams(int send_cs,
|
|
|
|
|
const uint8_t* send_key,
|
|
|
|
|
int send_key_len,
|
2017-11-10 16:44:46 -08:00
|
|
|
const std::vector<int>& send_extension_ids,
|
2017-09-22 12:12:30 -07:00
|
|
|
int recv_cs,
|
|
|
|
|
const uint8_t* recv_key,
|
2017-11-10 16:44:46 -08:00
|
|
|
int recv_key_len,
|
|
|
|
|
const std::vector<int>& recv_extension_ids);
|
2017-09-22 12:12:30 -07:00
|
|
|
|
|
|
|
|
// Create new send/recv sessions and set the negotiated crypto keys for RTCP
|
|
|
|
|
// packet encryption. The keys can either come from SDES negotiation or DTLS
|
|
|
|
|
// handshake.
|
|
|
|
|
bool SetRtcpParams(int send_cs,
|
|
|
|
|
const uint8_t* send_key,
|
|
|
|
|
int send_key_len,
|
2017-11-10 16:44:46 -08:00
|
|
|
const std::vector<int>& send_extension_ids,
|
2017-09-22 12:12:30 -07:00
|
|
|
int recv_cs,
|
|
|
|
|
const uint8_t* recv_key,
|
2017-11-10 16:44:46 -08:00
|
|
|
int recv_key_len,
|
|
|
|
|
const std::vector<int>& recv_extension_ids);
|
2017-09-22 12:12:30 -07:00
|
|
|
|
|
|
|
|
void ResetParams();
|
|
|
|
|
|
|
|
|
|
// If external auth is enabled, SRTP will write a dummy auth tag that then
|
|
|
|
|
// later must get replaced before the packet is sent out. Only supported for
|
|
|
|
|
// non-GCM cipher suites and can be checked through "IsExternalAuthActive"
|
|
|
|
|
// if it is actually used. This method is only valid before the RTP params
|
|
|
|
|
// have been set.
|
|
|
|
|
void EnableExternalAuth();
|
|
|
|
|
bool IsExternalAuthEnabled() const;
|
|
|
|
|
|
|
|
|
|
// A SrtpTransport supports external creation of the auth tag if a non-GCM
|
|
|
|
|
// cipher is used. This method is only valid after the RTP params have
|
|
|
|
|
// been set.
|
|
|
|
|
bool IsExternalAuthActive() const;
|
|
|
|
|
|
|
|
|
|
// Returns srtp overhead for rtp packets.
|
|
|
|
|
bool GetSrtpOverhead(int* srtp_overhead) const;
|
|
|
|
|
|
|
|
|
|
// Returns rtp auth params from srtp context.
|
|
|
|
|
bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len);
|
|
|
|
|
|
|
|
|
|
// Helper method to get RTP Absoulute SendTime extension header id if
|
|
|
|
|
// present in remote supported extensions list.
|
|
|
|
|
void CacheRtpAbsSendTimeHeaderExtension(int rtp_abs_sendtime_extn_id) {
|
|
|
|
|
rtp_abs_sendtime_extn_id_ = rtp_abs_sendtime_extn_id;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-19 13:38:02 -07:00
|
|
|
private:
|
2017-09-22 12:12:30 -07:00
|
|
|
void CreateSrtpSessions();
|
|
|
|
|
|
2017-07-19 13:38:02 -07:00
|
|
|
void ConnectToRtpTransport();
|
|
|
|
|
|
2017-09-22 12:12:30 -07:00
|
|
|
bool SendPacket(bool rtcp,
|
|
|
|
|
rtc::CopyOnWriteBuffer* packet,
|
|
|
|
|
const rtc::PacketOptions& options,
|
|
|
|
|
int flags);
|
|
|
|
|
|
2017-07-19 13:38:02 -07:00
|
|
|
void OnPacketReceived(bool rtcp,
|
|
|
|
|
rtc::CopyOnWriteBuffer* packet,
|
|
|
|
|
const rtc::PacketTime& packet_time);
|
|
|
|
|
void OnReadyToSend(bool ready) { SignalReadyToSend(ready); }
|
2017-11-13 13:26:07 -08:00
|
|
|
void OnNetworkRouteChanged(rtc::Optional<rtc::NetworkRoute> network_route);
|
2017-07-19 13:38:02 -07:00
|
|
|
|
2017-09-22 12:12:30 -07:00
|
|
|
bool ProtectRtp(void* data, int in_len, int max_len, int* out_len);
|
|
|
|
|
|
|
|
|
|
// Overloaded version, outputs packet index.
|
|
|
|
|
bool ProtectRtp(void* data,
|
|
|
|
|
int in_len,
|
|
|
|
|
int max_len,
|
|
|
|
|
int* out_len,
|
|
|
|
|
int64_t* index);
|
|
|
|
|
bool ProtectRtcp(void* data, int in_len, int max_len, int* out_len);
|
|
|
|
|
|
|
|
|
|
// Decrypts/verifies an invidiual RTP/RTCP packet.
|
|
|
|
|
// If an HMAC is used, this will decrease the packet size.
|
|
|
|
|
bool UnprotectRtp(void* data, int in_len, int* out_len);
|
2017-08-31 16:00:07 -07:00
|
|
|
|
2017-09-22 12:12:30 -07:00
|
|
|
bool UnprotectRtcp(void* data, int in_len, int* out_len);
|
|
|
|
|
|
|
|
|
|
const std::string content_name_;
|
2017-09-19 01:12:52 -07:00
|
|
|
std::unique_ptr<RtpTransportInternal> rtp_transport_;
|
2017-09-22 12:12:30 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<cricket::SrtpSession> send_session_;
|
|
|
|
|
std::unique_ptr<cricket::SrtpSession> recv_session_;
|
|
|
|
|
std::unique_ptr<cricket::SrtpSession> send_rtcp_session_;
|
|
|
|
|
std::unique_ptr<cricket::SrtpSession> recv_rtcp_session_;
|
|
|
|
|
|
|
|
|
|
bool external_auth_enabled_ = false;
|
|
|
|
|
|
|
|
|
|
int rtp_abs_sendtime_extn_id_ = -1;
|
2017-07-19 13:38:02 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // PC_SRTPTRANSPORT_H_
|