1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
* Copyright (C) 2000-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_EXTENSIONS_H
#define GNUTLS_EXTENSIONS_H
#include <gnutls/gnutls.h>
/* Session and generic TLS extensions handling functions */
int _gnutls_ext_init(void);
void _gnutls_ext_deinit(void);
void _gnutls_extension_list_add_sr(gnutls_session_t session);
void _gnutls_ext_free_session_data(gnutls_session_t session);
/* functions to be used by extensions internally
*/
void _gnutls_ext_unset_session_data(gnutls_session_t session, uint16_t id);
void _gnutls_ext_set_session_data(gnutls_session_t session, uint16_t type,
gnutls_ext_priv_data_t);
int _gnutls_ext_get_session_data(gnutls_session_t session, uint16_t type,
gnutls_ext_priv_data_t *);
int _gnutls_ext_get_resumed_session_data(gnutls_session_t session,
uint16_t type,
gnutls_ext_priv_data_t * data);
/* obtain the message this extension was received at */
inline static gnutls_ext_flags_t _gnutls_ext_get_msg(gnutls_session_t session)
{
return session->internals.ext_msg;
}
inline static void _gnutls_ext_set_msg(gnutls_session_t session, gnutls_ext_flags_t msg)
{
session->internals.ext_msg = msg;
}
/* for session packing */
int _gnutls_ext_pack(gnutls_session_t session, gnutls_buffer_st * packed);
int _gnutls_ext_unpack(gnutls_session_t session,
gnutls_buffer_st * packed);
inline static const char *ext_msg_validity_to_str(gnutls_ext_flags_t msg)
{
switch(msg) {
case GNUTLS_EXT_FLAG_CLIENT_HELLO:
return "client hello";
case GNUTLS_EXT_FLAG_TLS12_SERVER_HELLO:
return "TLS 1.2 server hello";
case GNUTLS_EXT_FLAG_TLS13_SERVER_HELLO:
return "TLS 1.3 server hello";
case GNUTLS_EXT_FLAG_EE:
return "encrypted extensions";
case GNUTLS_EXT_FLAG_CT:
return "certificate";
case GNUTLS_EXT_FLAG_CR:
return "certificate request";
case GNUTLS_EXT_FLAG_NST:
return "new session ticket";
case GNUTLS_EXT_FLAG_HRR:
return "hello retry request";
default:
return "(unknown)";
}
}
typedef struct extension_entry_st {
const char *name; /* const overriden when free_struct is set */
unsigned free_struct;
uint16_t id;
gnutls_ext_parse_type_t parse_type;
unsigned validity; /* multiple items of gnutls_ext_flags_t */
/* this function must return 0 when Not Applicable
* size of extension data if ok
* < 0 on other error.
*/
gnutls_ext_recv_func recv_func;
/* this function must return 0 when Not Applicable
* size of extension data if ok
* GNUTLS_E_INT_RET_0 if extension data size is zero
* < 0 on other error.
*/
gnutls_ext_send_func send_func;
gnutls_ext_deinit_data_func deinit_func; /* this will be called to deinitialize
* internal data
*/
gnutls_ext_pack_func pack_func; /* packs internal data to machine independent format */
gnutls_ext_unpack_func unpack_func; /* unpacks internal data */
/* non-zero if that extension cannot be overriden by the applications.
* That should be set to extensions which allocate data early, e.g., on
* gnutls_init(), or modify the TLS protocol in a way that the application
* cannot control. */
unsigned cannot_be_overriden;
} extension_entry_st;
int _gnutls_ext_register(extension_entry_st *);
const extension_entry_st *
_gnutls_ext_ptr(tls_ext_vals_st *v, uint16_t id, gnutls_ext_parse_type_t parse_type);
extern extension_entry_st const *_gnutls_extfunc[];
#endif
|