/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)_gnutls_get_cred( |
69 | 0 | 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 = _gnutls_auth_info_init(session, GNUTLS_CRD_ANON, |
76 | 0 | sizeof(anon_auth_info_st), 1)) < 0) { |
77 | 0 | gnutls_assert(); |
78 | 0 | return ret; |
79 | 0 | } |
80 | | |
81 | 0 | ret = _gnutls_figure_dh_params(session, cred->dh_params, |
82 | 0 | cred->params_func, cred->dh_sec_param); |
83 | 0 | if (ret < 0) { |
84 | 0 | return gnutls_assert_val(ret); |
85 | 0 | } |
86 | | |
87 | 0 | ret = _gnutls_dh_common_print_server_kx(session, data); |
88 | 0 | if (ret < 0) { |
89 | 0 | gnutls_assert(); |
90 | 0 | } |
91 | |
|
92 | 0 | return ret; |
93 | 0 | } |
94 | | |
95 | | static int proc_anon_client_kx(gnutls_session_t session, uint8_t *data, |
96 | | size_t _data_size) |
97 | 0 | { |
98 | 0 | return _gnutls_proc_dh_common_client_kx(session, data, _data_size, |
99 | 0 | NULL); |
100 | 0 | } |
101 | | |
102 | | int proc_anon_server_kx(gnutls_session_t session, uint8_t *data, |
103 | | size_t _data_size) |
104 | 0 | { |
105 | 0 | int ret; |
106 | | |
107 | | /* set auth_info */ |
108 | 0 | if ((ret = _gnutls_auth_info_init(session, GNUTLS_CRD_ANON, |
109 | 0 | sizeof(anon_auth_info_st), 1)) < 0) { |
110 | 0 | gnutls_assert(); |
111 | 0 | return ret; |
112 | 0 | } |
113 | | |
114 | 0 | ret = _gnutls_proc_dh_common_server_kx(session, data, _data_size); |
115 | 0 | if (ret < 0) { |
116 | 0 | gnutls_assert(); |
117 | 0 | return ret; |
118 | 0 | } |
119 | | |
120 | 0 | return 0; |
121 | 0 | } |
122 | | |
123 | | #endif /* ENABLE_ANON */ |