Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: webrtc/pc/srtptransport.h

Issue 2997983002: Completed the functionalities of SrtpTransport. (Closed)
Patch Set: Create the SrtpTransport by default and reset it to nullptr if the insecure RTP protocol is used. Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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. This
26 // functionality is currently implemented by SrtpFilter and BaseChannel, but 27 // functionality is currently implemented by SrtpFilter and BaseChannel, but
27 // will be moved here in the future. 28 // will be moved here in the future.
28 class SrtpTransport : public RtpTransportInternal { 29 class SrtpTransport : public RtpTransportInternal {
29 public: 30 public:
(...skipping 28 matching lines...) Expand all
58 } 59 }
59 60
60 PacketTransportInterface* GetRtcpPacketTransport() const override { 61 PacketTransportInterface* GetRtcpPacketTransport() const override {
61 return rtp_transport_->GetRtcpPacketTransport(); 62 return rtp_transport_->GetRtcpPacketTransport();
62 } 63 }
63 64
64 bool IsWritable(bool rtcp) const override { 65 bool IsWritable(bool rtcp) const override {
65 return rtp_transport_->IsWritable(rtcp); 66 return rtp_transport_->IsWritable(rtcp);
66 } 67 }
67 68
69 // The transport becomes active if the send_session_ and recv_session_ are
70 // created.
71 bool IsActive() const;
72
68 bool SendPacket(bool rtcp, 73 bool SendPacket(bool rtcp,
69 rtc::CopyOnWriteBuffer* packet, 74 rtc::CopyOnWriteBuffer* packet,
70 const rtc::PacketOptions& options, 75 const rtc::PacketOptions& options,
71 int flags) override; 76 int flags) override;
72 77
73 bool HandlesPayloadType(int payload_type) const override { 78 bool HandlesPayloadType(int payload_type) const override {
74 return rtp_transport_->HandlesPayloadType(payload_type); 79 return rtp_transport_->HandlesPayloadType(payload_type);
75 } 80 }
76 81
77 void AddHandledPayloadType(int payload_type) override { 82 void AddHandledPayloadType(int payload_type) override {
78 rtp_transport_->AddHandledPayloadType(payload_type); 83 rtp_transport_->AddHandledPayloadType(payload_type);
79 } 84 }
80 85
81 RtcpParameters GetRtcpParameters() const override { 86 RtcpParameters GetRtcpParameters() const override {
82 return rtp_transport_->GetRtcpParameters(); 87 return rtp_transport_->GetRtcpParameters();
83 } 88 }
84 89
85 RTCError SetRtcpParameters(const RtcpParameters& parameters) override { 90 RTCError SetRtcpParameters(const RtcpParameters& parameters) override {
86 return rtp_transport_->SetRtcpParameters(parameters); 91 return rtp_transport_->SetRtcpParameters(parameters);
87 } 92 }
88 93
89 // TODO(zstein): Remove this when we remove RtpTransportAdapter. 94 // TODO(zstein): Remove this when we remove RtpTransportAdapter.
90 RtpTransportAdapter* GetInternal() override { return nullptr; } 95 RtpTransportAdapter* GetInternal() override { return nullptr; }
91 96
97 // Create new send/recv sessions and set the negotiated crypto keys for RTP
98 // packet encryption. The keys can either come from SDES negotiation or DTLS
99 // handshake.
100 bool SetRtpParams(int send_cs,
101 const uint8_t* send_key,
102 int send_key_len,
103 int recv_cs,
104 const uint8_t* recv_key,
105 int recv_key_len);
106
107 // Create new send/recv sessions and set the negotiated crypto keys for RTCP
108 // packet encryption. The keys can either come from SDES negotiation or DTLS
109 // handshake.
110 bool SetRtcpParams(int send_cs,
111 const uint8_t* send_key,
112 int send_key_len,
113 int recv_cs,
114 const uint8_t* recv_key,
115 int recv_key_len);
116
117 // When the send/recv sessions have been created, just updated the crypto
118 // keys.
pthatcher 2017/08/28 21:42:56 Why do we have this split between SetRtpParams and
Zhi Huang 2017/08/29 18:40:35 SetRtpParams calls SrtpSession::SetSend/Recv; Upd
119 bool UpdateRtpParams(int send_cs,
120 const uint8_t* send_key,
121 int send_key_len,
122 int recv_cs,
123 const uint8_t* recv_key,
124 int recv_key_len);
125
126 void ResetParams();
127
128 // Set the header extension ids that should be encrypted for the given source.
129 void SetEncryptedHeaderExtensionIds(cricket::ContentSource source,
130 const std::vector<int>& extension_ids);
131
132 // If external auth is enabled, SRTP will write a dummy auth tag that then
133 // later must get replaced before the packet is sent out. Only supported for
134 // non-GCM cipher suites and can be checked through "IsExternalAuthActive"
135 // if it is actually used. This method is only valid before the RTP params
136 // have been set.
137 void EnableExternalAuth();
138 bool IsExternalAuthEnabled() const;
139
140 // A SrtpTransport supports external creation of the auth tag if a non-GCM
141 // cipher is used. This method is only valid after the RTP params have
142 // been set.
143 bool IsExternalAuthActive() const;
144
145 // Returns srtp overhead for rtp packets.
146 bool GetSrtpOverhead(int* srtp_overhead) const;
147
148 // Returns rtp auth params from srtp context.
149 bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len);
150
151 // Helper method to get RTP Absoulute SendTime extension header id if
152 // present in remote supported extensions list.
153 void CacheRtpAbsSendTimeHeaderExtension(int rtp_abs_sendtime_extn_id) {
154 rtp_abs_sendtime_extn_id_ = rtp_abs_sendtime_extn_id;
155 }
156
92 private: 157 private:
158 void CreateSrtpSessions();
159
93 void ConnectToRtpTransport(); 160 void ConnectToRtpTransport();
94 161
95 void OnPacketReceived(bool rtcp, 162 void OnPacketReceived(bool rtcp,
96 rtc::CopyOnWriteBuffer* packet, 163 rtc::CopyOnWriteBuffer* packet,
97 const rtc::PacketTime& packet_time); 164 const rtc::PacketTime& packet_time);
98 165
99 void OnReadyToSend(bool ready) { SignalReadyToSend(ready); } 166 void OnReadyToSend(bool ready) { SignalReadyToSend(ready); }
100 167
168 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len);
169
170 // Overloaded version, outputs packet index.
171 bool ProtectRtp(void* data,
172 int in_len,
173 int max_len,
174 int* out_len,
175 int64_t* index);
176 bool ProtectRtcp(void* data, int in_len, int max_len, int* out_len);
177
178 // Decrypts/verifies an invidiual RTP/RTCP packet.
179 // If an HMAC is used, this will decrease the packet size.
180 bool UnprotectRtp(void* data, int in_len, int* out_len);
181
182 bool UnprotectRtcp(void* data, int in_len, int* out_len);
183
101 const std::string content_name_; 184 const std::string content_name_;
185 std::unique_ptr<RtpTransportInternal> rtp_transport_;
102 186
103 std::unique_ptr<RtpTransportInternal> rtp_transport_; 187 std::unique_ptr<cricket::SrtpSession> send_session_;
188 std::unique_ptr<cricket::SrtpSession> recv_session_;
189 std::unique_ptr<cricket::SrtpSession> send_rtcp_session_;
190 std::unique_ptr<cricket::SrtpSession> recv_rtcp_session_;
191
192 std::vector<int> send_encrypted_header_extension_ids_;
193 std::vector<int> recv_encrypted_header_extension_ids_;
194 bool external_auth_enabled_ = false;
195
196 int rtp_abs_sendtime_extn_id_ = -1;
104 }; 197 };
105 198
106 } // namespace webrtc 199 } // namespace webrtc
107 200
108 #endif // WEBRTC_PC_SRTPTRANSPORT_H_ 201 #endif // WEBRTC_PC_SRTPTRANSPORT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698