Commit Graph

112 Commits

Author SHA1 Message Date
Pascal Knecht e3757300eb tls-crypto: Add signature scheme config file filter
And add signature scheme unit tests.
2021-02-12 14:35:23 +01:00
Pascal Knecht e5b6565730 tls-crypto: Rename DH group/key exchange method config option
TLS key exchange methods are now configured with `ke_group`.
2021-02-12 14:35:23 +01:00
Tobias Brunner 8cf3998f1a tls-crypto: Only log modified TLS versions if successfully set
If no cipher suites are available, the new versions are the previous
values but reversed (i.e. the versions were not changed but we still
ended up with a log message saying "TLS min/max TLS 1.3/TLS 1.0 ...").

Also switched to using the numeric version names to avoid the repeated
"TLS" prefix.
2021-02-12 14:35:23 +01:00
Pascal Knecht 9ef46cfaf9 tls-peer: Mutual authentication support for TLS 1.3 2021-02-12 14:35:23 +01:00
Pascal Knecht d8e42a3d4e tls-crypto: Share private key search between client and server
This way the client also properly considers the TLS version and the signature
schemes supported by the server.

Co-authored-by: Tobias Brunner <tobias@strongswan.org>
2021-02-12 14:35:23 +01:00
Pascal Knecht d2fc9b0961 tls-server: Mutual authentication support for TLS 1.3
This commit also addresses the side effect that additional messages have
an influence on the derivation of the application traffic secrets. Therefore,
key derivation is relocated after the server finished message has been sent,
so the additional messages from the client (Certificate, CertificateVerify)
don't affect the key derivation. Only the outbound key is switched there, the
inbound key remains in use until the client's finished message has been
processed.
2021-02-12 14:35:23 +01:00
Pascal Knecht 6b23543abd tls-crypto: Move AEAD ownership to the protection layer
This separates key derivation from key switching.
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 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 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
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 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
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 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 1466d4da25 tls-crypto: Add method to update application traffic keys 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 2e1c0a2776 tls-crypto: Rename methods to calculate finished message
Instead of the version number use "legacy" for the one for earlier TLS
versions.
2021-02-12 11:45:44 +01:00
Tobias Brunner f116a4823f tls-crypto: Use internal PRF of tls-hkdf to generate finished message
Also adds additional checks.
2021-02-12 11:45:44 +01:00
Tobias Brunner de983a3cb9 tls-crypto: Simplify signature creation/verification 2021-02-12 11:45:44 +01:00
Tobias Brunner 2921f43705 tls-crypto: Simplify handshake/application key derivation and rename methods
Also consistently change the ciphers outside of tls_crypto_t and
simplify key derivation in tls_peer_t and fix a memory leak.
2021-02-12 11:45:44 +01:00
Tobias Brunner 3101120c75 tls-crypto: Enumerate x25519/448 and rename constant for consistency 2021-02-12 11:45:44 +01:00
Tobias Brunner 53ba0801ac tls-crypto: Simplify hash algorithm handling 2021-02-12 11:45:44 +01:00
Tobias Brunner 43c8f950a7 tls-crypto: Delay instantiation of cipher suites
This way we can take into account the version set via setter on tls_t.
2021-02-12 11:45:44 +01:00
Tobias Brunner 281766c5e6 tls-crypto: Filter TLS cipher suites by min/max version
There is no point proposing legacy (or future) cipher suites depending on
the proposed TLS versions. It was actually possible to negotiate and use
cipher suites only defined for TLS 1.2 with earlier TLS versions.
2021-02-12 11:45:44 +01:00
Tobias Brunner 436571b2f0 tls-crypto: Correctly filter cipher suites based on PRF algorithms
The previous check operated on the first array element.
2021-02-12 11:45:44 +01:00
Tobias Brunner b7ea969b32 tls-crypto: Use correct key length for ChaCha20/Poly1305 2021-02-12 11:45:44 +01:00
bytinbit 7a2b02667c libtls: Implement TLS 1.3 handshake on client-side
The code is a minimal handshake with the HelloRetryRequest message
implementation missing.
Can be tested with an OpenSSL server running TLS 1.3. The server must
be at least version 1.1.1 (September 2018).

Co-authored-by: ryru <pascal.knecht@hsr.ch>
2021-02-12 11:45:44 +01:00
Tobias Brunner d5cf2d1f85 tls-crypto: Fix usage of chunk_from_chars()
See 8ea13bbc5c for details.

References #3249.
2020-01-30 18:18:06 +01:00
Tobias Brunner 2db6d5b8b3 Fixed some typos, courtesy of codespell 2018-02-13 12:19:54 +01:00
Tobias Brunner de280c2e03 private-key: Add optional parameters argument to sign() method 2017-11-08 16:48:10 +01:00
Tobias Brunner a413571f3b public-key: Add optional parameters argument to verify() method 2017-11-08 16:48:10 +01:00
Tobias Brunner 525cc46cab Change interface for enumerator_create_filter() callback
This avoids the unportable 5 pointer hack, but requires enumerating in
the callback.
2017-05-26 13:56:44 +02:00
Andreas Steffen 40f2589abf gmp: Support of SHA-3 RSA signatures 2016-09-22 17:34:31 +02:00
Andreas Steffen b12c53ce77 Use standard unsigned integer types 2016-03-24 18:52:48 +01:00
Martin Willi 064fe9c963 enum: Return boolean result for enum_from_name() lookup
Handling the result for enum_from_name() is difficult, as checking for
negative return values requires a cast if the enum type is unsigned. The new
signature clearly differentiates lookup result from lookup value.

Further, this actually allows to convert real -1 enum values, which could not
be distinguished from "not-found" and the -1 return value.

This also fixes several clang warnings where enums are unsigned.
2014-05-16 15:42:07 +02:00
Martin Willi ddf5222096 tls: Introduce a generic TLS purpose that accepts NULL encryption ciphers 2014-04-01 14:28:55 +02:00
Martin Willi ac5717c9e9 tls: Export a function to list supported TLS cipher suites 2014-04-01 14:28:55 +02:00
Martin Willi e67e8dd197 tls: Fix some TLS cipher suite enum names
It is important to have them mapped correctly, as we use these official TLS
identifiers to configure specific TLS suites.
2014-03-31 16:07:53 +02:00
Martin Willi b886dad498 tls: Fix AEAD algorithm filtering, avoid filtering all suites if no AEAD found 2014-03-31 15:56:12 +02:00
Martin Willi 48d6b57c30 tls: Offer TLS signature schemes in ClientHello in order of preference
Additionally, we now query plugin features to find out what schemes we exactly
support.
2014-03-31 15:56:12 +02:00
Martin Willi d06890d6e2 tls: Define AES-GCM cipher suites from RFC 5288/5289 2014-03-31 15:56:12 +02:00