Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Unreleased

* Add PSK (Pre-Shared Key) cipher suite for DTLS 1.2 (RFC 4279, RFC 7925)
* `PSK_AES128_CCM_8` (0xC0A8)
* Add `Dtls::new_12_psk()` constructor for PSK-only sessions
* Add `PskResolver` trait and PSK config builder methods
* Fix client to handle optional ServerKeyExchange in PSK handshakes (RFC 4279 §2)

# 0.4.3

* Fix server auto-sensing DTLS version with fragmented ClientHello #87
Expand Down
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024"
license = "MIT OR Apache-2.0"
repository = "https://github.com/algesten/dimpl"
readme = "README.md"
keywords = ["dtls", "tls", "webrtc"]
keywords = ["dtls", "tls", "webrtc", "psk"]
categories = ["network-programming", "cryptography", "security"]

# MSRV
Expand All @@ -17,13 +17,14 @@ rust-version = "1.85.0"
default = ["aws-lc-rs", "rcgen"]

# Default crypto provider
aws-lc-rs = ["dep:aws-lc-rs", "_crypto-common"]
aws-lc-rs = ["dep:aws-lc-rs", "dep:ccm", "dep:aes", "_crypto-common"]

# Pure Rust crypto provider
rust-crypto = [
"dep:aes-gcm", "dep:chacha20poly1305", "dep:chacha20", "dep:p256",
"dep:p384", "dep:x25519-dalek", "dep:sha2", "dep:hmac", "dep:hkdf",
"dep:ecdsa", "dep:generic-array", "dep:rand_core",
"dep:ccm", "dep:aes",
"_crypto-common"
]

Expand Down Expand Up @@ -68,6 +69,8 @@ generic-array = { version = "0.14", optional = true }
rand_core = { version = "0.6", optional = true }
chacha20poly1305 = { version = "0.10", optional = true }
chacha20 = { version = "0.9", optional = true }
ccm = { version = "0.5", default-features = false, optional = true }
aes = { version = "0.8", optional = true }
x25519-dalek = { version = "2", optional = true, features = ["static_secrets"] }

# certificate generation
Expand Down
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ verification and SRTP key export yourself.

### Version selection

Three constructors control which DTLS version is used:
- [`Dtls::new_12`][new_12] — explicit DTLS 1.2
Four constructors control which DTLS version is used:
- [`Dtls::new_12`][new_12] — explicit DTLS 1.2 (certificate‑based)
- [`Dtls::new_12_psk`][new_12_psk] — explicit DTLS 1.2 (PSK, no certificates)
- [`Dtls::new_13`][new_13] — explicit DTLS 1.3
- [`Dtls::new_auto`][new_auto] — auto‑sense: the first
incoming ClientHello determines the version (based on the
Expand All @@ -34,6 +35,8 @@ Three constructors control which DTLS version is used:
- `ECDHE_ECDSA_AES256_GCM_SHA384`
- `ECDHE_ECDSA_AES128_GCM_SHA256`
- `ECDHE_ECDSA_CHACHA20_POLY1305_SHA256`
- **PSK cipher suites (TLS 1.2 over DTLS)**
- `PSK_AES128_CCM_8`
- **Cipher suites (TLS 1.3 over DTLS)**
- `TLS_AES_128_GCM_SHA256`
- `TLS_AES_256_GCM_SHA384`
Expand All @@ -44,7 +47,6 @@ Three constructors control which DTLS version is used:
- **DTLS‑SRTP**: Exports keying material for `SRTP_AEAD_AES_256_GCM`,
`SRTP_AEAD_AES_128_GCM`, and `SRTP_AES128_CM_SHA1_80` ([RFC 5764], [RFC 7714]).
- **Extended Master Secret** ([RFC 7627]) is negotiated and enforced (DTLS 1.2).
- Not supported: PSK cipher suites.

### Certificate model
During the handshake the engine emits
Expand Down Expand Up @@ -131,6 +133,37 @@ let dtls = mk_dtls_client();
let _ = example_event_loop(dtls);
```

## Example (PSK client)

```rust
use std::sync::Arc;
use std::time::Instant;

use dimpl::{Config, Dtls, PskResolver};

struct MyPsk;

impl PskResolver for MyPsk {
fn resolve(&self, identity: &[u8]) -> Option<Vec<u8>> {
if identity == b"device-01" {
Some(b"shared-secret-key".to_vec())
} else {
None
}
}
}

let config = Arc::new(
Config::builder()
.with_psk_client(b"device-01".to_vec(), Arc::new(MyPsk))
.build()
.unwrap(),
);

let mut dtls = Dtls::new_12_psk(config, Instant::now());
dtls.set_active(true); // client role
```

#### MSRV
Rust 1.85.0

Expand All @@ -139,6 +172,7 @@ Rust 1.85.0
- Renegotiation is not implemented (WebRTC does full restart).

[new_12]: https://docs.rs/dimpl/latest/dimpl/struct.Dtls.html#method.new_12
[new_12_psk]: https://docs.rs/dimpl/latest/dimpl/struct.Dtls.html#method.new_12_psk
[new_13]: https://docs.rs/dimpl/latest/dimpl/struct.Dtls.html#method.new_13
[new_auto]: https://docs.rs/dimpl/latest/dimpl/struct.Dtls.html#method.new_auto
[peer_cert]: https://docs.rs/dimpl/latest/dimpl/enum.Output.html#variant.PeerCert
Expand Down
2 changes: 1 addition & 1 deletion src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl HybridClientHello {
ch_body.push(0);

// cipher_suites: 1.3 suites first, then 1.2 suites (filtered by config)
let mut suites: ArrayVec<u16, 8> = ArrayVec::new();
let mut suites: ArrayVec<u16, 16> = ArrayVec::new();
for cs in config.dtls13_cipher_suites() {
suites.push(cs.suite().as_u16());
}
Expand Down
Loading