Coverage Report

Created: 2023-03-26 08:33

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