/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 gen_anon_ecdh_server_kx(gnutls_session_t session, |
64 | | 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)_gnutls_get_cred( |
70 | 0 | 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 = _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 = _gnutls_ecdh_common_print_server_kx(session, data, |
83 | 0 | get_group(session)); |
84 | 0 | if (ret < 0) { |
85 | 0 | gnutls_assert(); |
86 | 0 | } |
87 | |
|
88 | 0 | return ret; |
89 | 0 | } |
90 | | |
91 | | static int proc_anon_ecdh_client_kx(gnutls_session_t session, uint8_t *data, |
92 | | size_t _data_size) |
93 | 0 | { |
94 | 0 | gnutls_anon_server_credentials_t cred; |
95 | |
|
96 | 0 | cred = (gnutls_anon_server_credentials_t)_gnutls_get_cred( |
97 | 0 | session, GNUTLS_CRD_ANON); |
98 | 0 | if (cred == NULL) { |
99 | 0 | gnutls_assert(); |
100 | 0 | return GNUTLS_E_INSUFFICIENT_CREDENTIALS; |
101 | 0 | } |
102 | | |
103 | 0 | return _gnutls_proc_ecdh_common_client_kx(session, data, _data_size, |
104 | 0 | get_group(session), NULL); |
105 | 0 | } |
106 | | |
107 | | int proc_anon_ecdh_server_kx(gnutls_session_t session, uint8_t *data, |
108 | | size_t _data_size) |
109 | 0 | { |
110 | 0 | int ret; |
111 | | |
112 | | /* set auth_info */ |
113 | 0 | if ((ret = _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_ecdh_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 */ |