Commit Graph

17819 Commits

Author SHA1 Message Date
Pascal Knecht 5e579ebe8f tls-test: Load keys of any type
Only RSA keys were possible until now.
2021-02-12 14:35:23 +01:00
Pascal Knecht 34f66ce6cb tls-crypto: Support EdDSA keys with ECDSA cipher suites
Ed25519 and Ed448 are now usable in all TLS versions for connections that
use an ECDSA cipher suite, as per RFC 8422.
2021-02-12 14:35:23 +01:00
Pascal Knecht 9803fb82f4 tls-server: Consider supported signature algorithms when selecting key/certificate
This won't work if the client doesn't send a `signature_algorithms`
extension.  But since the default is SHA1/RSA, most will send it to at
least announce stronger hash algorithms if not ECDSA.
2021-02-12 14:35:23 +01:00
Pascal Knecht 06112f3fe2 tls-crypto: Distinguish between signing and verifying signature schemes
strongSwan supports RSA_PSS_RSAE schemes for signing but does not
differentiate between rsaEncryption and rsassaPss encoding. Thus
RSA_PSS_PSS schemes are only used for verifying signatures.
2021-02-12 14:35:23 +01:00
Pascal Knecht e731396280 tls-server: Check if peer sent hash and signature algorithms
It is mandatory to receive the `signature_algorithms` extension when a
server is authenticating with a certificate, which is always the case.
2021-02-12 14:35:23 +01:00
Pascal Knecht 91c9e4d576 tls-crypto: Add missing signature scheme constants
Some peers, e.g. Firefox, send a wide range of signature algorithms. To
prevent numeric identifiers in the log these algorithms are added here.
2021-02-12 14:35:23 +01:00
Pascal Knecht 0dfe1590b6 tls-server: Fix invalid signature algorithm and supported groups parsing
The extension's content length field was wrongly added to the content data.

Fixes: 06109c4717 ("Implemented "signature algorithm" hello extension")
2021-02-12 14:35:23 +01:00
Pascal Knecht 3767a4a655 tls-server: Support multiple client key shares
A client can send one or multiple key shares from which the server picks
one it supports (checked in its preferred order).  A retry is requested if
none of the key shares are supported.
2021-02-12 14:35:23 +01:00
Pascal Knecht 64e2506f5b libtls: Add TLS version negotiation test cases
These client to server negotiation test cases are implemented:
- TLS 1.0 => TLS 1.3
- TLS 1.1 => TLS 1.3
- TLS 1.2 => TLS 1.3
- TLS 1.3 => TLS 1.3

- TLS 1.3 => TLS 1.0
- TLS 1.3 => TLS 1.1
- TLS 1.3 => TLS 1.2
- TLS 1.3 => TLS 1.3

- TLS 1.0 => TLS 1.2
- TLS 1.1 => TLS 1.2
- TLS 1.2 => TLS 1.2
- TLS 1.3 => TLS 1.2
2021-02-12 14:35:23 +01:00
Pascal Knecht c3e7132468 tls-server: Support HelloRetryRequest (HRR)
Adds support to request and handle retries with a different DH group.

Only the first key share extension sent by the client is currently
considered, so this might result in protocol errors if the server requests
a group for which the client already sent a key share.
2021-02-12 14:35:23 +01:00
Pascal Knecht e53bee9dbe tls-crypto: Add support to configure DH groups to use
And add new test cases to test TLS 1.3 connections for each supported DH
group.
2021-02-12 14:35:23 +01:00
Tobias Brunner 9514aa2dcc diffie-hellman: Add enum names that match proposal keywords 2021-02-12 14:35:23 +01:00
Pascal Knecht 066ac8809c tls-crypto: Generalizing DH group to TLS group mapping
This simplifies writing the key share extension as the TLS group does
not have to be cached.
2021-02-12 14:35:23 +01:00
Pascal Knecht ab70f68cf9 tls-server: Support KeyUpdate requests and answers 2021-02-12 14:35:23 +01:00
Pascal Knecht 5c4cb40e47 tls-server: Refactor writing of key share extensions
Client and server now share the same code to write this extension.
2021-02-12 14:35:23 +01:00
Pascal Knecht 7fbe2e27ec tls-server: TLS 1.3 support for TLS server implementation
Add basic support to establish a TLS 1.3 connection with a client capable
of the same protocol version.
2021-02-12 14:35:23 +01:00
Pascal Knecht 328d7af6d2 tls-crypto: Rename parameter to be more consistent
Also add missing parameter in documentation of calculate_finished method.
2021-02-12 14:35:23 +01:00
Pascal Knecht 6549adb608 tls-crypto: Fix invalid signature algorithm list building
List building also added an additional length field which is required by
client-side TLS extensions but not for server-side certificate request
extension. Now the method only returns a list of supported signature
algorithms and the implementation is responsible to add additional
length fields.

Fixes: 07f826af67 ("Fixed encoding of TLS extensions (elliptic_curves and signature_algorithms)")
2021-02-12 14:35:23 +01:00
Pascal Knecht f81c04e9e3 libtls: Add missing cipher suite and TLS extension constants
- TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
- TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
- TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256

- Encrypt then MAC
- Extended master secret
- Session ticket

and also add missing suites in the unit test.
2021-02-12 14:35:23 +01:00
Pascal Knecht d107198fcb tls-crypto: Rework cipher suite preference order
The reworked list follows the order of modern browsers such as
Firefox. The new order prefers more secure ciphers over weaker ones.
2021-02-12 14:35:23 +01:00
Tobias Brunner 06424efa17 tls-server: Determine supported/configured suites and versions early
If we don't do this, we might negotiate a TLS version for which we don't
have any suites configured, so that the cipher suite negotiation
subsequently fails.
2021-02-12 14:35:23 +01:00
Pascal Knecht 8a6edc08a4 tls-crypto: Check if TLS versions and cipher suites match
Only suggest TLS versions of supported cipher suites.  For instance, do not
suggest TLS 1.3 if none of its cipher suites (requiring GCM/CCM or
ChaPoly) are available.
2021-02-12 14:35:23 +01:00
Pascal Knecht f920125304 tls-peer: Don't initiate TLS connection if no cipher suites are supported
If zero cipher suites are left after all filters, tls-peer does not
try to establish a connection to the server anymore.
2021-02-12 14:35:23 +01:00
Tobias Brunner 06aad98ff0 tls-test: Make plugin list configurable via environment variable 2021-02-12 14:35:23 +01:00
Tobias Brunner 00a6280aab tls-peer: Return INVALID_STATE after changing TLS 1.3 keys
Even though we return from build(), we are not actually sending a response,
so we can't return NEED_MORE (would send an invalid ClientHello message) and
if we return SUCCESS, the EAP layer treats this as failure (there is a comment
in eap_authenticator_t about client methods never returning SUCCESS from
process()).  Instead we return INVALID_STATE, which allows tls_t.build() to
exit from the build() loop immediately and send the already generated Finished
message.
2021-02-12 14:35:23 +01:00
Tobias Brunner 121ac4b9e3 tls-crypto: Generate MSK for TLS 1.3
We generate material for both MSK and EMSK even though we only need the
former.  Because HKDF-Expand-Label(), on which the export functionality
is based, encodes the requested key length, we have to allocate the same
number of bytes as e.g. FreeRADIUS does (i.e. if we only request 64
bytes, those won't be the same as the first 64 bytes after requesting
128 bytes).

Unfortunately, key derivation for TLS-based methods is currently not
standardized for TLS 1.3.  There is a draft [1], which defines a scheme
that's different from previous versions (instead of individual label
strings it uses a single one and passes the EAP type/code as context
value to TLS-Export()).  The current code is compatible to FreeRADIUS
3.0.x, which doesn't implement it according to that draft yet (there are
unreleased changes for EAP-TLS, not for the other methods, but these only
switch the label, no context value is passed).  In a separate draft
for EAP-TLS [2] there is an altogether different scheme defined in the
latest version (label combined with EAP method, no context and separate
derivation for MSK and EMSK).

So this is a mess and we will have to change this later with the inevitable
compatibility issues (we should definitely disable TLS 1.3 by default).

[1] https://tools.ietf.org/html/draft-ietf-emu-tls-eap-types
[2] https://tools.ietf.org/html/draft-ietf-emu-eap-tls13
2021-02-12 14:35:23 +01:00
Tobias Brunner d2fe921cf5 tls-hkdf: Add method that allows exporting key material 2021-02-12 11:45:44 +01:00
Tobias Brunner 86cda1a3c0 tls-hkdf: Handle label expansion inside expand_label()
We have to expand arbitrary external labels the same way when exporting
key material.
2021-02-12 11:45:44 +01:00
Tobias Brunner 3e89d26e1c tls-hkdf: Pass secret to derive_secret() explicitly 2021-02-12 11:45:44 +01:00
Tobias Brunner 4e2b8f9c71 tls-hkdf: Store OKM in local variables 2021-02-12 11:45:44 +01:00
Tobias Brunner 1b593e1d48 tls-crypto: Add support for RSA-PSS signatures
PKCS#1 v1.5 signatures are not defined for use with TLS 1.3 (they can
only appear in certificates, we now send a signature_algorithms_cert
extension to indicate support for them).  So for RSA certificates, we
must support RSA-PSS signatures.

There are two sets of schemes, that are differentiated by the type of
RSA key used for the signature, one is for classic RSA keys (rsaEncryption
OID), which can also be used with PKCS#1 when using TLS 1.2, the other
is for RSA-PSS keys (RSASSA-PSS OID), which are not yet commonly
used (and can't be generated by our pki tool).  According to the RFC,
PSS must also be supported for TLS 1.2 if the schemes are included in
the signature_algorithms extension (e.g. OpenSSL does not use PKCS#1 v1.5
anymore if PSS is proposed).

This changes how these schemes are stored and enumerated (they are not
treated as combination of hash algo and key type anymore).

Legacy schemes (MD5/SHA-1) are removed.
2021-02-12 11:45:47 +01:00
Tobias Brunner e02f19e3c6 tls-peer: Support answering KeyUpdate requests 2021-02-12 11:45:44 +01:00
Tobias Brunner 27360d3407 tls-socket: Change how EOF of the underlying socket is handled
With the previous code, there was an issue when replying to TLS 1.3
post-handshake messages.  In this case, SUCCESS is eventually returned
from build(), however, no actual data has been received so in_done is 0.
This was interpreted as EOF, plain_eof was set to TRUE and no further data
was read from the socket afterwards.

Returning SUCCESS from build() if the exchange is initiated by
write_(), as is the case with the finished reply, never was a problem
because there the return value of 0 is not interpreted as EOF.
2021-02-12 11:45:44 +01:00
Tobias Brunner bfcb49b393 tls-peer: Add support to handle KeyUpdate message
We currently don't support switching our own keys and sending the
message if requested by the server.
2021-02-12 11:45:44 +01:00
Tobias Brunner 1466d4da25 tls-crypto: Add method to update application traffic keys 2021-02-12 11:45:44 +01:00
Tobias Brunner b51c1d468e tls-hkdf: Support updating client/server traffic secrets 2021-02-12 11:45:44 +01:00
Tobias Brunner 09fbaad6bd tls-socket: Don't fail reading if sending data failed
If data is processed that eventually includes a TLS close notify, build()
will fail after a close notify has been sent in turn.  However, propagating
that error immediately when reading prevented ever returning the data
already processed before the close notify was received.
2021-02-12 11:45:44 +01:00
Tobias Brunner d532d6c7bc tls-peer: Correctly handle classic ECDH key-share format
Similar to TLS 1.2 but uses a 16-bit length header.
2021-02-12 11:45:44 +01:00
Tobias Brunner 8e35b1f1a5 tls-test: Add options to configure TLS versions 2021-02-12 11:45:44 +01:00
Tobias Brunner a7f2818832 tls-socket: Allow configuring both minimum and maximum TLS versions 2021-02-12 11:45:44 +01:00
Tobias Brunner c4576a1f57 tls: Allow setting both minimum and maximum TLS versions
This allows to increase the initial minimum version and also prevents
sending a list of versions during retries when 1.3 was already
negotiated.
2021-02-12 11:45:44 +01:00
Tobias Brunner 2b6565c236 tls-peer: Handle HelloRetryRequest
Adds support to handle retries with different DH group and/or a cookie
extension.
2021-02-12 11:45:44 +01:00
Tobias Brunner 2271d67f07 tls-crypto: Add method to hash handshake data and use result as initial transcript
This is used for HelloRetryRequest.
2021-02-12 11:45:44 +01:00
Tobias Brunner 64e63c68c8 tls-crypto: Destroy HKDF instance if keys are derived multiple times
This will be the case during a retry.
2021-02-12 11:45:44 +01:00
Tobias Brunner 851b605e21 tls-peer: Refactor writing of extensions and use less hard-coded DH group
Note that this breaks connecting to many TLS 1.3 servers until we support
HelloRetryRequest as we now send a key_share for ECP_256 while still
proposing other groups, so many servers request to use CURVE_25519.
2021-02-12 11:45:44 +01:00
Tobias Brunner de31646a09 tls-peer: Refactor sending/processing finished message
Also fixes leaks.
2021-02-12 11:45:44 +01:00
Tobias Brunner 44cda40d58 tls-peer: Simply ignore certificate request context
This SHALL be zero length for server authentication anyway.
2021-02-12 11:45:44 +01:00
Tobias Brunner bfa3178836 tls-peer: Use existing code to verify certificate and signature 2021-02-12 11:45:44 +01:00
Tobias Brunner c78b2bee5d tls-peer: Refactor parsing of TLS extensions
Also adds proper error handling.
2021-02-12 11:45:44 +01:00
Tobias Brunner f0ed5f9125 tls-peer: Fix parsing of encrypted extensions 2021-02-12 11:45:44 +01:00