Commit Graph

13958 Commits

Author SHA1 Message Date
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 dc49d457a2 tls-server: Terminate connection if peer certificate is required but not sent
This change mainly affects legacy TLS versions because TLS 1.3
connections are terminated by the server once the peer does not send a
CertificateVerify message next to its empty Certificate message.
2021-02-12 14:35:23 +01:00
Pascal Knecht 4bba89fff3 tls-server: Make CertificateRequest conditional in old TLS versions
The server implementation now only sends a CertificateRequest message if
it has identity information to verify client certificates.
2021-02-12 14:35:23 +01:00
Pascal Knecht 4635f348fa tls-server: Share trusted public key search between client and server 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 534a781646 tls-hkdf: Always use correct base key to derive finished message
The cached traffic secrets change once the application traffic secrets
are derived, but we must always use the correct base key to derive the
finished message, which are the handshake traffic secrets (RFC 8446,
section 4.4).
2021-02-12 14:35:23 +01:00
Pascal Knecht 0aaf1242d9 libtls: Add unit tests for Ed25519 and Ed448 keys
TLS 1.0 to TLS 1.3 socket connection tests with each key type.
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 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 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
Tobias Brunner 4c40a3d3f0 tls-peer: Fix parsing of intermediate CA certificates 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 a9f661f52a tls-hkdf: Add helper method to allocate data from the internal PRF 2021-02-12 11:45:44 +01:00
Tobias Brunner 6a0ee0c23c tls-hkdf: Cleanups and refactorings
The main refactoring is how secrets (PSK/DH) are handled.
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 fff1974012 tls-hkdf: Make labels enum a proper type 2021-02-12 11:45:44 +01:00
Tobias Brunner 8495138d4a tls-peer: Support x25519/448 for TLS 1.2
These DH groups don't use the point format prefix (RFC 8422 deprecated
any other format anyway).  Since they are enumerated now, they can also
be used by servers for TLS 1.2.
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
Tobias Brunner ba3c90ded1 libtls: Some code style fixes 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
Pascal K 02d7405512 libtls: Implement HKDF for TLS 1.3
TLS 1.3 uses HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
as defined in RFC 5869 to compute traffic secrets.

Co-authored-by: bytinbit <meline.sieber@hsr.ch>
2021-02-12 11:45:44 +01:00
Tobias Brunner 3d83d348f4 libtls: Add support to run unit tests with a custom plugin list 2021-02-12 11:45:44 +01:00
Tobias Brunner 818dc86568 libtls: Add TLS 1.3 implementation of tls_aead_t
The key material, in particular the nonce/IV, is derived differently and
the IV is also generated in a different way.  Additionally, the actual
content type is encrypted and there may be optional padding to mask the
actual size of the encrypted data.
2021-02-12 11:45:44 +01:00
Tobias Brunner ba2bcdd882 libtls: Allow tls_aead_t to change the content type
The actual content type is encrypted with TLS 1.3, the type in the record
header is always Application Data.
2021-02-12 11:45:44 +01:00
Tobias Brunner 781ad0b93b openssl: Allocate our own buffer for i2d_* wrapper macro
If we pass a pointer to NULL, the memory allocated by OpenSSL has to be
freed with OPENSSL_free().  Otherwise, this can lead to random
crashes/freezes for Windows builds as seen on AppVeyor.  To not
complicate things for callers of this macro, we allocate our own memory,
which we already do for other i2d_* calls.
2021-02-11 16:40:58 +01:00
Tobias Brunner 6a440f83ab openssl: Reset HMAC key if chunk_empty is passed
If no valid key is configured (e.g. because it's inadvertently uninitialized),
we should not just reuse the previous key.

The `key_set` flag is not necessary anymore because a non-NULL key is set
during initialization since 6b347d5232 ("openssl: Ensure underlying hash
algorithm is available during HMAC init").
2021-02-11 16:40:58 +01:00
Tobias Brunner cd10ae2ff0 android: Explicitly apply DNS servers to the TUN device
If the peer deletes the CHILD_SA, we recreate it due to the close
action.  However, if we create a new TUN device, we do so with a new
VpnService.Builder object and on that the DNS servers were never applied.
The latter happened only on the fly in the attribute handler when an
IKE_SA was established.  Now we do this explicitly when creating the TUN
device, like the virtual IPs and routes.  While we could avoid the
recreation of the TUN device if the CHILD_SA is recreated, there is the
theoretical possibility that the remote traffic selectors change.  This
way we also avoid adding stuff to the builder in different places.

Fixes #3637.
2021-02-04 16:52:15 +01:00
Tobias Brunner 4dc9edfa55 swanctl: Don't print status message if nothing was loaded to stderr
This is not an error (as reflected by the returned status code) so we
should not print to stderr as output there might still be considered an
error (or at least an audit-worthy event) by some scripts.
2021-02-04 16:50:36 +01:00
Thomas Egerer 2566eb2194 plugin-loader: Add optional filter for plugin features
In some cases, the algorithms that have been compiled into a plugin have
to be disabled at runtime. Based on the array returned by the get_features()
function the optionally provided function can strip algorithms or even
callbacks or registrations from a plugin, giving us a handy and powerful way
for runtime feature configuration aside from the plugin list.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2021-02-04 16:39:27 +01:00
Tobias Brunner e6a6fc33b6 path: Also accept / as directory separator on Windows
This adds helper functions to determine the first or last directory separator
in a string and to check if a given character is a separator.

Paths starting with a separator are now also considered absolute on
Windows as these are rooted at the current drive.

Note that it's fine to use DIRECTORY_SEPARATOR when combining strings as
Windows API calls accept both forward and backward slashes as separators.

Co-authored-by: Michał Skalski <mskalski@enigma.com.pl>

References #3684.
2021-02-03 17:27:57 +01:00
Tobias Brunner 3de65f8d67 enumerator: Implement globbing enumerator on Windows
We don't have glob() available there.  This replacement should work
similarly for simple cases like `include conf.d/*.conf`.

Fixes #3684.
2021-02-03 17:27:31 +01:00
Tobias Brunner 4525233b1e vici: Fix refcount for CA certificates when reloading authority sections
Fixes: 3c5e7eaa88 ("vici: Keep track of all CA certificates in vici_authority_t")
2021-01-27 16:50:17 +01:00
Tobias Brunner 6c26267b07 openssl: Fix potential crash with ECDH on Windows
Apparently, we should use OPENSSL_free() to release memory allocated by
OpenSSL.  While it generally maps to free() that's apparently not the
case on Windows, where the ECP test vectors caused `ACCESS_VIOLATION
exception` crashes (not always the same vector).

Fixes: 74e02ff5e6 ("openssl: Mainly use EVP interface for ECDH")
2021-01-27 16:37:45 +01:00
Tobias Brunner 55df5e9797 openssl: Avoid conflicts with wincrypt.h on Windows
There are several conflicts with newer versions of OpenSSL (> 1.0).
2021-01-27 16:32:43 +01:00
Michał Skalski f30187d422 pkcs11: Fix build on Windows
Windows provides CreateMutexA/W with an alias called CreateMutex that
selects one of the other two based on the UNICODE constant.
2021-01-25 15:16:12 +01:00
Dan James 95a0d800c9 farp: Add support for macOS and FreeBSD
Co-authored-by: Tobias Brunner <tobias@strongswan.org>

Closes strongswan/strongswan#189.
References #3498.
2021-01-22 10:44:05 +01:00
Tobias Brunner 74e02ff5e6 openssl: Mainly use EVP interface for ECDH
Functions like ECDH_compute_key() will be removed with OpenSSL 3 (which
will require additional changes as other functions will be deprecated or
removed too).
2021-01-20 17:53:35 +01:00
Tobias Brunner 5fdc979770 openssl: Extract helper function to derive a shared DH secret 2021-01-20 17:53:35 +01:00
Tobias Brunner 86fb24c2c5 Remove the ecp_x_coordinate_only option
This was for compatibility with very old releases and only complicates
things unnecessarily nowadays.
2021-01-20 17:53:35 +01:00
Mahantesh Salimath 7733ff7d4e openssl: Use ECDH_compute_key() for 'x-coordinate only' setting
ECDH_compute_key() was not used because it only gives x-coordinate of
the result. However, the default setting, as per the errata mentioned,
is to use x-coordinate only.
Use ECDH_compute_key() for this setting as it additionally allows HW
offload of the computation using dynamic engine feature in OpenSSL.
EC_POINT_mul() doesn't allow HW offload.

Signed-off-by: Mahantesh Salimath <mahantesh@nvidia.com>
2021-01-20 17:53:35 +01:00
Tobias Brunner aa3d5bf791 Revert "nm: Remove dummy TUN device"
This reverts commit a28c6269a4.

We add a dummy TUN device again because systemd-resolved insists on
managing DNS servers per interface.

Fixes #3615.
2021-01-19 14:49:48 +01:00
Tobias Brunner bd9b50dcd3 load-tester: Correctly encode serial of generated client certificates
The previous approach would lead to additional zero prefixes in the
encoding of the serial (which is a positive integer, not an arbitrary
blob).

Fixes #3667.
2021-01-18 17:44:59 +01:00
Коренберг Марк d8e4a2a777 identification: Change abbreviation for surname/serialNumber RDNs
To align with RFC 4519, section 2.31/32, the abbreviation for surname
is changed to "SN" that was previously used for serialNumber, which does
not have an abbreviation.

This mapping had its origins in the X.509 patch for FreeS/WAN that was
started in 2000.  It was aligned with how OpenSSL did this in earlier
versions.  However, there it was changed already in March 2002 (commit
ffbe98b7630d604263cfb1118c67ca2617a8e222) to make it compatible with
RFC 2256 (predecessor of RFC 4519).

Co-authored-by: Tobias Brunner <tobias@strongswan.org>

Closes strongswan/strongswan#179.
2021-01-18 17:41:37 +01:00
Tobias Brunner 2610cd7928 vici: Decode error messages in Python bindings
Otherwise we might end up with b'<errmsg>' in the output.
2021-01-18 17:39:15 +01:00
Tobias Brunner 414f2c3754 mem-pool: Be less strict when reassigning existing online leases
Also assign online leases to a peer connecting from the same endpoint
when it requests any virtual IP.  This is mainly a workaround for
Windows clients that remember the virtual IPv6 address and re-request it
the next time the connection is initiated (even if it is not a
reauthentication) but don't do the same for virtual IPv4 addresses.
This can result in duplicate policies with different reqids because
these are allocated for unique sets of traffic selectors.

Fixes #3541.
2021-01-18 13:58:01 +01:00
Tobias Brunner d79cefc3fc vici: Expose ike-update event 2021-01-18 11:34:40 +01:00
Tobias Brunner 2b255f01af ike-mobike: Use ike_sa_t::update_hosts() to trigger events
We should trigger the ike_update() event for MOBIKE updates and since
update_hosts() updates the children we can reuse that code too.
2021-01-18 11:34:40 +01:00
Tobias Brunner 51c7cf9a04 ike-sa: Add flags to force updating hosts/CHILD_SAs
This allows more fine grained control over what's updated and does not
require multiple calls of the method. Plus we'll be able to use it in
the ike-mobike task.
2021-01-18 11:34:40 +01:00
Tobias Brunner 08a3ee0cce bus: Change ike_update() signature and only call it once
This avoids multiple events when both addresses change (e.g. switching
address families).
2021-01-18 11:34:40 +01:00
Tobias Brunner 16fcdb460a charon-tkm: Don't use starter/stroke with charon-tkm anymore
For the tests, the unused init script that was used before switching to
charon-systemd is repurposed to manage the daemon.
2021-01-11 15:28:01 +01:00
Tobias Brunner b322539ef5 charon-tkm: Deinitialize IKE tkm-rpc client
This is necessary if tkm-rpc supports multiple parallel client requests.
2021-01-08 17:22:37 +01:00
Tobias Brunner e637cf8b4a charon-tkm: Remove -gnat05 option not supported by newer compilers 2021-01-08 17:22:36 +01:00
Adrian-Ken Rueegsegger a0a0571bd1 charon-tkm: Reverse cert chain processing order
Verify certificate chains starting from the root CA certificate and
moving towards the leaf/user certificate.

Also update TKM-RPC and TKM in testing scripts to version supporting the
reworked CC handling.
2021-01-08 17:22:36 +01:00
Adrian-Ken Rueegsegger f8242127a2 charon-tkm: Add support for multiple CAs
Load CA certificate id mapping from config and pass the correct CA ID to
TKM when checking certificate chains. The mapping of CA certificate to
CA ID is done via SHA-1 hash of the CA certificates subjectPublicKey.
2021-01-08 17:22:36 +01:00
Adrian-Ken Rueegsegger 73d2a11aee charon-tkm: Register TKM cred encoder before init
Make sure the credential encoder is available early to allow getting
public key fingerprints.
2021-01-08 17:22:36 +01:00
Andreas Steffen 2889133cc0 imc_attestation: Fixed double free of tpm_version_info chunk 2021-01-08 11:00:15 +01:00
Andreas Steffen 08760dd927 tpm: Intel FW TPM always uses locality 0 2021-01-08 11:00:15 +01:00
Andreas Steffen 2ea1dac203 libimcv: Support symlinks introduced by usrmerge
Debian, Ubuntu, Fedora et. al. started to apply usrmerge to their
latest Linux distributions, i.e.  /bin, /sbin, and /lib are now
symbolical links to /usr/bin, /usr/sbin, and /usr/lib, respectively.
Since executables and libraries are contained only once in Linux
packages (e.g. /bin/cp in coreutils but not /usr/bin/cp) this leads
to missing file measurments due to the symlinks when doing remote
attestation.

The new ita_attr_symlinks PA-TNC attribute fixes this problem by
collecting symbolic links pointing to directories on the client
platform.
2021-01-08 11:00:15 +01:00
Andreas Steffen 9b4a2322d6 libimcv: Evaluate IMA SHA-256 measurements 2021-01-08 11:00:15 +01:00
Tobias Brunner ea7945a4f5 wolfssl: Disable ECC curves based on minimum ECC key size
wolfSSL 4.6.0 provides a new option to configure the minimum ECC key
size (--with-eccminsz), which currently defaults to 224 bits.
2021-01-04 16:09:56 +01:00
Tobias Brunner 6e2e359f38 wolfssl: Correctly enable Brainpool curves 2021-01-04 16:09:22 +01:00
Tobias Brunner ec9f986b61 Ignore verbose parser generator output file more generally
Depending on from where bison is called, the file might not end up in
the same directory as the .y file, but the location of the Makefile.
This has been seen on FreeBSD.
2020-12-15 10:42:43 +01:00
Tobias Brunner 192581e785 Replace two deprecated parser generator directives
There is a conflict between Flex's bison-bridge and Bison's api.prefix
options.  Apparently, the former was added without consulting the Bison
devs and requires YYSTYPE, which is not added to the header anymore by
the latter.  Instead, we just provide the proper definition of yyflex()
manually (as recommended by the Bison docs), so the option is not
required anymore.
2020-12-15 10:42:43 +01:00
Tobias Brunner eb4cd8e3b1 imv-scanner: Fix potentially unsafe port filter attribute destruction
DESTROY_IF() checks if the given value is not NULL, before calling
destroy() on it, which does not work for sub-structs.  If
port_filter_attr is NULL, this could crash.
2020-12-03 12:19:06 +01:00
Tobias Brunner 25ec2d04aa child-rekey: Don't migrate child-create task if we already are deleting
If we are already deleting the old/redundant CHILD_SA, we must not
migrate the child-create task as that would destroy the new CHILD_SA we
already moved to the IKE_SA.

Fixes #3644.
2020-12-03 11:06:23 +01:00
Tobias Brunner 7d2d94f3e1 host-resolver: Don't wait for a reply if there are no threads
Without threads handling the resolution, there is no point waiting
for a reply.  If no subsequent resolution successfully starts a
thread (there might not even be one), we'd wait indefinitely.

Fixes #3634.
2020-12-03 08:36:20 +01:00
Tobias Brunner 9248f636b0 kernel-netlink: Make sure we successfully opened a Netlink socket
This is in addition to the fix in the destructor in 991e9e5dc9.
2020-12-03 08:34:18 +01:00
Tobias Brunner e8fae43768 identification: Validate ASN.1 DN in from_data() constructor
The DN is otherwise not parsed until compared/printed.  This avoids
false detections as ASN.1 DN if e.g. an email address starts with "0",
which is 0x30 = ASN.1 sequence tag, and the next character denotes
the exact length of the rest of the string (see the unit tests for an
example).
2020-12-03 08:23:54 +01:00
Tobias Brunner 4c61d7aedc android: New release after avoiding marking VPN connections as metered 2020-12-02 16:09:38 +01:00
Tobias Brunner b32a9be419 android: Don't default to marking VPN connections as metered
For apps targeting Android 10, where a method to change this was added, the
default changed so that all VPN connections are marked as metered.  This means
certain background operations (e.g. syncing data) are not performed anymore
even when connected to a WiFi.  By setting this to false, the metered state
of the VPN connection reflects that of the underlying networks.
2020-12-01 16:00:09 +01:00
Tobias Brunner abb3f67bd1 pem: Make sure we actually parsed some data
This could happen if there is no separating empty line between header
and body.

References #3627.
2020-11-13 16:40:01 +01:00
Tobias Brunner ce433c9b29 kernel-wfp: Declare constants explicitly as extern
Newer compilers otherwise complain that there are multiple definitions
of these (in header and .c file).
2020-11-13 16:38:17 +01:00
Tobias Brunner 4fc6b79b93 libimcv: Avoid compiler warning in segmentation unit test
Newer versions of GCC complain that the variable may be used
uninitialized.
2020-11-13 16:38:17 +01:00
Tobias Brunner eec08b41a8 windows: Don't declare [v]asprintf()
None of our build environments seem to require these declarations.  And
current versions of MinGW-w64 define them as inline functions in stdio.h
so these declarations clashed with that ("static declaration of '...'
follows non-static declaration").
2020-11-13 16:38:17 +01:00
Shmulik Ladkani 1607e538e9 controller: Always return SUCCESS when terminating IKE_SAs without callback
If no callback is specified, terminate_ike_execute() is invoked without the
listener waiting on the IKE state change.

Now, if 'force' is false, then ike_sa->delete() just queues an
IKE_DELETE task, and returns SUCCESS - indicating successful task
manager initiation.

However, terminate_ike_execute() ignored this success and set the
status to FAILED.

This is not ideal, as it will be the overall return code of
terminate_ike(), although no failure did occur. This eventually leads
vici's "terminate" to return "Command failed: terminating SA failed",
as seen in this example:

    In [9]: list(session.terminate({'ike-id': 2960, 'timeout': -1}))
    ---------------------------------------------------------------------------
    CommandException                          Traceback (most recent call last)
    <ipython-input-9-5f95b5cea88f> in <module>()
    ----> 1 list(session.terminate({'ike-id': 2960, 'timeout': -1}))

    vici/session.pyc in streamed_request(self, command, event_stream_type, message)
        136                 raise CommandException(
        137                     "Command failed: {errmsg}".format(
    --> 138                         errmsg=command_response["errmsg"]
        139                     )
        140                 )

    CommandException: Command failed: terminating SA failed

If we consider both queueing the task and actually destroying the IKS_SA
a success, we can just always return SUCCESS if we don't have a
callback. There is also no need to explicitly set the status to FAILED
if a listener is waiting as that's the default anyway.

Co-authored-by: Tobias Brunner <tobias@strongswan.org>

Closes strongswan/strongswan#185.
2020-11-04 19:42:41 +01:00
Tobias Brunner 70b0c730d0 gcrypt: Use a dummy buffer to initialize static allocations
In FIPS mode, libgcrypt uses a DRBG, which behaves differently when the
length passed to gcry_create_nonce() or gcry_randomize() is <= 0.  It
expects a struct and explicitly checks that the passed pointer is not
NULL.
2020-11-04 10:06:46 +01:00
Tobias Brunner a59842eb95 parser-helper: Don't attempt to open anything but regular files
A crash could be provoked e.g. via STRONGSWAN_CONF=. or any other
path to a directory.
2020-11-04 10:06:46 +01:00
Tobias Brunner 991e9e5dc9 kernel-netlink: Only attempt to remove routing rule if we have a socket 2020-11-04 10:06:46 +01:00
Tobias Brunner 19343998bb imv-attestation: Fix typo in default value for hash_algorithm option 2020-11-04 10:06:46 +01:00
Tobias Brunner f0f65b20ae libimcv: Remove empty 'swid' Doxygen group
The corresponding IMC/IMV were already removed with a31f9b7691 ("libimcv:
Removed TCG SWID IMC/IMV support").
2020-11-04 10:06:46 +01:00
Tobias Brunner a6f0e19bf5 Fixed some typos, courtesy of codespell 2020-11-04 10:06:46 +01:00
Tobias Brunner bb87e63ca6 child-sa: Delete inbound SAs even if not installed to remove allocated SPIs
If we can't establish an SA, this should delete the allocated SPI.
2020-10-30 13:08:16 +01:00
Tobias Brunner ef636316d2 vici: Send all queued messages during shutdown
This ensures that e.g. ike/child-updown messages are sent that were
queued but couldn't be sent (even the job to enable to on_write() callback
requires a worker thread that's not around anymore during shutdown).

References #3602.
2020-10-30 09:58:42 +01:00
Tobias Brunner 6586f07162 ikev2: Clear fragments of a retransmitted message if we receive the next one
The message_t object used for defragmentation was only cleared after
all fragments have been received and the message was delivered.  So
if we received only some fragments of a retransmitted message, the
fragments of the next message were not processed (message_t returns
INVALID_ARG if the message ID does not match causing the message to
get ignored).  This rendered the IKE_SA unusable as the client
obviously never retransmitted the fragments of that previous message
after it received our response.
2020-10-29 14:06:19 +01:00
Tobias Brunner 01fee62f46 android: New release after adding IPv6 support and several fixes 2020-10-29 10:57:07 +01:00
Tobias Brunner ec317c29ca android: Throw an exception if UUID can't get parsed
The parser is quite picky and e.g. doesn't accept UUIDs without dashes.
Even without a specific error, this at least points the users into the
right direction.

Fixes #3583.
2020-10-29 10:57:07 +01:00
Tobias Brunner 80337f4f9d android: Prevent illegalStateException when showing power whitelist dialog
If the activity is not active when the service connection is
established and handleIntent() is called, the activity's state is already
saved and any fragment transaction would result in an illegalStateException
due to state loss.  We just ignore this and wait for another initiation
attempt (via onNewIntent()).
2020-10-29 10:22:52 +01:00
Tobias Brunner 264435f626 android: Handle restarts of control activity with power whitelist dialog better
With the flag set, we basically ignore the resent intent, which is not
ideal if we have not yet actually started another activity.  The information
dialog we show first would disappear when closing and reopening the app
or even just rotating it (we hide all dialogs when receiving an intent),
but since the flag was restored, the dialog was not shown again even
when attempting to start other connections.
2020-10-29 10:22:52 +01:00
Tobias Brunner 21476a8d91 android: Make IPv6 transport flag configurable in the GUI 2020-10-29 10:22:52 +01:00
Tobias Brunner 7d10095123 android: Import IPv6 transport flag 2020-10-29 10:22:52 +01:00
Tobias Brunner 3581914387 android: Add flag to enable IPv6 transport addresses 2020-10-29 10:22:51 +01:00
Tobias Brunner 0bc826c2f2 android: IPV6_PKTINFO is supported (i.e. struct in6_pktinfo is available) 2020-10-29 10:22:51 +01:00
Tobias Brunner 294c022fae android: Add ability to lookup IPv6 source addresses 2020-10-29 10:22:51 +01:00
Tobias Brunner 217d8ab81e android: Fix port scanning IMC
Since 9e88bb987d ("Subscribed Scanner IMC/IMV to IETF_FIREWALL PA subtype")
the port filter attribute is requested with a different message type.
2020-10-29 10:22:51 +01:00
Tobias Brunner 1c82e65cbe android: Ignore deprecation warning for legacy code in NetworkManager 2020-10-29 10:22:51 +01:00
Tobias Brunner a7713372d3 android: Replace deprecated getFragmentManager() in TNC-related Fragments 2020-10-29 10:22:51 +01:00
Tobias Brunner e106fce483 android: Consistently use PreferenceManager from AndroidX
android.preference.PreferenceManager has been deprecated.  The one from
AndroidX was already in use in some places.
2020-10-29 10:22:51 +01:00
Tobias Brunner ea303d3f5a android: Update dependencies 2020-10-29 10:22:51 +01:00
Tobias Brunner f71f6f659f android: Set compile-/targetSdkVersion to 29
This will be mandatory for existing apps on Nov 2, 2020.
2020-10-29 10:22:51 +01:00