diff options
| author | Benjamin Saunders <[email protected]> | 2018-03-05 01:27:36 -0800 |
|---|---|---|
| committer | Benjamin Saunders <[email protected]> | 2018-03-09 20:33:49 -0800 |
| commit | b0bc1c770e74eff45ae71e2c30e4a6f5fbaae600 (patch) | |
| tree | 6e231241775483f0234d97998788ce69fefdd220 /openssl/src/ssl/test.rs | |
| parent | FFI for OpenSSL 1.1.1 custom extension support (diff) | |
| download | rust-openssl-b0bc1c770e74eff45ae71e2c30e4a6f5fbaae600.tar.xz rust-openssl-b0bc1c770e74eff45ae71e2c30e4a6f5fbaae600.zip | |
High-level API for OpenSSL 1.1.1 custom extension support
Diffstat (limited to 'openssl/src/ssl/test.rs')
| -rw-r--r-- | openssl/src/ssl/test.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/openssl/src/ssl/test.rs b/openssl/src/ssl/test.rs index ae8c12de..3f1e8476 100644 --- a/openssl/src/ssl/test.rs +++ b/openssl/src/ssl/test.rs @@ -1353,6 +1353,44 @@ fn no_version_overlap() { guard.join().unwrap(); } +#[test] +#[cfg(all(feature = "v111", ossl111))] +fn custom_extensions() { + static FOUND_EXTENSION: AtomicBool = ATOMIC_BOOL_INIT; + + 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::tls()).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(); + ctx.add_custom_ext( + 12345, ssl::ExtensionContext::CLIENT_HELLO, + |_, _, _| unreachable!(), + |_, _, data, _| { FOUND_EXTENSION.store(data == b"hello", Ordering::SeqCst); Ok(()) } + ).unwrap(); + let ssl = Ssl::new(&ctx.build()).unwrap(); + ssl.accept(stream).unwrap(); + }); + + let stream = TcpStream::connect(addr).unwrap(); + let mut ctx = SslContext::builder(SslMethod::tls()).unwrap(); + ctx.add_custom_ext( + 12345, ssl::ExtensionContext::CLIENT_HELLO, + |_, _, _| Ok(Some(b"hello"[..].into())), + |_, _, _, _| unreachable!() + ).unwrap(); + let ssl = Ssl::new(&ctx.build()).unwrap(); + ssl.connect(stream).unwrap(); + + guard.join().unwrap(); + assert!(FOUND_EXTENSION.load(Ordering::SeqCst)); +} + fn _check_kinds() { fn is_send<T: Send>() {} fn is_sync<T: Sync>() {} |