tokio-openssl-0.6.3/.cargo_vcs_info.json0000644000000001120000000000100136420ustar { "git": { "sha1": "df062b7d2d0b548090d2ec4ec4fa4ccb530a61fc" } } tokio-openssl-0.6.3/.github/dependabot.yml000064400000000000000000000002210072674642500166530ustar 00000000000000version: 2 updates: - package-ecosystem: cargo directory: "/" schedule: interval: daily time: "13:00" open-pull-requests-limit: 10 tokio-openssl-0.6.3/.github/workflows/ci.yml000064400000000000000000000023010072674642500171770ustar 00000000000000name: CI on: pull_request: branches: - master push: branches: - master env: RUSTFLAGS: -D warnings RUST_BACKTRACE: 1 jobs: test: name: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install Rust run: | rustup update --no-self-update stable rustup default stable - name: Get Rust version id: rust-version run: echo "::set-output name=version:$(rustc --version)" - name: Index cache uses: actions/cache@v2 with: path: ~/.cargo/registry/index key: index-${{ github.run_id }} restore-keys: | index- - name: Create lockfile run: cargo generate-lockfile - name: Registry cache uses: actions/cache@v2 with: path: ~/.cargo/registry/cache key: registry-${{ hashFiles('Cargo.lock') }} - name: Fetch dependencies run: cargo fetch - name: Target cache uses: actions/cache@v2 with: path: target key: target-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }} - name: Test run: cargo test tokio-openssl-0.6.3/.github/workflows/rustfmt.yml000064400000000000000000000004640072674642500203200ustar 00000000000000name: Enforce Rust formatting on: push: branches: [ master ] pull_request: branches: [ master ] jobs: rustfmt: name: rustfmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: sfackler/actions/rustup@master - uses: sfackler/actions/rustfmt@master tokio-openssl-0.6.3/.gitignore000064400000000000000000000000370072674642500144600ustar 00000000000000target Cargo.lock .idea/ *.iml tokio-openssl-0.6.3/Cargo.toml0000644000000017560000000000100116570ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "tokio-openssl" version = "0.6.3" authors = ["Alex Crichton "] description = "An implementation of SSL streams for Tokio backed by OpenSSL\n" license = "MIT/Apache-2.0" repository = "https://github.com/sfackler/tokio-openssl" [dependencies.futures-util] version = "0.3" default-features = false [dependencies.openssl] version = "0.10.32" [dependencies.openssl-sys] version = "0.9" [dependencies.tokio] version = "1.0" [dev-dependencies.tokio] version = "1.0" features = ["full"] tokio-openssl-0.6.3/Cargo.toml.orig000064400000000000000000000007470072674642500153670ustar 00000000000000[package] name = "tokio-openssl" version = "0.6.3" authors = ["Alex Crichton "] license = "MIT/Apache-2.0" edition = "2018" repository = "https://github.com/sfackler/tokio-openssl" description = """ An implementation of SSL streams for Tokio backed by OpenSSL """ [dependencies] futures-util = { version = "0.3", default-features = false } openssl = "0.10.32" openssl-sys = "0.9" tokio = "1.0" [dev-dependencies] tokio = { version = "1.0", features = ["full"] } tokio-openssl-0.6.3/LICENSE-APACHE000064400000000000000000000251260072674642500144220ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2016 Tokio contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. tokio-openssl-0.6.3/LICENSE-MIT000064400000000000000000000020460072674642500141260ustar 00000000000000Copyright (c) 2016 Tokio contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tokio-openssl-0.6.3/README.md000064400000000000000000000013240072674642500137470ustar 00000000000000# tokio-openssl An implementation of SSL streams for Tokio built on top of the [`openssl` crate] [Documentation](https://docs.rs/tokio-openssl) [`openssl` crate]: https://github.com/sfackler/rust-openssl # License This project is licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. tokio-openssl-0.6.3/build.rs000064400000000000000000000004120072674642500141320ustar 00000000000000use std::env; fn main() { if let Ok(version) = env::var("DEP_OPENSSL_VERSION_NUMBER") { let version = u64::from_str_radix(&version, 16).unwrap(); if version >= 0x1_01_01_00_0 { println!("cargo:rustc-cfg=ossl111"); } } } tokio-openssl-0.6.3/src/lib.rs000064400000000000000000000217640072674642500144050ustar 00000000000000//! Async TLS streams backed by OpenSSL. //! //! This crate provides a wrapper around the [`openssl`] crate's [`SslStream`](ssl::SslStream) type //! that works with with [`tokio`]'s [`AsyncRead`] and [`AsyncWrite`] traits rather than std's //! blocking [`Read`] and [`Write`] traits. #![warn(missing_docs)] use futures_util::future; use openssl::error::ErrorStack; use openssl::ssl::{self, ErrorCode, ShutdownResult, Ssl, SslRef}; use std::fmt; use std::io::{self, Read, Write}; use std::pin::Pin; use std::slice; use std::task::{Context, Poll}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; #[cfg(test)] mod test; struct StreamWrapper { stream: S, context: usize, } impl fmt::Debug for StreamWrapper where S: fmt::Debug, { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.stream, fmt) } } impl StreamWrapper { /// # Safety /// /// Must be called with `context` set to a valid pointer to a live `Context` object, and the /// wrapper must be pinned in memory. unsafe fn parts(&mut self) -> (Pin<&mut S>, &mut Context<'_>) { debug_assert_ne!(self.context, 0); let stream = Pin::new_unchecked(&mut self.stream); let context = &mut *(self.context as *mut _); (stream, context) } } impl Read for StreamWrapper where S: AsyncRead, { fn read(&mut self, buf: &mut [u8]) -> io::Result { let (stream, cx) = unsafe { self.parts() }; let mut buf = ReadBuf::new(buf); match stream.poll_read(cx, &mut buf)? { Poll::Ready(()) => Ok(buf.filled().len()), Poll::Pending => Err(io::Error::from(io::ErrorKind::WouldBlock)), } } } impl Write for StreamWrapper where S: AsyncWrite, { fn write(&mut self, buf: &[u8]) -> io::Result { let (stream, cx) = unsafe { self.parts() }; match stream.poll_write(cx, buf) { Poll::Ready(r) => r, Poll::Pending => Err(io::Error::from(io::ErrorKind::WouldBlock)), } } fn flush(&mut self) -> io::Result<()> { let (stream, cx) = unsafe { self.parts() }; match stream.poll_flush(cx) { Poll::Ready(r) => r, Poll::Pending => Err(io::Error::from(io::ErrorKind::WouldBlock)), } } } fn cvt(r: io::Result) -> Poll> { match r { Ok(v) => Poll::Ready(Ok(v)), Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => Poll::Pending, Err(e) => Poll::Ready(Err(e)), } } fn cvt_ossl(r: Result) -> Poll> { match r { Ok(v) => Poll::Ready(Ok(v)), Err(e) => match e.code() { ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => Poll::Pending, _ => Poll::Ready(Err(e)), }, } } /// An asynchronous version of [`openssl::ssl::SslStream`]. #[derive(Debug)] pub struct SslStream(ssl::SslStream>); impl SslStream where S: AsyncRead + AsyncWrite, { /// Like [`SslStream::new`](ssl::SslStream::new). pub fn new(ssl: Ssl, stream: S) -> Result { ssl::SslStream::new(ssl, StreamWrapper { stream, context: 0 }).map(SslStream) } /// Like [`SslStream::connect`](ssl::SslStream::connect). pub fn poll_connect( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { self.with_context(cx, |s| cvt_ossl(s.connect())) } /// A convenience method wrapping [`poll_connect`](Self::poll_connect). pub async fn connect(mut self: Pin<&mut Self>) -> Result<(), ssl::Error> { future::poll_fn(|cx| self.as_mut().poll_connect(cx)).await } /// Like [`SslStream::accept`](ssl::SslStream::accept). pub fn poll_accept(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.with_context(cx, |s| cvt_ossl(s.accept())) } /// A convenience method wrapping [`poll_accept`](Self::poll_accept). pub async fn accept(mut self: Pin<&mut Self>) -> Result<(), ssl::Error> { future::poll_fn(|cx| self.as_mut().poll_accept(cx)).await } /// Like [`SslStream::do_handshake`](ssl::SslStream::do_handshake). pub fn poll_do_handshake( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { self.with_context(cx, |s| cvt_ossl(s.do_handshake())) } /// A convenience method wrapping [`poll_do_handshake`](Self::poll_do_handshake). pub async fn do_handshake(mut self: Pin<&mut Self>) -> Result<(), ssl::Error> { future::poll_fn(|cx| self.as_mut().poll_do_handshake(cx)).await } /// Like [`SslStream::read_early_data`](ssl::SslStream::read_early_data). #[cfg(ossl111)] pub fn poll_read_early_data( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { self.with_context(cx, |s| cvt_ossl(s.read_early_data(buf))) } /// A convenience method wrapping [`poll_read_early_data`](Self::poll_read_early_data). #[cfg(ossl111)] pub async fn read_early_data( mut self: Pin<&mut Self>, buf: &mut [u8], ) -> Result { future::poll_fn(|cx| self.as_mut().poll_read_early_data(cx, buf)).await } /// Like [`SslStream::write_early_data`](ssl::SslStream::write_early_data). #[cfg(ossl111)] pub fn poll_write_early_data( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { self.with_context(cx, |s| cvt_ossl(s.write_early_data(buf))) } /// A convenience method wrapping [`poll_write_early_data`](Self::poll_write_early_data). #[cfg(ossl111)] pub async fn write_early_data( mut self: Pin<&mut Self>, buf: &[u8], ) -> Result { future::poll_fn(|cx| self.as_mut().poll_write_early_data(cx, buf)).await } } impl SslStream { /// Returns a shared reference to the `Ssl` object associated with this stream. pub fn ssl(&self) -> &SslRef { self.0.ssl() } /// Returns a shared reference to the underlying stream. pub fn get_ref(&self) -> &S { &self.0.get_ref().stream } /// Returns a mutable reference to the underlying stream. pub fn get_mut(&mut self) -> &mut S { &mut self.0.get_mut().stream } /// Returns a pinned mutable reference to the underlying stream. pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut S> { unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().0.get_mut().stream) } } fn with_context(self: Pin<&mut Self>, ctx: &mut Context<'_>, f: F) -> R where F: FnOnce(&mut ssl::SslStream>) -> R, { let this = unsafe { self.get_unchecked_mut() }; this.0.get_mut().context = ctx as *mut _ as usize; let r = f(&mut this.0); this.0.get_mut().context = 0; r } } impl AsyncRead for SslStream where S: AsyncRead + AsyncWrite, { fn poll_read( self: Pin<&mut Self>, ctx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { self.with_context(ctx, |s| { // This isn't really "proper", but rust-openssl doesn't currently expose a suitable interface even though // OpenSSL itself doesn't require the buffer to be initialized. So this is good enough for now. let slice = unsafe { let buf = buf.unfilled_mut(); slice::from_raw_parts_mut(buf.as_mut_ptr().cast::(), buf.len()) }; match cvt(s.read(slice))? { Poll::Ready(nread) => { unsafe { buf.assume_init(nread); } buf.advance(nread); Poll::Ready(Ok(())) } Poll::Pending => Poll::Pending, } }) } } impl AsyncWrite for SslStream where S: AsyncRead + AsyncWrite, { fn poll_write(self: Pin<&mut Self>, ctx: &mut Context, buf: &[u8]) -> Poll> { self.with_context(ctx, |s| cvt(s.write(buf))) } fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context) -> Poll> { self.with_context(ctx, |s| cvt(s.flush())) } fn poll_shutdown(mut self: Pin<&mut Self>, ctx: &mut Context) -> Poll> { match self.as_mut().with_context(ctx, |s| s.shutdown()) { Ok(ShutdownResult::Sent) | Ok(ShutdownResult::Received) => {} Err(ref e) if e.code() == ErrorCode::ZERO_RETURN => {} Err(ref e) if e.code() == ErrorCode::WANT_READ || e.code() == ErrorCode::WANT_WRITE => { return Poll::Pending; } Err(e) => { return Poll::Ready(Err(e .into_io_error() .unwrap_or_else(|e| io::Error::new(io::ErrorKind::Other, e)))); } } self.get_pin_mut().poll_shutdown(ctx) } } tokio-openssl-0.6.3/src/test.rs000064400000000000000000000055110072674642500146060ustar 00000000000000use crate::SslStream; use futures_util::future; use openssl::ssl::{Ssl, SslAcceptor, SslConnector, SslFiletype, SslMethod}; use std::net::ToSocketAddrs; use std::pin::Pin; use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; #[tokio::test] async fn google() { let addr = "google.com:443".to_socket_addrs().unwrap().next().unwrap(); let stream = TcpStream::connect(&addr).await.unwrap(); let ssl = SslConnector::builder(SslMethod::tls()) .unwrap() .build() .configure() .unwrap() .into_ssl("google.com") .unwrap(); let mut stream = SslStream::new(ssl, stream).unwrap(); Pin::new(&mut stream).connect().await.unwrap(); stream.write_all(b"GET / HTTP/1.0\r\n\r\n").await.unwrap(); let mut buf = vec![]; stream.read_to_end(&mut buf).await.unwrap(); let response = String::from_utf8_lossy(&buf); let response = response.trim_end(); // any response code is fine assert!(response.starts_with("HTTP/1.0 ")); assert!(response.ends_with("") || response.ends_with("")); } #[tokio::test] async fn server() { let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); let server = async move { let mut acceptor = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap(); acceptor .set_private_key_file("tests/key.pem", SslFiletype::PEM) .unwrap(); acceptor .set_certificate_chain_file("tests/cert.pem") .unwrap(); let acceptor = acceptor.build(); let ssl = Ssl::new(acceptor.context()).unwrap(); let stream = listener.accept().await.unwrap().0; let mut stream = SslStream::new(ssl, stream).unwrap(); Pin::new(&mut stream).accept().await.unwrap(); let mut buf = [0; 4]; stream.read_exact(&mut buf).await.unwrap(); assert_eq!(&buf, b"asdf"); stream.write_all(b"jkl;").await.unwrap(); future::poll_fn(|ctx| Pin::new(&mut stream).poll_shutdown(ctx)) .await .unwrap() }; let client = async { let mut connector = SslConnector::builder(SslMethod::tls()).unwrap(); connector.set_ca_file("tests/cert.pem").unwrap(); let ssl = connector .build() .configure() .unwrap() .into_ssl("localhost") .unwrap(); let stream = TcpStream::connect(&addr).await.unwrap(); let mut stream = SslStream::new(ssl, stream).unwrap(); Pin::new(&mut stream).connect().await.unwrap(); stream.write_all(b"asdf").await.unwrap(); let mut buf = vec![]; stream.read_to_end(&mut buf).await.unwrap(); assert_eq!(buf, b"jkl;"); }; future::join(server, client).await; } tokio-openssl-0.6.3/tests/cert.pem000064400000000000000000000024010072674642500152670ustar 00000000000000-----BEGIN CERTIFICATE----- MIIDhTCCAm2gAwIBAgIJALClJS+cq+ykMA0GCSqGSIb3DQEBCwUAMFkxCzAJBgNV BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX aWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0xNjExMjgwNTU5 MjNaFw0yNjExMjYwNTU5MjNaMFkxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21l LVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNV BAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL4k A0mghV17MPi033tKh1IK4pM6zpzHFrgi2smU97O/kxvSbNnDoZHEdqq3AtRcjELg HeKTd02jyAHxGoRTAVORIp0p4LCCvlR7EnHH78e3vIq3lkLe5uqyujnx2NJJIrIX r5Y+Z3QuMUSAix6GreAb19KcTZG82igvh4dOQP/pmlqQsyrPpioLy50O2NuBqU5Q xyevFRHsWfe3M7ayzJBVwMpDJxg3saOETXgzMzfKtrj2Pw0mfcHQMtsPv7z85ug0 yyd9iXwwLYx2RqZ6epChsWuY2zj7Zfcis3DzbsrW8/J758KNkjZVWS9aJmDGsT3R xRlVDnIeow/SWi5qtqECAwEAAaNQME4wHQYDVR0OBBYEFNU1F6I+C06y6rN1yjn0 i/ARufw1MB8GA1UdIwQYMBaAFNU1F6I+C06y6rN1yjn0i/ARufw1MAwGA1UdEwQF MAMBAf8wDQYJKoZIhvcNAQELBQADggEBACvFmTY+QSrc9EIAtuGk20L4OHrkOoRv veMIu3PAGbrzjE0rRC1qeLqkqudlWCk+xE6nNe90tB0qyY8AOgj68K2OplrJIhqt rxJ/Ohtbepwi53Q5npRoib6f9aL+FuT0hnVtVon2ngWRizSdH/CY7vCWuJjTtlon 3J8TGPA1cnj8FtEEfF3ISd0/XCE2oar875FOscf7S0eLnORbuunCVU/RaNn25h/r 9EhvoaPZ6cSZpt7UliMkSt6b07/A2SwU5C19BS1XoqGH02P9OV0pmuJn7N/fOGer aVbDiPpb+UAUHFUSyu32iK6T2/6OuJS7MQ1cI2biB2SWgWNBTmhRF1s= -----END CERTIFICATE----- tokio-openssl-0.6.3/tests/key.pem000064400000000000000000000032500072674642500151250ustar 00000000000000-----BEGIN PRIVATE KEY----- MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC+JANJoIVdezD4 tN97SodSCuKTOs6cxxa4ItrJlPezv5Mb0mzZw6GRxHaqtwLUXIxC4B3ik3dNo8gB 8RqEUwFTkSKdKeCwgr5UexJxx+/Ht7yKt5ZC3ubqsro58djSSSKyF6+WPmd0LjFE gIsehq3gG9fSnE2RvNooL4eHTkD/6ZpakLMqz6YqC8udDtjbgalOUMcnrxUR7Fn3 tzO2ssyQVcDKQycYN7GjhE14MzM3yra49j8NJn3B0DLbD7+8/OboNMsnfYl8MC2M dkamenqQobFrmNs4+2X3IrNw827K1vPye+fCjZI2VVkvWiZgxrE90cUZVQ5yHqMP 0louarahAgMBAAECggEAd08brQCHjs/1O6orLS7n2IgyAhZ9fQzD6ckdJi5Oe8Cz K1sPqFlEMbZoi9iIcv6bmH8O4ZSM4O/rWaSTcgKvq2M/qASWE8wGZ/ZN7Y16nQRi z1xBcjZyCUUa668g0VrI5Z1NNWZ0/gbaLVTHduEli6GM/H/NgKxS67JfRXzJ9onl d6vrK+xmeHyA7QSOieEDettaNCvm+HjU8mmOb4F1pCNZktDrch5rI8EzQlmFQuq4 y50YLRZGSlK1QLjzMnT//oaP7mHjN/inzZTHBvTzhU2OjcjzEW7l4ry224Sdu/eH lhEnNk2eq+mH/yESkn3sJcmH4uYIXh8Dyvcy/uVkPQKBgQDzSC89qxT4sls9n0sL 0DfVhq1D7kEXggD/4wNA714N24N/NWi5BYUDZVh9Kxqy9SuWlFYg1L1ZNZHB02aV GJdEiFMFgRea2E5NHnhWop+qYPq5N9jD72MHmz/6swX9VGi1p5DqjzK2hWMgoih9 4ky1zxMw+P+aDaQ6xwZF1nr+mwKBgQDIFKTvaJYjqQ/lzRMIPLA3sg6RQ+Mqwt/C BZ9Oc3DGtuglV8F73i7ML2Ptg0GtVZo3NJgGzMerpNvEoc1pDCuZkzSYitcYysQQ wsailMQFCv9jJ9g28lSGKlEPYhcLejH8ZRi8jH0fObHIvgr7komNvvPIDFnw/uR8 WsgrloD1cwKBgAdlAkqVkKWehjdxSA6r3YaX+Vw/OatFQFKGy+qFXA5/xZdwQCaf jFN2GSJ01PLrkM+a4qNM1BSKFEwX6N5PSQnEOwHH0rfaK0cczfuUJdY/7F8E24nZ FOF+TouINX5lumkLFtSKVbhGhaTQSPrKjhpYmPS8HMjJ8Vv4ALDOvB5RAoGBAJAS RX3bCpmdCESKOdUplh5UyaaSgsZs0qCsWb0s5R1B4cHaAgnGwF3pFgSWCjndNRHh fkMPPAv9xv49IGMvD0ojtLDO8Pn6L9p91niFtOyIscNdkpRmRLTjTcFM+ZkbIVlE Ft7WLtbIPZt2NQRXzVLTGEmJk040zKQ63n58flm/AoGBAKt97WLeHB9S/q0dpEGX Qk+1BXRAH0/4wK9lNrSeaw+npFr8rNN9K3sIBC/XnOwhT+wbKBpOoBT3PNHbNxVr EPPQ/pPmZ1TcHc7bszJnZon2S2PFJRDN4601X1/eFoTvakBnLlt1096paaolSmCG nYED9qXuh2VzUU1GgcqPXgf/ -----END PRIVATE KEY-----