35 #if defined(ENABLE_PKCS11) && defined(ENABLE_CRYPTO_MBEDTLS)
40 #include <mbedtls/x509.h>
43 pkcs11_get_x509_cert(pkcs11h_certificate_t pkcs11_cert, mbedtls_x509_crt *cert)
45 unsigned char *cert_blob = NULL;
46 size_t cert_blob_size = 0;
49 if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, NULL,
50 &cert_blob_size) != CKR_OK)
52 msg(
M_WARN,
"PKCS#11: Cannot retrieve certificate object size");
57 if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, cert_blob,
58 &cert_blob_size) != CKR_OK)
60 msg(
M_WARN,
"PKCS#11: Cannot retrieve certificate object");
64 if (!
mbed_ok(mbedtls_x509_crt_parse(cert, cert_blob, cert_blob_size)))
66 msg(
M_WARN,
"PKCS#11: Could not parse certificate");
77 pkcs11_sign(
void *pkcs11_cert,
const void *src,
size_t src_len,
78 void *dst,
size_t dst_len)
80 return CKR_OK == pkcs11h_certificate_signAny(pkcs11_cert, CKM_RSA_PKCS,
81 src, src_len, dst, &dst_len);
85 pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
90 ssl_ctx->pkcs11_cert = certificate;
93 if (!pkcs11_get_x509_cert(certificate, ssl_ctx->
crt_chain))
95 msg(
M_WARN,
"PKCS#11: Cannot initialize certificate");
101 msg(
M_WARN,
"PKCS#11: Cannot register signing function");
109 pkcs11_certificate_dn(pkcs11h_certificate_t cert,
struct gc_arena *gc)
112 mbedtls_x509_crt mbed_crt = { 0 };
114 if (!pkcs11_get_x509_cert(cert, &mbed_crt))
116 msg(
M_WARN,
"PKCS#11: Cannot retrieve mbed TLS certificate object");
122 msg(
M_WARN,
"PKCS#11: mbed TLS cannot parse subject");
127 mbedtls_x509_crt_free(&mbed_crt);
133 pkcs11_certificate_serial(pkcs11h_certificate_t cert,
char *serial,
137 mbedtls_x509_crt mbed_crt = { 0 };
139 if (!pkcs11_get_x509_cert(cert, &mbed_crt))
141 msg(
M_WARN,
"PKCS#11: Cannot retrieve mbed TLS certificate object");
145 if (mbedtls_x509_serial_gets(serial, serial_len, &mbed_crt.serial) < 0)
147 msg(
M_WARN,
"PKCS#11: mbed TLS cannot parse serial");
153 mbedtls_x509_crt_free(&mbed_crt);