Coverage Report

Created: 2023-03-26 08:33

/src/gnutls/lib/auth/anon.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
3
 * Copyright (C) 2017 Red Hat, Inc.
4
 *
5
 * Author: Nikos Mavrogiannopoulos
6
 *
7
 * This file is part of GnuTLS.
8
 *
9
 * The GnuTLS is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public License
11
 * as published by the Free Software Foundation; either version 2.1 of
12
 * the License, or (at your option) any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful, but
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
21
 *
22
 */
23
24
/* This file contains the Anonymous Diffie-Hellman key exchange part of
25
 * the anonymous authentication. The functions here are used in the
26
 * handshake.
27
 */
28
29
#include "gnutls_int.h"
30
31
#if defined(ENABLE_ANON) && defined(ENABLE_DHE)
32
33
# include "auth.h"
34
# include "errors.h"
35
# include "dh.h"
36
# include "auth/anon.h"
37
# include "num.h"
38
# include "mpi.h"
39
# include <state.h>
40
# include <auth/dh_common.h>
41
42
static int gen_anon_server_kx(gnutls_session_t, gnutls_buffer_st *);
43
static int proc_anon_client_kx(gnutls_session_t, uint8_t *, size_t);
44
static int proc_anon_server_kx(gnutls_session_t, uint8_t *, size_t);
45
46
const mod_auth_st anon_auth_struct = {
47
  "ANON",
48
  NULL,
49
  NULL,
50
  gen_anon_server_kx,
51
  _gnutls_gen_dh_common_client_kx,  /* this can be shared */
52
  NULL,
53
  NULL,
54
55
  NULL,
56
  NULL,     /* certificate */
57
  proc_anon_server_kx,
58
  proc_anon_client_kx,
59
  NULL,
60
  NULL
61
};
62
63
static int gen_anon_server_kx(gnutls_session_t session, gnutls_buffer_st * data)
64
0
{
65
0
  int ret;
66
0
  gnutls_anon_server_credentials_t cred;
67
68
0
  cred = (gnutls_anon_server_credentials_t)
69
0
      _gnutls_get_cred(session, GNUTLS_CRD_ANON);
70
0
  if (cred == NULL) {
71
0
    gnutls_assert();
72
0
    return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
73
0
  }
74
75
0
  if ((ret =
76
0
       _gnutls_auth_info_init(session, GNUTLS_CRD_ANON,
77
0
            sizeof(anon_auth_info_st), 1)) < 0) {
78
0
    gnutls_assert();
79
0
    return ret;
80
0
  }
81
82
0
  ret =
83
0
      _gnutls_figure_dh_params(session, cred->dh_params,
84
0
             cred->params_func, cred->dh_sec_param);
85
0
  if (ret < 0) {
86
0
    return gnutls_assert_val(ret);
87
0
  }
88
89
0
  ret = _gnutls_dh_common_print_server_kx(session, data);
90
0
  if (ret < 0) {
91
0
    gnutls_assert();
92
0
  }
93
94
0
  return ret;
95
0
}
96
97
static int
98
proc_anon_client_kx(gnutls_session_t session, uint8_t * data, size_t _data_size)
99
0
{
100
0
  return
101
0
      _gnutls_proc_dh_common_client_kx(session, data, _data_size, NULL);
102
103
0
}
104
105
int
106
proc_anon_server_kx(gnutls_session_t session, uint8_t * data, size_t _data_size)
107
0
{
108
109
0
  int ret;
110
111
  /* set auth_info */
112
0
  if ((ret =
113
0
       _gnutls_auth_info_init(session, GNUTLS_CRD_ANON,
114
0
            sizeof(anon_auth_info_st), 1)) < 0) {
115
0
    gnutls_assert();
116
0
    return ret;
117
0
  }
118
119
0
  ret = _gnutls_proc_dh_common_server_kx(session, data, _data_size);
120
0
  if (ret < 0) {
121
0
    gnutls_assert();
122
0
    return ret;
123
0
  }
124
125
0
  return 0;
126
0
}
127
128
#endif        /* ENABLE_ANON */