19 months agotls-hkdf: Handle label expansion inside expand_label()
Tobias Brunner [Tue, 1 Sep 2020 16:48:41 +0000 (18:48 +0200)]
tls-hkdf: Handle label expansion inside expand_label()

We have to expand arbitrary external labels the same way when exporting
key material.

19 months agotls-hkdf: Pass secret to derive_secret() explicitly
Tobias Brunner [Tue, 1 Sep 2020 16:35:02 +0000 (18:35 +0200)]
tls-hkdf: Pass secret to derive_secret() explicitly

19 months agotls-hkdf: Store OKM in local variables
Tobias Brunner [Mon, 31 Aug 2020 15:08:07 +0000 (17:08 +0200)]
tls-hkdf: Store OKM in local variables

19 months agotls-crypto: Add support for RSA-PSS signatures
Tobias Brunner [Fri, 28 Aug 2020 06:59:37 +0000 (08:59 +0200)]
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.

19 months agotls-peer: Support answering KeyUpdate requests
Tobias Brunner [Fri, 28 Aug 2020 08:23:43 +0000 (10:23 +0200)]
tls-peer: Support answering KeyUpdate requests

19 months agotls-socket: Change how EOF of the underlying socket is handled
Tobias Brunner [Fri, 28 Aug 2020 09:56:36 +0000 (11:56 +0200)]
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.

19 months agotls-peer: Add support to handle KeyUpdate message
Tobias Brunner [Thu, 27 Aug 2020 09:51:58 +0000 (11:51 +0200)]
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.

19 months agotls-crypto: Add method to update application traffic keys
Tobias Brunner [Thu, 27 Aug 2020 09:51:00 +0000 (11:51 +0200)]
tls-crypto: Add method to update application traffic keys

19 months agotls-hkdf: Support updating client/server traffic secrets
Tobias Brunner [Thu, 27 Aug 2020 09:50:00 +0000 (11:50 +0200)]
tls-hkdf: Support updating client/server traffic secrets

19 months agotls-socket: Don't fail reading if sending data failed
Tobias Brunner [Wed, 26 Aug 2020 15:42:21 +0000 (17:42 +0200)]
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.

19 months agotls-peer: Correctly handle classic ECDH key-share format
Tobias Brunner [Wed, 26 Aug 2020 14:08:26 +0000 (16:08 +0200)]
tls-peer: Correctly handle classic ECDH key-share format

Similar to TLS 1.2 but uses a 16-bit length header.

19 months agotls-test: Add options to configure TLS versions
Tobias Brunner [Wed, 26 Aug 2020 13:00:30 +0000 (15:00 +0200)]
tls-test: Add options to configure TLS versions

19 months agotls-socket: Allow configuring both minimum and maximum TLS versions
Tobias Brunner [Wed, 26 Aug 2020 12:40:51 +0000 (14:40 +0200)]
tls-socket: Allow configuring both minimum and maximum TLS versions

19 months agotls: Allow setting both minimum and maximum TLS versions
Tobias Brunner [Wed, 26 Aug 2020 12:37:59 +0000 (14:37 +0200)]
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

19 months agotls-peer: Handle HelloRetryRequest
Tobias Brunner [Tue, 25 Aug 2020 15:23:45 +0000 (17:23 +0200)]
tls-peer: Handle HelloRetryRequest

Adds support to handle retries with different DH group and/or a cookie

19 months agotls-crypto: Add method to hash handshake data and use result as initial transcript
Tobias Brunner [Tue, 25 Aug 2020 15:17:55 +0000 (17:17 +0200)]
tls-crypto: Add method to hash handshake data and use result as initial transcript

This is used for HelloRetryRequest.

19 months agotls-crypto: Destroy HKDF instance if keys are derived multiple times
Tobias Brunner [Tue, 25 Aug 2020 15:13:17 +0000 (17:13 +0200)]
tls-crypto: Destroy HKDF instance if keys are derived multiple times

This will be the case during a retry.

19 months agotls-peer: Refactor writing of extensions and use less hard-coded DH group
Tobias Brunner [Tue, 25 Aug 2020 14:18:27 +0000 (16:18 +0200)]
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.

19 months agotls-peer: Refactor sending/processing finished message
Tobias Brunner [Tue, 25 Aug 2020 14:25:37 +0000 (16:25 +0200)]
tls-peer: Refactor sending/processing finished message

Also fixes leaks.

19 months agotls-peer: Simply ignore certificate request context
Tobias Brunner [Tue, 25 Aug 2020 15:21:02 +0000 (17:21 +0200)]
tls-peer: Simply ignore certificate request context

This SHALL be zero length for server authentication anyway.

19 months agotls-peer: Use existing code to verify certificate and signature
Tobias Brunner [Tue, 25 Aug 2020 14:17:27 +0000 (16:17 +0200)]
tls-peer: Use existing code to verify certificate and signature

19 months agotls-peer: Refactor parsing of TLS extensions
Tobias Brunner [Tue, 25 Aug 2020 14:14:54 +0000 (16:14 +0200)]
tls-peer: Refactor parsing of TLS extensions

Also adds proper error handling.

19 months agotls-peer: Fix parsing of encrypted extensions
Tobias Brunner [Fri, 28 Aug 2020 06:54:49 +0000 (08:54 +0200)]
tls-peer: Fix parsing of encrypted extensions

19 months agotls-peer: Fix parsing of intermediate CA certificates
Tobias Brunner [Tue, 25 Aug 2020 14:11:59 +0000 (16:11 +0200)]
tls-peer: Fix parsing of intermediate CA certificates

19 months agotls-crypto: Rename methods to calculate finished message
Tobias Brunner [Tue, 25 Aug 2020 14:52:20 +0000 (16:52 +0200)]
tls-crypto: Rename methods to calculate finished message

Instead of the version number use "legacy" for the one for earlier TLS

19 months agotls-crypto: Use internal PRF of tls-hkdf to generate finished message
Tobias Brunner [Tue, 25 Aug 2020 14:49:52 +0000 (16:49 +0200)]
tls-crypto: Use internal PRF of tls-hkdf to generate finished message

Also adds additional checks.

19 months agotls-hkdf: Add helper method to allocate data from the internal PRF
Tobias Brunner [Tue, 25 Aug 2020 14:44:17 +0000 (16:44 +0200)]
tls-hkdf: Add helper method to allocate data from the internal PRF

19 months agotls-hkdf: Cleanups and refactorings
Tobias Brunner [Tue, 25 Aug 2020 14:01:27 +0000 (16:01 +0200)]
tls-hkdf: Cleanups and refactorings

The main refactoring is how secrets (PSK/DH) are handled.

19 months agotls-crypto: Simplify signature creation/verification
Tobias Brunner [Tue, 25 Aug 2020 13:58:46 +0000 (15:58 +0200)]
tls-crypto: Simplify signature creation/verification

19 months agotls-crypto: Simplify handshake/application key derivation and rename methods
Tobias Brunner [Tue, 25 Aug 2020 11:22:04 +0000 (13:22 +0200)]
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.

19 months agotls-hkdf: Make labels enum a proper type
Tobias Brunner [Tue, 25 Aug 2020 11:35:54 +0000 (13:35 +0200)]
tls-hkdf: Make labels enum a proper type

19 months agotls-peer: Support x25519/448 for TLS 1.2
Tobias Brunner [Wed, 26 Aug 2020 13:23:53 +0000 (15:23 +0200)]
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.

19 months agotls-crypto: Enumerate x25519/448 and rename constant for consistency
Tobias Brunner [Tue, 25 Aug 2020 11:16:52 +0000 (13:16 +0200)]
tls-crypto: Enumerate x25519/448 and rename constant for consistency

19 months agotls-crypto: Simplify hash algorithm handling
Tobias Brunner [Tue, 25 Aug 2020 11:14:05 +0000 (13:14 +0200)]
tls-crypto: Simplify hash algorithm handling

19 months agotls-crypto: Delay instantiation of cipher suites
Tobias Brunner [Tue, 25 Aug 2020 13:46:29 +0000 (15:46 +0200)]
tls-crypto: Delay instantiation of cipher suites

This way we can take into account the version set via setter on tls_t.

19 months agotls-crypto: Filter TLS cipher suites by min/max version
Tobias Brunner [Tue, 25 Aug 2020 11:54:08 +0000 (13:54 +0200)]
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.

19 months agotls-crypto: Correctly filter cipher suites based on PRF algorithms
Tobias Brunner [Tue, 25 Aug 2020 11:47:00 +0000 (13:47 +0200)]
tls-crypto: Correctly filter cipher suites based on PRF algorithms

The previous check operated on the first array element.

19 months agotls-crypto: Use correct key length for ChaCha20/Poly1305
Tobias Brunner [Wed, 26 Aug 2020 10:18:06 +0000 (12:18 +0200)]
tls-crypto: Use correct key length for ChaCha20/Poly1305

19 months agolibtls: Some code style fixes
Tobias Brunner [Tue, 25 Aug 2020 14:32:40 +0000 (16:32 +0200)]
libtls: Some code style fixes

19 months agotls-test: Make address family configurable and simplify DNS/socket handling
Tobias Brunner [Tue, 25 Aug 2020 11:09:55 +0000 (13:09 +0200)]
tls-test: Make address family configurable and simplify DNS/socket handling

19 months agolibtls: Implement TLS 1.3 handshake on client-side
bytinbit [Thu, 21 May 2020 07:37:38 +0000 (09:37 +0200)]
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 <>
19 months agolibtls: Implement HKDF for TLS 1.3
Pascal K [Thu, 21 May 2020 05:57:14 +0000 (07:57 +0200)]
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 <>
19 months agolibtls: Add support to run unit tests with a custom plugin list
Tobias Brunner [Wed, 22 Apr 2020 14:27:00 +0000 (16:27 +0200)]
libtls: Add support to run unit tests with a custom plugin list

19 months agolibtls: Add TLS 1.3 implementation of tls_aead_t
Tobias Brunner [Wed, 22 Apr 2020 14:03:01 +0000 (16:03 +0200)]
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.

19 months agolibtls: Allow tls_aead_t to change the content type
Tobias Brunner [Wed, 22 Apr 2020 13:44:31 +0000 (15:44 +0200)]
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.

19 months agotesting: extended sleep time tkm/xfrmproxy tests 5.9.2dr2
Andreas Steffen [Fri, 12 Feb 2021 08:44:00 +0000 (09:44 +0100)]
testing: extended sleep time tkm/xfrmproxy tests

19 months agoVersion bump to 5.9.2dr2
Andreas Steffen [Wed, 10 Feb 2021 09:04:34 +0000 (10:04 +0100)]
Version bump to 5.9.2dr2

19 months agotesting: Copy /etc/resolv.conf from host in chroot script
Tobias Brunner [Fri, 18 Dec 2020 13:18:47 +0000 (14:18 +0100)]
testing: Copy /etc/resolv.conf from host in chroot script

This makes installing packages etc. easier.

19 months agoappveyor: Set timezone on the build system
Tobias Brunner [Thu, 11 Feb 2021 09:20:43 +0000 (10:20 +0100)]
appveyor: Set timezone on the build system

For some reason, setting the time zone via TZ to `GST-1GDT` in the utils test
doesn't work anymore (the DST zone is not considered, it's as if only `GST-1`
was configured).

19 months agoappveyor: Create dummy strongswan.conf file to avoid log messages
Tobias Brunner [Wed, 10 Feb 2021 17:04:41 +0000 (18:04 +0100)]
appveyor: Create dummy strongswan.conf file to avoid log messages

Only relevant when increasing the verbosity, but causes quite a lot of
them then.

19 months agoappveyor: Print OpenSSL version
Tobias Brunner [Wed, 10 Feb 2021 17:04:27 +0000 (18:04 +0100)]
appveyor: Print OpenSSL version

19 months agoopenssl: Allocate our own buffer for i2d_* wrapper macro
Tobias Brunner [Wed, 10 Feb 2021 16:55:06 +0000 (17:55 +0100)]
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.

19 months agoopenssl: Reset HMAC key if chunk_empty is passed
Tobias Brunner [Fri, 18 Dec 2020 13:17:37 +0000 (14:17 +0100)]
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 6b347d5232c7 ("openssl: Ensure underlying hash
algorithm is available during HMAC init").

19 months agoandroid: Explicitly apply DNS servers to the TUN device
Tobias Brunner [Tue, 24 Nov 2020 15:50:55 +0000 (16:50 +0100)]
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.

19 months agoswanctl: Don't print status message if nothing was loaded to stderr
Tobias Brunner [Wed, 27 Jan 2021 13:51:56 +0000 (14:51 +0100)]
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.

19 months agoplugin-loader: Add optional filter for plugin features
Thomas Egerer [Thu, 28 Jan 2021 17:49:08 +0000 (17:49 +0000)]
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 <>
19 months agopath: Also accept / as directory separator on Windows
Tobias Brunner [Mon, 1 Feb 2021 13:35:09 +0000 (14:35 +0100)]
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 <>
References #3684.

19 months agoenumerator: Implement globbing enumerator on Windows
Tobias Brunner [Thu, 28 Jan 2021 14:10:52 +0000 (15:10 +0100)]
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.

20 months agovici: Fix refcount for CA certificates when reloading authority sections
Tobias Brunner [Wed, 20 Jan 2021 14:52:33 +0000 (15:52 +0100)]
vici: Fix refcount for CA certificates when reloading authority sections

Fixes: 3c5e7eaa88b0 ("vici: Keep track of all CA certificates in vici_authority_t")

20 months agoopenssl: Fix potential crash with ECDH on Windows
Tobias Brunner [Tue, 26 Jan 2021 18:33:24 +0000 (19:33 +0100)]
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: 74e02ff5e624 ("openssl: Mainly use EVP interface for ECDH")

20 months agoopenssl: Avoid conflicts with wincrypt.h on Windows
Tobias Brunner [Tue, 26 Jan 2021 10:17:20 +0000 (11:17 +0100)]
openssl: Avoid conflicts with wincrypt.h on Windows

There are several conflicts with newer versions of OpenSSL (> 1.0).

20 months agoappveyor: Also build against newer OpenSSL versions
Tobias Brunner [Tue, 26 Jan 2021 09:25:03 +0000 (10:25 +0100)]
appveyor: Also build against newer OpenSSL versions

The original version is 1.0.2, which we keep as that version is not in
use on other platforms anymore.

20 months agoEnable Windows CI build of pkcs11 plugin
Michał Skalski [Sun, 24 Jan 2021 20:30:41 +0000 (21:30 +0100)]
Enable Windows CI build of pkcs11 plugin

20 months agopkcs11: Fix build on Windows
Michał Skalski [Sun, 24 Jan 2021 20:14:57 +0000 (21:14 +0100)]
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.

20 months agogithub: Enable farp plugin on macOS
Tobias Brunner [Tue, 19 Jan 2021 16:04:58 +0000 (17:04 +0100)]
github: Enable farp plugin on macOS

20 months agocirrus: Build farp plugin on FreeBSD
Tobias Brunner [Tue, 19 Jan 2021 16:03:56 +0000 (17:03 +0100)]
cirrus: Build farp plugin on FreeBSD

20 months agofarp: Add support for macOS and FreeBSD
Dan James [Sun, 20 Dec 2020 00:04:16 +0000 (19:04 -0500)]
farp: Add support for macOS and FreeBSD

Co-authored-by: Tobias Brunner <>
Closes strongswan/strongswan#189.
References #3498.

20 months agoMerge branch 'openssl-ecp'
Tobias Brunner [Wed, 20 Jan 2021 16:54:42 +0000 (17:54 +0100)]
Merge branch 'openssl-ecp'

Uses the EVP interface for ECDH with newer OpenSSL versions, which,
compared to the previous low-level use of EC_POINT_mul() supports
hardware offloading.  We used this because of the ecp_x_coordinate_only
option, which is now removed as it's been obsolete for a long time and
complicated the code.  There is still some legacy code for OpenSSL 1.0
and the old BoringSSL version we currently use for the Android app.

Closes strongswan/strongswan#186.

20 months agoopenssl: Mainly use EVP interface for ECDH
Tobias Brunner [Tue, 1 Dec 2020 10:45:05 +0000 (11:45 +0100)]
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).

20 months agoopenssl: Extract helper function to derive a shared DH secret
Tobias Brunner [Tue, 1 Dec 2020 10:43:40 +0000 (11:43 +0100)]
openssl: Extract helper function to derive a shared DH secret

20 months agoRemove the ecp_x_coordinate_only option
Tobias Brunner [Tue, 1 Dec 2020 09:13:30 +0000 (10:13 +0100)]
Remove the ecp_x_coordinate_only option

This was for compatibility with very old releases and only complicates
things unnecessarily nowadays.

20 months agoopenssl: Use ECDH_compute_key() for 'x-coordinate only' setting
Mahantesh Salimath [Mon, 30 Nov 2020 22:03:03 +0000 (22:03 +0000)]
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 <>
20 months agoRevert "nm: Remove dummy TUN device"
Tobias Brunner [Mon, 30 Nov 2020 10:48:07 +0000 (11:48 +0100)]
Revert "nm: Remove dummy TUN device"

This reverts commit a28c6269a4aeb5369fed8933fa1baf0cd8847622.

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

Fixes #3615.

20 months agoload-tester: Correctly encode serial of generated client certificates
Tobias Brunner [Fri, 8 Jan 2021 09:06:06 +0000 (10:06 +0100)]
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

Fixes #3667.

20 months agoidentification: Change abbreviation for surname/serialNumber RDNs
Коренберг Марк [Wed, 15 Jul 2020 08:25:56 +0000 (13:25 +0500)]
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 <>
Closes strongswan/strongswan#179.

20 months agovici: Decode error messages in Python bindings
Tobias Brunner [Wed, 13 Jan 2021 13:41:50 +0000 (14:41 +0100)]
vici: Decode error messages in Python bindings

Otherwise we might end up with b'<errmsg>' in the output.

20 months agomem-pool: Be less strict when reassigning existing online leases
Tobias Brunner [Tue, 24 Nov 2020 08:24:25 +0000 (09:24 +0100)]
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.

20 months agoMerge branch 'ike-update-event'
Tobias Brunner [Mon, 18 Jan 2021 12:31:01 +0000 (13:31 +0100)]
Merge branch 'ike-update-event'

This modifies the signature of the listener_t::ike_update() callback so
that both addresses are passed and it's only called once if both
addresses change (e.g. for an address family switch).

The callback is now also triggered for MOBIKE updates and the event is
exposed via vici.

Fixes #3602.

20 months agovici: Expose ike-update event
Tobias Brunner [Thu, 22 Oct 2020 17:12:39 +0000 (19:12 +0200)]
vici: Expose ike-update event

20 months agoike-mobike: Use ike_sa_t::update_hosts() to trigger events
Tobias Brunner [Tue, 27 Oct 2020 16:18:41 +0000 (17:18 +0100)]
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.

20 months agoike-sa: Add flags to force updating hosts/CHILD_SAs
Tobias Brunner [Tue, 27 Oct 2020 18:06:21 +0000 (19:06 +0100)]
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.

20 months agobus: Change ike_update() signature and only call it once
Tobias Brunner [Tue, 27 Oct 2020 16:02:21 +0000 (17:02 +0100)]
bus: Change ike_update() signature and only call it once

This avoids multiple events when both addresses change (e.g. switching
address families).

20 months agotesting: Add scenarios that use a CA with two intermediate CA certificates
Tobias Brunner [Tue, 15 Dec 2020 17:07:28 +0000 (18:07 +0100)]
testing: Add scenarios that use a CA with two intermediate CA certificates

Mainly to test TKM's ability for handling multiple CAs and that the
received intermediate CA certificates are passed in the right order.
But also added a regular scenario where two intermediate CA certificates
are sent by one of the clients.

20 months agocharon-tkm: Don't use starter/stroke with charon-tkm anymore
Tobias Brunner [Tue, 24 Nov 2020 16:33:13 +0000 (17:33 +0100)]
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.

20 months agocharon-tkm: Deinitialize IKE tkm-rpc client
Tobias Brunner [Mon, 9 Nov 2020 14:54:00 +0000 (15:54 +0100)]
charon-tkm: Deinitialize IKE tkm-rpc client

This is necessary if tkm-rpc supports multiple parallel client requests.

20 months agocharon-tkm: Remove -gnat05 option not supported by newer compilers
Tobias Brunner [Mon, 9 Nov 2020 14:52:54 +0000 (15:52 +0100)]
charon-tkm: Remove -gnat05 option not supported by newer compilers

20 months agocharon-tkm: Reverse cert chain processing order
Adrian-Ken Rueegsegger [Thu, 22 Oct 2020 17:11:32 +0000 (19:11 +0200)]
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.

20 months agotesting: Use latest TKM RPC library
Adrian-Ken Rueegsegger [Wed, 21 Oct 2020 15:35:12 +0000 (17:35 +0200)]
testing: Use latest TKM RPC library

Brings some cleanups and minor improvements.

20 months agotesting: Use multi-CA aware TKM
Adrian-Ken Rueegsegger [Fri, 25 Sep 2020 16:36:34 +0000 (18:36 +0200)]
testing: Use multi-CA aware TKM

Also add CA ID to tkm_keymanager command.

20 months agotesting: Add CA ID mappings to TKM tests
Adrian-Ken Rueegsegger [Fri, 25 Sep 2020 08:47:46 +0000 (10:47 +0200)]
testing: Add CA ID mappings to TKM tests

Extend the build-certs-chroot script is to fill in the public key
fingerprint of the CA certificate in the appropriate strongswan.con

20 months agocharon-tkm: Add support for multiple CAs
Adrian-Ken Rueegsegger [Wed, 23 Sep 2020 16:59:23 +0000 (18:59 +0200)]
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.

20 months agocharon-tkm: Register TKM cred encoder before init
Adrian-Ken Rueegsegger [Mon, 28 Sep 2020 15:39:18 +0000 (17:39 +0200)]
charon-tkm: Register TKM cred encoder before init

Make sure the credential encoder is available early to allow getting
public key fingerprints.

20 months agotesting: Switch to https for codelabs recipes
Adrian-Ken Rueegsegger [Fri, 25 Sep 2020 16:36:25 +0000 (18:36 +0200)]
testing: Switch to https for codelabs recipes

20 months agotesting: Explicitly encode backing image format in metadata 5.9.2dr1
Tobias Brunner [Fri, 8 Jan 2021 10:08:49 +0000 (11:08 +0100)]
testing: Explicitly encode backing image format in metadata

Apparently, there is no probing anymore in newer versions of qemu due
to security considerations.

20 months agoVersion bump to 5.9.2dr1
Andreas Steffen [Fri, 8 Jan 2021 09:34:48 +0000 (10:34 +0100)]
Version bump to 5.9.2dr1

20 months agoimc_attestation: Fixed double free of tpm_version_info chunk
Andreas Steffen [Thu, 7 Jan 2021 11:59:20 +0000 (12:59 +0100)]
imc_attestation: Fixed double free of tpm_version_info chunk

20 months agotpm: Intel FW TPM always uses locality 0
Andreas Steffen [Thu, 31 Dec 2020 15:00:59 +0000 (16:00 +0100)]
tpm: Intel FW TPM always uses locality 0

20 months agolibimcv: Support symlinks introduced by usrmerge
Andreas Steffen [Wed, 30 Dec 2020 09:16:57 +0000 (10:16 +0100)]
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

The new ita_attr_symlinks PA-TNC attribute fixes this problem by
collecting symbolic links pointing to directories on the client

20 months agolibimcv: Evaluate IMA SHA-256 measurements
Andreas Steffen [Thu, 17 Dec 2020 11:14:23 +0000 (12:14 +0100)]
libimcv: Evaluate IMA SHA-256 measurements

20 months agogithub: Bump wolfSSL to 4.6.0
Tobias Brunner [Mon, 4 Jan 2021 13:47:52 +0000 (14:47 +0100)]
github: Bump wolfSSL to 4.6.0

Also enables Brainpool curves (this only enables the BP curves, while
--enable-ecccustcurves=all would also enable several others we don't support).