rustls/README.md

304 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/ctz/rustls/master/admin/rustls-logo-web.png">
</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's pronounced 'rustles'. It uses <a href = "https://github.com/briansmith/ring"><em>ring</em></a> for cryptography and <a href = "https://github.com/briansmith/webpki">libwebpki</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
expected. [Here's what I'm working on now](https://github.com/ctz/rustls/projects/1).
If you'd like to help out, please see [CONTRIBUTING.md](CONTRIBUTING.md).
2016-05-30 20:34:05 +00:00
[![Build Status](https://travis-ci.org/ctz/rustls.svg?branch=master)](https://travis-ci.org/ctz/rustls)
2019-03-10 17:53:03 +00:00
[![Build Status](https://dev.azure.com/ctz99/ctz/_apis/build/status/ctz.rustls?branchName=master)](https://dev.azure.com/ctz99/ctz/_build/latest?definitionId=3&branchName=master)
[![Coverage Status (codecov.io)](https://codecov.io/gh/ctz/rustls/branch/master/graph/badge.svg)](https://codecov.io/gh/ctz/rustls/)
2016-09-25 18:47:19 +00:00
[![Documentation](https://docs.rs/rustls/badge.svg)](https://docs.rs/rustls/)
2016-05-30 20:34:05 +00:00
2016-09-27 20:44:33 +00:00
## Release history:
2020-04-12 18:31:53 +00:00
* Next release:
- Allow custom certificate validation implementations to also
handle handshake signature computation. This allows uses in non-web
contexts, where `webpki` is not likely to process the certificates
in use. Thanks to @DemiMarie-parity.
- Performance improvements. Thanks to @nviennot.
2020-05-15 19:37:44 +00:00
- Fixed client authentication being unduly rejected by client when server
uses the superseded certificate_types field of CertificateRequest.
- *Breaking API change*: The writev_tls API has been removed, in favour
of using vectored IO support now offered by std::io::Write.
2020-02-22 20:38:48 +00:00
* 0.17.0 (2020-02-22):
- *Breaking API change*: ALPN protocols offered by the client are passed
to the server certificate resolution trait (`ResolvesServerCert`).
- *Breaking API change*: The server certificate resolution trait now
2019-09-15 20:35:33 +00:00
takes a struct containing its arguments, so new data can be passed
to these functions without further breaking changes.
- Signature schemes offered by the client are now filtered to those
compatible with the client-offered ciphersuites. Prior to this change
it was likely that server key type switching would not work for clients
that offer signature schemes mismatched with their ciphersuites.
2020-02-11 21:52:20 +00:00
- Add manual with goal-oriented documentation, and rationale for design
decisions.
- *Breaking API change*: `AlwaysResolvesClientCert::new` is now fallible,
as is `ClientConfig::set_single_client_cert`.
2019-08-10 08:01:15 +00:00
* 0.16.0 (2019-08-10):
2019-05-19 19:10:56 +00:00
- Optimisation of read path for polled non-blocking IO.
2019-07-06 02:38:40 +00:00
- Correct an omission in TLS1.3 middlebox compatibility mode, causing
2019-05-19 19:10:56 +00:00
handshake failures with servers behind buggy middleboxes.
2019-08-10 08:01:15 +00:00
- Move to *ring* 0.16.
- Assorted refactoring to reduce memory usage during and after
handshake.
- Update other dependencies.
2019-04-02 19:44:10 +00:00
* 0.15.2 (2019-04-02):
- Moved example code around for benefit of Fuchsia.
- Example code fixes for Windows -- Windows is now a tested platform.
- QUIC-specific bug fixes.
- Update dependencies.
2019-01-29 08:51:28 +00:00
* 0.15.1 (2019-01-29):
2019-01-27 21:03:36 +00:00
- Fix incorrect offering of SHA1.
2019-01-20 20:32:11 +00:00
* 0.15.0 (2019-01-20):
2019-01-11 22:08:05 +00:00
- Update dependencies.
- *Breaking API change*: ALPN protocols are now encoded as a `Vec<u8>`, not
a `String`. This alters the type of:
- `ClientConfig::alpn_protocols`
- `ClientConfig::set_protocols`
- `ServerConfig::alpn_protocols`
- `ServerConfig::set_protocols`
- `Session::get_alpn_protocol`
- Emit a warning when receiving an invalid SNI extension, such as one
including an IP address.
- Extended QUIC support for later QUIC drafts.
2019-01-20 12:47:22 +00:00
- Correct bug where we'd send more than one fatal alert for
handshake failure cases.
- Discontinue support for SHA1 signatures.
2019-01-20 20:32:11 +00:00
- Move to Rust 2018 edition.
2018-09-30 16:42:31 +00:00
* 0.14.0 (2018-09-30):
2018-07-31 20:18:27 +00:00
- Introduce client-side support for 0-RTT data in TLS1.3.
- Fix a bug in rustls::Stream for non-blocking transports.
2019-01-11 22:08:05 +00:00
- Move TLS1.3 support from draft 23 to final RFC8446 version.
- Don't offer (eg) TLS1.3 if no TLS1.3 suites are configured.
- Support stateful resumption in TLS1.3. Stateless resumption
was previously supported, but is not the default configuration.
2018-09-29 19:09:53 +00:00
- *Breaking API change*: `generate()` removed from `StoresServerSessions` trait.
- *Breaking API change*: `take()` added to `StoresServerSessions` trait.
* 0.13.1 (2018-08-17):
- Fix a bug in rustls::Stream for non-blocking transports
(backport).
2018-07-15 11:13:10 +00:00
* 0.13.0 (2018-07-15):
2018-04-01 15:48:17 +00:00
- Move TLS1.3 support from draft 22 to 23.
2018-05-12 19:37:58 +00:00
- Add support for `SSLKEYLOGFILE`; not enabled by default.
- Add support for basic usage in QUIC.
2018-05-23 20:19:57 +00:00
- `ServerConfig::set_single_cert` and company now report errors.
- Add support for vectored IO: `writev_tls` can now be used to
optimise system call usage.
2018-06-02 15:16:41 +00:00
- Support ECDSA signing for server and client authentication.
2018-07-15 11:13:10 +00:00
- Add type like `rustls::Stream` which owns its underlying TCP stream
and rustls session.
2018-09-30 16:42:31 +00:00
See [OLDCHANGES.md](OLDCHANGES.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.
2016-07-03 11:41:33 +00:00
* ECDSA or RSA server authentication by clients.
2018-06-02 15:16:41 +00:00
* ECDSA 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 MTU 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.
* TLS1.2 resumption via tickets (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.
2016-08-14 20:01:37 +00:00
* Client authentication by clients.
* Client authentication by servers.
2017-02-19 09:18:30 +00:00
* Extended master secret support (RFC7627).
2017-12-10 18:51:01 +00:00
* Exporters (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
The following things are broken, obsolete, badly designed, underspecified,
dangerous and/or insane. Rustls does not support:
* 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.
* AES-GCM with unsafe nonces.
There are plenty of other libraries that provide these features should you
need them.
2016-05-30 20:34:05 +00:00
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`. The interface looks like:
2016-05-30 20:34:05 +00:00
2016-09-11 16:51:51 +00:00
```tlsclient
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 [options] [--suite SUITE ...] [--proto PROTO ...] <hostname>
2016-09-11 16:51:51 +00:00
tlsclient (--version | -v)
tlsclient (--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.
--mtu MTU Limit outgoing messages to MTU 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:
```
2019-08-25 09:33:52 +00:00
$ cargo run --example tlsclient -- --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
```
2019-08-25 09:33:52 +00:00
$ cargo run --example tlsclient -- --http expired.badssl.com
2016-06-01 18:41:19 +00:00
TLS error: WebPKIError(CertExpired)
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`. The interface looks like:
2016-09-11 16:51:51 +00:00
```tlsserver
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 --certs CERTFILE --key KEYFILE [--suite SUITE ...] [--proto PROTO ...] [options] echo
tlsserver --certs CERTFILE --key KEYFILE [--suite SUITE ...] [--proto PROTO ...] [options] http
tlsserver --certs CERTFILE --key KEYFILE [--suite SUITE ...] [--proto PROTO ...] [options] forward <fport>
2016-09-11 16:51:51 +00:00
tlsserver (--version | -v)
tlsserver (--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:
```
2019-08-25 09:33:52 +00:00
$ cargo run --example tlsserver -- --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
2019-08-25 09:33:52 +00:00
$ echo hello world | cargo run --example tlsclient -- --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.