/src/gnutls/lib/ext/post_handshake.c
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 | | /* This file contains the code for the Post-Handshake TLS 1.3 extension. |
24 | | */ |
25 | | |
26 | | #include "gnutls_int.h" |
27 | | #include "errors.h" |
28 | | #include "num.h" |
29 | | #include "hello_ext.h" |
30 | | #include "ext/post_handshake.h" |
31 | | #include "auth/cert.h" |
32 | | |
33 | | static int _gnutls_post_handshake_recv_params(gnutls_session_t session, |
34 | | const uint8_t *data, |
35 | | size_t data_size); |
36 | | static int _gnutls_post_handshake_send_params(gnutls_session_t session, |
37 | | gnutls_buffer_st *extdata); |
38 | | |
39 | | const hello_ext_entry_st ext_mod_post_handshake = { |
40 | | .name = "Post Handshake Auth", |
41 | | .tls_id = 49, |
42 | | .gid = GNUTLS_EXTENSION_POST_HANDSHAKE, |
43 | | .client_parse_point = GNUTLS_EXT_TLS, |
44 | | .server_parse_point = GNUTLS_EXT_TLS, |
45 | | .validity = GNUTLS_EXT_FLAG_TLS | GNUTLS_EXT_FLAG_CLIENT_HELLO, |
46 | | .recv_func = _gnutls_post_handshake_recv_params, |
47 | | .send_func = _gnutls_post_handshake_send_params, |
48 | | .pack_func = NULL, |
49 | | .unpack_func = NULL, |
50 | | .deinit_func = NULL, |
51 | | .cannot_be_overriden = 1 |
52 | | }; |
53 | | |
54 | | static int _gnutls_post_handshake_recv_params(gnutls_session_t session, |
55 | | const uint8_t *data, |
56 | | size_t _data_size) |
57 | 0 | { |
58 | 0 | const version_entry_st *vers; |
59 | |
|
60 | 0 | if (session->security_parameters.entity == GNUTLS_SERVER) { |
61 | 0 | vers = get_version(session); |
62 | 0 | if (unlikely(vers == NULL)) |
63 | 0 | return 0; |
64 | | |
65 | 0 | if ((session->internals.flags & GNUTLS_POST_HANDSHAKE_AUTH) && |
66 | 0 | vers->post_handshake_auth) |
67 | 0 | session->security_parameters.post_handshake_auth = 1; |
68 | 0 | } |
69 | | |
70 | 0 | return 0; |
71 | 0 | } |
72 | | |
73 | | /* returns data_size or a negative number on failure |
74 | | */ |
75 | | static int _gnutls_post_handshake_send_params(gnutls_session_t session, |
76 | | gnutls_buffer_st *extdata) |
77 | 0 | { |
78 | 0 | gnutls_certificate_credentials_t cred; |
79 | 0 | const version_entry_st *max; |
80 | |
|
81 | 0 | if (session->security_parameters.entity != GNUTLS_CLIENT || |
82 | 0 | !(session->internals.flags & GNUTLS_POST_HANDSHAKE_AUTH)) { |
83 | | /* not sent on server side */ |
84 | 0 | return 0; |
85 | 0 | } |
86 | | |
87 | 0 | cred = (gnutls_certificate_credentials_t)_gnutls_get_cred( |
88 | 0 | session, GNUTLS_CRD_CERTIFICATE); |
89 | 0 | if (cred == NULL) /* no certificate authentication */ |
90 | 0 | return gnutls_assert_val(0); |
91 | | |
92 | 0 | max = _gnutls_version_max(session); |
93 | 0 | if (unlikely(max == NULL)) |
94 | 0 | return gnutls_assert_val(0); |
95 | | |
96 | 0 | if (max->post_handshake_auth) |
97 | 0 | return GNUTLS_E_INT_RET_0; |
98 | 0 | else |
99 | 0 | return 0; |
100 | 0 | } |