36 #if defined(ENABLE_PKCS11) && defined(ENABLE_CRYPTO_MBEDTLS)
41 #include <mbedtls/x509.h>
44 pkcs11_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");
78 pkcs11_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);
86 pkcs11_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");
110 pkcs11_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);
134 pkcs11_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);