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, |
33 | | gnutls_ext_raw_process_func cb, |
34 | | const uint8_t * data, int data_size); |
35 | | |
36 | | inline static |
37 | | int _gnutls_extv_append_init(gnutls_buffer_st * buf) |
38 | 0 | { |
39 | 0 | unsigned pos; |
40 | 0 | int ret; |
41 | |
|
42 | 0 | pos = buf->length; |
43 | |
|
44 | 0 | ret = _gnutls_buffer_append_prefix(buf, 16, 0); |
45 | 0 | if (ret < 0) |
46 | 0 | return gnutls_assert_val(ret); |
47 | | |
48 | 0 | return pos; |
49 | 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 |
50 | | |
51 | | /* its input is the buffer and the return value of _gnutls_extv_append_init() |
52 | | * @is_hello: should be true for client and server hello messages. |
53 | | */ |
54 | | inline static |
55 | | int _gnutls_extv_append_final(gnutls_buffer_st * buf, unsigned init, |
56 | | unsigned is_hello) |
57 | 0 | { |
58 | 0 | unsigned size = buf->length - init - 2; |
59 | |
|
60 | 0 | if (size > UINT16_MAX) /* sent too many extensions */ |
61 | 0 | return gnutls_assert_val(GNUTLS_E_HANDSHAKE_TOO_LARGE); |
62 | | |
63 | 0 | if (size > 0) |
64 | 0 | _gnutls_write_uint16(size, &buf->data[init]); |
65 | 0 | else if (is_hello && size == 0) { |
66 | | /* there is no point to send empty extension bytes, and |
67 | | * they are known to break certain clients */ |
68 | 0 | buf->length -= 2; |
69 | 0 | } |
70 | |
|
71 | 0 | return 0; |
72 | 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 |
73 | | |
74 | | typedef int (*extv_append_func)(void *ctx, gnutls_buffer_st * buf); |
75 | | |
76 | | int _gnutls_extv_append(gnutls_buffer_st * buf, |
77 | | uint16_t tls_id, void *ctx, extv_append_func cb); |
78 | | |
79 | | #endif /* GNUTLS_LIB_EXTV_H */ |