36#if defined(ENABLE_CRYPTO_OPENSSL)
46#include <openssl/bn.h>
47#include <openssl/err.h>
48#include <openssl/x509v3.h>
59 ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
64 X509 *current_cert = X509_STORE_CTX_get_current_cert(ctx);
77 subject =
"(Failed to retrieve certificate subject)";
116#ifdef ENABLE_X509ALTUSERNAME
134 "ERROR: --x509-username-field 'ext:%s' not supported",
fieldname);
164 if (
strlen(buf) != name->d.ia5->length)
209 unsigned char *buf =
NULL;
263#ifdef ENABLE_X509ALTUSERNAME
264 if (
strncmp(
"ext:", x509_username_field, 4) == 0)
278 if (!serial || cn_len <= strlen(serial)+2)
283 snprintf(common_name, cn_len,
"0x%s", serial);
289 x509_username_field, common_name, cn_len))
300 ASN1_INTEGER *asn1_i;
302 char *openssl_serial, *serial;
304 asn1_i = X509_get_serialNumber(cert);
305 bignum = ASN1_INTEGER_to_BN(asn1_i, NULL);
306 openssl_serial = BN_bn2dec(bignum);
311 OPENSSL_free(openssl_serial);
319 const ASN1_INTEGER *asn1_i = X509_get_serialNumber(cert);
327 BIO *out = BIO_new_file(filename,
"w");
333 if (!PEM_write_bio_X509(out, cert))
350 const EVP_MD *sha1 = EVP_sha1();
360 const EVP_MD *sha256 = EVP_sha256();
435 if (xt->
nid != NID_undef)
442 msg(msglevel,
"x509_track: no such attribute '%s'",
name);
451 size_t name_expand_size;
455 name_expand_size = 64 + strlen(
name);
456 name_expand = (
char *) malloc(name_expand_size);
458 snprintf(name_expand, name_expand_size,
"X509_%d_%s", depth,
name);
467 X509_NAME *x509_name = X509_get_subject_name(x509);
468 const char nullc =
'\0';
506 unsigned char *buf =
NULL;
561 unsigned char *buf =
NULL;
567 for (
i = 0;
i < n; ++
i)
639 msg(
M_WARN,
"X509: Certificate is a client certificate yet it's purpose "
640 "cannot be verified (check may fail in the future)");
667 msg(
M_WARN,
"X509: Certificate is a server certificate yet it's purpose "
668 "cannot be verified (check may fail in the future)");
698 for (
size_t i = 0;
i < 8;
i++)
709 if ((
nku & 0xff) == 0)
727 "ERROR: Certificate has key usage %04x, expected one of:",
nku);
748 msg(
D_HANDSHAKE,
"Certificate does not have extended key usage extension");
char * format_hex_ex(const uint8_t *data, int size, int maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc)
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
bool string_mod(char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace)
Modifies a string in place by replacing certain classes of characters of it with a specified characte...
char * string_alloc(const char *str, struct gc_arena *gc)
#define CC_ANY
any character
static bool buf_inc_len(struct buffer *buf, int inc)
#define CC_CRLF
carriage return or newline
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
static void strncpynt(char *dest, const char *src, size_t maxlen)
static void check_malloc_return(void *p)
static void gc_free(struct gc_arena *a)
#define CC_PRINT
printable (>= 32, != 127)
static struct gc_arena gc_new(void)
#define crypto_msg(flags,...)
Retrieve any OpenSSL errors, then print the supplied error message.
void setenv_str(struct env_set *es, const char *name, const char *value)
void setenv_str_incr(struct env_set *es, const char *name, const char *value)
Store the supplied name value pair in the env_set.
int verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
Verify that the remote OpenVPN peer's certificate allows setting up a VPN tunnel.
OpenSSL compatibility stub.
#define SSLF_CRL_VERIFY_DIR
int mydata_index
Allocate space in SSL objects in which to store a struct tls_session pointer back to parent.
Control Channel OpenSSL Backend.
result_t verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depth)
void cert_hash_remember(struct tls_session *session, const int error_depth, const struct buffer *cert_hash)
Control Channel Verification Module.
#define OPENVPN_KU_REQUIRED
Require keyUsage to be present in cert (0xFFFF is an invalid KU value)
#define NS_CERT_CHECK_CLIENT
Do not perform Netscape certificate type verification.
#define NS_CERT_CHECK_NONE
Do not perform Netscape certificate type verification.
#define NS_CERT_CHECK_SERVER
Do not perform Netscape certificate type verification.
Control Channel Verification Module library-specific backend interface.
result_t
Result of verification function.
mbedtls_x509_crt openvpn_x509_cert_t
char * x509_get_subject(X509 *cert, struct gc_arena *gc)
static result_t extract_x509_field_ssl(X509_NAME *x509, const char *field_name, char *out, int size)
struct buffer x509_get_sha1_fingerprint(X509 *cert, struct gc_arena *gc)
result_t x509_verify_cert_ku(X509 *x509, const unsigned *const expected_ku, int expected_len)
bool tls_verify_crl_missing(const struct tls_options *opt)
Return true iff a CRL is configured, but is not loaded.
result_t backend_x509_write_pem(openvpn_x509_cert_t *cert, const char *filename)
struct buffer x509_get_sha256_fingerprint(X509 *cert, struct gc_arena *gc)
result_t x509_verify_cert_eku(X509 *x509, const char *const expected_oid)
static void do_setenv_x509(struct env_set *es, const char *name, char *value, int depth)
char * backend_x509_get_serial_hex(openvpn_x509_cert_t *cert, struct gc_arena *gc)
result_t x509_verify_ns_cert_type(openvpn_x509_cert_t *peer_cert, const int usage)
void x509_setenv_track(const struct x509_track *xt, struct env_set *es, const int depth, X509 *x509)
char * backend_x509_get_serial(openvpn_x509_cert_t *cert, struct gc_arena *gc)
void x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel, struct gc_arena *gc)
result_t backend_x509_get_username(char *common_name, int cn_len, char *x509_username_field, X509 *peer_cert)
void x509_setenv(struct env_set *es, int cert_depth, openvpn_x509_cert_t *peer_cert)
Control Channel Verification Module OpenSSL backend.
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Structure containing the hash for a single certificate.
Garbage collection arena used to keep track of dynamically allocated memory.
struct tls_root_ctx ssl_ctx
Security parameter state of a single session within a VPN tunnel.
const struct x509_track * next
static int cleanup(void **state)