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. 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: |
30 SrtpTransport(bool rtcp_mux_enabled, const std::string& content_name); | 31 SrtpTransport(bool rtcp_mux_enabled, const std::string& content_name); |
31 | 32 |
32 // TODO(zstein): Consider taking an RtpTransport instead of an | 33 // TODO(zstein): Consider taking an RtpTransport instead of an |
33 // RtpTransportInternal. | 34 // RtpTransportInternal. |
34 SrtpTransport(std::unique_ptr<RtpTransportInternal> transport, | 35 SrtpTransport(std::unique_ptr<RtpTransportInternal> transport, |
Taylor Brandstetter
2017/08/23 22:13:30
If we remove support for upgrading from plain RTP
Zhi Huang
2017/08/24 23:38:07
Acknowledged.
| |
35 const std::string& content_name); | 36 const std::string& content_name); |
36 | 37 |
37 void SetRtcpMuxEnabled(bool enable) override { | 38 void SetRtcpMuxEnabled(bool enable) override { |
38 rtp_transport_->SetRtcpMuxEnabled(enable); | 39 rtp_transport_->SetRtcpMuxEnabled(enable); |
39 } | 40 } |
40 | 41 |
41 rtc::PacketTransportInternal* rtp_packet_transport() const override { | 42 rtc::PacketTransportInternal* rtp_packet_transport() const override { |
42 return rtp_transport_->rtp_packet_transport(); | 43 return rtp_transport_->rtp_packet_transport(); |
43 } | 44 } |
44 | 45 |
(...skipping 13 matching lines...) Expand all Loading... | |
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 bool IsActive() const; | |
Taylor Brandstetter
2017/08/23 22:13:30
Some comments for this method and the other new me
Zhi Huang
2017/08/24 23:38:07
Done.
| |
70 | |
68 bool SendPacket(bool rtcp, | 71 bool SendPacket(bool rtcp, |
69 rtc::CopyOnWriteBuffer* packet, | 72 rtc::CopyOnWriteBuffer* packet, |
70 const rtc::PacketOptions& options, | 73 const rtc::PacketOptions& options, |
71 int flags) override; | 74 int flags) override; |
72 | 75 |
73 bool HandlesPayloadType(int payload_type) const override { | 76 bool HandlesPayloadType(int payload_type) const override { |
74 return rtp_transport_->HandlesPayloadType(payload_type); | 77 return rtp_transport_->HandlesPayloadType(payload_type); |
75 } | 78 } |
76 | 79 |
77 void AddHandledPayloadType(int payload_type) override { | 80 void AddHandledPayloadType(int payload_type) override { |
78 rtp_transport_->AddHandledPayloadType(payload_type); | 81 rtp_transport_->AddHandledPayloadType(payload_type); |
79 } | 82 } |
80 | 83 |
81 RtcpParameters GetRtcpParameters() const override { | 84 RtcpParameters GetRtcpParameters() const override { |
82 return rtp_transport_->GetRtcpParameters(); | 85 return rtp_transport_->GetRtcpParameters(); |
83 } | 86 } |
84 | 87 |
85 RTCError SetRtcpParameters(const RtcpParameters& parameters) override { | 88 RTCError SetRtcpParameters(const RtcpParameters& parameters) override { |
86 return rtp_transport_->SetRtcpParameters(parameters); | 89 return rtp_transport_->SetRtcpParameters(parameters); |
87 } | 90 } |
88 | 91 |
89 // TODO(zstein): Remove this when we remove RtpTransportAdapter. | 92 // TODO(zstein): Remove this when we remove RtpTransportAdapter. |
90 RtpTransportAdapter* GetInternal() override { return nullptr; } | 93 RtpTransportAdapter* GetInternal() override { return nullptr; } |
91 | 94 |
95 bool SetRtpParams(int send_cs, | |
96 const uint8_t* send_key, | |
97 int send_key_len, | |
98 int recv_cs, | |
99 const uint8_t* recv_key, | |
100 int recv_key_len); | |
101 | |
102 bool SetRtcpParams(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 bool UpdateRtpParams(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 void SetEncryptedHeaderExtensionIds(cricket::ContentSource source, | |
119 const std::vector<int>& extension_ids); | |
120 | |
121 // If external auth is enabled, SRTP will write a dummy auth tag that then | |
122 // later must get replaced before the packet is sent out. Only supported for | |
123 // non-GCM cipher suites and can be checked through "IsExternalAuthActive" | |
124 // if it is actually used. This method is only valid before the RTP params | |
125 // have been set. | |
126 void EnableExternalAuth(); | |
127 bool IsExternalAuthEnabled() const; | |
128 | |
129 // A SrtpTransport supports external creation of the auth tag if a non-GCM | |
130 // cipher is used. This method is only valid after the RTP params have | |
131 // been set. | |
132 bool IsExternalAuthActive() const; | |
133 | |
134 // Returns srtp overhead for rtp packets. | |
135 bool GetSrtpOverhead(int* srtp_overhead) const; | |
136 | |
137 void CacheRtpAbsSendTimeHeaderExtension(int rtp_abs_sendtime_extn_id) { | |
138 rtp_abs_sendtime_extn_id_ = rtp_abs_sendtime_extn_id; | |
139 } | |
140 | |
92 private: | 141 private: |
142 void CreateSrtpSessions(); | |
143 | |
93 void ConnectToRtpTransport(); | 144 void ConnectToRtpTransport(); |
94 | 145 |
95 void OnPacketReceived(bool rtcp, | 146 void OnPacketReceived(bool rtcp, |
96 rtc::CopyOnWriteBuffer* packet, | 147 rtc::CopyOnWriteBuffer* packet, |
97 const rtc::PacketTime& packet_time); | 148 const rtc::PacketTime& packet_time); |
98 | 149 |
99 void OnReadyToSend(bool ready) { SignalReadyToSend(ready); } | 150 void OnReadyToSend(bool ready) { SignalReadyToSend(ready); } |
100 | 151 |
152 bool ProtectRtp(void* data, int in_len, int max_len, int* out_len); | |
153 | |
154 // Overloaded version, outputs packet index. | |
155 bool ProtectRtp(void* data, | |
156 int in_len, | |
157 int max_len, | |
158 int* out_len, | |
159 int64_t* index); | |
160 bool ProtectRtcp(void* data, int in_len, int max_len, int* out_len); | |
161 | |
162 // Decrypts/verifies an invidiual RTP/RTCP packet. | |
163 // If an HMAC is used, this will decrease the packet size. | |
164 bool UnprotectRtp(void* data, int in_len, int* out_len); | |
165 | |
166 bool UnprotectRtcp(void* data, int in_len, int* out_len); | |
167 | |
168 // Returns rtp auth params from srtp context. | |
169 bool GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len); | |
170 | |
101 const std::string content_name_; | 171 const std::string content_name_; |
172 std::unique_ptr<RtpTransportInternal> rtp_transport_; | |
102 | 173 |
103 std::unique_ptr<RtpTransportInternal> rtp_transport_; | 174 std::unique_ptr<cricket::SrtpSession> send_session_; |
175 std::unique_ptr<cricket::SrtpSession> recv_session_; | |
176 std::unique_ptr<cricket::SrtpSession> send_rtcp_session_; | |
177 std::unique_ptr<cricket::SrtpSession> recv_rtcp_session_; | |
178 | |
179 std::vector<int> send_encrypted_header_extension_ids_; | |
180 std::vector<int> recv_encrypted_header_extension_ids_; | |
181 bool external_auth_enabled_ = false; | |
182 | |
183 int rtp_abs_sendtime_extn_id_ = -1; | |
104 }; | 184 }; |
105 | 185 |
106 } // namespace webrtc | 186 } // namespace webrtc |
107 | 187 |
108 #endif // WEBRTC_PC_SRTPTRANSPORT_H_ | 188 #endif // WEBRTC_PC_SRTPTRANSPORT_H_ |
OLD | NEW |