36#if defined(ENABLE_PKCS11) && defined(ENABLE_CRYPTO_MBEDTLS)
41#include <mbedtls/x509.h>
44pkcs11_get_x509_cert(pkcs11h_certificate_t pkcs11_cert, mbedtls_x509_crt *cert)
46 unsigned char *cert_blob = NULL;
47 size_t cert_blob_size = 0;
50 if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, NULL,
51 &cert_blob_size) != CKR_OK)
53 msg(
M_WARN,
"PKCS#11: Cannot retrieve certificate object size");
58 if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, cert_blob,
59 &cert_blob_size) != CKR_OK)
61 msg(
M_WARN,
"PKCS#11: Cannot retrieve certificate object");
65 if (!
mbed_ok(mbedtls_x509_crt_parse(cert, cert_blob, cert_blob_size)))
67 msg(
M_WARN,
"PKCS#11: Could not parse certificate");
78pkcs11_sign(
void *pkcs11_cert,
const void *src,
size_t src_len,
79 void *dst,
size_t dst_len)
81 return CKR_OK == pkcs11h_certificate_signAny(pkcs11_cert, CKM_RSA_PKCS,
82 src, src_len, dst, &dst_len);
86pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
91 ssl_ctx->pkcs11_cert = certificate;
94 if (!pkcs11_get_x509_cert(certificate, ssl_ctx->
crt_chain))
96 msg(
M_WARN,
"PKCS#11: Cannot initialize certificate");
102 msg(
M_WARN,
"PKCS#11: Cannot register signing function");
110pkcs11_certificate_dn(pkcs11h_certificate_t cert,
struct gc_arena *
gc)
113 mbedtls_x509_crt mbed_crt = { 0 };
115 if (!pkcs11_get_x509_cert(cert, &mbed_crt))
117 msg(
M_WARN,
"PKCS#11: Cannot retrieve mbed TLS certificate object");
123 msg(
M_WARN,
"PKCS#11: mbed TLS cannot parse subject");
128 mbedtls_x509_crt_free(&mbed_crt);
134pkcs11_certificate_serial(pkcs11h_certificate_t cert,
char *serial,
138 mbedtls_x509_crt mbed_crt = { 0 };
140 if (!pkcs11_get_x509_cert(cert, &mbed_crt))
142 msg(
M_WARN,
"PKCS#11: Cannot retrieve mbed TLS certificate object");
146 if (mbedtls_x509_serial_gets(serial, serial_len, &mbed_crt.serial) < 0)
148 msg(
M_WARN,
"PKCS#11: mbed TLS cannot parse serial");
154 mbedtls_x509_crt_free(&mbed_crt);
static void check_malloc_return(void *p)
#define ALLOC_OBJ_CLEAR(dptr, type)
#define mbed_ok(errval)
Check errval and log on error.
PKCS #11 SSL library-specific backend.
int tls_ctx_use_external_signing_func(struct tls_root_ctx *ctx, external_sign_func sign_func, void *sign_ctx)
Call the supplied signing function to create a TLS signature during the TLS handshake.
Control Channel Verification Module library-specific backend interface.
char * x509_get_subject(openvpn_x509_cert_t *cert, struct gc_arena *gc)
Garbage collection arena used to keep track of dynamically allocated memory.
Structure that wraps the TLS context.
mbedtls_x509_crt * crt_chain
Local Certificate chain.
static int cleanup(void **state)