Blame lib/anon_cred.c

Packit 549fdc
/*
Packit 549fdc
 * Copyright (C) 2001-2012 Free Software Foundation, 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
#include "gnutls_int.h"
Packit 549fdc
Packit 549fdc
#ifdef ENABLE_ANON
Packit 549fdc
Packit 549fdc
#include "errors.h"
Packit 549fdc
#include <auth/anon.h>
Packit 549fdc
#include "auth.h"
Packit 549fdc
#include "dh.h"
Packit 549fdc
#include "num.h"
Packit 549fdc
#include "mpi.h"
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_anon_free_server_credentials:
Packit 549fdc
 * @sc: is a #gnutls_anon_server_credentials_t type.
Packit 549fdc
 *
Packit 549fdc
 * Free a gnutls_anon_server_credentials_t structure.
Packit 549fdc
 **/
Packit 549fdc
void
Packit 549fdc
gnutls_anon_free_server_credentials(gnutls_anon_server_credentials_t sc)
Packit 549fdc
{
Packit 549fdc
	if (sc->deinit_dh_params) {
Packit 549fdc
		gnutls_dh_params_deinit(sc->dh_params);
Packit 549fdc
	}
Packit 549fdc
	gnutls_free(sc);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_anon_allocate_server_credentials:
Packit 549fdc
 * @sc: is a pointer to a #gnutls_anon_server_credentials_t type.
Packit 549fdc
 *
Packit 549fdc
 * Allocate a gnutls_anon_server_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_anon_allocate_server_credentials(gnutls_anon_server_credentials_t *
Packit 549fdc
					sc)
Packit 549fdc
{
Packit 549fdc
Packit 549fdc
	*sc = gnutls_calloc(1, sizeof(anon_server_credentials_st));
Packit 549fdc
Packit 549fdc
	return 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_anon_free_client_credentials:
Packit 549fdc
 * @sc: is a #gnutls_anon_client_credentials_t type.
Packit 549fdc
 *
Packit 549fdc
 * Free a gnutls_anon_client_credentials_t structure.
Packit 549fdc
 **/
Packit 549fdc
void
Packit 549fdc
gnutls_anon_free_client_credentials(gnutls_anon_client_credentials_t sc)
Packit 549fdc
{
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
static struct gnutls_anon_client_credentials_st anon_dummy_struct;
Packit 549fdc
static const gnutls_anon_client_credentials_t anon_dummy =
Packit 549fdc
    &anon_dummy_struct;
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_anon_allocate_client_credentials:
Packit 549fdc
 * @sc: is a pointer to a #gnutls_anon_client_credentials_t type.
Packit 549fdc
 *
Packit 549fdc
 * Allocate a gnutls_anon_client_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_anon_allocate_client_credentials(gnutls_anon_client_credentials_t *
Packit 549fdc
					sc)
Packit 549fdc
{
Packit 549fdc
	/* anon_dummy is only there for *sc not to be null.
Packit 549fdc
	 * it is not used at all;
Packit 549fdc
	 */
Packit 549fdc
	*sc = anon_dummy;
Packit 549fdc
Packit 549fdc
	return 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_anon_set_server_dh_params:
Packit 549fdc
 * @res: is a gnutls_anon_server_credentials_t type
Packit 549fdc
 * @dh_params: The Diffie-Hellman parameters.
Packit 549fdc
 *
Packit 549fdc
 * This function will set the Diffie-Hellman parameters for an
Packit 549fdc
 * anonymous server to use.  These parameters will be used in
Packit 549fdc
 * Anonymous Diffie-Hellman cipher suites.
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
void
Packit 549fdc
gnutls_anon_set_server_dh_params(gnutls_anon_server_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
 * gnutls_anon_set_server_known_dh_params:
Packit 549fdc
 * @res: is a gnutls_anon_server_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 an
Packit 549fdc
 * anonymous server to use.  These parameters will be used in
Packit 549fdc
 * Anonymous 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_anon_set_server_known_dh_params(gnutls_anon_server_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
/**
Packit 549fdc
 * gnutls_anon_set_server_params_function:
Packit 549fdc
 * @res: is a gnutls_certificate_credentials_t type
Packit 549fdc
 * @func: is the function to be called
Packit 549fdc
 *
Packit 549fdc
 * This function will set a callback in order for the server to get
Packit 549fdc
 * the Diffie-Hellman parameters for anonymous authentication.  The
Packit 549fdc
 * callback should return %GNUTLS_E_SUCCESS (0) on success.
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_anon_set_server_params_function(gnutls_anon_server_credentials_t
Packit 549fdc
				       res, gnutls_params_function * func)
Packit 549fdc
{
Packit 549fdc
	res->params_func = func;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/**
Packit 549fdc
 * gnutls_anon_set_params_function:
Packit 549fdc
 * @res: is a gnutls_anon_server_credentials_t type
Packit 549fdc
 * @func: is the function to be called
Packit 549fdc
 *
Packit 549fdc
 * This function will set a callback in order for the server to get
Packit 549fdc
 * the Diffie-Hellman or RSA parameters for anonymous authentication.
Packit 549fdc
 * The callback should return %GNUTLS_E_SUCCESS (0) on success.
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_anon_set_params_function(gnutls_anon_server_credentials_t res,
Packit 549fdc
				gnutls_params_function * func)
Packit 549fdc
{
Packit 549fdc
	res->params_func = func;
Packit 549fdc
}
Packit 549fdc
#endif