Blame lib/cert.c

Packit 549fdc
/*
Packit 549fdc
 * Copyright (C) 2001-2016 Free Software Foundation, Inc.
Packit 549fdc
 * Copyright (C) 2015-2017 Red Hat, Inc.
Packit 549fdc
 *
Packit 549fdc
 * Author: Nikos Mavrogiannopoulos
Packit 549fdc
 *
Packit 549fdc
 * This file is part of GnuTLS.
Packit 549fdc
 *
Packit 549fdc
 * The GnuTLS is free software; you can redistribute it and/or
Packit 549fdc
 * modify it under the terms of the GNU Lesser General Public License
Packit 549fdc
 * as published by the Free Software Foundation; either version 2.1 of
Packit 549fdc
 * the License, or (at your option) any later version.
Packit 549fdc
 *
Packit 549fdc
 * This library is distributed in the hope that it will be useful, but
Packit 549fdc
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 549fdc
 * Lesser General Public License for more details.
Packit 549fdc
 *
Packit 549fdc
 * You should have received a copy of the GNU Lesser General Public License
Packit 549fdc
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
Packit 549fdc
 *
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
/* Some of the stuff needed for Certificate authentication is contained
Packit 549fdc
 * in this file.
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
#include "gnutls_int.h"
Packit 549fdc
#include "errors.h"
Packit 549fdc
#include <auth/cert.h>
Packit 549fdc
#include <datum.h>
Packit 549fdc
#include <mpi.h>
Packit 549fdc
#include <global.h>
Packit 549fdc
#include <algorithms.h>
Packit 549fdc
#include <dh.h>
Packit 549fdc
#include "str.h"
Packit 549fdc
#include <state.h>
Packit 549fdc
#include <auth.h>
Packit 549fdc
#include <x509.h>
Packit 549fdc
#include <str_array.h>
Packit 549fdc
#include <x509/verify-high.h>
Packit 549fdc
#include "x509/x509_int.h"
Packit 549fdc
#include "dh.h"
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_free_keys:
Packit 549fdc
 * @sc: is a #gnutls_certificate_credentials_t type.
Packit 549fdc
 *
Packit 549fdc
 * This function will delete all the keys and the certificates associated
Packit 549fdc
 * with the given credentials. This function must not be called when a
Packit 549fdc
 * TLS negotiation that uses the credentials is in progress.
Packit 549fdc
 *
Packit 549fdc
 **/
Packit 549fdc
void gnutls_certificate_free_keys(gnutls_certificate_credentials_t sc)
Packit 549fdc
{
Packit 549fdc
	unsigned i, j;
Packit 549fdc
Packit 549fdc
	for (i = 0; i < sc->ncerts; i++) {
Packit 549fdc
		for (j = 0; j < sc->certs[i].cert_list_length; j++) {
Packit 549fdc
			gnutls_pcert_deinit(&sc->certs[i].cert_list[j]);
Packit 549fdc
		}
Packit 549fdc
		gnutls_free(sc->certs[i].cert_list);
Packit 549fdc
		gnutls_free(sc->certs[i].ocsp_response_file);
Packit 549fdc
		_gnutls_str_array_clear(&sc->certs[i].names);
Packit 549fdc
		gnutls_privkey_deinit(sc->certs[i].pkey);
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	gnutls_free(sc->certs);
Packit 549fdc
	gnutls_free(sc->sorted_cert_idx);
Packit 549fdc
	sc->certs = NULL;
Packit 549fdc
	sc->sorted_cert_idx = NULL;
Packit 549fdc
Packit 549fdc
	sc->ncerts = 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_free_cas:
Packit 549fdc
 * @sc: is a #gnutls_certificate_credentials_t type.
Packit 549fdc
 *
Packit 549fdc
 * This function will delete all the CAs associated with the given
Packit 549fdc
 * credentials. Servers that do not use
Packit 549fdc
 * gnutls_certificate_verify_peers2() may call this to save some
Packit 549fdc
 * memory.
Packit 549fdc
 **/
Packit 549fdc
void gnutls_certificate_free_cas(gnutls_certificate_credentials_t sc)
Packit 549fdc
{
Packit 549fdc
	/* FIXME: do nothing for now */
Packit 549fdc
	return;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_get_issuer:
Packit 549fdc
 * @sc: is a #gnutls_certificate_credentials_t type.
Packit 549fdc
 * @cert: is the certificate to find issuer for
Packit 549fdc
 * @issuer: Will hold the issuer if any. Should be treated as constant.
Packit 549fdc
 * @flags: Use zero or %GNUTLS_TL_GET_COPY
Packit 549fdc
 *
Packit 549fdc
 * This function will return the issuer of a given certificate.
Packit 549fdc
 * If the flag %GNUTLS_TL_GET_COPY is specified a copy of the issuer
Packit 549fdc
 * will be returned which must be freed using gnutls_x509_crt_deinit().
Packit 549fdc
 * In that case the provided @issuer must not be initialized.
Packit 549fdc
 *
Packit 549fdc
 * As with gnutls_x509_trust_list_get_issuer() this function requires
Packit 549fdc
 * the %GNUTLS_TL_GET_COPY flag in order to operate with PKCS#11 trust
Packit 549fdc
 * lists in a thread-safe way. 
Packit 549fdc
 *
Packit 549fdc
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
Packit 549fdc
 *   negative error value.
Packit 549fdc
 *
Packit 549fdc
 * Since: 3.0
Packit 549fdc
 **/
Packit 549fdc
int
Packit 549fdc
gnutls_certificate_get_issuer(gnutls_certificate_credentials_t sc,
Packit 549fdc
			      gnutls_x509_crt_t cert,
Packit 549fdc
			      gnutls_x509_crt_t * issuer,
Packit 549fdc
			      unsigned int flags)
Packit 549fdc
{
Packit 549fdc
	return gnutls_x509_trust_list_get_issuer(sc->tlist, cert, issuer,
Packit 549fdc
						 flags);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_get_crt_raw:
Packit 549fdc
 * @sc: is a #gnutls_certificate_credentials_t type.
Packit 549fdc
 * @idx1: the index of the certificate chain if multiple are present
Packit 549fdc
 * @idx2: the index of the certificate in the chain. Zero gives the server's certificate.
Packit 549fdc
 * @cert: Will hold the DER encoded certificate.
Packit 549fdc
 *
Packit 549fdc
 * This function will return the DER encoded certificate of the
Packit 549fdc
 * server or any other certificate on its certificate chain (based on @idx2).
Packit 549fdc
 * The returned data should be treated as constant and only accessible during the lifetime
Packit 549fdc
 * of @sc. The @idx1 matches the value gnutls_certificate_set_x509_key() and friends
Packit 549fdc
 * functions.
Packit 549fdc
 *
Packit 549fdc
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
Packit 549fdc
 *   negative error value. In case the indexes are out of bounds %GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
Packit 549fdc
 *   is returned.
Packit 549fdc
 *
Packit 549fdc
 * Since: 3.2.5
Packit 549fdc
 **/
Packit 549fdc
int
Packit 549fdc
gnutls_certificate_get_crt_raw(gnutls_certificate_credentials_t sc,
Packit 549fdc
			       unsigned idx1,
Packit 549fdc
			       unsigned idx2, gnutls_datum_t * cert)
Packit 549fdc
{
Packit 549fdc
	if (idx1 >= sc->ncerts)
Packit 549fdc
		return
Packit 549fdc
		    gnutls_assert_val
Packit 549fdc
		    (GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE);
Packit 549fdc
Packit 549fdc
	if (idx2 >= sc->certs[idx1].cert_list_length)
Packit 549fdc
		return
Packit 549fdc
		    gnutls_assert_val
Packit 549fdc
		    (GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE);
Packit 549fdc
Packit 549fdc
	cert->data = sc->certs[idx1].cert_list[idx2].cert.data;
Packit 549fdc
	cert->size = sc->certs[idx1].cert_list[idx2].cert.size;
Packit 549fdc
Packit 549fdc
	return 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_free_ca_names:
Packit 549fdc
 * @sc: is a #gnutls_certificate_credentials_t type.
Packit 549fdc
 *
Packit 549fdc
 * This function will delete all the CA name in the given
Packit 549fdc
 * credentials. Clients may call this to save some memory since in
Packit 549fdc
 * client side the CA names are not used. Servers might want to use
Packit 549fdc
 * this function if a large list of trusted CAs is present and
Packit 549fdc
 * sending the names of it would just consume bandwidth without providing 
Packit 549fdc
 * information to client.
Packit 549fdc
 *
Packit 549fdc
 * CA names are used by servers to advertise the CAs they support to
Packit 549fdc
 * clients.
Packit 549fdc
 **/
Packit 549fdc
void gnutls_certificate_free_ca_names(gnutls_certificate_credentials_t sc)
Packit 549fdc
{
Packit 549fdc
	_gnutls_free_datum(&sc->tlist->x509_rdn_sequence);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_free_credentials:
Packit 549fdc
 * @sc: is a #gnutls_certificate_credentials_t type.
Packit 549fdc
 *
Packit 549fdc
 * Free a gnutls_certificate_credentials_t structure.
Packit 549fdc
 *
Packit 549fdc
 * This function does not free any temporary parameters associated
Packit 549fdc
 * with this structure (ie RSA and DH parameters are not freed by this
Packit 549fdc
 * function).
Packit 549fdc
 **/
Packit 549fdc
void
Packit 549fdc
gnutls_certificate_free_credentials(gnutls_certificate_credentials_t sc)
Packit 549fdc
{
Packit 549fdc
	gnutls_x509_trust_list_deinit(sc->tlist, 1);
Packit 549fdc
	gnutls_certificate_free_keys(sc);
Packit 549fdc
	memset(sc->pin_tmp, 0, sizeof(sc->pin_tmp));
Packit 549fdc
Packit 549fdc
	if (sc->deinit_dh_params) {
Packit 549fdc
		gnutls_dh_params_deinit(sc->dh_params);
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	gnutls_free(sc);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_allocate_credentials:
Packit 549fdc
 * @res: is a pointer to a #gnutls_certificate_credentials_t type.
Packit 549fdc
 *
Packit 549fdc
 * Allocate a gnutls_certificate_credentials_t structure.
Packit 549fdc
 *
Packit 549fdc
 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
Packit 549fdc
 **/
Packit 549fdc
int
Packit 549fdc
gnutls_certificate_allocate_credentials(gnutls_certificate_credentials_t *
Packit 549fdc
					res)
Packit 549fdc
{
Packit 549fdc
	int ret;
Packit 549fdc
Packit 549fdc
	*res = gnutls_calloc(1, sizeof(certificate_credentials_st));
Packit 549fdc
Packit 549fdc
	if (*res == NULL)
Packit 549fdc
		return GNUTLS_E_MEMORY_ERROR;
Packit 549fdc
Packit 549fdc
	ret = gnutls_x509_trust_list_init(&(*res)->tlist, 0);
Packit 549fdc
	if (ret < 0) {
Packit 549fdc
		gnutls_assert();
Packit 549fdc
		gnutls_free(*res);
Packit 549fdc
		return GNUTLS_E_MEMORY_ERROR;
Packit 549fdc
	}
Packit 549fdc
	(*res)->verify_bits = DEFAULT_MAX_VERIFY_BITS;
Packit 549fdc
	(*res)->verify_depth = DEFAULT_MAX_VERIFY_DEPTH;
Packit 549fdc
Packit 549fdc
Packit 549fdc
	return 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_server_set_request:
Packit 549fdc
 * @session: is a #gnutls_session_t type.
Packit 549fdc
 * @req: is one of GNUTLS_CERT_REQUEST, GNUTLS_CERT_REQUIRE
Packit 549fdc
 *
Packit 549fdc
 * This function specifies if we (in case of a server) are going to
Packit 549fdc
 * send a certificate request message to the client. If @req is
Packit 549fdc
 * GNUTLS_CERT_REQUIRE then the server will return an error if the
Packit 549fdc
 * peer does not provide a certificate. If you do not call this
Packit 549fdc
 * function then the client will not be asked to send a certificate.
Packit 549fdc
 **/
Packit 549fdc
void
Packit 549fdc
gnutls_certificate_server_set_request(gnutls_session_t session,
Packit 549fdc
				      gnutls_certificate_request_t req)
Packit 549fdc
{
Packit 549fdc
	session->internals.send_cert_req = req;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_set_retrieve_function:
Packit 549fdc
 * @cred: is a #gnutls_certificate_credentials_t type.
Packit 549fdc
 * @func: is the callback function
Packit 549fdc
 *
Packit 549fdc
 * This function sets a callback to be called in order to retrieve the
Packit 549fdc
 * certificate to be used in the handshake. The callback will take control
Packit 549fdc
 * only if a certificate is requested by the peer. You are advised
Packit 549fdc
 * to use gnutls_certificate_set_retrieve_function2() because it
Packit 549fdc
 * is much more efficient in the processing it requires from gnutls.
Packit 549fdc
 *
Packit 549fdc
 * The callback's function prototype is:
Packit 549fdc
 * int (*callback)(gnutls_session_t, const gnutls_datum_t* req_ca_dn, int nreqs,
Packit 549fdc
 * const gnutls_pk_algorithm_t* pk_algos, int pk_algos_length, gnutls_retr2_st* st);
Packit 549fdc
 *
Packit 549fdc
 * @req_ca_dn is only used in X.509 certificates.
Packit 549fdc
 * Contains a list with the CA names that the server considers trusted.
Packit 549fdc
 * This is a hint and typically the client should send a certificate that is signed
Packit 549fdc
 * by one of these CAs. These names, when available, are DER encoded. To get a more
Packit 549fdc
 * meaningful value use the function gnutls_x509_rdn_get().
Packit 549fdc
 *
Packit 549fdc
 * @pk_algos contains a list with server's acceptable public key algorithms.
Packit 549fdc
 * The certificate returned should support the server's given algorithms.
Packit 549fdc
 *
Packit 549fdc
 * @st should contain the certificates and private keys.
Packit 549fdc
 *
Packit 549fdc
 * If the callback function is provided then gnutls will call it, in the
Packit 549fdc
 * handshake, after the certificate request message has been received.
Packit 549fdc
 *
Packit 549fdc
 * In server side pk_algos and req_ca_dn are NULL.
Packit 549fdc
 *
Packit 549fdc
 * The callback function should set the certificate list to be sent,
Packit 549fdc
 * and return 0 on success. If no certificate was selected then the
Packit 549fdc
 * number of certificates should be set to zero. The value (-1)
Packit 549fdc
 * indicates error and the handshake will be terminated. If both certificates
Packit 549fdc
 * are set in the credentials and a callback is available, the callback
Packit 549fdc
 * takes predence.
Packit 549fdc
 *
Packit 549fdc
 * Since: 3.0
Packit 549fdc
 **/
Packit 549fdc
void gnutls_certificate_set_retrieve_function
Packit 549fdc
    (gnutls_certificate_credentials_t cred,
Packit 549fdc
     gnutls_certificate_retrieve_function * func)
Packit 549fdc
{
Packit 549fdc
	cred->get_cert_callback = func;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_set_retrieve_function2:
Packit 549fdc
 * @cred: is a #gnutls_certificate_credentials_t type.
Packit 549fdc
 * @func: is the callback function
Packit 549fdc
 *
Packit 549fdc
 * This function sets a callback to be called in order to retrieve the
Packit 549fdc
 * certificate to be used in the handshake. The callback will take control
Packit 549fdc
 * only if a certificate is requested by the peer.
Packit 549fdc
 *
Packit 549fdc
 * The callback's function prototype is:
Packit 549fdc
 * int (*callback)(gnutls_session_t, const gnutls_datum_t* req_ca_dn, int nreqs,
Packit 549fdc
 * const gnutls_pk_algorithm_t* pk_algos, int pk_algos_length, gnutls_pcert_st** pcert,
Packit 549fdc
 * unsigned int *pcert_length, gnutls_privkey_t * pkey);
Packit 549fdc
 *
Packit 549fdc
 * @req_ca_dn is only used in X.509 certificates.
Packit 549fdc
 * Contains a list with the CA names that the server considers trusted.
Packit 549fdc
 * This is a hint and typically the client should send a certificate that is signed
Packit 549fdc
 * by one of these CAs. These names, when available, are DER encoded. To get a more
Packit 549fdc
 * meaningful value use the function gnutls_x509_rdn_get().
Packit 549fdc
 *
Packit 549fdc
 * @pk_algos contains a list with server's acceptable public key algorithms.
Packit 549fdc
 * The certificate returned should support the server's given algorithms.
Packit 549fdc
 *
Packit 549fdc
 * @pcert should contain a single certificate and public key or a list of them.
Packit 549fdc
 *
Packit 549fdc
 * @pcert_length is the size of the previous list.
Packit 549fdc
 *
Packit 549fdc
 * @pkey is the private key.
Packit 549fdc
 *
Packit 549fdc
 * If the callback function is provided then gnutls will call it, in the
Packit 549fdc
 * handshake, after the certificate request message has been received.
Packit 549fdc
 * All the provided by the callback values will not be released or
Packit 549fdc
 * modified by gnutls.
Packit 549fdc
 *
Packit 549fdc
 * In server side pk_algos and req_ca_dn are NULL.
Packit 549fdc
 *
Packit 549fdc
 * The callback function should set the certificate list to be sent,
Packit 549fdc
 * and return 0 on success. If no certificate was selected then the
Packit 549fdc
 * number of certificates should be set to zero. The value (-1)
Packit 549fdc
 * indicates error and the handshake will be terminated. If both certificates
Packit 549fdc
 * are set in the credentials and a callback is available, the callback
Packit 549fdc
 * takes predence.
Packit 549fdc
 *
Packit 549fdc
 * Since: 3.0
Packit 549fdc
 **/
Packit 549fdc
void gnutls_certificate_set_retrieve_function2
Packit 549fdc
    (gnutls_certificate_credentials_t cred,
Packit 549fdc
     gnutls_certificate_retrieve_function2 * func) 
Packit 549fdc
{
Packit 549fdc
	cred->get_cert_callback2 = func;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_set_verify_function:
Packit 549fdc
 * @cred: is a #gnutls_certificate_credentials_t type.
Packit 549fdc
 * @func: is the callback function
Packit 549fdc
 *
Packit 549fdc
 * This function sets a callback to be called when peer's certificate
Packit 549fdc
 * has been received in order to verify it on receipt rather than
Packit 549fdc
 * doing after the handshake is completed.
Packit 549fdc
 *
Packit 549fdc
 * The callback's function prototype is:
Packit 549fdc
 * int (*callback)(gnutls_session_t);
Packit 549fdc
 *
Packit 549fdc
 * If the callback function is provided then gnutls will call it, in the
Packit 549fdc
 * handshake, just after the certificate message has been received.
Packit 549fdc
 * To verify or obtain the certificate the gnutls_certificate_verify_peers2(),
Packit 549fdc
 * gnutls_certificate_type_get(), gnutls_certificate_get_peers() functions
Packit 549fdc
 * can be used.
Packit 549fdc
 *
Packit 549fdc
 * The callback function should return 0 for the handshake to continue
Packit 549fdc
 * or non-zero to terminate.
Packit 549fdc
 *
Packit 549fdc
 * Since: 2.10.0
Packit 549fdc
 **/
Packit 549fdc
void
Packit 549fdc
 gnutls_certificate_set_verify_function
Packit 549fdc
    (gnutls_certificate_credentials_t cred,
Packit 549fdc
     gnutls_certificate_verify_function * func)
Packit 549fdc
{
Packit 549fdc
	cred->verify_callback = func;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/*-
Packit 549fdc
 * _gnutls_x509_extract_certificate_activation_time - return the peer's certificate activation time
Packit 549fdc
 * @cert: should contain an X.509 DER encoded certificate
Packit 549fdc
 *
Packit 549fdc
 * This function will return the certificate's activation time in UNIX time
Packit 549fdc
 * (ie seconds since 00:00:00 UTC January 1, 1970).
Packit 549fdc
 *
Packit 549fdc
 * Returns a (time_t) -1 in case of an error.
Packit 549fdc
 *
Packit 549fdc
 -*/
Packit 549fdc
static time_t
Packit 549fdc
_gnutls_x509_get_raw_crt_activation_time(const gnutls_datum_t * cert)
Packit 549fdc
{
Packit 549fdc
	gnutls_x509_crt_t xcert;
Packit 549fdc
	time_t result;
Packit 549fdc
Packit 549fdc
	result = gnutls_x509_crt_init(&xcert);
Packit 549fdc
	if (result < 0)
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
Packit 549fdc
	result = gnutls_x509_crt_import(xcert, cert, GNUTLS_X509_FMT_DER);
Packit 549fdc
	if (result < 0) {
Packit 549fdc
		gnutls_x509_crt_deinit(xcert);
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	result = gnutls_x509_crt_get_activation_time(xcert);
Packit 549fdc
Packit 549fdc
	gnutls_x509_crt_deinit(xcert);
Packit 549fdc
Packit 549fdc
	return result;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/*-
Packit 549fdc
 * gnutls_x509_extract_certificate_expiration_time:
Packit 549fdc
 * @cert: should contain an X.509 DER encoded certificate
Packit 549fdc
 *
Packit 549fdc
 * This function will return the certificate's expiration time in UNIX
Packit 549fdc
 * time (ie seconds since 00:00:00 UTC January 1, 1970).  Returns a
Packit 549fdc
 *
Packit 549fdc
 * (time_t) -1 in case of an error.
Packit 549fdc
 *
Packit 549fdc
 -*/
Packit 549fdc
static time_t
Packit 549fdc
_gnutls_x509_get_raw_crt_expiration_time(const gnutls_datum_t * cert)
Packit 549fdc
{
Packit 549fdc
	gnutls_x509_crt_t xcert;
Packit 549fdc
	time_t result;
Packit 549fdc
Packit 549fdc
	result = gnutls_x509_crt_init(&xcert);
Packit 549fdc
	if (result < 0)
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
Packit 549fdc
	result = gnutls_x509_crt_import(xcert, cert, GNUTLS_X509_FMT_DER);
Packit 549fdc
	if (result < 0) {
Packit 549fdc
		gnutls_x509_crt_deinit(xcert);
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	result = gnutls_x509_crt_get_expiration_time(xcert);
Packit 549fdc
Packit 549fdc
	gnutls_x509_crt_deinit(xcert);
Packit 549fdc
Packit 549fdc
	return result;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_verify_peers2:
Packit 549fdc
 * @session: is a gnutls session
Packit 549fdc
 * @status: is the output of the verification
Packit 549fdc
 *
Packit 549fdc
 * This function will verify the peer's certificate and store
Packit 549fdc
 * the status in the @status variable as a bitwise OR of gnutls_certificate_status_t
Packit 549fdc
 * values or zero if the certificate is trusted. Note that value in @status
Packit 549fdc
 * is set only when the return value of this function is success (i.e, failure 
Packit 549fdc
 * to trust a certificate does not imply a negative return value).
Packit 549fdc
 * The default verification flags used by this function can be overridden
Packit 549fdc
 * using gnutls_certificate_set_verify_flags().
Packit 549fdc
 *
Packit 549fdc
 * This function will take into account the OCSP Certificate Status TLS extension,
Packit 549fdc
 * as well as the following X.509 certificate extensions: Name Constraints,
Packit 549fdc
 * Key Usage, and Basic Constraints (pathlen).
Packit 549fdc
 * 
Packit 549fdc
 * To avoid denial of service attacks some
Packit 549fdc
 * default upper limits regarding the certificate key size and chain
Packit 549fdc
 * size are set. To override them use gnutls_certificate_set_verify_limits().
Packit 549fdc
 *
Packit 549fdc
 * Note that you must also check the peer's name in order to check if
Packit 549fdc
 * the verified certificate belongs to the actual peer, see gnutls_x509_crt_check_hostname(),
Packit 549fdc
 * or use gnutls_certificate_verify_peers3().
Packit 549fdc
 *
Packit 549fdc
 * Returns: %GNUTLS_E_SUCCESS (0) when the validation is performed, or a negative error code otherwise.
Packit 549fdc
 * A successful error code means that the @status parameter must be checked to obtain the validation status.
Packit 549fdc
 **/
Packit 549fdc
int
Packit 549fdc
gnutls_certificate_verify_peers2(gnutls_session_t session,
Packit 549fdc
				 unsigned int *status)
Packit 549fdc
{
Packit 549fdc
	return gnutls_certificate_verify_peers(session, NULL, 0, status);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_verify_peers3:
Packit 549fdc
 * @session: is a gnutls session
Packit 549fdc
 * @hostname: is the expected name of the peer; may be %NULL
Packit 549fdc
 * @status: is the output of the verification
Packit 549fdc
 *
Packit 549fdc
 * This function will verify the peer's certificate and store the
Packit 549fdc
 * the status in the @status variable as a bitwise OR of gnutls_certificate_status_t
Packit 549fdc
 * values or zero if the certificate is trusted. Note that value in @status
Packit 549fdc
 * is set only when the return value of this function is success (i.e, failure 
Packit 549fdc
 * to trust a certificate does not imply a negative return value).
Packit 549fdc
 * The default verification flags used by this function can be overridden
Packit 549fdc
 * using gnutls_certificate_set_verify_flags(). See the documentation
Packit 549fdc
 * of gnutls_certificate_verify_peers2() for details in the verification process.
Packit 549fdc
 *
Packit 549fdc
 * If the @hostname provided is non-NULL then this function will compare
Packit 549fdc
 * the hostname in the certificate against it. The comparison will follow
Packit 549fdc
 * the RFC6125 recommendations. If names do not match the
Packit 549fdc
 * %GNUTLS_CERT_UNEXPECTED_OWNER status flag will be set.
Packit 549fdc
 *
Packit 549fdc
 * In order to verify the purpose of the end-certificate (by checking the extended
Packit 549fdc
 * key usage), use gnutls_certificate_verify_peers().
Packit 549fdc
 *
Packit 549fdc
 * Returns: %GNUTLS_E_SUCCESS (0) when the validation is performed, or a negative error code otherwise.
Packit 549fdc
 * A successful error code means that the @status parameter must be checked to obtain the validation status.
Packit 549fdc
 *
Packit 549fdc
 * Since: 3.1.4
Packit 549fdc
 **/
Packit 549fdc
int
Packit 549fdc
gnutls_certificate_verify_peers3(gnutls_session_t session,
Packit 549fdc
				 const char *hostname,
Packit 549fdc
				 unsigned int *status)
Packit 549fdc
{
Packit 549fdc
gnutls_typed_vdata_st data;
Packit 549fdc
Packit 549fdc
	data.type = GNUTLS_DT_DNS_HOSTNAME;
Packit 549fdc
	data.size = 0;
Packit 549fdc
	data.data = (void*)hostname;
Packit 549fdc
Packit 549fdc
	return gnutls_certificate_verify_peers(session, &data, 1, status);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_verify_peers:
Packit 549fdc
 * @session: is a gnutls session
Packit 549fdc
 * @data: an array of typed data
Packit 549fdc
 * @elements: the number of data elements
Packit 549fdc
 * @status: is the output of the verification
Packit 549fdc
 *
Packit 549fdc
 * This function will verify the peer's certificate and store the
Packit 549fdc
 * the status in the @status variable as a bitwise OR of gnutls_certificate_status_t
Packit 549fdc
 * values or zero if the certificate is trusted. Note that value in @status
Packit 549fdc
 * is set only when the return value of this function is success (i.e, failure 
Packit 549fdc
 * to trust a certificate does not imply a negative return value).
Packit 549fdc
 * The default verification flags used by this function can be overridden
Packit 549fdc
 * using gnutls_certificate_set_verify_flags(). See the documentation
Packit 549fdc
 * of gnutls_certificate_verify_peers2() for details in the verification process.
Packit 549fdc
 *
Packit 549fdc
 * The acceptable @data types are %GNUTLS_DT_DNS_HOSTNAME, %GNUTLS_DT_RFC822NAME and %GNUTLS_DT_KEY_PURPOSE_OID.
Packit 549fdc
 * The former two accept as data a null-terminated hostname or email address, and the latter a null-terminated
Packit 549fdc
 * object identifier (e.g., %GNUTLS_KP_TLS_WWW_SERVER).
Packit 549fdc
 *
Packit 549fdc
 * If a DNS hostname is provided then this function will compare
Packit 549fdc
 * the hostname in the certificate against the given. If names do not match the 
Packit 549fdc
 * %GNUTLS_CERT_UNEXPECTED_OWNER status flag will be set.
Packit 549fdc
 * If a key purpose OID is provided and the end-certificate contains the extended key
Packit 549fdc
 * usage PKIX extension, it will be required to be have the provided key purpose 
Packit 549fdc
 * or be marked for any purpose, otherwise verification status will have the
Packit 549fdc
 * %GNUTLS_CERT_SIGNER_CONSTRAINTS_FAILURE flag set.
Packit 549fdc
 *
Packit 549fdc
 * Returns: %GNUTLS_E_SUCCESS (0) when the validation is performed, or a negative error code otherwise.
Packit 549fdc
 * A successful error code means that the @status parameter must be checked to obtain the validation status.
Packit 549fdc
 *
Packit 549fdc
 * Since: 3.3.0
Packit 549fdc
 **/
Packit 549fdc
int
Packit 549fdc
gnutls_certificate_verify_peers(gnutls_session_t session,
Packit 549fdc
				gnutls_typed_vdata_st * data,
Packit 549fdc
				unsigned int elements,
Packit 549fdc
				unsigned int *status)
Packit 549fdc
{
Packit 549fdc
	cert_auth_info_t info;
Packit 549fdc
Packit 549fdc
	CHECK_AUTH(GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST);
Packit 549fdc
Packit 549fdc
	info = _gnutls_get_auth_info(session, GNUTLS_CRD_CERTIFICATE);
Packit 549fdc
	if (info == NULL) {
Packit 549fdc
		return GNUTLS_E_NO_CERTIFICATE_FOUND;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	if (info->raw_certificate_list == NULL || info->ncerts == 0)
Packit 549fdc
		return GNUTLS_E_NO_CERTIFICATE_FOUND;
Packit 549fdc
Packit 549fdc
Packit 549fdc
	switch (gnutls_certificate_type_get(session)) {
Packit 549fdc
	case GNUTLS_CRT_X509:
Packit 549fdc
		return _gnutls_x509_cert_verify_peers(session, data, elements,
Packit 549fdc
						      status);
Packit 549fdc
	default:
Packit 549fdc
		return GNUTLS_E_INVALID_REQUEST;
Packit 549fdc
	}
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_expiration_time_peers:
Packit 549fdc
 * @session: is a gnutls session
Packit 549fdc
 *
Packit 549fdc
 * This function will return the peer's certificate expiration time.
Packit 549fdc
 *
Packit 549fdc
 * Returns: (time_t)-1 on error.
Packit 549fdc
 *
Packit 549fdc
 * Deprecated: gnutls_certificate_verify_peers2() now verifies expiration times.
Packit 549fdc
 **/
Packit 549fdc
time_t gnutls_certificate_expiration_time_peers(gnutls_session_t session)
Packit 549fdc
{
Packit 549fdc
	cert_auth_info_t info;
Packit 549fdc
Packit 549fdc
	CHECK_AUTH(GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST);
Packit 549fdc
Packit 549fdc
	info = _gnutls_get_auth_info(session, GNUTLS_CRD_CERTIFICATE);
Packit 549fdc
	if (info == NULL) {
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	if (info->raw_certificate_list == NULL || info->ncerts == 0) {
Packit 549fdc
		gnutls_assert();
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	switch (gnutls_certificate_type_get(session)) {
Packit 549fdc
	case GNUTLS_CRT_X509:
Packit 549fdc
		return
Packit 549fdc
		    _gnutls_x509_get_raw_crt_expiration_time(&info->
Packit 549fdc
							     raw_certificate_list
Packit 549fdc
							     [0]);
Packit 549fdc
	default:
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
	}
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_activation_time_peers:
Packit 549fdc
 * @session: is a gnutls session
Packit 549fdc
 *
Packit 549fdc
 * This function will return the peer's certificate activation time.
Packit 549fdc
 *
Packit 549fdc
 * Returns: (time_t)-1 on error.
Packit 549fdc
 *
Packit 549fdc
 * Deprecated: gnutls_certificate_verify_peers2() now verifies activation times.
Packit 549fdc
 **/
Packit 549fdc
time_t gnutls_certificate_activation_time_peers(gnutls_session_t session)
Packit 549fdc
{
Packit 549fdc
	cert_auth_info_t info;
Packit 549fdc
Packit 549fdc
	CHECK_AUTH(GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST);
Packit 549fdc
Packit 549fdc
	info = _gnutls_get_auth_info(session, GNUTLS_CRD_CERTIFICATE);
Packit 549fdc
	if (info == NULL) {
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	if (info->raw_certificate_list == NULL || info->ncerts == 0) {
Packit 549fdc
		gnutls_assert();
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	switch (gnutls_certificate_type_get(session)) {
Packit 549fdc
	case GNUTLS_CRT_X509:
Packit 549fdc
		return
Packit 549fdc
		    _gnutls_x509_get_raw_crt_activation_time(&info->
Packit 549fdc
							     raw_certificate_list
Packit 549fdc
							     [0]);
Packit 549fdc
	default:
Packit 549fdc
		return (time_t) - 1;
Packit 549fdc
	}
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
#define TEST_TEXT "test text"
Packit 549fdc
/* returns error if the certificate has different algorithm than
Packit 549fdc
 * the given key parameters.
Packit 549fdc
 */
Packit 549fdc
int _gnutls_check_key_cert_match(gnutls_certificate_credentials_t res)
Packit 549fdc
{
Packit 549fdc
	gnutls_datum_t test = {(void*)TEST_TEXT, sizeof(TEST_TEXT)-1};
Packit 549fdc
	gnutls_datum_t sig = {NULL, 0};
Packit 549fdc
	int pk, pk2, ret;
Packit 549fdc
	unsigned sign_algo;
Packit 549fdc
Packit 549fdc
	if (res->flags & GNUTLS_CERTIFICATE_SKIP_KEY_CERT_MATCH)
Packit 549fdc
		return 0;
Packit 549fdc
Packit 549fdc
	pk =
Packit 549fdc
	    gnutls_pubkey_get_pk_algorithm(res->certs[res->ncerts - 1].
Packit 549fdc
					   cert_list[0].pubkey, NULL);
Packit 549fdc
	pk2 =
Packit 549fdc
	    gnutls_privkey_get_pk_algorithm(res->certs[res->ncerts - 1].pkey,
Packit 549fdc
					    NULL);
Packit 549fdc
Packit 549fdc
	if (GNUTLS_PK_IS_RSA(pk) && GNUTLS_PK_IS_RSA(pk2)) {
Packit 549fdc
		if (pk2 == GNUTLS_PK_RSA_PSS && pk == GNUTLS_PK_RSA) {
Packit 549fdc
			_gnutls_debug_log("you cannot mix an RSA-PSS key with an RSA certificate\n");
Packit 549fdc
			return GNUTLS_E_CERTIFICATE_KEY_MISMATCH;
Packit 549fdc
		}
Packit 549fdc
Packit 549fdc
		if (pk2 == GNUTLS_PK_RSA_PSS || pk == GNUTLS_PK_RSA_PSS)
Packit 549fdc
			pk = GNUTLS_PK_RSA_PSS;
Packit 549fdc
	} else if (pk2 != pk) {
Packit 549fdc
		gnutls_assert();
Packit 549fdc
		_gnutls_debug_log("key is %s, certificate is %s\n", gnutls_pk_get_name(pk2),
Packit 549fdc
			gnutls_pk_get_name(pk));
Packit 549fdc
		return GNUTLS_E_CERTIFICATE_KEY_MISMATCH;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	sign_algo = gnutls_pk_to_sign(pk, GNUTLS_DIG_SHA256);
Packit 549fdc
Packit 549fdc
	/* now check if keys really match. We use the sign/verify approach
Packit 549fdc
	 * because we cannot always obtain the parameters from the abstract
Packit 549fdc
	 * keys (e.g. PKCS #11). */
Packit 549fdc
	ret = gnutls_privkey_sign_data2(res->certs[res->ncerts - 1].pkey,
Packit 549fdc
		sign_algo, 0, &test, &sig);
Packit 549fdc
	if (ret < 0) {
Packit 549fdc
		/* for some reason we couldn't sign that. That shouldn't have
Packit 549fdc
		 * happened, but since it did, report the issue and do not
Packit 549fdc
		 * try the key matching test */
Packit 549fdc
		_gnutls_debug_log("%s: failed signing\n", __func__);
Packit 549fdc
		goto finish;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	ret = gnutls_pubkey_verify_data2(res->certs[res->ncerts - 1].cert_list[0].pubkey,
Packit 549fdc
					 sign_algo,
Packit 549fdc
					 GNUTLS_VERIFY_ALLOW_BROKEN, &test, &sig);
Packit 549fdc
Packit 549fdc
	gnutls_free(sig.data);
Packit 549fdc
Packit 549fdc
	if (ret < 0)
Packit 549fdc
		return gnutls_assert_val(GNUTLS_E_CERTIFICATE_KEY_MISMATCH);
Packit 549fdc
Packit 549fdc
 finish:
Packit 549fdc
	return 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_verification_status_print:
Packit 549fdc
 * @status: The status flags to be printed
Packit 549fdc
 * @type: The certificate type
Packit 549fdc
 * @out: Newly allocated datum with (0) terminated string.
Packit 549fdc
 * @flags: should be zero
Packit 549fdc
 *
Packit 549fdc
 * This function will pretty print the status of a verification
Packit 549fdc
 * process -- eg. the one obtained by gnutls_certificate_verify_peers3().
Packit 549fdc
 *
Packit 549fdc
 * The output @out needs to be deallocated using gnutls_free().
Packit 549fdc
 *
Packit 549fdc
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
Packit 549fdc
 *   negative error value.
Packit 549fdc
 *
Packit 549fdc
 * Since: 3.1.4
Packit 549fdc
 **/
Packit 549fdc
int
Packit 549fdc
gnutls_certificate_verification_status_print(unsigned int status,
Packit 549fdc
					     gnutls_certificate_type_t
Packit 549fdc
					     type, gnutls_datum_t * out,
Packit 549fdc
					     unsigned int flags)
Packit 549fdc
{
Packit 549fdc
	gnutls_buffer_st str;
Packit 549fdc
Packit 549fdc
	_gnutls_buffer_init(&str);
Packit 549fdc
Packit 549fdc
	if (status == 0)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The certificate is trusted. "));
Packit 549fdc
	else
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The certificate is NOT trusted. "));
Packit 549fdc
Packit 549fdc
	if (type == GNUTLS_CRT_X509) {
Packit 549fdc
		if (status & GNUTLS_CERT_REVOKED)
Packit 549fdc
			_gnutls_buffer_append_str(&str,
Packit 549fdc
						  _
Packit 549fdc
						  ("The certificate chain is revoked. "));
Packit 549fdc
Packit 549fdc
		if (status & GNUTLS_CERT_MISMATCH)
Packit 549fdc
			_gnutls_buffer_append_str(&str,
Packit 549fdc
						  _
Packit 549fdc
						  ("The certificate doesn't match the local copy (TOFU). "));
Packit 549fdc
Packit 549fdc
		if (status & GNUTLS_CERT_REVOCATION_DATA_SUPERSEDED)
Packit 549fdc
			_gnutls_buffer_append_str(&str,
Packit 549fdc
						  _
Packit 549fdc
						  ("The revocation or OCSP data are old and have been superseded. "));
Packit 549fdc
Packit 549fdc
		if (status & GNUTLS_CERT_REVOCATION_DATA_ISSUED_IN_FUTURE)
Packit 549fdc
			_gnutls_buffer_append_str(&str,
Packit 549fdc
						  _
Packit 549fdc
						  ("The revocation or OCSP data are issued with a future date. "));
Packit 549fdc
Packit 549fdc
		if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
Packit 549fdc
			_gnutls_buffer_append_str(&str,
Packit 549fdc
						  _
Packit 549fdc
						  ("The certificate issuer is unknown. "));
Packit 549fdc
Packit 549fdc
		if (status & GNUTLS_CERT_SIGNER_NOT_CA)
Packit 549fdc
			_gnutls_buffer_append_str(&str,
Packit 549fdc
						  _
Packit 549fdc
						  ("The certificate issuer is not a CA. "));
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_INSECURE_ALGORITHM)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The certificate chain uses insecure algorithm. "));
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_SIGNER_CONSTRAINTS_FAILURE)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The certificate chain violates the signer's constraints. "));
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_PURPOSE_MISMATCH)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The certificate chain does not match the intended purpose. "));
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_NOT_ACTIVATED)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The certificate chain uses not yet valid certificate. "));
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_EXPIRED)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The certificate chain uses expired certificate. "));
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_SIGNATURE_FAILURE)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The signature in the certificate is invalid. "));
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_UNEXPECTED_OWNER)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The name in the certificate does not match the expected. "));
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_MISSING_OCSP_STATUS)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The certificate requires the server to include an OCSP status in its response, but the OCSP status is missing. "));
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_INVALID_OCSP_STATUS)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The received OCSP status response is invalid. "));
Packit 549fdc
Packit 549fdc
	if (status & GNUTLS_CERT_UNKNOWN_CRIT_EXTENSIONS)
Packit 549fdc
		_gnutls_buffer_append_str(&str,
Packit 549fdc
					  _
Packit 549fdc
					  ("The certificate contains an unknown critical extension. "));
Packit 549fdc
Packit 549fdc
	return _gnutls_buffer_to_datum(&str, out, 1);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
#if defined(ENABLE_DHE) || defined(ENABLE_ANON)
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_set_dh_params:
Packit 549fdc
 * @res: is a gnutls_certificate_credentials_t type
Packit 549fdc
 * @dh_params: the Diffie-Hellman parameters.
Packit 549fdc
 *
Packit 549fdc
 * This function will set the Diffie-Hellman parameters for a
Packit 549fdc
 * certificate server to use. These parameters will be used in
Packit 549fdc
 * Ephemeral Diffie-Hellman cipher suites.  Note that only a pointer
Packit 549fdc
 * to the parameters are stored in the certificate handle, so you
Packit 549fdc
 * must not deallocate the parameters before the certificate is deallocated.
Packit 549fdc
 *
Packit 549fdc
 * Deprecated: This function is unnecessary and discouraged on GnuTLS 3.6.0
Packit 549fdc
 * or later. Since 3.6.0, DH parameters are negotiated
Packit 549fdc
 * following RFC7919.
Packit 549fdc
 *
Packit 549fdc
 **/
Packit 549fdc
void
Packit 549fdc
gnutls_certificate_set_dh_params(gnutls_certificate_credentials_t res,
Packit 549fdc
				 gnutls_dh_params_t dh_params)
Packit 549fdc
{
Packit 549fdc
	if (res->deinit_dh_params) {
Packit 549fdc
		res->deinit_dh_params = 0;
Packit 549fdc
		gnutls_dh_params_deinit(res->dh_params);
Packit 549fdc
		res->dh_params = NULL;
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	res->dh_params = dh_params;
Packit 549fdc
	res->dh_sec_param = gnutls_pk_bits_to_sec_param(GNUTLS_PK_DH, _gnutls_mpi_get_nbits(dh_params->params[0]));
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_certificate_set_known_dh_params:
Packit 549fdc
 * @res: is a gnutls_certificate_credentials_t type
Packit 549fdc
 * @sec_param: is an option of the %gnutls_sec_param_t enumeration
Packit 549fdc
 *
Packit 549fdc
 * This function will set the Diffie-Hellman parameters for a
Packit 549fdc
 * certificate server to use. These parameters will be used in
Packit 549fdc
 * Ephemeral Diffie-Hellman cipher suites and will be selected from
Packit 549fdc
 * the FFDHE set of RFC7919 according to the security level provided.
Packit 549fdc
 *
Packit 549fdc
 * Deprecated: This function is unnecessary and discouraged on GnuTLS 3.6.0
Packit 549fdc
 * or later. Since 3.6.0, DH parameters are negotiated
Packit 549fdc
 * following RFC7919.
Packit 549fdc
 *
Packit 549fdc
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
Packit 549fdc
 *   negative error value.
Packit 549fdc
 *
Packit 549fdc
 * Since: 3.5.6
Packit 549fdc
 **/
Packit 549fdc
int
Packit 549fdc
gnutls_certificate_set_known_dh_params(gnutls_certificate_credentials_t res,
Packit 549fdc
				       gnutls_sec_param_t sec_param)
Packit 549fdc
{
Packit 549fdc
	res->dh_sec_param = sec_param;
Packit 549fdc
Packit 549fdc
	return 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
#endif				/* DH */