OpenVPN
Macros | Functions
openssl_compat.h File Reference
#include "buffer.h"
#include <openssl/rsa.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
Include dependency graph for openssl_compat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define OPENSSL_VERSION   SSLEAY_VERSION
 
#define OpenSSL_version   SSLeay_version
 
#define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT   RSA_F_RSA_EAY_PRIVATE_ENCRYPT
 

Functions

static int EVP_MD_CTX_reset (EVP_MD_CTX *ctx)
 Reset a message digest context. More...
 
static void EVP_MD_CTX_free (EVP_MD_CTX *ctx)
 Free an existing message digest context. More...
 
static EVP_MD_CTX * EVP_MD_CTX_new (void)
 Allocate a new message digest object. More...
 
static int HMAC_CTX_reset (HMAC_CTX *ctx)
 Reset a HMAC context. More...
 
static void HMAC_CTX_free (HMAC_CTX *ctx)
 Cleanup and free an existing HMAC context. More...
 
static HMAC_CTX * HMAC_CTX_new (void)
 Allocate a new HMAC context object. More...
 
static void * SSL_CTX_get_default_passwd_cb_userdata (SSL_CTX *ctx)
 Fetch the default password callback user data from the SSL context. More...
 
static pem_password_cb * SSL_CTX_get_default_passwd_cb (SSL_CTX *ctx)
 Fetch the default password callback from the SSL context. More...
 
static EVP_PKEY * X509_get0_pubkey (const X509 *x)
 Get the public key from a X509 certificate. More...
 
static STACK_OF (X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *store)
 Fetch the X509 object stack from the X509 store. More...
 
static void X509_OBJECT_free (X509_OBJECT *obj)
 Destroy a X509 object. More...
 
static int X509_OBJECT_get_type (const X509_OBJECT *obj)
 Get the type of an X509 object. More...
 
static RSA * EVP_PKEY_get0_RSA (EVP_PKEY *pkey)
 Get the RSA object of a public key. More...
 
static EC_KEY * EVP_PKEY_get0_EC_KEY (EVP_PKEY *pkey)
 Get the EC_KEY object of a public key. More...
 
static int EVP_PKEY_id (const EVP_PKEY *pkey)
 Get the PKEY type. More...
 
static DSA * EVP_PKEY_get0_DSA (EVP_PKEY *pkey)
 Get the DSA object of a public key. More...
 
static void RSA_set_flags (RSA *rsa, int flags)
 Set the RSA flags. More...
 
static void RSA_get0_key (const RSA *rsa, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
 Get the RSA parameters. More...
 
static int RSA_set0_key (RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d)
 Set the RSA parameters. More...
 
static int RSA_bits (const RSA *rsa)
 Number of significant RSA bits. More...
 
static void DSA_get0_pqg (const DSA *dsa, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
 Get the DSA parameters. More...
 
static int DSA_bits (const DSA *dsa)
 Number of significant DSA bits. More...
 
static RSA_METHOD * RSA_meth_new (const char *name, int flags)
 Allocate a new RSA method object. More...
 
static void RSA_meth_free (RSA_METHOD *meth)
 Free an existing RSA_METHOD object. More...
 
static int RSA_meth_set_pub_enc (RSA_METHOD *meth, int(*pub_enc)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
 Set the public encoding function of an RSA_METHOD object. More...
 
static int RSA_meth_set_pub_dec (RSA_METHOD *meth, int(*pub_dec)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
 Set the public decoding function of an RSA_METHOD object. More...
 
static int RSA_meth_set_priv_enc (RSA_METHOD *meth, int(*priv_enc)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
 Set the private encoding function of an RSA_METHOD object. More...
 
static int RSA_meth_set_priv_dec (RSA_METHOD *meth, int(*priv_dec)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
 Set the private decoding function of an RSA_METHOD object. More...
 
static int RSA_meth_set_init (RSA_METHOD *meth, int(*init)(RSA *rsa))
 Set the init function of an RSA_METHOD object. More...
 
static int RSA_meth_set_sign (RSA_METHOD *meth, int(*sign)(int type, const unsigned char *m, unsigned int m_length, unsigned char *sigret, unsigned int *siglen, const RSA *rsa))
 Set the sign function of an RSA_METHOD object. More...
 
static int RSA_meth_set_finish (RSA_METHOD *meth, int(*finish)(RSA *rsa))
 Set the finish function of an RSA_METHOD object. More...
 
static int RSA_meth_set0_app_data (RSA_METHOD *meth, void *app_data)
 Set the application data of an RSA_METHOD object. More...
 
static void * RSA_meth_get0_app_data (const RSA_METHOD *meth)
 Get the application data of an RSA_METHOD object. More...
 
static int EC_GROUP_order_bits (const EC_GROUP *group)
 Gets the number of bits of the order of an EC_GROUP. More...
 
static int SSL_CTX_get_min_proto_version (SSL_CTX *ctx)
 Return the min SSL protocol version currently enabled in the context. More...
 
static int SSL_CTX_get_max_proto_version (SSL_CTX *ctx)
 Return the max SSL protocol version currently enabled in the context. More...
 
static int SSL_CTX_set_min_proto_version (SSL_CTX *ctx, long tls_ver_min)
 Mimics SSL_CTX_set_min_proto_version for OpenSSL < 1.1. More...
 
static int SSL_CTX_set_max_proto_version (SSL_CTX *ctx, long tls_ver_max)
 Mimics SSL_CTX_set_max_proto_version for OpenSSL < 1.1. More...
 

Macro Definition Documentation

◆ OPENSSL_VERSION

#define OPENSSL_VERSION   SSLEAY_VERSION

Definition at line 683 of file openssl_compat.h.

Referenced by get_ssl_library_version().

◆ OpenSSL_version

#define OpenSSL_version   SSLeay_version

Definition at line 687 of file openssl_compat.h.

Referenced by get_ssl_library_version().

◆ RSA_F_RSA_OSSL_PRIVATE_ENCRYPT

#define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT   RSA_F_RSA_EAY_PRIVATE_ENCRYPT

Definition at line 691 of file openssl_compat.h.

Referenced by priv_enc_CNG(), rsa_priv_enc(), and rsa_sign_CNG().

Function Documentation

◆ DSA_bits()

static int DSA_bits ( const DSA *  dsa)
inlinestatic

Number of significant DSA bits.

Parameters
rsaThe DSA object ; shall not be NULL
Returns
The number of DSA bits or 0 on error

Definition at line 426 of file openssl_compat.h.

References DSA_get0_pqg().

Referenced by print_details().

◆ DSA_get0_pqg()

static void DSA_get0_pqg ( const DSA *  dsa,
const BIGNUM **  p,
const BIGNUM **  q,
const BIGNUM **  g 
)
inlinestatic

Get the DSA parameters.

Parameters
dsaThe DSA object
pThe p parameter
qThe q parameter
gThe g parameter

Definition at line 400 of file openssl_compat.h.

Referenced by DSA_bits().

◆ EC_GROUP_order_bits()

static int EC_GROUP_order_bits ( const EC_GROUP *  group)
inlinestatic

Gets the number of bits of the order of an EC_GROUP.

Parameters
groupEC_GROUP object
Returns
number of bits of group order.

Definition at line 671 of file openssl_compat.h.

Referenced by print_details().

◆ EVP_MD_CTX_free()

static void EVP_MD_CTX_free ( EVP_MD_CTX *  ctx)
inlinestatic

Free an existing message digest context.

Parameters
ctxThe message digest context

Definition at line 71 of file openssl_compat.h.

References free.

Referenced by md_ctx_free().

◆ EVP_MD_CTX_new()

static EVP_MD_CTX* EVP_MD_CTX_new ( void  )
inlinestatic

Allocate a new message digest object.

Returns
A zero'ed message digest object

Definition at line 84 of file openssl_compat.h.

References ALLOC_OBJ_CLEAR.

Referenced by md_ctx_new().

◆ EVP_MD_CTX_reset()

static int EVP_MD_CTX_reset ( EVP_MD_CTX *  ctx)
inlinestatic

Reset a message digest context.

Parameters
ctxThe message digest context
Returns
1 on success, 0 on error

Definition at line 57 of file openssl_compat.h.

Referenced by md_ctx_cleanup().

◆ EVP_PKEY_get0_DSA()

static DSA* EVP_PKEY_get0_DSA ( EVP_PKEY *  pkey)
inlinestatic

Get the DSA object of a public key.

Parameters
pkeyPublic key object
Returns
The underlying DSA object

Definition at line 284 of file openssl_compat.h.

Referenced by print_details().

◆ EVP_PKEY_get0_EC_KEY()

static EC_KEY* EVP_PKEY_get0_EC_KEY ( EVP_PKEY *  pkey)
inlinestatic

Get the EC_KEY object of a public key.

Parameters
pkeyPublic key object
Returns
The underlying EC_KEY object

Definition at line 256 of file openssl_compat.h.

Referenced by finish(), print_details(), and tls_ctx_use_external_rsa_key().

◆ EVP_PKEY_get0_RSA()

static RSA* EVP_PKEY_get0_RSA ( EVP_PKEY *  pkey)
inlinestatic

Get the RSA object of a public key.

Parameters
pkeyPublic key object
Returns
The underlying RSA object

Definition at line 242 of file openssl_compat.h.

Referenced by find_certificate_in_store(), print_details(), ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ EVP_PKEY_id()

static int EVP_PKEY_id ( const EVP_PKEY *  pkey)
inlinestatic

Get the PKEY type.

Parameters
pkeyPublic key object
Returns
The key type

Definition at line 270 of file openssl_compat.h.

Referenced by find_certificate_in_store(), print_details(), SSL_CTX_use_CryptoAPI_certificate(), and tls_ctx_use_management_external_key().

◆ HMAC_CTX_free()

static void HMAC_CTX_free ( HMAC_CTX *  ctx)
inlinestatic

Cleanup and free an existing HMAC context.

Parameters
ctxThe HMAC context

Definition at line 124 of file openssl_compat.h.

References free.

Referenced by hmac_ctx_free().

◆ HMAC_CTX_new()

static HMAC_CTX* HMAC_CTX_new ( void  )
inlinestatic

Allocate a new HMAC context object.

Returns
A zero'ed HMAC context object

Definition at line 138 of file openssl_compat.h.

References ALLOC_OBJ_CLEAR.

Referenced by hmac_ctx_new().

◆ HMAC_CTX_reset()

static int HMAC_CTX_reset ( HMAC_CTX *  ctx)
inlinestatic

Reset a HMAC context.

OpenSSL 1.1+ removes APIs HMAC_CTX_init() and HMAC_CTX_cleanup() and replace them with a single call that does a cleanup followed by an init. A proper _reset() for OpenSSL < 1.1 should perform a similar set of operations.

It means that before we kill a HMAC context, we'll have to cleanup again, as we probably have allocated a few resources when we forced an init.

Parameters
ctxThe HMAC context
Returns
1 on success, 0 on error

Definition at line 109 of file openssl_compat.h.

Referenced by hmac_ctx_cleanup(), and hmac_ctx_init().

◆ RSA_bits()

static int RSA_bits ( const RSA *  rsa)
inlinestatic

Number of significant RSA bits.

Parameters
rsaThe RSA object ; shall not be NULL
Returns
The number of RSA bits or 0 on error

Definition at line 382 of file openssl_compat.h.

References RSA_get0_key().

Referenced by find_certificate_in_store(), and print_details().

◆ RSA_get0_key()

static void RSA_get0_key ( const RSA *  rsa,
const BIGNUM **  n,
const BIGNUM **  e,
const BIGNUM **  d 
)
inlinestatic

Get the RSA parameters.

Parameters
rsaThe RSA object
nThe n parameter
eThe e parameter
dThe d parameter

Definition at line 317 of file openssl_compat.h.

Referenced by RSA_bits(), ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_free()

static void RSA_meth_free ( RSA_METHOD *  meth)
inlinestatic

Free an existing RSA_METHOD object.

Parameters
methThe RSA_METHOD object

Definition at line 460 of file openssl_compat.h.

References free.

Referenced by finish(), openvpn_extkey_rsa_finish(), ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_get0_app_data()

static void* RSA_meth_get0_app_data ( const RSA_METHOD *  meth)
inlinestatic

Get the application data of an RSA_METHOD object.

Parameters
methThe RSA_METHOD object
Returns
pointer to application data, may be NULL

Definition at line 657 of file openssl_compat.h.

Referenced by find_certificate_in_store(), finish(), rsa_priv_enc(), and rsa_sign_CNG().

◆ RSA_meth_new()

static RSA_METHOD* RSA_meth_new ( const char *  name,
int  flags 
)
inlinestatic

Allocate a new RSA method object.

Parameters
nameThe object name
flagsConfiguration flags
Returns
A new RSA method object

Definition at line 443 of file openssl_compat.h.

References ALLOC_OBJ_CLEAR, flags, and string_alloc().

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_set0_app_data()

static int RSA_meth_set0_app_data ( RSA_METHOD *  meth,
void *  app_data 
)
inlinestatic

Set the application data of an RSA_METHOD object.

Parameters
methThe RSA_METHOD object
app_dataApplication data
Returns
1 on success, 0 on error

Definition at line 638 of file openssl_compat.h.

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_set_finish()

static int RSA_meth_set_finish ( RSA_METHOD *  meth,
int(*)(RSA *rsa)  finish 
)
inlinestatic

Set the finish function of an RSA_METHOD object.

Parameters
methThe RSA_METHOD object
finishthe finish function
Returns
1 on success, 0 on error

Definition at line 618 of file openssl_compat.h.

References finish().

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_set_init()

static int RSA_meth_set_init ( RSA_METHOD *  meth,
int(*)(RSA *rsa)  init 
)
inlinestatic

Set the init function of an RSA_METHOD object.

Parameters
methThe RSA_METHOD object
initthe init function
Returns
1 on success, 0 on error

Definition at line 577 of file openssl_compat.h.

References init().

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_set_priv_dec()

static int RSA_meth_set_priv_dec ( RSA_METHOD *  meth,
int(*)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)  priv_dec 
)
inlinestatic

Set the private decoding function of an RSA_METHOD object.

Parameters
methThe RSA_METHOD object
priv_decthe private decoding function
Returns
1 on success, 0 on error

Definition at line 554 of file openssl_compat.h.

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_set_priv_enc()

static int RSA_meth_set_priv_enc ( RSA_METHOD *  meth,
int(*)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)  priv_enc 
)
inlinestatic

Set the private encoding function of an RSA_METHOD object.

Parameters
methThe RSA_METHOD object
priv_encthe private encoding function
Returns
1 on success, 0 on error

Definition at line 531 of file openssl_compat.h.

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_set_pub_dec()

static int RSA_meth_set_pub_dec ( RSA_METHOD *  meth,
int(*)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)  pub_dec 
)
inlinestatic

Set the public decoding function of an RSA_METHOD object.

Parameters
methThe RSA_METHOD object
pub_decthe public decoding function
Returns
1 on success, 0 on error

Definition at line 508 of file openssl_compat.h.

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_set_pub_enc()

static int RSA_meth_set_pub_enc ( RSA_METHOD *  meth,
int(*)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)  pub_enc 
)
inlinestatic

Set the public encoding function of an RSA_METHOD object.

Parameters
methThe RSA_METHOD object
pub_encthe public encoding function
Returns
1 on success, 0 on error

Definition at line 485 of file openssl_compat.h.

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_meth_set_sign()

static int RSA_meth_set_sign ( RSA_METHOD *  meth,
int(*)(int type, const unsigned char *m, unsigned int m_length, unsigned char *sigret, unsigned int *siglen, const RSA *rsa)  sign 
)
inlinestatic

Set the sign function of an RSA_METHOD object.

Parameters
methThe RSA_METHOD object
signThe sign function
Returns
1 on success, 0 on error

Definition at line 598 of file openssl_compat.h.

Referenced by ssl_ctx_set_rsakey().

◆ RSA_set0_key()

static int RSA_set0_key ( RSA *  rsa,
BIGNUM *  n,
BIGNUM *  e,
BIGNUM *  d 
)
inlinestatic

Set the RSA parameters.

Parameters
rsaThe RSA object
nThe n parameter
eThe e parameter
dThe d parameter
Returns
1 on success, 0 on error

Definition at line 346 of file openssl_compat.h.

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ RSA_set_flags()

static void RSA_set_flags ( RSA *  rsa,
int  flags 
)
inlinestatic

Set the RSA flags.

Parameters
rsaThe RSA object
flagsNew flags value

Definition at line 298 of file openssl_compat.h.

References flags.

Referenced by ssl_ctx_set_rsakey(), and tls_ctx_use_external_rsa_key().

◆ SSL_CTX_get_default_passwd_cb()

static pem_password_cb* SSL_CTX_get_default_passwd_cb ( SSL_CTX *  ctx)
inlinestatic

Fetch the default password callback from the SSL context.

Parameters
ctxSSL context
Returns
The password callback

Definition at line 168 of file openssl_compat.h.

Referenced by tls_ctx_load_cert_file(), and tls_ctx_load_priv_file().

◆ SSL_CTX_get_default_passwd_cb_userdata()

static void* SSL_CTX_get_default_passwd_cb_userdata ( SSL_CTX *  ctx)
inlinestatic

Fetch the default password callback user data from the SSL context.

Parameters
ctxSSL context
Returns
The password callback user data

Definition at line 154 of file openssl_compat.h.

Referenced by tls_ctx_load_cert_file(), and tls_ctx_load_priv_file().

◆ SSL_CTX_get_max_proto_version()

static int SSL_CTX_get_max_proto_version ( SSL_CTX *  ctx)
inlinestatic

Return the max SSL protocol version currently enabled in the context.

If no valid version >= TLS1.0 is found, return 0.

Definition at line 721 of file openssl_compat.h.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ SSL_CTX_get_min_proto_version()

static int SSL_CTX_get_min_proto_version ( SSL_CTX *  ctx)
inlinestatic

Return the min SSL protocol version currently enabled in the context.

If no valid version >= TLS1.0 is found, return 0.

Definition at line 698 of file openssl_compat.h.

Referenced by SSL_CTX_use_CryptoAPI_certificate(), and tls_ctx_set_tls_versions().

◆ SSL_CTX_set_max_proto_version()

static int SSL_CTX_set_max_proto_version ( SSL_CTX *  ctx,
long  tls_ver_max 
)
inlinestatic

Mimics SSL_CTX_set_max_proto_version for OpenSSL < 1.1.

Definition at line 772 of file openssl_compat.h.

Referenced by show_available_tls_ciphers_list(), SSL_CTX_use_CryptoAPI_certificate(), and tls_ctx_set_tls_versions().

◆ SSL_CTX_set_min_proto_version()

static int SSL_CTX_set_min_proto_version ( SSL_CTX *  ctx,
long  tls_ver_min 
)
inlinestatic

Mimics SSL_CTX_set_min_proto_version for OpenSSL < 1.1.

Definition at line 743 of file openssl_compat.h.

Referenced by show_available_tls_ciphers_list(), and tls_ctx_set_tls_versions().

◆ STACK_OF()

static STACK_OF ( X509_OBJECT  )
inlinestatic

Fetch the X509 object stack from the X509 store.

Parameters
storeX509 object store
Returns
the X509 object stack

Definition at line 196 of file openssl_compat.h.

Referenced by backend_tls_ctx_reload_crl(), show_available_tls_ciphers_list(), tls_ctx_load_ca(), tls_ctx_load_pkcs12(), and tls_verify_crl_missing().

◆ X509_get0_pubkey()

static EVP_PKEY* X509_get0_pubkey ( const X509 *  x)
inlinestatic

Get the public key from a X509 certificate.

Parameters
xX509 certificate
Returns
The certificate public key

Definition at line 182 of file openssl_compat.h.

Referenced by SSL_CTX_use_CryptoAPI_certificate(), and tls_ctx_use_management_external_key().

◆ X509_OBJECT_free()

static void X509_OBJECT_free ( X509_OBJECT *  obj)
inlinestatic

Destroy a X509 object.

Parameters
objX509 object

Definition at line 210 of file openssl_compat.h.

Referenced by backend_tls_ctx_reload_crl().

◆ X509_OBJECT_get_type()

static int X509_OBJECT_get_type ( const X509_OBJECT *  obj)
inlinestatic

Get the type of an X509 object.

Parameters
objX509 object
Returns
The underlying object type

Definition at line 228 of file openssl_compat.h.

Referenced by backend_tls_ctx_reload_crl(), and tls_verify_crl_missing().