Coverage Report

Created: 2025-03-18 06:55

/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, \
31
0
        (datum))
32
33
#define _gnutls_copy_psk_hint(info, datum) \
34
0
  _gnutls_copy_psk_string(&(info)->hint, &(info)->hint_len, (datum))
35
36
typedef struct gnutls_psk_client_credentials_st {
37
  gnutls_datum_t username;
38
  gnutls_datum_t key;
39
  gnutls_psk_client_credentials_function3 *get_function;
40
  gnutls_psk_client_credentials_function2 *get_function2;
41
  gnutls_psk_client_credentials_function *get_function1;
42
  /* TLS 1.3 - The HMAC algorithm to use to compute the binder values */
43
  const mac_entry_st *binder_algo;
44
} psk_client_credentials_st;
45
46
typedef struct gnutls_psk_server_credentials_st {
47
  char *password_file;
48
  /* callback functions, instead of reading the password files.
49
   */
50
  gnutls_psk_server_credentials_function3 *pwd_callback;
51
  gnutls_psk_server_credentials_function2 *pwd_callback2;
52
  gnutls_psk_server_credentials_function *pwd_callback1;
53
54
  /* For DHE_PSK */
55
  gnutls_dh_params_t dh_params;
56
  unsigned int deinit_dh_params;
57
  gnutls_sec_param_t dh_sec_param;
58
  /* this callback is used to retrieve the DH or RSA
59
   * parameters.
60
   */
61
  gnutls_params_function *params_func;
62
63
  /* Identity hint. */
64
  char *hint;
65
  /* TLS 1.3 - HMAC algorithm for the binder values */
66
  const mac_entry_st *binder_algo;
67
} psk_server_cred_st;
68
69
typedef struct psk_auth_info_st {
70
  char *username;
71
  uint16_t username_len;
72
  dh_info_st dh;
73
  char *hint;
74
  uint16_t hint_len;
75
} *psk_auth_info_t;
76
77
typedef struct psk_auth_info_st psk_auth_info_st;
78
79
inline static int _gnutls_copy_psk_string(char **dest, uint16_t *dest_len,
80
            const gnutls_datum_t str)
81
0
{
82
0
  char *_tmp;
83
84
0
  assert(MAX_USERNAME_SIZE >= str.size);
85
86
0
  _tmp = gnutls_malloc(str.size + 1);
87
0
  if (_tmp == NULL)
88
0
    return GNUTLS_E_MEMORY_ERROR;
89
0
  memcpy(_tmp, str.data, str.size);
90
0
  _tmp[str.size] = '\0';
91
92
0
  gnutls_free(*dest);
93
0
  *dest = _tmp;
94
0
  *dest_len = str.size;
95
96
0
  return GNUTLS_E_SUCCESS;
97
0
}
Unexecuted instantiation: handshake-tls13.c:_gnutls_copy_psk_string
Unexecuted instantiation: handshake.c:_gnutls_copy_psk_string
Unexecuted instantiation: hello_ext.c:_gnutls_copy_psk_string
Unexecuted instantiation: auth.c:_gnutls_copy_psk_string
Unexecuted instantiation: session_pack.c:_gnutls_copy_psk_string
Unexecuted instantiation: fingerprint.c:_gnutls_copy_psk_string
Unexecuted instantiation: state.c:_gnutls_copy_psk_string
Unexecuted instantiation: dh-session.c:_gnutls_copy_psk_string
Unexecuted instantiation: cert-session.c:_gnutls_copy_psk_string
Unexecuted instantiation: handshake-checks.c:_gnutls_copy_psk_string
Unexecuted instantiation: session_ticket.c:_gnutls_copy_psk_string
Unexecuted instantiation: psk.c:_gnutls_copy_psk_string
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
Unexecuted instantiation: dh_common.c:_gnutls_copy_psk_string
Unexecuted instantiation: psk_passwd.c:_gnutls_copy_psk_string
Unexecuted instantiation: ciphersuites.c:_gnutls_copy_psk_string
Unexecuted instantiation: dhe_psk.c:_gnutls_copy_psk_string
Unexecuted instantiation: ecdhe.c:_gnutls_copy_psk_string
Unexecuted instantiation: rsa_psk.c:_gnutls_copy_psk_string
98
99
#ifdef ENABLE_PSK
100
101
int _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, gnutls_buffer_st *data);
104
int _gnutls_gen_psk_client_kx(gnutls_session_t, gnutls_buffer_st *);
105
106
#else
107
#define _gnutls_set_psk_session_key(x, y, z) GNUTLS_E_UNIMPLEMENTED_FEATURE
108
#endif /* ENABLE_PSK */
109
110
#endif /* GNUTLS_LIB_AUTH_PSK_H */