rustls/README.md

299 lines
12 KiB
Markdown
Raw Permalink Normal View History

2019-12-12 05:57:24 +00:00
<p align="center">
<img width="460" height="300" src="https://raw.githubusercontent.com/rustls/rustls/main/admin/rustls-logo-web.png">
2019-12-12 05:57:24 +00:00
</p>
2018-06-03 12:04:13 +00:00
2019-12-12 05:57:24 +00:00
<p align="center">
Rustls is a modern TLS library written in Rust. It uses <a href = "https://github.com/briansmith/ring"><em>ring</em></a> for cryptography and <a href = "https://github.com/briansmith/webpki">webpki</a> for certificate
2016-05-30 20:34:05 +00:00
verification.
2019-12-12 05:57:24 +00:00
</p>
2016-05-30 20:34:05 +00:00
# Status
Rustls is ready for use. There are no major breaking interface changes
2021-06-20 16:23:10 +00:00
envisioned after the set included in the 0.20 release.
If you'd like to help out, please see [CONTRIBUTING.md](CONTRIBUTING.md).
2016-05-30 20:34:05 +00:00
[![Build Status](https://github.com/rustls/rustls/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/rustls/rustls/actions/workflows/build.yml?query=branch%3Amain)
[![Coverage Status (codecov.io)](https://codecov.io/gh/rustls/rustls/branch/main/graph/badge.svg)](https://codecov.io/gh/rustls/rustls/)
2016-09-25 18:47:19 +00:00
[![Documentation](https://docs.rs/rustls/badge.svg)](https://docs.rs/rustls/)
[![Chat](https://img.shields.io/discord/976380008299917365?logo=discord)](https://discord.gg/MCSB76RU96)
2016-05-30 20:34:05 +00:00
## Release history
2016-09-27 20:44:33 +00:00
* Next release
2020-11-22 13:22:18 +00:00
- Planned: removal of unused signature verification schemes at link-time.
2023-01-12 15:54:32 +00:00
* 0.20.8 (2023-01-12)
2022-11-16 12:08:51 +00:00
- Yield an error from `ConnectionCommon::read_tls()` if buffers are full.
Both a full deframer buffer and a full incoming plaintext buffer will
now cause an error to be returned. Callers should call `process_new_packets()`
2023-01-12 15:54:32 +00:00
and read out the plaintext data from `reader()` after each successful call to `read_tls()`.
2023-01-10 23:13:56 +00:00
- The minimum supported Rust version is now 1.57.0 due to some dependencies
requiring it.
2022-10-15 14:42:36 +00:00
* 0.20.7 (2022-10-18)
- Expose secret extraction API under the `secret_extraction` cargo feature.
This is designed to enable switching from rustls to kTLS (kernel TLS
offload) after a successful TLS 1.2/1.3 handshake, for example.
- Move filtering of signature schemes after config selection, avoiding the need
for linking in encryption/decryption code for all cipher suites at the cost of
exposing more signature schemes in the `ClientHello` emitted by the `Acceptor`.
- Expose AlertDescription, ContentType, and HandshakeType,
SignatureAlgorithm, and NamedGroup as part of the stable API. Previously they
were part of the unstable internals API, but were referenced by parts of the
stable API.
2022-10-15 14:42:36 +00:00
- We now have a [Discord channel](https://discord.gg/MCSB76RU96) for community
discussions.
- The minimum supported Rust version is now 1.56.0 due to several dependencies
requiring it.
2022-05-18 07:30:33 +00:00
* 0.20.6 (2022-05-18)
- 0.20.5 included a change to track more context for the `Error::CorruptMessage`
which made API-incompatible changes to the `Error` type. We yanked 0.20.5
and have reverted that change as part of 0.20.6.
2022-05-14 17:12:55 +00:00
* 0.20.5 (2022-05-14)
- Correct compatbility with servers which return no TLS extensions and take
advantage of a special case encoding.
- Remove spurious warn-level logging introduced in 0.20.3.
2022-05-18 07:30:33 +00:00
- Expose cipher suites in `ClientHello` type.
- Allow verification of IP addresses with `dangerous_config` enabled.
- Retry I/O operations in `ConnectionCommon::complete_io()` when interrupted.
2022-05-14 17:12:55 +00:00
- Fix server::ResolvesServerCertUsingSni case sensitivity.
2022-02-19 08:18:10 +00:00
* 0.20.4 (2022-02-19)
- Correct regression in QUIC 0-RTT support.
2022-02-13 14:59:33 +00:00
* 0.20.3 (2022-02-13)
- Support loading ECDSA keys in SEC1 format.
- Support receipt of 0-RTT "early data" in TLS1.3 servers. It is not enabled
by default; opt in by setting `ServerConfig::max_early_data_size` to a non-zero
value.
- Support sending of data with the first server flight. This is also not
enabled by default either: opt in by setting `ServerConfig::send_half_rtt_data`.
- Support `read_buf` interface when compiled with nightly. This means
data can be safely read out of a rustls connection into a buffer without
the buffer requiring initialisation first. Set the `read_buf` feature to
use this.
- Improve efficiency when writing vectors of TLS types.
- Reduce copying and improve efficiency in TLS1.2 handshake.
2021-11-21 10:33:39 +00:00
* 0.20.2 (2021-11-21)
2021-11-15 21:17:48 +00:00
- Fix `CipherSuite::as_str()` value (as introduced in 0.20.1).
2021-11-14 16:40:58 +00:00
* 0.20.1 (2021-11-14)
- Allow cipher suite enum items to be stringified.
- Improve documentation of configuration builder types.
- Ensure unused cipher suites can be removed at link-time.
- Ensure single-use error types implement `std::error::Error`, and are public.
2018-09-30 16:42:31 +00:00
See [RELEASE_NOTES.md](RELEASE_NOTES.md) for further change history.
2016-09-27 20:44:33 +00:00
2016-06-21 00:49:25 +00:00
# Documentation
2016-08-28 21:33:19 +00:00
Lives here: https://docs.rs/rustls/
2016-06-21 00:49:25 +00:00
2016-05-30 20:34:05 +00:00
# Approach
2016-07-03 11:41:33 +00:00
Rustls is a TLS library that aims to provide a good level of cryptographic security,
requires no configuration to achieve that security, and provides no unsafe features or
obsolete cryptography.
## Current features
2018-08-11 14:26:01 +00:00
* TLS1.2 and TLS1.3.
2020-06-21 09:58:01 +00:00
* ECDSA, Ed25519 or RSA server authentication by clients.
* ECDSA, Ed25519 or RSA server authentication by servers.
2016-07-03 11:41:33 +00:00
* Forward secrecy using ECDHE; with curve25519, nistp256 or nistp384 curves.
* AES128-GCM and AES256-GCM bulk encryption, with safe nonces.
* ChaCha20-Poly1305 bulk encryption ([RFC7905](https://tools.ietf.org/html/rfc7905)).
2016-07-03 11:41:33 +00:00
* ALPN support.
* SNI support.
* Tunable fragment size to make TLS messages match size of underlying transport.
2018-06-02 15:16:41 +00:00
* Optional use of vectored IO to minimise system calls.
2017-01-30 21:22:07 +00:00
* TLS1.2 session resumption.
2021-03-17 08:49:57 +00:00
* TLS1.2 resumption via tickets ([RFC5077](https://tools.ietf.org/html/rfc5077)).
2018-06-02 15:16:41 +00:00
* TLS1.3 resumption via tickets or session storage.
2018-08-11 14:26:01 +00:00
* TLS1.3 0-RTT data for clients.
* TLS1.3 0-RTT data for servers.
2016-08-14 20:01:37 +00:00
* Client authentication by clients.
* Client authentication by servers.
2021-03-17 08:49:57 +00:00
* Extended master secret support ([RFC7627](https://tools.ietf.org/html/rfc7627)).
* Exporters ([RFC5705](https://tools.ietf.org/html/rfc5705)).
2017-07-16 16:25:39 +00:00
* OCSP stapling by servers.
* SCT stapling by servers.
* SCT verification by clients.
2016-07-03 11:41:33 +00:00
## Possible future features
* PSK support.
2017-07-16 16:25:39 +00:00
* OCSP verification by clients.
2016-07-03 11:41:33 +00:00
* Certificate pinning.
## Non-features
For reasons [explained in the manual](https://docs.rs/rustls/latest/rustls/manual/_02_tls_vulnerabilities/index.html),
rustls does not and will not support:
2016-07-03 11:41:33 +00:00
* SSL1, SSL2, SSL3, TLS1 or TLS1.1.
* RC4.
* DES or triple DES.
* EXPORT ciphersuites.
* MAC-then-encrypt ciphersuites.
* Ciphersuites without forward secrecy.
* Renegotiation.
* Kerberos.
* Compression.
* Discrete-log Diffie-Hellman.
* Automatic protocol version downgrade.
There are plenty of other libraries that provide these features should you
need them.
2016-05-30 20:34:05 +00:00
### Platform support
Rustls uses [`ring`](https://crates.io/crates/ring) for implementing the
cryptography in TLS. As a result, rustls only runs on platforms
[supported by `ring`](https://github.com/briansmith/ring#online-automated-testing).
At the time of writing this means x86, x86-64, armv7, and aarch64.
Rustls requires Rust 1.56 or later.
2016-07-03 12:09:48 +00:00
# Example code
There are two example programs which use
2016-11-08 14:35:53 +00:00
[mio](https://github.com/carllerche/mio) to do asynchronous IO.
2016-05-30 20:34:05 +00:00
2016-07-03 11:41:33 +00:00
## Client example program
The client example program is named `tlsclient-mio`. The interface looks like:
2016-05-30 20:34:05 +00:00
```tlsclient-mio
2016-07-03 11:41:33 +00:00
Connects to the TLS server at hostname:PORT. The default PORT
is 443. By default, this reads a request from stdin (to EOF)
before making the connection. --http replaces this with a
basic HTTP GET request for /.
If --cafile is not supplied, a built-in set of CA certificates
are used from the webpki-roots crate.
2016-07-03 11:41:33 +00:00
Usage:
tlsclient-mio [options] [--suite SUITE ...] [--proto PROTO ...] [--protover PROTOVER ...] <hostname>
tlsclient-mio (--version | -v)
tlsclient-mio (--help | -h)
2016-07-03 11:41:33 +00:00
Options:
2016-09-11 16:51:51 +00:00
-p, --port PORT Connect to PORT [default: 443].
2016-07-03 11:41:33 +00:00
--http Send a basic HTTP GET request for /.
--cafile CAFILE Read root certificates from CAFILE.
--auth-key KEY Read client authentication key from KEY.
--auth-certs CERTS Read client authentication certificates from CERTS.
CERTS must match up with KEY.
--protover VERSION Disable default TLS version list, and use
VERSION instead. May be used multiple times.
2016-07-03 11:41:33 +00:00
--suite SUITE Disable default cipher suite list, and use
SUITE instead. May be used multiple times.
2016-07-03 11:41:33 +00:00
--proto PROTOCOL Send ALPN extension containing PROTOCOL.
May be used multiple times to offer several protocols.
2016-07-03 11:41:33 +00:00
--cache CACHE Save session cache to file CACHE.
2016-09-11 16:51:51 +00:00
--no-tickets Disable session ticket support.
2018-04-01 15:48:17 +00:00
--no-sni Disable server name indication support.
2017-08-12 20:31:10 +00:00
--insecure Disable certificate verification.
2016-07-03 11:41:33 +00:00
--verbose Emit log output.
--max-frag-size M Limit outgoing messages to M bytes.
2016-09-11 16:51:51 +00:00
--version, -v Show tool version.
--help, -h Show this screen.
2016-07-03 11:41:33 +00:00
```
Some sample runs:
```
$ cargo run --bin tlsclient-mio -- --http mozilla-modern.badssl.com
2016-06-01 18:41:19 +00:00
HTTP/1.1 200 OK
2016-05-30 20:34:05 +00:00
Server: nginx/1.6.2 (Ubuntu)
2016-06-01 18:41:19 +00:00
Date: Wed, 01 Jun 2016 18:44:00 GMT
2016-05-30 20:34:05 +00:00
Content-Type: text/html
Content-Length: 644
2016-07-03 11:41:33 +00:00
(...)
2016-05-30 20:34:05 +00:00
```
or
```
$ cargo run --bin tlsclient-mio -- --http expired.badssl.com
2021-04-09 08:09:10 +00:00
TLS error: WebPkiError(CertExpired, ValidateServerCert)
2016-06-01 18:41:19 +00:00
Connection closed
2016-05-30 20:34:05 +00:00
```
2016-07-03 11:41:33 +00:00
## Server example program
The server example program is named `tlsserver-mio`. The interface looks like:
2016-07-03 11:41:33 +00:00
```tlsserver-mio
2016-07-03 11:41:33 +00:00
Runs a TLS server on :PORT. The default PORT is 443.
`echo' mode means the server echoes received data on each connection.
2017-08-12 20:31:10 +00:00
`http' mode means the server blindly sends a HTTP response on each
connection.
2016-07-03 11:41:33 +00:00
`forward' means the server forwards plaintext to a connection made to
localhost:fport.
2017-08-12 20:31:10 +00:00
`--certs' names the full certificate chain, `--key' provides the
RSA private key.
2016-07-03 11:41:33 +00:00
Usage:
tlsserver-mio --certs CERTFILE --key KEYFILE [--suite SUITE ...] [--proto PROTO ...] [--protover PROTOVER ...] [options] echo
tlsserver-mio --certs CERTFILE --key KEYFILE [--suite SUITE ...] [--proto PROTO ...] [--protover PROTOVER ...] [options] http
tlsserver-mio --certs CERTFILE --key KEYFILE [--suite SUITE ...] [--proto PROTO ...] [--protover PROTOVER ...] [options] forward <fport>
tlsserver-mio (--version | -v)
tlsserver-mio (--help | -h)
2016-07-03 11:41:33 +00:00
Options:
2016-09-11 16:51:51 +00:00
-p, --port PORT Listen on PORT [default: 443].
2016-07-03 11:41:33 +00:00
--certs CERTFILE Read server certificates from CERTFILE.
This should contain PEM-format certificates
in the right order (the first certificate should
certify KEYFILE, the last should be a root CA).
2016-09-11 16:51:51 +00:00
--key KEYFILE Read private key from KEYFILE. This should be a RSA
2017-08-12 20:31:10 +00:00
private key or PKCS8-encoded private key, in PEM format.
--ocsp OCSPFILE Read DER-encoded OCSP response from OCSPFILE and staple
to certificate. Optional.
--auth CERTFILE Enable client authentication, and accept certificates
signed by those roots provided in CERTFILE.
--require-auth Send a fatal alert if the client does not complete client
authentication.
2016-09-11 16:51:51 +00:00
--resumption Support session resumption.
2016-09-20 01:15:26 +00:00
--tickets Support tickets.
--protover VERSION Disable default TLS version list, and use
VERSION instead. May be used multiple times.
2016-07-03 11:41:33 +00:00
--suite SUITE Disable default cipher suite list, and use
SUITE instead. May be used multiple times.
2016-07-03 11:41:33 +00:00
--proto PROTOCOL Negotiate PROTOCOL using ALPN.
May be used multiple times.
2016-07-03 11:41:33 +00:00
--verbose Emit log output.
2016-09-11 16:51:51 +00:00
--version, -v Show tool version.
--help, -h Show this screen.
2016-07-03 11:41:33 +00:00
```
Here's a sample run; we start a TLS echo server, then connect to it with
`openssl` and `tlsclient-mio`:
2016-07-03 11:41:33 +00:00
```
$ cargo run --bin tlsserver-mio -- --certs test-ca/rsa/end.fullchain --key test-ca/rsa/end.rsa -p 8443 echo &
2016-07-03 11:41:33 +00:00
$ echo hello world | openssl s_client -ign_eof -quiet -connect localhost:8443
depth=2 CN = ponytown RSA CA
verify error:num=19:self signed certificate in certificate chain
hello world
^C
$ echo hello world | cargo run --bin tlsclient-mio -- --cafile test-ca/rsa/ca.cert -p 8443 localhost
2016-07-03 11:41:33 +00:00
hello world
^C
```
2016-06-19 16:42:57 +00:00
# License
Rustls is distributed under the following three licenses:
- Apache License version 2.0.
- MIT license.
- ISC license.
These are included as LICENSE-APACHE, LICENSE-MIT and LICENSE-ISC
respectively. You may use this software under the terms of any
of these licenses, at your option.
# Code of conduct
This project adopts the [Rust Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct).
Please email rustls-mod@googlegroups.com to report any instance of misconduct, or if you
have any comments or questions on the Code of Conduct.