Add support for Mbed TLS 4
Some checks are pending
Build / Check code style with clang-format (push) Waiting to run
Build / Android - arm64-v8a (push) Waiting to run
Build / gcc-mingw - x64 - Debug - OSSL (push) Waiting to run
Build / gcc-mingw - x64 - Release - OSSL (push) Waiting to run
Build / gcc-mingw - x86 - Debug - OSSL (push) Waiting to run
Build / gcc-mingw - x86 - Release - OSSL (push) Waiting to run
Build / mingw unittest argv - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest auth_token - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest buffer - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest crypto - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest cryptoapi - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest misc - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest ncp - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest options_parse - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest packet_id - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest pkt - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest provider - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest ssl - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest tls_crypt - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest user_pass - x64 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest argv - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest auth_token - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest buffer - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest crypto - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest cryptoapi - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest misc - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest ncp - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest options_parse - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest packet_id - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest pkt - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest provider - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest ssl - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest tls_crypt - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest user_pass - x64 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest argv - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest auth_token - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest buffer - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest crypto - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest cryptoapi - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest misc - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest ncp - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest options_parse - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest packet_id - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest pkt - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest provider - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest ssl - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest tls_crypt - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest user_pass - x86 - Debug - OSSL (push) Blocked by required conditions
Build / mingw unittest argv - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest auth_token - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest buffer - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest crypto - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest cryptoapi - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest misc - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest ncp - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest options_parse - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest packet_id - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest pkt - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest provider - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest ssl - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest tls_crypt - x86 - Release - OSSL (push) Blocked by required conditions
Build / mingw unittest user_pass - x86 - Release - OSSL (push) Blocked by required conditions
Build / gcc - ubuntu-24.04 - OpenSSL 3.0.13 --enable-pkcs11 (push) Waiting to run
Build / gcc - ubuntu-22.04 - OpenSSL 3.0.2 --enable-pkcs11 (push) Waiting to run
Build / clang-asan - ubuntu-22.04 - openssl (push) Waiting to run
Build / clang-asan - ubuntu-24.04 - openssl (push) Waiting to run
Build / macos-14 - libressl - asan (push) Waiting to run
Build / macos-14 - openssl@3 - asan (push) Waiting to run
Build / macos-15 - libressl - asan (push) Waiting to run
Build / macos-15 - openssl@3 - asan (push) Waiting to run
Build / macos-26 - libressl - asan (push) Waiting to run
Build / macos-26 - openssl@3 - asan (push) Waiting to run
Build / macos-14 - libressl - normal (push) Waiting to run
Build / macos-14 - openssl@3 - normal (push) Waiting to run
Build / macos-15 - libressl - normal (push) Waiting to run
Build / macos-15 - openssl@3 - normal (push) Waiting to run
Build / macos-26 - libressl - normal (push) Waiting to run
Build / macos-26 - openssl@3 - normal (push) Waiting to run
Build / msbuild - amd64 - openssl (push) Waiting to run
Build / msbuild - amd64-clang - openssl (push) Waiting to run
Build / msbuild - arm64 - openssl (push) Waiting to run
Build / msbuild - x86 - openssl (push) Waiting to run
Build / msbuild - x86-clang - openssl (push) Waiting to run
Build / clang asan - ubuntu-22.04 - libressl (push) Waiting to run
Build / gcc normal - ubuntu-22.04 - libressl (push) Waiting to run
Build / clang asan - ubuntu-22.04 - mbedtls3 (push) Waiting to run
Build / gcc normal - ubuntu-22.04 - mbedtls3 (push) Waiting to run
Build / clang asan - ubuntu-24.04 - awslc (push) Waiting to run
Build / gcc normal - ubuntu-24.04 - awslc (push) Waiting to run
Deploy Doxygen documentation to Pages / build (push) Waiting to run
Deploy Doxygen documentation to Pages / deploy (push) Blocked by required conditions

This commit adds support for Mbed TLS 4. This version comes with some
drastic changes. The crypto library has been completely redesigned, so
the contents of crypto_mbedtls.c are moved to crypto_mbedtls_legacy.c
and crypto_mbedtls.c handles the crypto for version 4.

Mbed TLS 4 also removed the feature for looking up a crypto algorithm by
name, so we need to translate algorithm names to Mbed TLS numbers in
OpenVPN. The tables are not yet complete. For symmetric algorithms, I
have added AES and Chacha-Poly which should be enough for most use
cases.

Change-Id: Ib251d546d993b96ed3bd8cb9111bcc627cdb0fae
Signed-off-by: Max Fillinger <maximilian.fillinger@sentyron.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1441
Message-Id: <20260123164746.7333-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35401.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
Max Fillinger 2026-01-23 17:47:39 +01:00 committed by Gert Doering
parent b10ee38ccd
commit 494fb71804
16 changed files with 2442 additions and 704 deletions

View file

@ -7,8 +7,8 @@ To build and install,
make
make install
This version requires mbed TLS version >= 3.2.1. Versions >= 4.0.0 are not
yet supported. Support for TLS 1.3 requires an Mbed TLS version >= 3.6.4.
This version requires mbed TLS version >= 3.2.1. Support for TLS 1.3 requires
an Mbed TLS version >= 3.6.4.
*************************************************************************

View file

@ -54,6 +54,7 @@ openvpn_SOURCES = \
comp-lz4.c comp-lz4.h \
crypto.c crypto.h crypto_backend.h \
crypto_openssl.c crypto_openssl.h \
crypto_mbedtls_legacy.c crypto_mbedtls_legacy.h \
crypto_mbedtls.c crypto_mbedtls.h \
crypto_epoch.c crypto_epoch.h \
dco.c dco.h dco_internal.h \

View file

@ -32,9 +32,16 @@
#ifdef ENABLE_CRYPTO_OPENSSL
#include "crypto_openssl.h"
#endif
#ifdef ENABLE_CRYPTO_MBEDTLS
#include <mbedtls/version.h>
#if MBEDTLS_VERSION_NUMBER < 0x04000000
#include "crypto_mbedtls_legacy.h"
#else
#include "crypto_mbedtls.h"
#endif
#endif
#include "basic.h"
#include "buffer.h"

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,4 @@
/*
* OpenVPN -- An application to securely tunnel IP networks
* over a single TCP/UDP port, with support for SSL/TLS-based
@ -23,85 +24,98 @@
/**
* @file
* Data Channel Cryptography mbed TLS-specific backend interface
* Data Channel Cryptography backend interface using the TF-PSA-Crypto library
* part of Mbed TLS 4.
*/
#ifndef CRYPTO_MBEDTLS_H_
#define CRYPTO_MBEDTLS_H_
#ifndef CRYPTO_MBEDTLS4_H_
#define CRYPTO_MBEDTLS4_H_
#include <stdbool.h>
#include <mbedtls/cipher.h>
#include <mbedtls/md.h>
#include <mbedtls/ctr_drbg.h>
#include <psa/crypto.h>
/** Generic message digest key type %context. */
typedef mbedtls_md_info_t md_kt_t;
/** Generic cipher %context. */
typedef mbedtls_cipher_context_t cipher_ctx_t;
/** Generic message digest %context. */
typedef mbedtls_md_context_t md_ctx_t;
/** Generic HMAC %context. */
typedef mbedtls_md_context_t hmac_ctx_t;
/* Use a dummy type for the provider */
typedef void provider_t;
#include "integer.h"
/** Maximum length of an IV */
#define OPENVPN_MAX_IV_LENGTH MBEDTLS_MAX_IV_LENGTH
#define OPENVPN_MAX_IV_LENGTH 16
/** Cipher is in CBC mode */
#define OPENVPN_MODE_CBC MBEDTLS_MODE_CBC
#define OPENVPN_MODE_CBC PSA_ALG_CBC_PKCS7
/** Cipher is in OFB mode */
#define OPENVPN_MODE_OFB MBEDTLS_MODE_OFB
#define OPENVPN_MODE_OFB PSA_ALG_OFB
/** Cipher is in CFB mode */
#define OPENVPN_MODE_CFB MBEDTLS_MODE_CFB
#define OPENVPN_MODE_CFB PSA_ALG_CFB
/** Cipher is in GCM mode */
#define OPENVPN_MODE_GCM MBEDTLS_MODE_GCM
#define OPENVPN_MODE_GCM PSA_ALG_GCM
typedef mbedtls_operation_t crypto_operation_t;
typedef int crypto_operation_t;
/** Cipher should encrypt */
#define OPENVPN_OP_ENCRYPT MBEDTLS_ENCRYPT
#define OPENVPN_OP_ENCRYPT 0
/** Cipher should decrypt */
#define OPENVPN_OP_DECRYPT MBEDTLS_DECRYPT
#define OPENVPN_OP_DECRYPT 1
#define MD4_DIGEST_LENGTH 16
#define MD5_DIGEST_LENGTH 16
#define SHA_DIGEST_LENGTH 20
#define SHA256_DIGEST_LENGTH 32
/**
* Returns a singleton instance of the mbed TLS random number generator.
*
* For PolarSSL/mbed TLS 1.1+, this is the CTR_DRBG random number generator. If it
* hasn't been initialised yet, the RNG will be initialised using the default
* entropy sources. Aside from the default platform entropy sources, an
* additional entropy source, the HAVEGE random number generator will also be
* added. During initialisation, a personalisation string will be added based
* on the time, the PID, and a pointer to the random context.
*/
mbedtls_ctr_drbg_context *rand_ctx_get(void);
typedef void provider_t;
#ifdef ENABLE_PREDICTION_RESISTANCE
/**
* Enable prediction resistance on the random number generator.
*/
void rand_ctx_enable_prediction_resistance(void);
typedef struct cipher_info
{
const char *name;
psa_key_type_t psa_key_type;
psa_algorithm_t psa_alg;
int key_bytes;
int iv_bytes;
int block_size;
} cipher_info_t;
#endif
typedef union psa_cipher_or_aead_operation
{
psa_cipher_operation_t cipher;
psa_aead_operation_t aead;
} cipher_operation_t;
typedef struct cipher_ctx
{
mbedtls_svc_key_id_t key;
psa_key_attributes_t key_attributes;
const cipher_info_t *cipher_info;
bool aead_finished;
cipher_operation_t operation;
uint8_t tag[16];
} cipher_ctx_t;
typedef struct md_info
{
const char *name;
psa_algorithm_t psa_alg;
} md_info_t;
typedef struct md_ctx
{
const md_info_t *md_info;
psa_hash_operation_t operation;
} md_ctx_t;
typedef struct hmac_ctx
{
mbedtls_svc_key_id_t key;
psa_key_attributes_t key_attributes;
const md_info_t *md_info;
psa_mac_operation_t operation;
} hmac_ctx_t;
/**
* Log the supplied mbed TLS error, prefixed by supplied prefix.
*
* @param flags Flags to indicate error type and priority.
* @param errval mbed TLS error code to convert to error message.
* @param errval mbed TLS error code.
* @param prefix Prefix to mbed TLS error message.
*
* @returns true if no errors are detected, false otherwise.
@ -112,7 +126,7 @@ bool mbed_log_err(unsigned int flags, int errval, const char *prefix);
* Log the supplied mbed TLS error, prefixed by function name and line number.
*
* @param flags Flags to indicate error type and priority.
* @param errval mbed TLS error code to convert to error message.
* @param errval mbed TLS error code.
* @param func Function name where error was reported.
* @param line Line number where error was reported.
*
@ -142,7 +156,8 @@ mbed_log_func_line_lite(unsigned int flags, int errval, const char *func, int li
* @param errval mbed TLS error code to convert to error message.
*
* @returns true if no errors are detected, false otherwise.
* TODO: The log function has been removed, do something about it?
*/
#define mbed_ok(errval) mbed_log_func_line_lite(D_CRYPT_ERRORS, errval, __func__, __LINE__)
#endif /* CRYPTO_MBEDTLS_H_ */
#endif /* CRYPTO_MBEDTLS4_H_ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,148 @@
/*
* OpenVPN -- An application to securely tunnel IP networks
* over a single TCP/UDP port, with support for SSL/TLS-based
* session authentication and key exchange,
* packet encryption, packet authentication, and
* packet compression.
*
* Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>
* Copyright (C) 2010-2026 Sentyron B.V. <openvpn@sentyron.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <https://www.gnu.org/licenses/>.
*/
/**
* @file
* Data Channel Cryptography mbed TLS-specific backend interface
*/
#ifndef CRYPTO_MBEDTLS_H_
#define CRYPTO_MBEDTLS_H_
#include <stdbool.h>
#include <mbedtls/cipher.h>
#include <mbedtls/md.h>
#include <mbedtls/ctr_drbg.h>
/** Generic message digest key type %context. */
typedef mbedtls_md_info_t md_kt_t;
/** Generic cipher %context. */
typedef mbedtls_cipher_context_t cipher_ctx_t;
/** Generic message digest %context. */
typedef mbedtls_md_context_t md_ctx_t;
/** Generic HMAC %context. */
typedef mbedtls_md_context_t hmac_ctx_t;
/* Use a dummy type for the provider */
typedef void provider_t;
/** Maximum length of an IV */
#define OPENVPN_MAX_IV_LENGTH MBEDTLS_MAX_IV_LENGTH
/** Cipher is in CBC mode */
#define OPENVPN_MODE_CBC MBEDTLS_MODE_CBC
/** Cipher is in OFB mode */
#define OPENVPN_MODE_OFB MBEDTLS_MODE_OFB
/** Cipher is in CFB mode */
#define OPENVPN_MODE_CFB MBEDTLS_MODE_CFB
/** Cipher is in GCM mode */
#define OPENVPN_MODE_GCM MBEDTLS_MODE_GCM
typedef mbedtls_operation_t crypto_operation_t;
/** Cipher should encrypt */
#define OPENVPN_OP_ENCRYPT MBEDTLS_ENCRYPT
/** Cipher should decrypt */
#define OPENVPN_OP_DECRYPT MBEDTLS_DECRYPT
#define MD4_DIGEST_LENGTH 16
#define MD5_DIGEST_LENGTH 16
#define SHA_DIGEST_LENGTH 20
#define SHA256_DIGEST_LENGTH 32
/**
* Returns a singleton instance of the mbed TLS random number generator.
*
* For PolarSSL/mbed TLS 1.1+, this is the CTR_DRBG random number generator. If it
* hasn't been initialised yet, the RNG will be initialised using the default
* entropy sources. Aside from the default platform entropy sources, an
* additional entropy source, the HAVEGE random number generator will also be
* added. During initialisation, a personalisation string will be added based
* on the time, the PID, and a pointer to the random context.
*/
mbedtls_ctr_drbg_context *rand_ctx_get(void);
#ifdef ENABLE_PREDICTION_RESISTANCE
/**
* Enable prediction resistance on the random number generator.
*/
void rand_ctx_enable_prediction_resistance(void);
#endif
/**
* Log the supplied mbed TLS error, prefixed by supplied prefix.
*
* @param flags Flags to indicate error type and priority.
* @param errval mbed TLS error code to convert to error message.
* @param prefix Prefix to mbed TLS error message.
*
* @returns true if no errors are detected, false otherwise.
*/
bool mbed_log_err(unsigned int flags, int errval, const char *prefix);
/**
* Log the supplied mbed TLS error, prefixed by function name and line number.
*
* @param flags Flags to indicate error type and priority.
* @param errval mbed TLS error code to convert to error message.
* @param func Function name where error was reported.
* @param line Line number where error was reported.
*
* @returns true if no errors are detected, false otherwise.
*/
bool mbed_log_func_line(unsigned int flags, int errval, const char *func, int line);
/** Wraps mbed_log_func_line() to prevent function calls for non-errors */
static inline bool
mbed_log_func_line_lite(unsigned int flags, int errval, const char *func, int line)
{
if (errval)
{
return mbed_log_func_line(flags, errval, func, line);
}
return true;
}
/**
* Check errval and log on error.
*
* Convenience wrapper to put around mbed TLS library calls, e.g.
* if (!mbed_ok (mbedtls_ssl_func())) return 0;
* or
* ASSERT (mbed_ok (mbedtls_ssl_func()));
*
* @param errval mbed TLS error code to convert to error message.
*
* @returns true if no errors are detected, false otherwise.
*/
#define mbed_ok(errval) mbed_log_func_line_lite(D_CRYPT_ERRORS, errval, __func__, __LINE__)
#endif /* CRYPTO_MBEDTLS_H_ */

View file

@ -34,6 +34,16 @@
#include "errlevel.h"
#include <mbedtls/asn1.h>
#include <mbedtls/pk.h>
#if MBEDTLS_VERSION_NUMBER < 0x04000000
#include <mbedtls/ctr_drbg.h>
#include "crypto_mbedtls_legacy.h"
#else
#include <mbedtls/oid.h>
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
#ifdef HAVE_PSA_CRYPTO_H
#include <psa/crypto.h>
#endif
@ -51,4 +61,176 @@ mbedtls_compat_psa_crypto_init(void)
#endif
}
#if MBEDTLS_VERSION_NUMBER >= 0x04000000
typedef struct
{
const char *name;
uint16_t tls_id;
} mbedtls_ecp_curve_info;
static inline int
mbedtls_oid_get_attr_short_name(const mbedtls_asn1_buf *oid, const char **desc)
{
/* The relevant OIDs all have equal length. */
if (oid->tag != MBEDTLS_ASN1_OID || oid->len != strlen(MBEDTLS_OID_AT_CN))
{
*desc = NULL;
return -1;
}
if (memcmp(oid->p, MBEDTLS_OID_AT_CN, oid->len) == 0)
{
*desc = "CN";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_SUR_NAME, oid->len) == 0)
{
*desc = "SN";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_SERIAL_NUMBER, oid->len) == 0)
{
*desc = "serialNumber";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_COUNTRY, oid->len) == 0)
{
*desc = "C";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_LOCALITY, oid->len) == 0)
{
*desc = "L";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_STATE, oid->len) == 0)
{
*desc = "ST";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_ORGANIZATION, oid->len) == 0)
{
*desc = "O";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_ORG_UNIT, oid->len) == 0)
{
*desc = "OU";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_TITLE, oid->len) == 0)
{
*desc = "title";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_POSTAL_ADDRESS, oid->len) == 0)
{
*desc = "postalAddress";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_POSTAL_CODE, oid->len) == 0)
{
*desc = "postalCode";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_GIVEN_NAME, oid->len) == 0)
{
*desc = "GN";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_INITIALS, oid->len) == 0)
{
*desc = "initials";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_GENERATION_QUALIFIER, oid->len) == 0)
{
*desc = "generationQualifier";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_UNIQUE_IDENTIFIER, oid->len) == 0)
{
*desc = "uniqueIdentifier";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_DN_QUALIFIER, oid->len) == 0)
{
*desc = "dnQualifier";
}
else if (memcmp(oid->p, MBEDTLS_OID_AT_PSEUDONYM, oid->len) == 0)
{
*desc = "pseudonym";
}
else
{
*desc = NULL;
return -1;
}
return 0;
}
static inline int
mbedtls_oid_get_extended_key_usage(const mbedtls_asn1_buf *oid, const char **desc)
{
/* The relevant OIDs all have equal length. */
if (oid->tag != MBEDTLS_ASN1_OID || oid->len != strlen(MBEDTLS_OID_SERVER_AUTH))
{
*desc = NULL;
return -1;
}
if (memcmp(oid->p, MBEDTLS_OID_SERVER_AUTH, oid->len) == 0)
{
*desc = "TLS Web Server Authentication";
}
else if (memcmp(oid->p, MBEDTLS_OID_CLIENT_AUTH, oid->len) == 0)
{
*desc = "TLS Web Client Authentication";
}
else if (memcmp(oid->p, MBEDTLS_OID_CODE_SIGNING, oid->len) == 0)
{
*desc = "Code Signing";
}
else if (memcmp(oid->p, MBEDTLS_OID_EMAIL_PROTECTION, oid->len) == 0)
{
*desc = "E-mail Protection";
}
else if (memcmp(oid->p, MBEDTLS_OID_TIME_STAMPING, oid->len) == 0)
{
*desc = "Time Stamping";
}
else if (memcmp(oid->p, MBEDTLS_OID_OCSP_SIGNING, oid->len) == 0)
{
*desc = "OCSP Signing";
}
else
{
*desc = NULL;
return -1;
}
return 0;
}
#endif /* MBEDTLS_VERSION_NUMBER >= 0x04000000 */
/* Some functions that operate on private keys use randomness to protect against
* side channels. In Mbed TLS 4, they automatically use the RNG in the PSA
* library, but in Mbed TLS 3, they require them as explicit arguments. */
static inline int
mbedtls_compat_pk_parse_key(mbedtls_pk_context *ctx,
const unsigned char *key, size_t keylen,
const unsigned char *pwd, size_t pwdlen)
{
#if MBEDTLS_VERSION_NUMBER >= 0x04000000
return mbedtls_pk_parse_key(ctx, key, keylen, pwd, pwdlen);
#else
return mbedtls_pk_parse_key(ctx, key, keylen, pwd, pwdlen, mbedtls_ctr_drbg_random, rand_ctx_get());
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
}
static inline int
mbedtls_compat_pk_parse_keyfile(mbedtls_pk_context *ctx, const char *path, const char *password)
{
#if MBEDTLS_VERSION_NUMBER >= 0x04000000
return mbedtls_pk_parse_keyfile(ctx, path, password);
#else
return mbedtls_pk_parse_keyfile(ctx, path, password, mbedtls_ctr_drbg_random, rand_ctx_get());
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
}
static inline int
mbedtls_compat_pk_check_pair(const mbedtls_pk_context *pub, const mbedtls_pk_context *prv)
{
#if MBEDTLS_VERSION_NUMBER >= 0x04000000
return mbedtls_pk_check_pair(pub, prv);
#else
return mbedtls_pk_check_pair(pub, prv, mbedtls_ctr_drbg_random, rand_ctx_get());
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
}
#endif /* MBEDTLS_COMPAT_H_ */

View file

@ -93,7 +93,9 @@ tls_ctx_server_new(struct tls_root_ctx *ctx)
ASSERT(NULL != ctx);
CLEAR(*ctx);
#if MBEDTLS_VERSION_NUMBER < 0x04000000
ALLOC_OBJ_CLEAR(ctx->dhm_ctx, mbedtls_dhm_context);
#endif
ALLOC_OBJ_CLEAR(ctx->ca_chain, mbedtls_x509_crt);
@ -107,7 +109,9 @@ tls_ctx_client_new(struct tls_root_ctx *ctx)
ASSERT(NULL != ctx);
CLEAR(*ctx);
#if MBEDTLS_VERSION_NUMBER < 0x04000000
ALLOC_OBJ_CLEAR(ctx->dhm_ctx, mbedtls_dhm_context);
#endif
ALLOC_OBJ_CLEAR(ctx->ca_chain, mbedtls_x509_crt);
ctx->endpoint = MBEDTLS_SSL_IS_CLIENT;
@ -128,8 +132,10 @@ tls_ctx_free(struct tls_root_ctx *ctx)
mbedtls_x509_crt_free(ctx->crt_chain);
free(ctx->crt_chain);
#if MBEDTLS_VERSION_NUMBER < 0x04000000
mbedtls_dhm_free(ctx->dhm_ctx);
free(ctx->dhm_ctx);
#endif
mbedtls_x509_crl_free(ctx->crl);
free(ctx->crl);
@ -348,6 +354,34 @@ tls_ctx_set_cert_profile(struct tls_root_ctx *ctx, const char *profile)
}
}
#if MBEDTLS_VERSION_NUMBER >= 0x04000000
static const mbedtls_ecp_curve_info ecp_curve_info_table[] = {
/* TODO: Fill out the table. */
{ "secp256r1", MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 },
{ "secp384r1", MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 },
{ "X25519", MBEDTLS_SSL_IANA_TLS_GROUP_X25519 },
{ "ffdhe2048", MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048 },
{ "ffdhe3072", MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072 },
{ "ffdhe4096", MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096 },
{ "ffdhe6144", MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144 },
{ "ffdhe8192", MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192 },
};
static const size_t ecp_curve_info_table_items = sizeof(ecp_curve_info_table) / sizeof(mbedtls_ecp_curve_info);
static const mbedtls_ecp_curve_info *
mbedtls_ecp_curve_info_from_name(const char *name)
{
for (size_t i = 0; i < ecp_curve_info_table_items; i++)
{
if (strcmp(name, ecp_curve_info_table[i].name) == 0)
{
return &ecp_curve_info_table[i];
}
}
return NULL;
}
#endif /* MBEDTLS_VERSION_NUMBER >= 0x04000000 */
void
tls_ctx_set_tls_groups(struct tls_root_ctx *ctx, const char *groups)
{
@ -409,6 +443,7 @@ tls_ctx_check_cert_time(const struct tls_root_ctx *ctx)
void
tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, bool dh_inline)
{
#if MBEDTLS_VERSION_NUMBER < 0x04000000
if (dh_inline)
{
if (!mbed_ok(mbedtls_dhm_parse_dhm(ctx->dhm_ctx, (const unsigned char *)dh_file,
@ -427,6 +462,12 @@ tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, bool dh_in
msg(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with " counter_format " bit key",
(counter_type)mbedtls_dhm_get_bitlen(ctx->dhm_ctx));
#else
if (strcmp(dh_file, "none") != 0)
{
msg(M_FATAL, "Mbed TLS 4 only supports pre-defined Diffie-Hellman groups.");
}
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
}
void
@ -500,29 +541,26 @@ tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file, bool
if (priv_key_inline)
{
status = mbedtls_pk_parse_key(ctx->priv_key, (const unsigned char *)priv_key_file,
strlen(priv_key_file) + 1, NULL, 0,
mbedtls_ctr_drbg_random, rand_ctx_get());
status = mbedtls_compat_pk_parse_key(ctx->priv_key, (const unsigned char *)priv_key_file,
strlen(priv_key_file) + 1, NULL, 0);
if (MBEDTLS_ERR_PK_PASSWORD_REQUIRED == status)
{
char passbuf[512] = { 0 };
pem_password_callback(passbuf, 512, 0, NULL);
status = mbedtls_pk_parse_key(
status = mbedtls_compat_pk_parse_key(
ctx->priv_key, (const unsigned char *)priv_key_file, strlen(priv_key_file) + 1,
(unsigned char *)passbuf, strlen(passbuf), mbedtls_ctr_drbg_random, rand_ctx_get());
(unsigned char *)passbuf, strlen(passbuf));
}
}
else
{
status = mbedtls_pk_parse_keyfile(ctx->priv_key, priv_key_file, NULL,
mbedtls_ctr_drbg_random, rand_ctx_get());
status = mbedtls_compat_pk_parse_keyfile(ctx->priv_key, priv_key_file, NULL);
if (MBEDTLS_ERR_PK_PASSWORD_REQUIRED == status)
{
char passbuf[512] = { 0 };
pem_password_callback(passbuf, 512, 0, NULL);
status = mbedtls_pk_parse_keyfile(ctx->priv_key, priv_key_file, passbuf,
mbedtls_ctr_drbg_random, rand_ctx_get());
status = mbedtls_compat_pk_parse_keyfile(ctx->priv_key, priv_key_file, passbuf);
}
}
if (!mbed_ok(status))
@ -538,8 +576,7 @@ tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file, bool
return 1;
}
if (!mbed_ok(mbedtls_pk_check_pair(&ctx->crt_chain->pk, ctx->priv_key,
mbedtls_ctr_drbg_random, rand_ctx_get())))
if (!mbed_ok(mbedtls_compat_pk_check_pair(&ctx->crt_chain->pk, ctx->priv_key)))
{
msg(M_WARN, "Private key does not match the certificate");
return 1;
@ -553,6 +590,7 @@ tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file, bool
#pragma GCC diagnostic ignored "-Wconversion"
#endif
#if MBEDTLS_VERSION_NUMBER < 0x04000000
/**
* external_pkcs1_sign implements a mbed TLS rsa_sign_func callback, that uses
* the management interface to request an RSA signature for the supplied hash.
@ -669,11 +707,16 @@ external_key_len(void *vctx)
return ctx->signature_length;
}
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
int
tls_ctx_use_external_signing_func(struct tls_root_ctx *ctx, external_sign_func sign_func,
void *sign_ctx)
{
#if MBEDTLS_VERSION_NUMBER >= 0x04000000
msg(M_WARN, "tls_ctx_use_external_signing_func is not implemented for Mbed TLS 4.");
return 1;
#else
ASSERT(NULL != ctx);
if (ctx->crt_chain == NULL)
@ -701,6 +744,7 @@ tls_ctx_use_external_signing_func(struct tls_root_ctx *ctx, external_sign_func s
}
return 0;
#endif /* MBEDTLS_VERSION_NUMBER >= 0x04000000 */
}
#ifdef ENABLE_MANAGEMENT
@ -938,6 +982,7 @@ my_debug(void *ctx, int level, const char *file, int line, const char *str)
void
tls_ctx_personalise_random(struct tls_root_ctx *ctx)
{
#if MBEDTLS_VERSION_NUMBER < 0x04000000
static char old_sha256_hash[32] = { 0 };
unsigned char sha256_hash[32] = { 0 };
mbedtls_ctr_drbg_context *cd_ctx = rand_ctx_get();
@ -960,6 +1005,7 @@ tls_ctx_personalise_random(struct tls_root_ctx *ctx)
memcpy(old_sha256_hash, sha256_hash, sizeof(old_sha256_hash));
}
}
#endif /* MBEDTLS_VERSION_NUMBER < 0x040000 */
}
#if defined(__GNUC__) || defined(__clang__)
@ -1069,7 +1115,9 @@ key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_root_ctx *ssl_
}
#endif
mbedtls_ssl_conf_dbg(ks_ssl->ssl_config, my_debug, NULL);
#if MBEDTLS_VERSION_NUMBER < 0x04000000
mbedtls_ssl_conf_rng(ks_ssl->ssl_config, mbedtls_ctr_drbg_random, rand_ctx_get());
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
mbedtls_ssl_conf_cert_profile(ks_ssl->ssl_config, &ssl_ctx->cert_profile);
@ -1100,12 +1148,14 @@ key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_root_ctx *ssl_
#endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
/* Initialise authentication information */
#if MBEDTLS_VERSION_NUMBER < 0x04000000
if (is_server)
{
mbed_ok(mbedtls_ssl_conf_dh_param_ctx(ks_ssl->ssl_config, ssl_ctx->dhm_ctx));
}
#endif
mbed_ok(mbedtls_ssl_conf_own_cert(ks_ssl->ssl_config, ssl_ctx->crt_chain, ssl_ctx->priv_key));
(void)mbed_ok(mbedtls_ssl_conf_own_cert(ks_ssl->ssl_config, ssl_ctx->crt_chain, ssl_ctx->priv_key));
/* Initialise SSL verification */
if (session->opt->ssl_flags & SSLF_CLIENT_CERT_OPTIONAL)
@ -1160,7 +1210,7 @@ key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_root_ctx *ssl_
/* Initialise SSL context */
ALLOC_OBJ_CLEAR(ks_ssl->ctx, mbedtls_ssl_context);
mbedtls_ssl_init(ks_ssl->ctx);
mbed_ok(mbedtls_ssl_setup(ks_ssl->ctx, ks_ssl->ssl_config));
(void)mbed_ok(mbedtls_ssl_setup(ks_ssl->ctx, ks_ssl->ssl_config));
/* We do verification in our own callback depending on the
* exact configuration. We do not rely on the default hostname
* verification. */
@ -1376,7 +1426,8 @@ key_state_read_plaintext(struct key_state_ssl *ks, struct buffer *buf)
/* Error during read, check for retry error */
if (retval < 0)
{
if (MBEDTLS_ERR_SSL_WANT_WRITE == retval || MBEDTLS_ERR_SSL_WANT_READ == retval)
if (MBEDTLS_ERR_SSL_WANT_WRITE == retval || MBEDTLS_ERR_SSL_WANT_READ == retval
|| MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET == retval)
{
return 0;
}
@ -1456,6 +1507,7 @@ show_available_tls_ciphers_list(const char *cipher_list, const char *tls_cert_pr
void
show_available_curves(void)
{
#if MBEDTLS_VERSION_NUMBER < 0x04000000
const mbedtls_ecp_curve_info *pcurve = mbedtls_ecp_curve_list();
if (NULL == pcurve)
@ -1470,6 +1522,9 @@ show_available_curves(void)
printf("%s\n", pcurve->name);
pcurve++;
}
#else
msg(M_FATAL, "Mbed TLS 4 has no mechanism to list supported curves.");
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
}
const char *

View file

@ -112,11 +112,13 @@ struct tls_key_cache
*/
struct tls_root_ctx
{
bool initialised; /**< True if the context has been initialised */
bool initialised; /**< True if the context has been initialised */
int endpoint; /**< Whether or not this is a server or a client */
int endpoint; /**< Whether or not this is a server or a client */
#if MBEDTLS_VERSION_NUMBER < 0x04000000
mbedtls_dhm_context *dhm_ctx; /**< Diffie-Helmann-Merkle context */
#endif
mbedtls_x509_crt *crt_chain; /**< Local Certificate chain */
mbedtls_x509_crt *ca_chain; /**< CA chain for remote verification */
mbedtls_pk_context *priv_key; /**< Local private key */

View file

@ -34,13 +34,22 @@
#if defined(ENABLE_CRYPTO_MBEDTLS)
#include <mbedtls/version.h>
#if MBEDTLS_VERSION_NUMBER < 0x04000000
#include "crypto_mbedtls_legacy.h"
#include <mbedtls/bignum.h>
#include <mbedtls/sha1.h>
#else
#include "crypto_mbedtls.h"
#endif
#include "mbedtls_compat.h"
#include "ssl_verify.h"
#include <mbedtls/asn1.h>
#include <mbedtls/error.h>
#include <mbedtls/bignum.h>
#include <mbedtls/oid.h>
#include <mbedtls/sha1.h>
#define MAX_SUBJECT_LENGTH 256
@ -171,11 +180,139 @@ backend_x509_get_username(char *cn, size_t cn_len, char *x509_username_field, mb
return SUCCESS;
}
#if MBEDTLS_VERSION_NUMBER >= 0x04000000
/* Mbed TLS 4 has no function to print the certificate serial number and does
* not expose the bignum functions anymore. So in order to write the serial
* number as a decimal string, we implement bignum % 10 and bignum / 10. */
static char
bignum_mod_10(const uint8_t *bignum, size_t bignum_length)
{
int result = 0;
for (size_t i = 0; i < bignum_length; i++)
{
result = (result * 256) % 10;
result = (result + bignum[i]) % 10;
}
return (char)result;
}
/* Divide bignum by 10 rounded down, in place. */
static void
bignum_div_10(uint8_t *bignum, size_t *bignum_length)
{
/*
* Some intuition for the algorithm below:
*
* We want to calculate
*
* (bignum[0] * 256^n + bignum[1] * 256^(n-1) + ... + bignum[n]) / 10.
*
* Let remainder = bignum[0] % 10 and carry = remainder * 256.
* Then we can write the above as
*
* (bignum[0] / 10) * 256^n
* + ((carry + bignum[1]) * 256^(n-1) + ... + bignum[n]) / 10.
*
* So now we have the first byte of our result. The second byte will be
* (carry + bignum[1]) / 10. Note that this fits into one byte because
* 0 <= remainder < 10. We calculate the next remainder and carry as
* remainder = (carry + bignum[1]) % 10 and carry = remainder * 256 and
* move on to the next byte until we are done.
*/
size_t new_length = 0;
int carry = 0;
for (size_t i = 0; i < *bignum_length; i++)
{
uint8_t next_byte = (uint8_t)((bignum[i] + carry) / 10);
int remainder = (bignum[i] + carry) % 10;
carry = remainder * 256;
/* Write the byte unless it's a leading zero. */
if (new_length != 0 || next_byte != 0)
{
bignum[new_length++] = next_byte;
}
}
*bignum_length = new_length;
}
/* Write the decimal representation of bignum to out, if enough space is available.
* Returns the number of bytes needed in out, or 0 on error. To calculate the
* necessary buffer size, the function can be called with out = NULL. */
static size_t
write_bignum(char *out, size_t out_size, const uint8_t *bignum, size_t bignum_length)
{
if (bignum_length == 0)
{
/* We want out to be "0". */
if (out != NULL)
{
if (out_size >= 2)
{
out[0] = '0';
out[1] = '\0';
}
else if (out_size > 0)
{
out[0] = '\0';
}
}
return 2;
}
uint8_t *bignum_copy = malloc(bignum_length);
if (bignum_copy == NULL)
{
return 0;
}
memcpy(bignum_copy, bignum, bignum_length);
size_t bytes_needed = 0;
size_t bytes_written = 0;
while (bignum_length > 0)
{
/* We're writing the digits in reverse order. We put them in the right order later. */
char digit = bignum_mod_10(bignum_copy, bignum_length);
if (out != NULL && bytes_written < out_size - 1)
{
out[bytes_written++] = '0' + (char)digit;
}
bytes_needed += 1;
bignum_div_10(bignum_copy, &bignum_length);
}
if (out != NULL)
{
if (bytes_written == bytes_needed)
{
/* We had space for all digits. Now reverse them. */
for (size_t i = 0; i < bytes_written / 2; i++)
{
char tmp = out[i];
out[i] = out[bytes_written - 1 - i];
out[bytes_written - 1 - i] = tmp;
}
out[bytes_written] = '\0';
}
else if (out_size > 0)
{
out[0] = '\0';
}
}
bytes_needed += 1;
free(bignum_copy);
return bytes_needed;
}
#endif /* MBEDTLS_VERSION_NUMBER >= 0x04000000 */
char *
backend_x509_get_serial(mbedtls_x509_crt *cert, struct gc_arena *gc)
{
char *buf = NULL;
size_t buflen = 0;
#if MBEDTLS_VERSION_NUMBER < 0x04000000
mbedtls_mpi serial_mpi = { 0 };
/* Transform asn1 integer serial into mbed TLS MPI */
@ -201,6 +338,21 @@ backend_x509_get_serial(mbedtls_x509_crt *cert, struct gc_arena *gc)
end:
mbedtls_mpi_free(&serial_mpi);
return buf;
#else
buflen = write_bignum(NULL, 0, cert->serial.p, cert->serial.len);
if (buflen == 0)
{
msg(M_WARN, "Failed to write serial to string.");
return NULL;
}
buf = gc_malloc(buflen, true, gc);
if (write_bignum(buf, buflen, cert->serial.p, cert->serial.len) != buflen)
{
msg(M_WARN, "Failed to write serial to string.");
return NULL;
}
return buf;
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
}
char *

View file

@ -475,7 +475,10 @@ socket_defined(const socket_descriptor_t sd)
#endif
#ifdef ENABLE_CRYPTO_MBEDTLS
#include <mbedtls/version.h>
#if MBEDTLS_VERSION_NUMBER < 0x04000000
#define ENABLE_PREDICTION_RESISTANCE
#endif /* MBEDTLS_VERSION_NUMBER < 0x04000000 */
#endif /* ENABLE_CRYPTO_MBEDTLS */
/*

View file

@ -55,6 +55,7 @@ ntlm_support_SOURCES = ntlm_support.c \
$(top_srcdir)/src/openvpn/crypto_epoch.c \
$(top_srcdir)/src/openvpn/crypto_openssl.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls_legacy.c \
$(top_srcdir)/src/openvpn/otime.c \
$(top_srcdir)/src/openvpn/packet_id.c \
$(top_srcdir)/src/openvpn/platform.c

View file

@ -57,7 +57,7 @@ SERVER_NAME_2="t_server_null_server-1195_tcp"
SERVER_SERVER_2="--server 10.29.42.0 255.255.255.0"
SERVER_MGMT_PORT_2="11195"
SERVER_EXEC_2="${SERVER_EXEC}"
SERVER_CONF_2="${SERVER_CONF_BASE} ${SERVER_SERVER_2} --lport 1195 --proto tcp --management 127.0.0.1 ${SERVER_MGMT_PORT_2} --dh ${DH}"
SERVER_CONF_2="${SERVER_CONF_BASE} ${SERVER_SERVER_2} --lport 1195 --proto tcp --management 127.0.0.1 ${SERVER_MGMT_PORT_2} --dh none"
SERVER_NAME_3="t_server_null_server-1196_udp"
SERVER_SERVER_3="--server 10.29.43.0 255.255.255.0"

View file

@ -76,6 +76,7 @@ crypto_testdriver_SOURCES = test_crypto.c \
$(top_srcdir)/src/openvpn/buffer.c \
$(top_srcdir)/src/openvpn/crypto.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls_legacy.c \
$(top_srcdir)/src/openvpn/crypto_openssl.c \
$(top_srcdir)/src/openvpn/crypto_epoch.c \
$(top_srcdir)/src/openvpn/otime.c \
@ -110,6 +111,7 @@ ssl_testdriver_SOURCES = test_ssl.c \
$(top_srcdir)/src/openvpn/cryptoapi.c \
$(top_srcdir)/src/openvpn/crypto_epoch.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls_legacy.c \
$(top_srcdir)/src/openvpn/crypto_openssl.c \
$(top_srcdir)/src/openvpn/env_set.c \
$(top_srcdir)/src/openvpn/mss.c \
@ -158,6 +160,7 @@ pkt_testdriver_SOURCES = test_pkt.c mock_msg.c mock_msg.h mock_win32_execve.c te
$(top_srcdir)/src/openvpn/crypto.c \
$(top_srcdir)/src/openvpn/crypto_epoch.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls_legacy.c \
$(top_srcdir)/src/openvpn/crypto_openssl.c \
$(top_srcdir)/src/openvpn/env_set.c \
$(top_srcdir)/src/openvpn/otime.c \
@ -188,6 +191,7 @@ tls_crypt_testdriver_SOURCES = test_tls_crypt.c \
$(top_srcdir)/src/openvpn/crypto.c \
$(top_srcdir)/src/openvpn/crypto_epoch.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls_legacy.c \
$(top_srcdir)/src/openvpn/crypto_openssl.c \
$(top_srcdir)/src/openvpn/env_set.c \
$(top_srcdir)/src/openvpn/otime.c \
@ -208,6 +212,7 @@ networking_testdriver_SOURCES = test_networking.c mock_msg.c \
$(top_srcdir)/src/openvpn/crypto.c \
$(top_srcdir)/src/openvpn/crypto_epoch.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls_legacy.c \
$(top_srcdir)/src/openvpn/crypto_openssl.c \
$(top_srcdir)/src/openvpn/fdmisc.c \
$(top_srcdir)/src/openvpn/otime.c \
@ -294,6 +299,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c \
$(top_srcdir)/src/openvpn/crypto.c \
$(top_srcdir)/src/openvpn/crypto_epoch.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls_legacy.c \
$(top_srcdir)/src/openvpn/crypto_openssl.c \
$(top_srcdir)/src/openvpn/otime.c \
$(top_srcdir)/src/openvpn/packet_id.c \
@ -332,6 +338,7 @@ ncp_testdriver_SOURCES = test_ncp.c \
$(top_srcdir)/src/openvpn/crypto.c \
$(top_srcdir)/src/openvpn/crypto_epoch.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
$(top_srcdir)/src/openvpn/crypto_mbedtls_legacy.c \
$(top_srcdir)/src/openvpn/crypto_openssl.c \
$(top_srcdir)/src/openvpn/otime.c \
$(top_srcdir)/src/openvpn/packet_id.c \

View file

@ -25,6 +25,10 @@
#include <stdlib.h>
#include <cmocka.h>
#if defined(ENABLE_CRYPTO_MBEDTLS)
#include "mbedtls_compat.h"
#endif
/* Do we use cmocka < 2.0.0? */
#ifndef HAVE_CMOCKA_VERSION_H
#define HAVE_OLD_CMOCKA_API 1
@ -58,6 +62,9 @@ openvpn_unit_test_setup(void)
{
assert_int_equal(setvbuf(stdout, NULL, _IONBF, BUFSIZ), 0);
assert_int_equal(setvbuf(stderr, NULL, _IONBF, BUFSIZ), 0);
#if defined(ENABLE_CRYPTO_MBEDTLS)
mbedtls_compat_psa_crypto_init();
#endif
}
/**