Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2017 Red Hat, 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_EXTV_H |
24 | | #define GNUTLS_LIB_EXTV_H |
25 | | |
26 | | #include <gnutls/gnutls.h> |
27 | | #include "str.h" |
28 | | |
29 | | /* Iterates through all TLS-type extensions in data, and |
30 | | * calls the callback function for each of them. The ctx, flags |
31 | | * and parse_type are passed verbatim to callback. */ |
32 | | int _gnutls_extv_parse(void *ctx, gnutls_ext_raw_process_func cb, |
33 | | const uint8_t *data, int data_size); |
34 | | |
35 | | inline static int _gnutls_extv_append_init(gnutls_buffer_st *buf) |
36 | 0 | { |
37 | 0 | unsigned pos; |
38 | 0 | int ret; |
39 | |
|
40 | 0 | pos = buf->length; |
41 | |
|
42 | 0 | ret = _gnutls_buffer_append_prefix(buf, 16, 0); |
43 | 0 | if (ret < 0) |
44 | 0 | return gnutls_assert_val(ret); |
45 | | |
46 | 0 | return pos; |
47 | 0 | } Unexecuted instantiation: hello_ext.c:_gnutls_extv_append_init Unexecuted instantiation: extv.c:_gnutls_extv_append_init Unexecuted instantiation: certificate_request.c:_gnutls_extv_append_init Unexecuted instantiation: session_ticket.c:_gnutls_extv_append_init Unexecuted instantiation: certificate.c:_gnutls_extv_append_init |
48 | | |
49 | | /* its input is the buffer and the return value of _gnutls_extv_append_init() |
50 | | * @is_hello: should be true for client and server hello messages. |
51 | | */ |
52 | | inline static int _gnutls_extv_append_final(gnutls_buffer_st *buf, |
53 | | unsigned init, unsigned is_hello) |
54 | 0 | { |
55 | 0 | unsigned size = buf->length - init - 2; |
56 | |
|
57 | 0 | if (size > UINT16_MAX) /* sent too many extensions */ |
58 | 0 | return gnutls_assert_val(GNUTLS_E_HANDSHAKE_TOO_LARGE); |
59 | | |
60 | 0 | if (size > 0) |
61 | 0 | _gnutls_write_uint16(size, &buf->data[init]); |
62 | 0 | else if (is_hello && size == 0) { |
63 | | /* there is no point to send empty extension bytes, and |
64 | | * they are known to break certain clients */ |
65 | 0 | buf->length -= 2; |
66 | 0 | } |
67 | |
|
68 | 0 | return 0; |
69 | 0 | } Unexecuted instantiation: hello_ext.c:_gnutls_extv_append_final Unexecuted instantiation: extv.c:_gnutls_extv_append_final Unexecuted instantiation: certificate_request.c:_gnutls_extv_append_final Unexecuted instantiation: session_ticket.c:_gnutls_extv_append_final Unexecuted instantiation: certificate.c:_gnutls_extv_append_final |
70 | | |
71 | | typedef int (*extv_append_func)(void *ctx, gnutls_buffer_st *buf); |
72 | | |
73 | | int _gnutls_extv_append(gnutls_buffer_st *buf, uint16_t tls_id, void *ctx, |
74 | | extv_append_func cb); |
75 | | |
76 | | #endif /* GNUTLS_LIB_EXTV_H */ |