Skip to content

Commit 0d01841

Browse files
Harald AlvestrandWebRTC LUCI CQ
authored andcommitted
Revert "Remove code supporting the SDES crypto mode in SDP"
This reverts commit ee212a7. Reason for revert: Don't remove until downstream issues resolved Original change's description: > Remove code supporting the SDES crypto mode in SDP > > Removes the ability to accept nonencrypted answers to encrypted offers. > Fixes some logic around bundled sessions and requirement for > transport parameters. > > Bug: webrtc:11066 > Change-Id: I56d8628d223614918a1e5260fdb8a117c8c02dbd > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/236344 > Commit-Queue: Harald Alvestrand <[email protected]> > Reviewed-by: Niels Moller <[email protected]> > Cr-Commit-Position: refs/heads/main@{#35298} # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:11066 Change-Id: I0c400ceffe1b08e0be7b44abbb54c8a032128f05 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/237223 Reviewed-by: Niels Moller <[email protected]> Reviewed-by: Henrik Boström <[email protected]> Commit-Queue: Harald Alvestrand <[email protected]> Cr-Commit-Position: refs/heads/main@{#35312}
1 parent c13e786 commit 0d01841

31 files changed

+2467
-173
lines changed

api/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ rtc_library("libjingle_peerconnection_api") {
133133
sources = [
134134
"candidate.cc",
135135
"candidate.h",
136+
"crypto_params.h",
136137
"data_channel_interface.cc",
137138
"data_channel_interface.h",
138139
"dtls_transport_interface.cc",

api/crypto_params.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
3+
*
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
6+
* tree. An additional intellectual property rights grant can be found
7+
* in the file PATENTS. All contributing project authors may
8+
* be found in the AUTHORS file in the root of the source tree.
9+
*/
10+
11+
#ifndef API_CRYPTO_PARAMS_H_
12+
#define API_CRYPTO_PARAMS_H_
13+
14+
#include <string>
15+
16+
namespace cricket {
17+
18+
// Parameters for SRTP negotiation, as described in RFC 4568.
19+
// TODO(benwright) - Rename to SrtpCryptoParams as these only apply to SRTP and
20+
// not generic crypto parameters for WebRTC.
21+
struct CryptoParams {
22+
CryptoParams() : tag(0) {}
23+
CryptoParams(int t,
24+
const std::string& cs,
25+
const std::string& kp,
26+
const std::string& sp)
27+
: tag(t), cipher_suite(cs), key_params(kp), session_params(sp) {}
28+
29+
bool Matches(const CryptoParams& params) const {
30+
return (tag == params.tag && cipher_suite == params.cipher_suite);
31+
}
32+
33+
int tag;
34+
std::string cipher_suite;
35+
std::string key_params;
36+
std::string session_params;
37+
};
38+
39+
} // namespace cricket
40+
41+
#endif // API_CRYPTO_PARAMS_H_

p2p/base/transport_description.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424

2525
namespace cricket {
2626

27+
// SEC_ENABLED and SEC_REQUIRED should only be used if the session
28+
// was negotiated over TLS, to protect the inline crypto material
29+
// exchange.
30+
// SEC_DISABLED: No crypto in outgoing offer, ignore any supplied crypto.
31+
// SEC_ENABLED: Crypto in outgoing offer and answer (if supplied in offer).
32+
// SEC_REQUIRED: Crypto in outgoing offer and answer. Fail any offer with absent
33+
// or unsupported crypto.
34+
// TODO(deadbeef): Remove this or rename it to something more appropriate, like
35+
// SdesPolicy.
36+
enum SecurePolicy { SEC_DISABLED, SEC_ENABLED, SEC_REQUIRED };
37+
2738
// Whether our side of the call is driving the negotiation, or the other side.
2839
enum IceRole { ICEROLE_CONTROLLING = 0, ICEROLE_CONTROLLED, ICEROLE_UNKNOWN };
2940

p2p/base/transport_description_factory.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
namespace cricket {
2323

24-
TransportDescriptionFactory::TransportDescriptionFactory() {}
24+
TransportDescriptionFactory::TransportDescriptionFactory()
25+
: secure_(SEC_DISABLED) {}
2526

2627
TransportDescriptionFactory::~TransportDescriptionFactory() = default;
2728

@@ -46,7 +47,7 @@ std::unique_ptr<TransportDescription> TransportDescriptionFactory::CreateOffer(
4647
}
4748

4849
// If we are trying to establish a secure transport, add a fingerprint.
49-
if (IsEncrypted()) {
50+
if (secure_ == SEC_ENABLED || secure_ == SEC_REQUIRED) {
5051
// Fail if we can't create the fingerprint.
5152
// If we are the initiator set role to "actpass".
5253
if (!SetSecurityInfo(desc.get(), CONNECTIONROLE_ACTPASS)) {
@@ -89,7 +90,7 @@ std::unique_ptr<TransportDescription> TransportDescriptionFactory::CreateAnswer(
8990
// Negotiate security params.
9091
if (offer && offer->identity_fingerprint.get()) {
9192
// The offer supports DTLS, so answer with DTLS, as long as we support it.
92-
if (IsEncrypted()) {
93+
if (secure_ == SEC_ENABLED || secure_ == SEC_REQUIRED) {
9394
ConnectionRole role = CONNECTIONROLE_NONE;
9495
// If the offer does not constrain the role, go with preference.
9596
if (offer->connection_role == CONNECTIONROLE_ACTPASS) {
@@ -115,7 +116,7 @@ std::unique_ptr<TransportDescription> TransportDescriptionFactory::CreateAnswer(
115116
return NULL;
116117
}
117118
}
118-
} else if (require_transport_attributes && IsEncrypted()) {
119+
} else if (require_transport_attributes && secure_ == SEC_REQUIRED) {
119120
// We require DTLS, but the other side didn't offer it. Fail.
120121
RTC_LOG(LS_WARNING) << "Failed to create TransportDescription answer "
121122
"because of incompatible security settings";

p2p/base/transport_description_factory.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ class TransportDescriptionFactory {
4040
TransportDescriptionFactory();
4141
~TransportDescriptionFactory();
4242

43+
SecurePolicy secure() const { return secure_; }
4344
// The certificate to use when setting up DTLS.
4445
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate() const {
4546
return certificate_;
4647
}
4748

48-
// Specifies the certificate to use.
49-
// When a certificate is set, transport will be encrypted.
49+
// Specifies the transport security policy to use.
50+
void set_secure(SecurePolicy s) { secure_ = s; }
51+
// Specifies the certificate to use (only used when secure != SEC_DISABLED).
5052
void set_certificate(
5153
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
5254
certificate_ = certificate;
5355
}
5456

55-
bool IsEncrypted() const { return certificate_ != nullptr; }
56-
5757
// Creates a transport description suitable for use in an offer.
5858
std::unique_ptr<TransportDescription> CreateOffer(
5959
const TransportOptions& options,
@@ -77,6 +77,7 @@ class TransportDescriptionFactory {
7777
bool SetSecurityInfo(TransportDescription* description,
7878
ConnectionRole role) const;
7979

80+
SecurePolicy secure_;
8081
rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
8182
};
8283

p2p/base/transport_description_factory_unittest.cc

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,17 @@ class TransportDescriptionFactoryTest : public ::testing::Test {
144144
}
145145

146146
protected:
147-
void SetDtls(bool f1_dtls, bool f2_dtls) {
148-
if (f1_dtls) {
147+
void SetDtls(bool dtls) {
148+
if (dtls) {
149+
f1_.set_secure(cricket::SEC_ENABLED);
150+
f2_.set_secure(cricket::SEC_ENABLED);
149151
f1_.set_certificate(cert1_);
150-
} else {
151-
f1_.set_certificate(nullptr);
152-
}
153-
if (f2_dtls) {
154152
f2_.set_certificate(cert2_);
155153
} else {
156-
f2_.set_certificate(nullptr);
154+
f1_.set_secure(cricket::SEC_DISABLED);
155+
f2_.set_secure(cricket::SEC_DISABLED);
157156
}
158157
}
159-
void SetDtls(bool dtls) { SetDtls(dtls, dtls); }
160158

161159
cricket::IceCredentialsIterator ice_credentials_;
162160
TransportDescriptionFactory f1_;
@@ -173,19 +171,33 @@ TEST_F(TransportDescriptionFactoryTest, TestOfferDefault) {
173171
}
174172

175173
TEST_F(TransportDescriptionFactoryTest, TestOfferDtls) {
176-
SetDtls(true);
174+
f1_.set_secure(cricket::SEC_ENABLED);
175+
f1_.set_certificate(cert1_);
177176
std::string digest_alg;
178177
ASSERT_TRUE(
179178
cert1_->GetSSLCertificate().GetSignatureDigestAlgorithm(&digest_alg));
180179
std::unique_ptr<TransportDescription> desc =
181180
f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_);
182181
CheckDesc(desc.get(), "", "", "", digest_alg);
182+
// Ensure it also works with SEC_REQUIRED.
183+
f1_.set_secure(cricket::SEC_REQUIRED);
184+
desc = f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_);
185+
CheckDesc(desc.get(), "", "", "", digest_alg);
186+
}
187+
188+
// Test generating an offer with DTLS fails with no identity.
189+
TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) {
190+
f1_.set_secure(cricket::SEC_ENABLED);
191+
std::unique_ptr<TransportDescription> desc =
192+
f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_);
193+
ASSERT_TRUE(desc.get() == NULL);
183194
}
184195

185196
// Test updating an offer with DTLS to pick ICE.
186197
// The ICE credentials should stay the same in the new offer.
187198
TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) {
188-
SetDtls(true);
199+
f1_.set_secure(cricket::SEC_ENABLED);
200+
f1_.set_certificate(cert1_);
189201
std::string digest_alg;
190202
ASSERT_TRUE(
191203
cert1_->GetSSLCertificate().GetSignatureDigestAlgorithm(&digest_alg));
@@ -225,7 +237,8 @@ TEST_F(TransportDescriptionFactoryTest, TestReanswer) {
225237

226238
// Test that we handle answering an offer with DTLS with no DTLS.
227239
TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) {
228-
SetDtls(true, false);
240+
f1_.set_secure(cricket::SEC_ENABLED);
241+
f1_.set_certificate(cert1_);
229242
std::unique_ptr<TransportDescription> offer =
230243
f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_);
231244
ASSERT_TRUE(offer.get() != NULL);
@@ -234,20 +247,31 @@ TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) {
234247
CheckDesc(desc.get(), "", "", "", "");
235248
}
236249

237-
// Test that we reject answering an offer without DTLS if we have DTLS enabled.
250+
// Test that we handle answering an offer without DTLS if we have DTLS enabled,
251+
// but fail if we require DTLS.
238252
TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) {
239-
SetDtls(false, true);
253+
f2_.set_secure(cricket::SEC_ENABLED);
254+
f2_.set_certificate(cert2_);
240255
std::unique_ptr<TransportDescription> offer =
241256
f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_);
242257
ASSERT_TRUE(offer.get() != NULL);
243258
std::unique_ptr<TransportDescription> desc = f2_.CreateAnswer(
244259
offer.get(), TransportOptions(), true, NULL, &ice_credentials_);
245-
ASSERT_FALSE(desc);
260+
CheckDesc(desc.get(), "", "", "", "");
261+
f2_.set_secure(cricket::SEC_REQUIRED);
262+
desc = f2_.CreateAnswer(offer.get(), TransportOptions(), true, NULL,
263+
&ice_credentials_);
264+
ASSERT_TRUE(desc.get() == NULL);
246265
}
247266

248-
// Test that we handle answering an DTLS offer with DTLS.
267+
// Test that we handle answering an DTLS offer with DTLS, both if we have
268+
// DTLS enabled and required.
249269
TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) {
250-
SetDtls(true, true);
270+
f1_.set_secure(cricket::SEC_ENABLED);
271+
f1_.set_certificate(cert1_);
272+
273+
f2_.set_secure(cricket::SEC_ENABLED);
274+
f2_.set_certificate(cert2_);
251275
// f2_ produces the answer that is being checked in this test, so the
252276
// answer must contain fingerprint lines with cert2_'s digest algorithm.
253277
std::string digest_alg2;
@@ -260,6 +284,10 @@ TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) {
260284
std::unique_ptr<TransportDescription> desc = f2_.CreateAnswer(
261285
offer.get(), TransportOptions(), true, NULL, &ice_credentials_);
262286
CheckDesc(desc.get(), "", "", "", digest_alg2);
287+
f2_.set_secure(cricket::SEC_REQUIRED);
288+
desc = f2_.CreateAnswer(offer.get(), TransportOptions(), true, NULL,
289+
&ice_credentials_);
290+
CheckDesc(desc.get(), "", "", "", digest_alg2);
263291
}
264292

265293
// Test that ice ufrag and password is changed in an updated offer and answer
@@ -326,7 +354,11 @@ TEST_F(TransportDescriptionFactoryTest, CreateAnswerIceCredentialsIterator) {
326354
}
327355

328356
TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActpassOffer) {
329-
SetDtls(true);
357+
f1_.set_secure(cricket::SEC_ENABLED);
358+
f1_.set_certificate(cert1_);
359+
360+
f2_.set_secure(cricket::SEC_ENABLED);
361+
f2_.set_certificate(cert2_);
330362
cricket::TransportOptions options;
331363
std::unique_ptr<TransportDescription> offer =
332364
f1_.CreateOffer(options, nullptr, &ice_credentials_);
@@ -337,7 +369,11 @@ TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActpassOffer) {
337369
}
338370

339371
TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActiveOffer) {
340-
SetDtls(true);
372+
f1_.set_secure(cricket::SEC_ENABLED);
373+
f1_.set_certificate(cert1_);
374+
375+
f2_.set_secure(cricket::SEC_ENABLED);
376+
f2_.set_certificate(cert2_);
341377
cricket::TransportOptions options;
342378
std::unique_ptr<TransportDescription> offer =
343379
f1_.CreateOffer(options, nullptr, &ice_credentials_);
@@ -349,7 +385,11 @@ TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActiveOffer) {
349385
}
350386

351387
TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsPassiveOffer) {
352-
SetDtls(true);
388+
f1_.set_secure(cricket::SEC_ENABLED);
389+
f1_.set_certificate(cert1_);
390+
391+
f2_.set_secure(cricket::SEC_ENABLED);
392+
f2_.set_certificate(cert2_);
353393
cricket::TransportOptions options;
354394
std::unique_ptr<TransportDescription> offer =
355395
f1_.CreateOffer(options, nullptr, &ice_credentials_);

pc/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ rtc_library("rtc_pc_base") {
8181
"sctp_transport.h",
8282
"sctp_utils.cc",
8383
"sctp_utils.h",
84+
"srtp_filter.cc",
85+
"srtp_filter.h",
8486
"srtp_session.cc",
8587
"srtp_session.h",
8688
"srtp_transport.cc",
@@ -884,6 +886,7 @@ if (rtc_include_tests && !build_with_chromium) {
884886
"rtp_transport_unittest.cc",
885887
"sctp_transport_unittest.cc",
886888
"session_description_unittest.cc",
889+
"srtp_filter_unittest.cc",
887890
"srtp_session_unittest.cc",
888891
"srtp_transport_unittest.cc",
889892
"test/rtp_transport_test_util.h",

pc/channel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "pc/rtp_transport.h"
4848
#include "pc/rtp_transport_internal.h"
4949
#include "pc/session_description.h"
50+
#include "pc/srtp_filter.h"
5051
#include "pc/srtp_transport.h"
5152
#include "rtc_base/async_packet_socket.h"
5253
#include "rtc_base/async_udp_socket.h"

pc/dtls_srtp_transport.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <vector>
1616

1717
#include "absl/types/optional.h"
18+
#include "api/crypto_params.h"
1819
#include "api/dtls_transport_interface.h"
1920
#include "api/rtc_error.h"
2021
#include "p2p/base/dtls_transport_internal.h"
@@ -48,6 +49,15 @@ class DtlsSrtpTransport : public SrtpTransport {
4849

4950
void SetOnDtlsStateChange(std::function<void(void)> callback);
5051

52+
RTCError SetSrtpSendKey(const cricket::CryptoParams& params) override {
53+
return RTCError(RTCErrorType::UNSUPPORTED_OPERATION,
54+
"Set SRTP keys for DTLS-SRTP is not supported.");
55+
}
56+
RTCError SetSrtpReceiveKey(const cricket::CryptoParams& params) override {
57+
return RTCError(RTCErrorType::UNSUPPORTED_OPERATION,
58+
"Set SRTP keys for DTLS-SRTP is not supported.");
59+
}
60+
5161
// If `active_reset_srtp_params_` is set to be true, the SRTP parameters will
5262
// be reset whenever the DtlsTransports are reset.
5363
void SetActiveResetSrtpParams(bool active_reset_srtp_params) {

0 commit comments

Comments
 (0)