/src/gnutls/lib/auth/psk.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2005-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 | | #ifndef GNUTLS_LIB_AUTH_PSK_H |
24 | | # define GNUTLS_LIB_AUTH_PSK_H |
25 | | |
26 | | # include <auth.h> |
27 | | # include <auth/dh_common.h> |
28 | | |
29 | | # define _gnutls_copy_psk_username(info, datum) \ |
30 | 0 | _gnutls_copy_psk_string(&(info)->username, &(info)->username_len, (datum)) |
31 | | |
32 | | # define _gnutls_copy_psk_hint(info, datum) \ |
33 | | _gnutls_copy_psk_string(&(info)->hint, &(info)->hint_len, (datum)) |
34 | | |
35 | | typedef struct gnutls_psk_client_credentials_st { |
36 | | gnutls_datum_t username; |
37 | | gnutls_datum_t key; |
38 | | gnutls_psk_client_credentials_function2 *get_function; |
39 | | gnutls_psk_client_credentials_function *get_function_legacy; |
40 | | /* TLS 1.3 - The HMAC algorithm to use to compute the binder values */ |
41 | | const mac_entry_st *binder_algo; |
42 | | } psk_client_credentials_st; |
43 | | |
44 | | typedef struct gnutls_psk_server_credentials_st { |
45 | | char *password_file; |
46 | | /* callback function, instead of reading the |
47 | | * password files. |
48 | | */ |
49 | | gnutls_psk_server_credentials_function2 *pwd_callback; |
50 | | gnutls_psk_server_credentials_function *pwd_callback_legacy; |
51 | | |
52 | | /* For DHE_PSK */ |
53 | | gnutls_dh_params_t dh_params; |
54 | | unsigned int deinit_dh_params; |
55 | | gnutls_sec_param_t dh_sec_param; |
56 | | /* this callback is used to retrieve the DH or RSA |
57 | | * parameters. |
58 | | */ |
59 | | gnutls_params_function *params_func; |
60 | | |
61 | | /* Identity hint. */ |
62 | | char *hint; |
63 | | /* TLS 1.3 - HMAC algorithm for the binder values */ |
64 | | const mac_entry_st *binder_algo; |
65 | | } psk_server_cred_st; |
66 | | |
67 | | typedef struct psk_auth_info_st { |
68 | | char *username; |
69 | | uint16_t username_len; |
70 | | dh_info_st dh; |
71 | | char *hint; |
72 | | uint16_t hint_len; |
73 | | } *psk_auth_info_t; |
74 | | |
75 | | typedef struct psk_auth_info_st psk_auth_info_st; |
76 | | |
77 | | inline static int |
78 | | _gnutls_copy_psk_string(char **dest, uint16_t * dest_len, |
79 | | const gnutls_datum_t str) |
80 | 0 | { |
81 | 0 | char *_tmp; |
82 | |
|
83 | 0 | assert(MAX_USERNAME_SIZE >= str.size); |
84 | | |
85 | 0 | _tmp = gnutls_malloc(str.size + 1); |
86 | 0 | if (_tmp == NULL) |
87 | 0 | return GNUTLS_E_MEMORY_ERROR; |
88 | 0 | memcpy(_tmp, str.data, str.size); |
89 | 0 | _tmp[str.size] = '\0'; |
90 | |
|
91 | 0 | gnutls_free(*dest); |
92 | 0 | *dest = _tmp; |
93 | 0 | *dest_len = str.size; |
94 | |
|
95 | 0 | return GNUTLS_E_SUCCESS; |
96 | 0 | } Unexecuted instantiation: key_share.c:_gnutls_copy_psk_string Unexecuted instantiation: pre_shared_key.c:_gnutls_copy_psk_string Unexecuted instantiation: psk_ke_modes.c:_gnutls_copy_psk_string Unexecuted instantiation: supported_groups.c:_gnutls_copy_psk_string |
97 | | |
98 | | # ifdef ENABLE_PSK |
99 | | |
100 | | int |
101 | | _gnutls_set_psk_session_key(gnutls_session_t session, gnutls_datum_t * key, |
102 | | gnutls_datum_t * psk2); |
103 | | int _gnutls_gen_psk_server_kx(gnutls_session_t session, |
104 | | gnutls_buffer_st * data); |
105 | | int _gnutls_gen_psk_client_kx(gnutls_session_t, gnutls_buffer_st *); |
106 | | |
107 | | # else |
108 | | # define _gnutls_set_psk_session_key(x,y,z) GNUTLS_E_UNIMPLEMENTED_FEATURE |
109 | | # endif /* ENABLE_PSK */ |
110 | | |
111 | | #endif /* GNUTLS_LIB_AUTH_PSK_H */ |