Skip to content

Commit dce1cfa

Browse files
authored
Restrict DTLS 1.2 key exchange to P-256/P-384 (for now)
1 parent dc05687 commit dce1cfa

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22

3+
* Restrict DTLS 1.2 key exchange to P-256/P-384 (for now) #70
34
* Add AEAD, encrypt_sn, and key exchange validation to CryptoProvider #68
45
* Add #[non_exhaustive] to public API enums likely to grow (breaking) #69
56
* feat: Add protocol_version() accessor to Dtls #59

src/crypto/validation/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ impl CryptoProvider {
4444
})
4545
}
4646

47+
/// Returns an iterator over key exchange groups supported for DTLS 1.2.
48+
///
49+
/// DTLS 1.2 only supports ECDHE with NIST curves:
50+
/// - P-256 (secp256r1)
51+
/// - P-384 (secp384r1)
52+
pub fn supported_dtls12_kx_groups(
53+
&self,
54+
) -> impl Iterator<Item = &'static dyn SupportedKxGroup> {
55+
self.kx_groups
56+
.iter()
57+
.copied()
58+
.filter(|kx| matches!(kx.name(), NamedGroup::Secp256r1 | NamedGroup::Secp384r1))
59+
}
60+
4761
/// Returns cipher suites compatible with a specific signature algorithm.
4862
///
4963
/// Combines provider filtering with signature algorithm compatibility.

src/dtls12/context.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,10 @@ impl CryptoContext {
160160
named_group: NamedGroup,
161161
kx_buf: &mut Buf,
162162
) -> Result<&[u8], String> {
163-
// Find the matching key exchange group from the provider
163+
// Find the matching key exchange group from the provider (DTLS 1.2 groups only)
164164
let kx_group = self
165165
.provider()
166-
.kx_groups
167-
.iter()
166+
.supported_dtls12_kx_groups()
168167
.find(|g| g.name() == named_group)
169168
.ok_or_else(|| format!("Unsupported ECDHE named group: {:?}", named_group))?;
170169

@@ -180,11 +179,10 @@ impl CryptoContext {
180179
server_public: &[u8],
181180
kx_buf: &mut Buf,
182181
) -> Result<(), String> {
183-
// Find the matching key exchange group from the provider
182+
// Find the matching key exchange group from the provider (DTLS 1.2 groups only)
184183
let kx_group = self
185184
.provider()
186-
.kx_groups
187-
.iter()
185+
.supported_dtls12_kx_groups()
188186
.find(|g| g.name() == group)
189187
.ok_or_else(|| format!("Unsupported ECDHE named group: {:?}", group))?;
190188

src/dtls12/message/extensions/supported_groups.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl SupportedGroupsExtension {
1313
/// Create a SupportedGroupsExtension from a crypto provider
1414
pub fn from_provider(provider: &CryptoProvider) -> Self {
1515
let mut groups = NamedGroupVec::new();
16-
for kx_group in provider.supported_kx_groups() {
16+
for kx_group in provider.supported_dtls12_kx_groups() {
1717
groups.push(kx_group.name());
1818
}
1919
SupportedGroupsExtension { groups }

0 commit comments

Comments
 (0)