From: Eric Farman <farman@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: qemu-s390x@nongnu.org, "Matthew Rosato" <mjrosato@linux.ibm.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"Zhuoying Cai" <zycai@linux.ibm.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Farhan Ali" <alifm@linux.ibm.com>,
"Thomas Huth" <thuth@redhat.com>,
"Eric Farman" <farman@linux.ibm.com>
Subject: [PULL 05/37] crypto/x509-utils: Add helper functions for certificate store
Date: Wed, 26 Aug 2026 08:51:40 -0400 [thread overview]
Message-ID: <20260826125213.1901252-6-farman@linux.ibm.com> (raw)
In-Reply-To: <20260826125213.1901252-1-farman@linux.ibm.com>
From: Zhuoying Cai <zycai@linux.ibm.com>
Introduce new helper functions for x509 certificate, which will be used
by the certificate store:
qcrypto_x509_convert_cert_der() - converts a certificate from PEM to DER format
These functions provide support for certificate format conversion.
Signed-off-by: Zhuoying Cai <zycai@linux.ibm.com>
Acked-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Farhan Ali <alifm@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260730214624.2328883-4-zycai@linux.ibm.com
Signed-off-by: Eric Farman <farman@linux.ibm.com>
---
crypto/x509-utils.c | 49 +++++++++++++++++++++++++++++++++++++
include/crypto/x509-utils.h | 21 ++++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/crypto/x509-utils.c b/crypto/x509-utils.c
index 1b497caae8..369e7ca6af 100644
--- a/crypto/x509-utils.c
+++ b/crypto/x509-utils.c
@@ -82,6 +82,46 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
return ret;
}
+int qcrypto_x509_convert_cert_der(uint8_t *cert, size_t size,
+ uint8_t **result, size_t *resultlen,
+ Error **errp)
+{
+ int ret = -1;
+ int rc;
+ gnutls_x509_crt_t crt;
+ gnutls_datum_t datum = {.data = cert, .size = size};
+ gnutls_datum_t datum_der = {.data = NULL, .size = 0};
+
+ rc = gnutls_x509_crt_init(&crt);
+ if (rc < 0) {
+ error_setg(errp, "Failed to initialize certificate: %s", gnutls_strerror(rc));
+ return ret;
+ }
+
+ rc = gnutls_x509_crt_import(crt, &datum, GNUTLS_X509_FMT_PEM);
+ if (rc != 0) {
+ error_setg(errp, "Failed to import certificate: %s", gnutls_strerror(rc));
+ goto cleanup;
+ }
+
+ rc = gnutls_x509_crt_export2(crt, GNUTLS_X509_FMT_DER, &datum_der);
+ if (rc != 0) {
+ error_setg(errp, "Failed to convert certificate to DER format: %s",
+ gnutls_strerror(rc));
+ goto cleanup;
+ }
+
+ *resultlen = datum_der.size;
+ *result = g_memdup2(datum_der.data, datum_der.size);
+
+ ret = 0;
+
+cleanup:
+ gnutls_x509_crt_deinit(crt);
+ g_free(datum_der.data);
+ return ret;
+}
+
#else /* ! CONFIG_GNUTLS */
int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
@@ -94,4 +134,13 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
return -1;
}
+int qcrypto_x509_convert_cert_der(uint8_t *cert, size_t size,
+ uint8_t **result,
+ size_t *resultlen,
+ Error **errp)
+{
+ error_setg(errp, "GNUTLS is required to export X.509 certificate");
+ return -1;
+}
+
#endif /* ! CONFIG_GNUTLS */
diff --git a/include/crypto/x509-utils.h b/include/crypto/x509-utils.h
index 1e99661a71..91ae79fb03 100644
--- a/include/crypto/x509-utils.h
+++ b/include/crypto/x509-utils.h
@@ -19,4 +19,25 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
size_t *resultlen,
Error **errp);
+/**
+ * qcrypto_x509_convert_cert_der
+ * @cert: pointer to the raw certificate data in PEM format
+ * @size: size of the certificate
+ * @result: output location for the allocated buffer for the certificate
+ * in DER format
+ * (the function allocates memory which must be freed by the caller)
+ * @resultlen: pointer to the size of the buffer (will be updated with the
+ * actual size of the DER-encoded certificate)
+ * @errp: error pointer
+ *
+ * Convert the given @cert from PEM to DER format.
+ *
+ * Returns: 0 on success,
+ * -1 on error.
+ */
+int qcrypto_x509_convert_cert_der(uint8_t *cert, size_t size,
+ uint8_t **result,
+ size_t *resultlen,
+ Error **errp);
+
#endif
--
2.55.0
next prev parent reply other threads:[~2026-08-26 12:56 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 12:51 [PULL 00/37] s390x queue Eric Farman
2026-08-26 12:51 ` [PULL 01/37] s390x/sclp: pv: only copy the original SCCB buffer Eric Farman
2026-08-26 12:51 ` [PULL 02/37] s390x/css: Fix css stsch detection to go beyond 8192 devices Eric Farman
2026-08-26 12:51 ` [PULL 03/37] Add boot-certs to s390-ccw-virtio machine type option Eric Farman
2026-08-26 12:51 ` [PULL 04/37] crypto/x509-utils: Refactor with GNUTLS fallback Eric Farman
2026-08-26 12:51 ` Eric Farman [this message]
2026-08-26 12:51 ` [PULL 06/37] hw/s390x/ipl: Create certificate store Eric Farman
2026-08-26 12:51 ` [PULL 07/37] s390x/diag: Introduce DIAG 320 for Certificate Store Facility Eric Farman
2026-08-26 12:51 ` [PULL 08/37] s390x/diag: Refactor address validation check from diag308_parm_check Eric Farman
2026-08-26 12:51 ` [PULL 09/37] s390x/diag: Implement DIAG 320 subcode 1 Eric Farman
2026-08-26 12:51 ` [PULL 10/37] crypto/x509-utils: Add helper functions for DIAG 320 subcode 2 Eric Farman
2026-08-26 12:51 ` [PULL 11/37] s390x/diag: Implement " Eric Farman
2026-08-26 12:51 ` [PULL 12/37] hw/s390x: Define finite size for single entry VCEntry Eric Farman
2026-08-26 12:51 ` [PULL 13/37] s390x/diag: Introduce DIAG 508 for secure IPL operations Eric Farman
2026-08-26 12:51 ` [PULL 14/37] crypto/x509-utils: Add helper functions for DIAG 508 subcode 1 Eric Farman
2026-08-26 12:51 ` [PULL 15/37] s390x/diag: Generalize s390_ipl_read/write to accept void * Eric Farman
2026-08-26 12:51 ` [PULL 16/37] s390x/diag: Implement DIAG 508 subcode 1 for signature verification Eric Farman
2026-08-26 12:51 ` [PULL 17/37] s390x/ipl: Introduce IPL Information Report Block (IIRB) Eric Farman
2026-08-26 12:51 ` [PULL 18/37] pc-bios/s390-ccw: Define memory for IPLB and convert IPLB to pointers Eric Farman
2026-08-26 12:51 ` [PULL 19/37] hw/s390x/ipl: Add IPIB flags to IPL Parameter Block Eric Farman
2026-08-26 12:51 ` [PULL 20/37] hw/s390x/ipl: Rework s390_ipl_map_iplb_chain for certificate storage Eric Farman
2026-08-26 12:51 ` [PULL 21/37] s390x: Guest support for Secure-IPL Facility Eric Farman
2026-08-26 12:51 ` [PULL 22/37] pc-bios/s390-ccw: Refactor zipl_run() Eric Farman
2026-08-26 12:51 ` [PULL 23/37] pc-bios/s390-ccw: Rework zipl_load_segment function Eric Farman
2026-08-26 12:51 ` [PULL 24/37] pc-bios/s390-ccw: Introduce ZiplBootMode enum for IPL mode selection Eric Farman
2026-08-26 12:52 ` [PULL 25/37] pc-bios/s390-ccw: Add signature verification for secure IPL in audit mode Eric Farman
2026-08-26 12:52 ` [PULL 26/37] pc-bios/s390-ccw: Add signed component address overlap checks Eric Farman
2026-08-26 12:52 ` [PULL 27/37] s390x: Guest support for Secure-IPL Code Loading Attributes Facility (SCLAF) Eric Farman
2026-08-26 12:52 ` [PULL 28/37] pc-bios/s390-ccw: Add additional security checks for secure boot Eric Farman
2026-08-26 12:52 ` [PULL 29/37] Add secure-boot to s390-ccw-virtio machine type option Eric Farman
2026-08-26 12:52 ` [PULL 30/37] hw/s390x/ipl: Set IPIB flags for secure IPL Eric Farman
2026-08-26 12:52 ` [PULL 31/37] pc-bios/s390-ccw: Handle true secure IPL mode Eric Farman
2026-08-26 12:52 ` [PULL 32/37] hw/s390x/ipl: Handle secure boot with multiple boot devices Eric Farman
2026-08-26 12:52 ` [PULL 33/37] tests/functional/s390x: Add secure IPL functional test Eric Farman
2026-08-26 12:52 ` [PULL 34/37] docs/specs: Add secure IPL documentation Eric Farman
2026-08-26 12:52 ` [PULL 35/37] docs/system/s390x: " Eric Farman
2026-08-26 12:52 ` [PULL 36/37] MAINTAINERS: Add secure IPL files to S390-ccw boot group Eric Farman
2026-08-26 12:52 ` [PULL 37/37] pc-bios/s390-ccw.img: update s390x bios Eric Farman
2026-08-27 4:18 ` [PULL 00/37] s390x queue Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260826125213.1901252-6-farman@linux.ibm.com \
--to=farman@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=berrange@redhat.com \
--cc=cohuck@redhat.com \
--cc=mjrosato@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=thuth@redhat.com \
--cc=zycai@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.