|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2000-2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
* Copyright (C) 2017 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The GnuTLS is free software; you can redistribute it and/or
|
|
Packit Service |
4684c1 |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
4684c1 |
* the License, or (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This library is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* Lesser General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* This file contains everything for the Ephemeral Diffie-Hellman
|
|
Packit Service |
4684c1 |
* (DHE) key exchange. This is used in the handshake procedure of the
|
|
Packit Service |
4684c1 |
* certificate authentication.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "gnutls_int.h"
|
|
Packit Service |
4684c1 |
#include "auth.h"
|
|
Packit Service |
4684c1 |
#include "errors.h"
|
|
Packit Service |
4684c1 |
#include "dh.h"
|
|
Packit Service |
4684c1 |
#include "num.h"
|
|
Packit Service |
4684c1 |
#include "tls-sig.h"
|
|
Packit Service |
4684c1 |
#include <datum.h>
|
|
Packit Service |
4684c1 |
#include <algorithms.h>
|
|
Packit Service |
4684c1 |
#include <auth/cert.h>
|
|
Packit Service |
4684c1 |
#include <x509.h>
|
|
Packit Service |
4684c1 |
#include <state.h>
|
|
Packit Service |
4684c1 |
#include <auth/dh_common.h>
|
|
Packit Service |
4684c1 |
#include <auth/ecdhe.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int gen_dhe_server_kx(gnutls_session_t, gnutls_buffer_st *);
|
|
Packit Service |
4684c1 |
static int proc_dhe_server_kx(gnutls_session_t, uint8_t *, size_t);
|
|
Packit Service |
4684c1 |
static int proc_dhe_client_kx(gnutls_session_t, uint8_t *, size_t);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef ENABLE_DHE
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const mod_auth_st dhe_rsa_auth_struct = {
|
|
Packit Service |
4684c1 |
"DHE_RSA",
|
|
Packit Service |
4684c1 |
_gnutls_gen_cert_server_crt,
|
|
Packit Service |
4684c1 |
_gnutls_gen_cert_client_crt,
|
|
Packit Service |
4684c1 |
gen_dhe_server_kx,
|
|
Packit Service |
4684c1 |
_gnutls_gen_dh_common_client_kx,
|
|
Packit Service |
4684c1 |
_gnutls_gen_cert_client_crt_vrfy, /* gen client cert vrfy */
|
|
Packit Service |
4684c1 |
_gnutls_gen_cert_server_cert_req, /* server cert request */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_gnutls_proc_crt,
|
|
Packit Service |
4684c1 |
_gnutls_proc_crt,
|
|
Packit Service |
4684c1 |
proc_dhe_server_kx,
|
|
Packit Service |
4684c1 |
proc_dhe_client_kx,
|
|
Packit Service |
4684c1 |
_gnutls_proc_cert_client_crt_vrfy, /* proc client cert vrfy */
|
|
Packit Service |
4684c1 |
_gnutls_proc_cert_cert_req /* proc server cert request */
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
const mod_auth_st dhe_dss_auth_struct = {
|
|
Packit Service |
4684c1 |
"DHE_DSS",
|
|
Packit Service |
4684c1 |
_gnutls_gen_cert_server_crt,
|
|
Packit Service |
4684c1 |
_gnutls_gen_cert_client_crt,
|
|
Packit Service |
4684c1 |
gen_dhe_server_kx,
|
|
Packit Service |
4684c1 |
_gnutls_gen_dh_common_client_kx,
|
|
Packit Service |
4684c1 |
_gnutls_gen_cert_client_crt_vrfy, /* gen client cert vrfy */
|
|
Packit Service |
4684c1 |
_gnutls_gen_cert_server_cert_req, /* server cert request */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_gnutls_proc_crt,
|
|
Packit Service |
4684c1 |
_gnutls_proc_crt,
|
|
Packit Service |
4684c1 |
proc_dhe_server_kx,
|
|
Packit Service |
4684c1 |
proc_dhe_client_kx,
|
|
Packit Service |
4684c1 |
_gnutls_proc_cert_client_crt_vrfy, /* proc client cert vrfy */
|
|
Packit Service |
4684c1 |
_gnutls_proc_cert_cert_req /* proc server cert request */
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int
|
|
Packit Service |
4684c1 |
gen_dhe_server_kx(gnutls_session_t session, gnutls_buffer_st * data)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int ret = 0;
|
|
Packit Service |
4684c1 |
gnutls_certificate_credentials_t cred;
|
|
Packit Service |
4684c1 |
unsigned sig_pos;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
cred = (gnutls_certificate_credentials_t)
|
|
Packit Service |
4684c1 |
_gnutls_get_cred(session, GNUTLS_CRD_CERTIFICATE);
|
|
Packit Service |
4684c1 |
if (cred == NULL) {
|
|
Packit Service |
4684c1 |
gnutls_assert();
|
|
Packit Service |
4684c1 |
return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if ((ret = _gnutls_auth_info_init(session, GNUTLS_CRD_CERTIFICATE,
|
|
Packit Service |
4684c1 |
sizeof(cert_auth_info_st),
|
|
Packit Service |
4684c1 |
1)) < 0) {
|
|
Packit Service |
4684c1 |
gnutls_assert();
|
|
Packit Service |
4684c1 |
return ret;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret =
|
|
Packit Service |
4684c1 |
_gnutls_figure_dh_params(session, cred->dh_params, cred->params_func, cred->dh_sec_param);
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
sig_pos = data->length;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret =
|
|
Packit Service |
4684c1 |
_gnutls_dh_common_print_server_kx(session, data);
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
gnutls_assert();
|
|
Packit Service |
4684c1 |
return ret;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Generate the signature. */
|
|
Packit Service |
4684c1 |
return _gnutls_gen_dhe_signature(session, data, &data->data[sig_pos],
|
|
Packit Service |
4684c1 |
data->length-sig_pos);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int
|
|
Packit Service |
4684c1 |
proc_dhe_server_kx(gnutls_session_t session, uint8_t * data,
|
|
Packit Service |
4684c1 |
size_t _data_size)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_datum_t vdata;
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = _gnutls_proc_dh_common_server_kx(session, data, _data_size);
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
vdata.data = data;
|
|
Packit Service |
4684c1 |
vdata.size = ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return _gnutls_proc_dhe_signature(session, data + ret,
|
|
Packit Service |
4684c1 |
_data_size - ret, &vdata);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int
|
|
Packit Service |
4684c1 |
proc_dhe_client_kx(gnutls_session_t session, uint8_t * data,
|
|
Packit Service |
4684c1 |
size_t _data_size)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
return _gnutls_proc_dh_common_client_kx(session, data, _data_size,
|
|
Packit Service |
4684c1 |
NULL);
|
|
Packit Service |
4684c1 |
}
|