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

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

Issue 2997983002: Completed the functionalities of SrtpTransport. (Closed)
Patch Set: Fix the chromimum issue. 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
« no previous file with comments | « webrtc/pc/srtpfilter_unittest.cc ('k') | webrtc/pc/srtptransport.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
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
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
61 bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet,
62 const rtc::PacketOptions& options,
63 int flags) override;
64
65 bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet,
66 const rtc::PacketOptions& options,
67 int flags) override;
68
64 bool IsWritable(bool rtcp) const override { 69 bool IsWritable(bool rtcp) const override {
65 return rtp_transport_->IsWritable(rtcp); 70 return rtp_transport_->IsWritable(rtcp);
66 } 71 }
67 72
68 bool SendPacket(bool rtcp, 73 // The transport becomes active if the send_session_ and recv_session_ are
69 rtc::CopyOnWriteBuffer* packet, 74 // created.
70 const rtc::PacketOptions& options, 75 bool IsActive() const;
71 int flags) override;
72 76
73 bool HandlesPayloadType(int payload_type) const override { 77 bool HandlesPayloadType(int payload_type) const override {
74 return rtp_transport_->HandlesPayloadType(payload_type); 78 return rtp_transport_->HandlesPayloadType(payload_type);
75 } 79 }
76 80
77 void AddHandledPayloadType(int payload_type) override { 81 void AddHandledPayloadType(int payload_type) override {
78 rtp_transport_->AddHandledPayloadType(payload_type); 82 rtp_transport_->AddHandledPayloadType(payload_type);
79 } 83 }
80 84
81 RTCError SetParameters(const RtpTransportParameters& parameters) override { 85 RTCError SetParameters(const RtpTransportParameters& parameters) override {
82 return rtp_transport_->SetParameters(parameters); 86 return rtp_transport_->SetParameters(parameters);
83 } 87 }
84 88
85 RtpTransportParameters GetParameters() const override { 89 RtpTransportParameters GetParameters() const override {
86 return rtp_transport_->GetParameters(); 90 return rtp_transport_->GetParameters();
87 } 91 }
88 92
89 // TODO(zstein): Remove this when we remove RtpTransportAdapter. 93 // TODO(zstein): Remove this when we remove RtpTransportAdapter.
90 RtpTransportAdapter* GetInternal() override { return nullptr; } 94 RtpTransportAdapter* GetInternal() override { return nullptr; }
91 95
96 // Create new send/recv sessions and set the negotiated crypto keys for RTP
97 // packet encryption. The keys can either come from SDES negotiation or DTLS
98 // handshake.
99 bool SetRtpParams(int send_cs,
100 const uint8_t* send_key,
101 int send_key_len,
102 int recv_cs,
103 const uint8_t* recv_key,
104 int recv_key_len);
105
106 // Create new send/recv sessions and set the negotiated crypto keys for RTCP
107 // packet encryption. The keys can either come from SDES negotiation or DTLS
108 // handshake.
109 bool SetRtcpParams(int send_cs,
110 const uint8_t* send_key,
111 int send_key_len,
112 int recv_cs,
113 const uint8_t* recv_key,
114 int recv_key_len);
115
116 void ResetParams();
117
118 // Set the header extension ids that should be encrypted for the given source.
119 // This method doesn't immediately update the SRTP session with the new IDs,
120 // and you need to call SetRtpParams for that to happen.
121 void SetEncryptedHeaderExtensionIds(cricket::ContentSource source,
122 const std::vector<int>& extension_ids);
123
124 // If external auth is enabled, SRTP will write a dummy auth tag that then
125 // later must get replaced before the packet is sent out. Only supported for
126 // non-GCM cipher suites and can be checked through "IsExternalAuthActive"
127 // if it is actually used. This method is only valid before the RTP params
128 // have been set.
129 void EnableExternalAuth();
130 bool IsExternalAuthEnabled() const;
131
132 // A SrtpTransport supports external creation of the auth tag if a non-GCM
133 // cipher is used. This method is only valid after the RTP params have
134 // been set.
135 bool IsExternalAuthActive() const;
136
137 // Returns srtp overhead for rtp packets.
138 bool GetSrtpOverhead(int* srtp_overhead) const;
139
140 // Returns rtp auth params from srtp context.
141 bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len);
142
143 // Helper method to get RTP Absoulute SendTime extension header id if
144 // present in remote supported extensions list.
145 void CacheRtpAbsSendTimeHeaderExtension(int rtp_abs_sendtime_extn_id) {
146 rtp_abs_sendtime_extn_id_ = rtp_abs_sendtime_extn_id;
147 }
148
92 private: 149 private:
150 void CreateSrtpSessions();
151
93 void ConnectToRtpTransport(); 152 void ConnectToRtpTransport();
94 153
154 bool SendPacket(bool rtcp,
155 rtc::CopyOnWriteBuffer* packet,
156 const rtc::PacketOptions& options,
157 int flags);
158
95 void OnPacketReceived(bool rtcp, 159 void OnPacketReceived(bool rtcp,
96 rtc::CopyOnWriteBuffer* packet, 160 rtc::CopyOnWriteBuffer* packet,
97 const rtc::PacketTime& packet_time); 161 const rtc::PacketTime& packet_time);
98 162
99 void OnReadyToSend(bool ready) { SignalReadyToSend(ready); } 163 void OnReadyToSend(bool ready) { SignalReadyToSend(ready); }
100 164
165 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len);
166
167 // Overloaded version, outputs packet index.
168 bool ProtectRtp(void* data,
169 int in_len,
170 int max_len,
171 int* out_len,
172 int64_t* index);
173 bool ProtectRtcp(void* data, int in_len, int max_len, int* out_len);
174
175 // Decrypts/verifies an invidiual RTP/RTCP packet.
176 // If an HMAC is used, this will decrease the packet size.
177 bool UnprotectRtp(void* data, int in_len, int* out_len);
178
179 bool UnprotectRtcp(void* data, int in_len, int* out_len);
180
101 const std::string content_name_; 181 const std::string content_name_;
182 std::unique_ptr<RtpTransportInternal> rtp_transport_;
102 183
103 std::unique_ptr<RtpTransportInternal> rtp_transport_; 184 std::unique_ptr<cricket::SrtpSession> send_session_;
185 std::unique_ptr<cricket::SrtpSession> recv_session_;
186 std::unique_ptr<cricket::SrtpSession> send_rtcp_session_;
187 std::unique_ptr<cricket::SrtpSession> recv_rtcp_session_;
188
189 std::vector<int> send_encrypted_header_extension_ids_;
190 std::vector<int> recv_encrypted_header_extension_ids_;
191 bool external_auth_enabled_ = false;
192
193 int rtp_abs_sendtime_extn_id_ = -1;
104 }; 194 };
105 195
106 } // namespace webrtc 196 } // namespace webrtc
107 197
108 #endif // WEBRTC_PC_SRTPTRANSPORT_H_ 198 #endif // WEBRTC_PC_SRTPTRANSPORT_H_
OLDNEW
« no previous file with comments | « webrtc/pc/srtpfilter_unittest.cc ('k') | webrtc/pc/srtptransport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698