2023-05-22 15:21:48 +02:00
# HTTPS Server (using Rustls)
2018-08-08 07:34:16 +02:00
## Usage
2020-05-19 05:46:00 +02:00
### Certificate
2022-03-06 01:43:10 +01:00
We put the self-signed certificate in this directory as an example but your browser would complain that it isn't secure. So we recommend to use [`mkcert`] to trust it. To use local CA, you should run:
2020-05-19 05:46:00 +02:00
2022-02-18 04:36:04 +01:00
```sh
2020-05-19 05:46:00 +02:00
mkcert -install
```
If you want to generate your own cert/private key file, then run:
2022-02-18 04:36:04 +01:00
```sh
2020-10-25 18:12:33 +01:00
mkcert 127.0.0.1 localhost
2020-05-19 05:46:00 +02:00
```
2020-10-25 18:12:33 +01:00
For `rsa` keys use `rsa_private_keys` function instead `pkcs8_private_keys`
2022-03-06 01:43:10 +01:00
2022-01-25 09:46:35 +01:00
```rs
2020-10-25 18:12:33 +01:00
let mut keys = pkcs8_private_keys(key_file).unwrap(); // pkcs8
let mut keys = rsa_private_keys(key_file).unwrap(); // rsa
2020-07-18 23:57:15 +02:00
```
2020-05-19 05:46:00 +02:00
[`mkcert`]: https://github.com/FiloSottile/mkcert
2021-08-24 16:19:43 +02:00
### Running the Example Server
2018-08-08 07:34:16 +02:00
2022-02-18 04:36:04 +01:00
```sh
2021-08-24 16:19:43 +02:00
cd security/rustls
2021-10-06 23:28:53 +02:00
cargo run # (or ``cargo watch -x run``)
2018-08-08 07:34:16 +02:00
# Started http server: 127.0.0.1:8443
```
2022-03-06 01:43:10 +01:00
If you prefer reloading you can substitute `cargo watch -x run` . That requires you install the `cargo-watch` crate.
2021-08-24 16:19:43 +02:00
2018-08-08 07:34:16 +02:00
### web client
2022-03-06 01:43:10 +01:00
- curl: `curl -v https://127.0.0.1:8443/index.html --compressed -k`
2018-08-08 07:34:16 +02:00
- browser: [https://127.0.0.1:8443/index.html ](https://127.0.0.1:8443/index.html )