tlscredsx509.c (98c710f2d5cdf37f29a267352eb1f3c28cbf369d) tlscredsx509.c (986bc8ded9a5459e72951cc91b53cf2b52eb735f)
1/*
2 * QEMU crypto TLS x509 credential support
3 *
4 * Copyright (c) 2015 Red Hat, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either

--- 6 unchanged lines hidden (view full) ---

15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include "qemu/osdep.h"
22#include "crypto/tlscredsx509.h"
1/*
2 * QEMU crypto TLS x509 credential support
3 *
4 * Copyright (c) 2015 Red Hat, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either

--- 6 unchanged lines hidden (view full) ---

15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include "qemu/osdep.h"
22#include "crypto/tlscredsx509.h"
23#include "crypto/tlscredspriv.h"
23#include "tlscredspriv.h"
24#include "crypto/secret.h"
25#include "qapi/error.h"
26#include "qom/object_interfaces.h"
27#include "trace.h"
28
29
30#ifdef CONFIG_GNUTLS
31

--- 578 unchanged lines hidden (view full) ---

610 GNUTLS_X509_FMT_PEM);
611 if (ret < 0) {
612 error_setg(errp, "Cannot load CA certificate '%s': %s",
613 cacert, gnutls_strerror(ret));
614 goto cleanup;
615 }
616
617 if (cert != NULL && key != NULL) {
24#include "crypto/secret.h"
25#include "qapi/error.h"
26#include "qom/object_interfaces.h"
27#include "trace.h"
28
29
30#ifdef CONFIG_GNUTLS
31

--- 578 unchanged lines hidden (view full) ---

610 GNUTLS_X509_FMT_PEM);
611 if (ret < 0) {
612 error_setg(errp, "Cannot load CA certificate '%s': %s",
613 cacert, gnutls_strerror(ret));
614 goto cleanup;
615 }
616
617 if (cert != NULL && key != NULL) {
618#if GNUTLS_VERSION_NUMBER >= 0x030111
618#if LIBGNUTLS_VERSION_NUMBER >= 0x030111
619 char *password = NULL;
620 if (creds->passwordid) {
621 password = qcrypto_secret_lookup_as_utf8(creds->passwordid,
622 errp);
623 if (!password) {
624 goto cleanup;
625 }
626 }
627 ret = gnutls_certificate_set_x509_key_file2(creds->data,
628 cert, key,
629 GNUTLS_X509_FMT_PEM,
630 password,
631 0);
632 g_free(password);
619 char *password = NULL;
620 if (creds->passwordid) {
621 password = qcrypto_secret_lookup_as_utf8(creds->passwordid,
622 errp);
623 if (!password) {
624 goto cleanup;
625 }
626 }
627 ret = gnutls_certificate_set_x509_key_file2(creds->data,
628 cert, key,
629 GNUTLS_X509_FMT_PEM,
630 password,
631 0);
632 g_free(password);
633#else /* GNUTLS_VERSION_NUMBER < 0x030111 */
633#else /* LIBGNUTLS_VERSION_NUMBER < 0x030111 */
634 if (creds->passwordid) {
635 error_setg(errp, "PKCS8 decryption requires GNUTLS >= 3.1.11");
636 goto cleanup;
637 }
638 ret = gnutls_certificate_set_x509_key_file(creds->data,
639 cert, key,
640 GNUTLS_X509_FMT_PEM);
634 if (creds->passwordid) {
635 error_setg(errp, "PKCS8 decryption requires GNUTLS >= 3.1.11");
636 goto cleanup;
637 }
638 ret = gnutls_certificate_set_x509_key_file(creds->data,
639 cert, key,
640 GNUTLS_X509_FMT_PEM);
641#endif /* GNUTLS_VERSION_NUMBER < 0x030111 */
641#endif
642 if (ret < 0) {
643 error_setg(errp, "Cannot load certificate '%s' & key '%s': %s",
644 cert, key, gnutls_strerror(ret));
645 goto cleanup;
646 }
647 }
648
649 if (cacrl != NULL) {

--- 221 unchanged lines hidden ---
642 if (ret < 0) {
643 error_setg(errp, "Cannot load certificate '%s' & key '%s': %s",
644 cert, key, gnutls_strerror(ret));
645 goto cleanup;
646 }
647 }
648
649 if (cacrl != NULL) {

--- 221 unchanged lines hidden ---