-
Notifications
You must be signed in to change notification settings - Fork 159
Expose DTLS version constants in SslVersion #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,6 +233,53 @@ fn test_connect_with_srtp_ssl() { | |
| assert_eq!(buf[..], buf2[..]); | ||
| } | ||
|
|
||
| /// Tests that DTLS 1.3 can be enabled and negotiated successfully. | ||
| #[test] | ||
| fn test_dtls_1_3_version() { | ||
| let listener = TcpListener::bind("127.0.0.1:0").unwrap(); | ||
| let addr = listener.local_addr().unwrap(); | ||
|
|
||
| let guard = thread::spawn(move || { | ||
| let stream = listener.accept().unwrap().0; | ||
| let mut ctx = SslContext::builder(SslMethod::dtls()).unwrap(); | ||
| ctx.set_certificate_file(Path::new("test/cert.pem"), SslFiletype::PEM) | ||
| .unwrap(); | ||
| ctx.set_private_key_file(Path::new("test/key.pem"), SslFiletype::PEM) | ||
| .unwrap(); | ||
| // Enable DTLS 1.3 | ||
| ctx.set_max_proto_version(Some(SslVersion::DTLS1_3)) | ||
| .unwrap(); | ||
| let mut ssl = Ssl::new(&ctx.build()).unwrap(); | ||
| ssl.set_mtu(1500).unwrap(); | ||
| let stream = ssl.accept(stream).unwrap(); | ||
|
|
||
| // Verify DTLS 1.3 was negotiated | ||
| let version = stream.ssl().version2().unwrap(); | ||
| assert_eq!(version, SslVersion::DTLS1_3); | ||
|
|
||
| stream | ||
| }); | ||
|
|
||
| let stream = TcpStream::connect(addr).unwrap(); | ||
| let mut ctx = SslContext::builder(SslMethod::dtls()).unwrap(); | ||
| // Enable DTLS 1.3 on client | ||
| ctx.set_max_proto_version(Some(SslVersion::DTLS1_3)) | ||
| .unwrap(); | ||
|
Comment on lines
+249
to
+267
|
||
| let mut ssl = Ssl::new(&ctx.build()).unwrap(); | ||
| ssl.set_mtu(1500).unwrap(); | ||
| let stream = ssl.connect(stream).unwrap(); | ||
|
|
||
| // Verify DTLS 1.3 was negotiated on client side | ||
| let version = stream.ssl().version2().unwrap(); | ||
| assert_eq!(version, SslVersion::DTLS1_3); | ||
|
|
||
| // Also check version string | ||
| let version_str = stream.ssl().version_str(); | ||
| assert_eq!(version_str, "DTLSv1.3"); | ||
|
|
||
| guard.join().unwrap(); | ||
| } | ||
|
|
||
| /// Tests that when the `SslStream` is created as a server stream, the protocols | ||
| /// are correctly advertised to the client. | ||
| #[test] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR adds DTLS variants to
SslVersion’sTryFrom<u16>,Debug, andDisplayimplementations, but the new behavior isn’t directly exercised by a unit test (the added DTLS negotiation test doesn’t cover formatting orTryFrom). Consider adding a small assertion-based test that validatesSslVersion::try_from(DTLS*_VERSION as u16)and the expectedDebug/Displaystrings for the new variants.