Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_PC_SRTPTRANSPORT_H_ | 11 #ifndef WEBRTC_PC_SRTPTRANSPORT_H_ |
| 12 #define WEBRTC_PC_SRTPTRANSPORT_H_ | 12 #define WEBRTC_PC_SRTPTRANSPORT_H_ |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <utility> | 16 #include <utility> |
| 17 | 17 |
| 18 #include "webrtc/pc/rtptransportinternal.h" | 18 #include "webrtc/pc/rtptransportinternal.h" |
| 19 #include "webrtc/pc/srtpfilter.h" | 19 #include "webrtc/pc/srtpfilter.h" |
| 20 #include "webrtc/pc/srtpsession.h" | |
| 20 #include "webrtc/rtc_base/checks.h" | 21 #include "webrtc/rtc_base/checks.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 // This class will eventually be a wrapper around RtpTransportInternal | 25 // This class will eventually be a wrapper around RtpTransportInternal |
| 25 // that protects and unprotects sent and received RTP packets. This | 26 // that protects and unprotects sent and received RTP packets. |
| 26 // functionality is currently implemented by SrtpFilter and BaseChannel, but | |
| 27 // will be moved here in the future. | |
| 28 class SrtpTransport : public RtpTransportInternal { | 27 class SrtpTransport : public RtpTransportInternal { |
| 29 public: | 28 public: |
| 30 SrtpTransport(bool rtcp_mux_enabled, const std::string& content_name); | 29 SrtpTransport(bool rtcp_mux_enabled, const std::string& content_name); |
| 31 | 30 |
| 32 // TODO(zstein): Consider taking an RtpTransport instead of an | |
| 33 // RtpTransportInternal. | |
| 34 SrtpTransport(std::unique_ptr<RtpTransportInternal> transport, | 31 SrtpTransport(std::unique_ptr<RtpTransportInternal> transport, |
| 35 const std::string& content_name); | 32 const std::string& content_name); |
| 36 | 33 |
| 37 void SetRtcpMuxEnabled(bool enable) override { | 34 void SetRtcpMuxEnabled(bool enable) override { |
| 38 rtp_transport_->SetRtcpMuxEnabled(enable); | 35 rtp_transport_->SetRtcpMuxEnabled(enable); |
| 39 } | 36 } |
| 40 | 37 |
| 41 rtc::PacketTransportInternal* rtp_packet_transport() const override { | 38 rtc::PacketTransportInternal* rtp_packet_transport() const override { |
| 42 return rtp_transport_->rtp_packet_transport(); | 39 return rtp_transport_->rtp_packet_transport(); |
| 43 } | 40 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 54 return rtp_transport_->rtcp_packet_transport(); | 51 return rtp_transport_->rtcp_packet_transport(); |
| 55 } | 52 } |
| 56 void SetRtcpPacketTransport(rtc::PacketTransportInternal* rtcp) override { | 53 void SetRtcpPacketTransport(rtc::PacketTransportInternal* rtcp) override { |
| 57 rtp_transport_->SetRtcpPacketTransport(rtcp); | 54 rtp_transport_->SetRtcpPacketTransport(rtcp); |
| 58 } | 55 } |
| 59 | 56 |
| 60 PacketTransportInterface* GetRtcpPacketTransport() const override { | 57 PacketTransportInterface* GetRtcpPacketTransport() const override { |
| 61 return rtp_transport_->GetRtcpPacketTransport(); | 58 return rtp_transport_->GetRtcpPacketTransport(); |
| 62 } | 59 } |
| 63 | 60 |
| 64 bool IsWritable(bool rtcp) const override { | 61 bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet, |
| 65 return rtp_transport_->IsWritable(rtcp); | 62 const rtc::PacketOptions& options) override; |
| 66 } | 63 |
| 64 bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet, | |
| 65 const rtc::PacketOptions& options) override; | |
| 67 | 66 |
| 68 bool SendPacket(bool rtcp, | 67 bool SendPacket(bool rtcp, |
| 69 rtc::CopyOnWriteBuffer* packet, | 68 rtc::CopyOnWriteBuffer* packet, |
| 70 const rtc::PacketOptions& options, | 69 const rtc::PacketOptions& options, |
| 71 int flags) override; | 70 int flags) override; |
| 72 | 71 |
| 72 bool IsWritable(bool rtcp) const override { | |
| 73 return rtp_transport_->IsWritable(rtcp); | |
| 74 } | |
| 75 | |
| 76 // The transport becomes active if the send_session_ and recv_session_ are | |
| 77 // created. | |
| 78 bool IsActive() const; | |
| 79 | |
| 73 bool HandlesPayloadType(int payload_type) const override { | 80 bool HandlesPayloadType(int payload_type) const override { |
| 74 return rtp_transport_->HandlesPayloadType(payload_type); | 81 return rtp_transport_->HandlesPayloadType(payload_type); |
| 75 } | 82 } |
| 76 | 83 |
| 77 void AddHandledPayloadType(int payload_type) override { | 84 void AddHandledPayloadType(int payload_type) override { |
| 78 rtp_transport_->AddHandledPayloadType(payload_type); | 85 rtp_transport_->AddHandledPayloadType(payload_type); |
| 79 } | 86 } |
| 80 | 87 |
| 81 RtcpParameters GetRtcpParameters() const override { | 88 RtcpParameters GetRtcpParameters() const override { |
| 82 return rtp_transport_->GetRtcpParameters(); | 89 return rtp_transport_->GetRtcpParameters(); |
| 83 } | 90 } |
| 84 | 91 |
| 85 RTCError SetRtcpParameters(const RtcpParameters& parameters) override { | 92 RTCError SetRtcpParameters(const RtcpParameters& parameters) override { |
| 86 return rtp_transport_->SetRtcpParameters(parameters); | 93 return rtp_transport_->SetRtcpParameters(parameters); |
| 87 } | 94 } |
| 88 | 95 |
| 89 // TODO(zstein): Remove this when we remove RtpTransportAdapter. | 96 // TODO(zstein): Remove this when we remove RtpTransportAdapter. |
| 90 RtpTransportAdapter* GetInternal() override { return nullptr; } | 97 RtpTransportAdapter* GetInternal() override { return nullptr; } |
| 91 | 98 |
| 99 // Create new send/recv sessions and set the negotiated crypto keys for RTP | |
| 100 // packet encryption. The keys can either come from SDES negotiation or DTLS | |
| 101 // handshake. | |
| 102 bool SetRtpParams(int send_cs, | |
| 103 const uint8_t* send_key, | |
| 104 int send_key_len, | |
| 105 int recv_cs, | |
| 106 const uint8_t* recv_key, | |
| 107 int recv_key_len); | |
| 108 | |
| 109 // Create new send/recv sessions and set the negotiated crypto keys for RTCP | |
| 110 // packet encryption. The keys can either come from SDES negotiation or DTLS | |
| 111 // handshake. | |
| 112 bool SetRtcpParams(int send_cs, | |
| 113 const uint8_t* send_key, | |
| 114 int send_key_len, | |
| 115 int recv_cs, | |
| 116 const uint8_t* recv_key, | |
| 117 int recv_key_len); | |
| 118 | |
| 119 void ResetParams(); | |
| 120 | |
| 121 // Set the header extension ids that should be encrypted for the given source. | |
|
Taylor Brandstetter
2017/08/30 21:24:26
Can you add a comment saying that this doesn't imm
Zhi Huang
2017/08/31 17:42:41
Done.
| |
| 122 void SetEncryptedHeaderExtensionIds(cricket::ContentSource source, | |
| 123 const std::vector<int>& extension_ids); | |
| 124 | |
| 125 // If external auth is enabled, SRTP will write a dummy auth tag that then | |
| 126 // later must get replaced before the packet is sent out. Only supported for | |
| 127 // non-GCM cipher suites and can be checked through "IsExternalAuthActive" | |
| 128 // if it is actually used. This method is only valid before the RTP params | |
| 129 // have been set. | |
| 130 void EnableExternalAuth(); | |
| 131 bool IsExternalAuthEnabled() const; | |
| 132 | |
| 133 // A SrtpTransport supports external creation of the auth tag if a non-GCM | |
| 134 // cipher is used. This method is only valid after the RTP params have | |
| 135 // been set. | |
| 136 bool IsExternalAuthActive() const; | |
| 137 | |
| 138 // Returns srtp overhead for rtp packets. | |
| 139 bool GetSrtpOverhead(int* srtp_overhead) const; | |
| 140 | |
| 141 // Returns rtp auth params from srtp context. | |
| 142 bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len); | |
| 143 | |
| 144 // Helper method to get RTP Absoulute SendTime extension header id if | |
| 145 // present in remote supported extensions list. | |
| 146 void CacheRtpAbsSendTimeHeaderExtension(int rtp_abs_sendtime_extn_id) { | |
| 147 rtp_abs_sendtime_extn_id_ = rtp_abs_sendtime_extn_id; | |
| 148 } | |
| 149 | |
| 92 private: | 150 private: |
| 151 void CreateSrtpSessions(); | |
| 152 | |
| 93 void ConnectToRtpTransport(); | 153 void ConnectToRtpTransport(); |
| 94 | 154 |
| 95 void OnPacketReceived(bool rtcp, | 155 void OnPacketReceived(bool rtcp, |
| 96 rtc::CopyOnWriteBuffer* packet, | 156 rtc::CopyOnWriteBuffer* packet, |
| 97 const rtc::PacketTime& packet_time); | 157 const rtc::PacketTime& packet_time); |
| 98 | 158 |
| 99 void OnReadyToSend(bool ready) { SignalReadyToSend(ready); } | 159 void OnReadyToSend(bool ready) { SignalReadyToSend(ready); } |
| 100 | 160 |
| 161 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); | |
| 162 | |
| 163 // Overloaded version, outputs packet index. | |
| 164 bool ProtectRtp(void* data, | |
| 165 int in_len, | |
| 166 int max_len, | |
| 167 int* out_len, | |
| 168 int64_t* index); | |
| 169 bool ProtectRtcp(void* data, int in_len, int max_len, int* out_len); | |
| 170 | |
| 171 // Decrypts/verifies an invidiual RTP/RTCP packet. | |
| 172 // If an HMAC is used, this will decrease the packet size. | |
| 173 bool UnprotectRtp(void* data, int in_len, int* out_len); | |
| 174 | |
| 175 bool UnprotectRtcp(void* data, int in_len, int* out_len); | |
| 176 | |
| 101 const std::string content_name_; | 177 const std::string content_name_; |
| 178 std::unique_ptr<RtpTransportInternal> rtp_transport_; | |
| 102 | 179 |
| 103 std::unique_ptr<RtpTransportInternal> rtp_transport_; | 180 std::unique_ptr<cricket::SrtpSession> send_session_; |
| 181 std::unique_ptr<cricket::SrtpSession> recv_session_; | |
| 182 std::unique_ptr<cricket::SrtpSession> send_rtcp_session_; | |
| 183 std::unique_ptr<cricket::SrtpSession> recv_rtcp_session_; | |
| 184 | |
| 185 std::vector<int> send_encrypted_header_extension_ids_; | |
| 186 std::vector<int> recv_encrypted_header_extension_ids_; | |
| 187 bool external_auth_enabled_ = false; | |
| 188 | |
| 189 int rtp_abs_sendtime_extn_id_ = -1; | |
| 104 }; | 190 }; |
| 105 | 191 |
| 106 } // namespace webrtc | 192 } // namespace webrtc |
| 107 | 193 |
| 108 #endif // WEBRTC_PC_SRTPTRANSPORT_H_ | 194 #endif // WEBRTC_PC_SRTPTRANSPORT_H_ |
| OLD | NEW |