diff options
| author | Steven Fackler <[email protected]> | 2018-03-11 15:33:42 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-03-11 15:33:42 -0700 |
| commit | 0bc7dd90343a44fdac52c03914fd71e5a8c4762e (patch) | |
| tree | 5b4ce5cde1a896abb1b65e9020e689a054777694 /openssl/src/ssl/test.rs | |
| parent | Merge pull request #863 from rohit-lshift/master (diff) | |
| parent | Merge branch 'master' into custom-extensions (diff) | |
| download | rust-openssl-0bc7dd90343a44fdac52c03914fd71e5a8c4762e.tar.xz rust-openssl-0bc7dd90343a44fdac52c03914fd71e5a8c4762e.zip | |
Merge pull request #860 from Ralith/custom-extensions
Custom extensions
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..8be3e4d6 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, + |_, _, _| -> Result<Option<&'static [u8]>, _> { 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")), + |_, _, _, _| 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>() {} |