Skip to content

Commit 05ba8d0

Browse files
authored
Expose the negotiated DTLS protocol version
1 parent cd3dde2 commit 05ba8d0

13 files changed

Lines changed: 82 additions & 3 deletions

File tree

crates/proto/src/crypto/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod dtls {
1414

1515
pub use dimpl::DtlsCertificate as DtlsCert;
1616
pub use dimpl::KeyingMaterial;
17+
pub use dimpl::ProtocolVersion;
1718
pub use dimpl::SrtpProfile;
1819
// Note: dimpl::Error is renamed to DtlsImplError to avoid conflict with str0m's DtlsError
1920
pub use dimpl::{Error as DtlsImplError, Output as DtlsOutput};

crates/proto/src/crypto/provider.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ pub trait DtlsInstance: CryptoSafe {
189189

190190
/// Return true if the instance is operating in the client role.
191191
fn is_active(&self) -> bool;
192+
193+
/// Return the negotiated DTLS protocol version. May return `None` before handshake completion.
194+
fn protocol_version(&self) -> Option<ProtocolVersion>;
192195
}
193196

194197
// ============================================================================

crypto/apple-crypto/src/dtls.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::sync::Arc;
77
use std::time::Instant;
88
use str0m_proto::crypto::CryptoError;
99
use str0m_proto::crypto::DtlsVersion;
10+
use str0m_proto::crypto::dtls::ProtocolVersion;
1011
use str0m_proto::crypto::dtls::{DtlsCert, DtlsImplError, DtlsInstance, DtlsOutput, DtlsProvider};
1112

1213
// Certificate Generation
@@ -164,6 +165,10 @@ impl DtlsInstance for AppleCryptoDtlsInstance {
164165
fn is_active(&self) -> bool {
165166
self.dtls.is_active()
166167
}
168+
169+
fn protocol_version(&self) -> Option<ProtocolVersion> {
170+
self.dtls.protocol_version()
171+
}
167172
}
168173

169174
#[cfg(test)]

crypto/aws-lc-rs/src/dtls.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::time::Instant;
55

66
use str0m_proto::crypto::CryptoError;
77
use str0m_proto::crypto::DtlsVersion;
8+
use str0m_proto::crypto::dtls::ProtocolVersion;
89
use str0m_proto::crypto::dtls::{DtlsCert, DtlsImplError, DtlsInstance, DtlsOutput, DtlsProvider};
910

1011
// ============================================================================
@@ -106,4 +107,8 @@ impl DtlsInstance for AwsLcRsDtlsInstance {
106107
fn is_active(&self) -> bool {
107108
self.dtls.is_active()
108109
}
110+
111+
fn protocol_version(&self) -> Option<ProtocolVersion> {
112+
self.dtls.protocol_version()
113+
}
109114
}

crypto/openssl/src/dtls_dimpl.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::sync::Arc;
44
use std::time::Instant;
55

66
use str0m_proto::crypto::dtls::DtlsImplError;
7+
use str0m_proto::crypto::dtls::ProtocolVersion;
78
use str0m_proto::crypto::dtls::{DtlsCert, DtlsInstance, DtlsOutput, DtlsProvider};
89
use str0m_proto::crypto::{CryptoError, DtlsVersion};
910

@@ -107,4 +108,8 @@ impl DtlsInstance for DimplDtlsInstance {
107108
fn is_active(&self) -> bool {
108109
self.dtls.is_active()
109110
}
111+
112+
fn protocol_version(&self) -> Option<ProtocolVersion> {
113+
self.dtls.protocol_version()
114+
}
110115
}

crypto/openssl/src/dtls_ossl.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use openssl::ssl::{SslOptions, SslStream, SslVerifyMode};
1313
use openssl::x509::X509;
1414

1515
use str0m_proto::DATAGRAM_MTU_TARGET;
16-
use str0m_proto::crypto::dtls::{DtlsCert, KeyingMaterial, SrtpProfile};
16+
use str0m_proto::crypto::dtls::{DtlsCert, KeyingMaterial, ProtocolVersion, SrtpProfile};
1717
use str0m_proto::crypto::dtls::{DtlsImplError, DtlsInstance, DtlsOutput, DtlsProvider};
1818
use str0m_proto::crypto::{CryptoError, DtlsVersion};
1919

@@ -611,6 +611,10 @@ impl DtlsInstance for OsslDtlsInstance {
611611
fn is_active(&self) -> bool {
612612
self.inner.is_active().unwrap_or(false)
613613
}
614+
615+
fn protocol_version(&self) -> Option<ProtocolVersion> {
616+
Some(ProtocolVersion::DTLS1_2)
617+
}
614618
}
615619

616620
// ============================================================================

crypto/rust-crypto/src/dtls.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::time::Instant;
55

66
use str0m_proto::crypto::CryptoError;
77
use str0m_proto::crypto::DtlsVersion;
8+
use str0m_proto::crypto::dtls::ProtocolVersion;
89
use str0m_proto::crypto::dtls::{DtlsCert, DtlsImplError, DtlsInstance, DtlsOutput, DtlsProvider};
910

1011
// ============================================================================
@@ -106,4 +107,8 @@ impl DtlsInstance for RustCryptoDtlsInstance {
106107
fn is_active(&self) -> bool {
107108
self.dtls.is_active()
108109
}
110+
111+
fn protocol_version(&self) -> Option<ProtocolVersion> {
112+
self.dtls.protocol_version()
113+
}
109114
}

crypto/wincrypto/src/dtls_dimpl.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::time::Instant;
55

66
use str0m_proto::crypto::CryptoError;
77
use str0m_proto::crypto::DtlsVersion;
8+
use str0m_proto::crypto::dtls::ProtocolVersion;
89
use str0m_proto::crypto::dtls::{DtlsCert, DtlsImplError, DtlsInstance, DtlsOutput, DtlsProvider};
910

1011
use dimpl::{Config, Dtls, DtlsCertificate};
@@ -97,6 +98,10 @@ impl DtlsInstance for WinCryptoDtlsInstance {
9798
fn is_active(&self) -> bool {
9899
self.dtls.is_active()
99100
}
101+
102+
fn protocol_version(&self) -> Option<ProtocolVersion> {
103+
self.dtls.protocol_version()
104+
}
100105
}
101106

102107
// ============================================================================

crypto/wincrypto/src/dtls_schannel.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::{Arc, LazyLock, Mutex};
55
use std::time::{Duration, Instant};
66
use str0m_proto::DATAGRAM_MTU_TARGET;
77
use str0m_proto::crypto::dtls::{DtlsCert, DtlsImplError, DtlsInstance, DtlsOutput, DtlsProvider};
8-
use str0m_proto::crypto::dtls::{KeyingMaterial, SrtpProfile};
8+
use str0m_proto::crypto::dtls::{KeyingMaterial, ProtocolVersion, SrtpProfile};
99
use str0m_proto::crypto::{CryptoError, DtlsVersion};
1010

1111
use crate::sys::{Certificate, Dtls, DtlsEvent};
@@ -248,4 +248,8 @@ impl DtlsInstance for WinCryptoDtlsInstance {
248248
fn is_active(&self) -> bool {
249249
self.dtls.is_client().unwrap_or(false)
250250
}
251+
252+
fn protocol_version(&self) -> Option<ProtocolVersion> {
253+
Some(ProtocolVersion::DTLS1_2)
254+
}
251255
}

src/change/direct.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::Rtc;
44
use crate::RtcError;
55
use crate::channel::ChannelId;
66
use crate::crypto::Fingerprint;
7+
use crate::crypto::dtls::ProtocolVersion;
78
use crate::media::{Media, MediaKind};
89
use crate::rtp_::MidRid;
910
use crate::rtp_::{Mid, Rid, Ssrc};
@@ -100,6 +101,15 @@ impl<'a> DirectApi<'a> {
100101
self.rtc.dtls.remote_fingerprint()
101102
}
102103

104+
/// Returns the negotiated DTLS protocol version.
105+
///
106+
/// Call this after receiving [`crate::Event::Connected`]
107+
/// to learn the negotiated DTLS version. Before the handshake completes,
108+
/// this may return `None`
109+
pub fn dtls_protocol_version(&self) -> Option<ProtocolVersion> {
110+
self.rtc.dtls.protocol_version()
111+
}
112+
103113
/// Sets the remote DTLS fingerprint.
104114
pub fn set_remote_fingerprint(&mut self, dtls_fingerprint: Fingerprint) {
105115
self.rtc.remote_fingerprint = Some(dtls_fingerprint);

0 commit comments

Comments
 (0)