Skip to content

Commit 03a147e

Browse files
authored
[DTLS] Use RSA_PKCS1_1024_8192_SHA256_FOR_LEGACY_USE_ONLY for short signatures (#342)
Add support for weaker signatures for DTLS behind a flag. With this, RSA keys between 1024 and 8192 bits can be negotiated and use for DTLS by opting in. Without opting in the minimum remains 2048 bits
1 parent 5ee261c commit 03a147e

File tree

11 files changed

+37
-3
lines changed

11 files changed

+37
-3
lines changed

dtls/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
* Added support for insecure/deprecated signature verification algorithms [#342](https://github.com/webrtc-rs/webrtc/pull/342) by [@chuigda](https://github.com/chuigda).
6+
57
## v0.7.0
68

79
* Increased minimum support rust version to `1.60.0`.

dtls/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub struct Config {
5858
/// to be vulnerable.
5959
pub insecure_hashes: bool,
6060

61+
/// insecure_verification allows the use of verification algorithms that are
62+
/// known to be vulnerable or deprecated
63+
pub insecure_verification: bool,
6164
/// VerifyPeerCertificate, if not nil, is called after normal
6265
/// certificate verification by either a client or server. It
6366
/// receives the certificate provided by the peer and also a flag
@@ -112,6 +115,7 @@ impl Default for Config {
112115
psk_identity_hint: None,
113116
insecure_skip_verify: false,
114117
insecure_hashes: false,
118+
insecure_verification: false,
115119
verify_peer_certificate: None,
116120
roots_cas: rustls::RootCertStore::empty(),
117121
client_cas: rustls::RootCertStore::empty(),

dtls/src/conn/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ impl DTLSConn {
210210
client_auth: config.client_auth,
211211
local_certificates: config.certificates.clone(),
212212
insecure_skip_verify: config.insecure_skip_verify,
213+
insecure_verification: config.insecure_verification,
213214
verify_peer_certificate: config.verify_peer_certificate.take(),
214215
roots_cas: config.roots_cas,
215216
client_cert_verifier: if config.client_auth as u8

dtls/src/crypto/crypto_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ fn test_certificate_verify() -> Result<()> {
193193
.iter()
194194
.map(|x| x.0.clone())
195195
.collect::<Vec<Vec<u8>>>(),
196+
false,
196197
)?;
197198

198199
//test ED25519
@@ -214,6 +215,7 @@ fn test_certificate_verify() -> Result<()> {
214215
.iter()
215216
.map(|x| x.0.clone())
216217
.collect::<Vec<Vec<u8>>>(),
218+
false,
217219
)?;
218220

219221
Ok(())

dtls/src/crypto/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ fn verify_signature(
324324
hash_algorithm: &SignatureHashAlgorithm,
325325
remote_key_signature: &[u8],
326326
raw_certificates: &[Vec<u8>],
327+
insecure_verification: bool,
327328
) -> Result<()> {
328329
if raw_certificates.is_empty() {
329330
return Err(Error::ErrLengthMismatch);
@@ -343,14 +344,22 @@ fn verify_signature(
343344
SignatureAlgorithm::Rsa if hash_algorithm.hash == HashAlgorithm::Sha1 => {
344345
&ring::signature::RSA_PKCS1_1024_8192_SHA1_FOR_LEGACY_USE_ONLY
345346
}
346-
SignatureAlgorithm::Rsa if hash_algorithm.hash == HashAlgorithm::Sha256 => {
347-
&ring::signature::RSA_PKCS1_2048_8192_SHA256
347+
SignatureAlgorithm::Rsa if (hash_algorithm.hash == HashAlgorithm::Sha256) => {
348+
if remote_key_signature.len() < 256 && insecure_verification {
349+
&ring::signature::RSA_PKCS1_1024_8192_SHA256_FOR_LEGACY_USE_ONLY
350+
} else {
351+
&ring::signature::RSA_PKCS1_2048_8192_SHA256
352+
}
348353
}
349354
SignatureAlgorithm::Rsa if hash_algorithm.hash == HashAlgorithm::Sha384 => {
350355
&ring::signature::RSA_PKCS1_2048_8192_SHA384
351356
}
352357
SignatureAlgorithm::Rsa if hash_algorithm.hash == HashAlgorithm::Sha512 => {
353-
&ring::signature::RSA_PKCS1_2048_8192_SHA512
358+
if remote_key_signature.len() < 256 && insecure_verification {
359+
&ring::signature::RSA_PKCS1_1024_8192_SHA512_FOR_LEGACY_USE_ONLY
360+
} else {
361+
&ring::signature::RSA_PKCS1_2048_8192_SHA512
362+
}
354363
}
355364
_ => return Err(Error::ErrKeySignatureVerifyUnimplemented),
356365
};
@@ -378,12 +387,14 @@ pub(crate) fn verify_key_signature(
378387
hash_algorithm: &SignatureHashAlgorithm,
379388
remote_key_signature: &[u8],
380389
raw_certificates: &[Vec<u8>],
390+
insecure_verification: bool,
381391
) -> Result<()> {
382392
verify_signature(
383393
message,
384394
hash_algorithm,
385395
remote_key_signature,
386396
raw_certificates,
397+
insecure_verification,
387398
)
388399
}
389400

@@ -431,12 +442,14 @@ pub(crate) fn verify_certificate_verify(
431442
hash_algorithm: &SignatureHashAlgorithm,
432443
remote_key_signature: &[u8],
433444
raw_certificates: &[Vec<u8>],
445+
insecure_verification: bool,
434446
) -> Result<()> {
435447
verify_signature(
436448
handshake_bodies,
437449
hash_algorithm,
438450
remote_key_signature,
439451
raw_certificates,
452+
insecure_verification,
440453
)
441454
}
442455

dtls/src/flight/flight4.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl Flight for Flight4 {
214214
&h.algorithm,
215215
&h.signature,
216216
&state.peer_certificates,
217+
cfg.insecure_verification,
217218
) {
218219
return Err((
219220
Some(Alert {

dtls/src/flight/flight5.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ async fn initalize_cipher_suite(
709709
&h.algorithm,
710710
&h.signature,
711711
&state.peer_certificates,
712+
cfg.insecure_verification,
712713
) {
713714
return Err((
714715
Some(Alert {

dtls/src/handshaker.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub(crate) struct HandshakeConfig {
8585
pub(crate) local_certificates: Vec<Certificate>,
8686
pub(crate) name_to_certificate: HashMap<String, Certificate>,
8787
pub(crate) insecure_skip_verify: bool,
88+
pub(crate) insecure_verification: bool,
8889
pub(crate) verify_peer_certificate: Option<VerifyPeerCertificateFn>,
8990
pub(crate) roots_cas: rustls::RootCertStore,
9091
pub(crate) server_cert_verifier: Arc<dyn rustls::ServerCertVerifier>,
@@ -109,6 +110,7 @@ impl Default for HandshakeConfig {
109110
local_certificates: vec![],
110111
name_to_certificate: HashMap::new(),
111112
insecure_skip_verify: false,
113+
insecure_verification: false,
112114
verify_peer_certificate: None,
113115
roots_cas: rustls::RootCertStore::empty(),
114116
server_cert_verifier: Arc::new(rustls::WebPKIVerifier::new()),

webrtc/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ directions that should not send. [#316](https://github.com/webrtc-rs/webrtc/pull
1212
* Add support for a mime type "audio/telephone-event" (rfc4733) [#322](https://github.com/webrtc-rs/webrtc/pull/322)
1313
* Fixed a panic that would sometimes happen when collecting stats. [#327](https://github.com/webrtc-rs/webrtc/pull/327) by [@k0nserv](https://github.com/k0nserv).
1414
* Added new extension marshaller/unmarshaller for VideoOrientation, and made marshallers serializable via serde [#331](https://github.com/webrtc-rs/webrtc/pull/331) [#332](https://github.com/webrtc-rs/webrtc/pull/332)
15+
* Added support for insecure/deprecated signature verification algorithms [#342](https://github.com/webrtc-rs/webrtc/pull/342).
1516
* Updated minimum rust version to `1.60.0`
1617
* Added a new `write_rtp_with_extensions` method to `TrackLocalStaticSample` and `TrackLocalStaticRTP`. [#336](https://github.com/webrtc-rs/webrtc/pull/336) by [@k0nserv](https://github.com/k0nserv).
1718
* Added a new `sample_writer` helper to `TrackLocalStaticSample`. [#336](https://github.com/webrtc-rs/webrtc/pull/336) by [@k0nserv](https://github.com/k0nserv).

webrtc/src/api/setting_engine/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub struct SettingEngine {
6565
pub(crate) sdp_media_level_fingerprints: bool,
6666
pub(crate) answering_dtls_role: DTLSRole,
6767
pub(crate) disable_certificate_fingerprint_verification: bool,
68+
pub(crate) allow_insecure_verification_algorithm: bool,
6869
pub(crate) disable_srtp_replay_protection: bool,
6970
pub(crate) disable_srtcp_replay_protection: bool,
7071
pub(crate) vnet: Option<Arc<Net>>,
@@ -246,6 +247,11 @@ impl SettingEngine {
246247
self.disable_certificate_fingerprint_verification = is_disabled;
247248
}
248249

250+
/// allow_insecure_verification_algorithm allows the usage of certain signature verification
251+
/// algorithm that are known to be vulnerable or deprecated.
252+
pub fn allow_insecure_verification_algorithm(&mut self, is_allowed: bool) {
253+
self.allow_insecure_verification_algorithm = is_allowed;
254+
}
249255
/// set_dtls_replay_protection_window sets a replay attack protection window size of dtls_transport connection.
250256
pub fn set_dtls_replay_protection_window(&mut self, n: usize) {
251257
self.replay_protection.dtls = n;

0 commit comments

Comments
 (0)