Merge pull request #40 from alexeldeib/ace/certs

fix: example server crash on insecure SSL
This commit is contained in:
Stjepan Glavina 2020-04-28 04:13:34 -07:00 committed by GitHub
commit 339b9d1849
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -107,15 +107,11 @@ My personal crate recommendation list:
## TLS certificate
Some code examples are using TLS for authentication.
To access HTTPS servers from your browser, you'll first need to import the
certificate from this repository (Chrome/Firefox):
1. Open browser settings and go to the certificate *Authorities* list.
2. Click *Import* and select `certificate.pem`.
3. Enable *Trust this CA to identify websites* and click *OK*.
4. Restart the browser (yes, you have to!) and go to [https://127.0.0.1:8001](https://127.0.0.1:8001)
Some code examples are using TLS for authentication. The repository
contains a self-signed certificate usable for testing. It should *not*
be used for real world scenarios. Browsers and tools like curl will
show this certificate as insecure. In browsers, accept the security
prompt or use `curl -k` on the command line to bypass security warnings.
The certificate file was generated using
[minica](https://github.com/jsha/minica) and

View File

@ -55,8 +55,12 @@ async fn listen(listener: Async<TcpListener>, tls: Option<TlsAcceptor>) -> Resul
}
Some(tls) => {
// In case of HTTPS, establish a secure TLS connection first.
let stream = tls.accept(stream).await?;
let stream = Arc::new(Mutex::new(stream));
let stream = tls.accept(stream).await;
if let Err(e) = stream {
println!("Failed to establish secure TLS connection: {:#?}", e);
continue;
};
let stream = Arc::new(Mutex::new(stream.unwrap()));
Task::spawn(async move { async_h1::accept(&host, stream, serve).await })
}
};