summaryrefslogtreecommitdiff
path: root/lib/ext/post_handshake.c
blob: fa1e870fde6036173d3da1fc8f8ea94a557eea4d (plain)
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
/*
 * Copyright (C) 2017 Red Hat, 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/>
 *
 */

/* This file contains the code for the Post-Handshake TLS 1.3 extension.
 */

#include "gnutls_int.h"
#include "errors.h"
#include "num.h"
#include <hello_ext.h>
#include <ext/post_handshake.h>
#include "auth/cert.h"

static int _gnutls_post_handshake_recv_params(gnutls_session_t session,
					  const uint8_t * data,
					  size_t data_size);
static int _gnutls_post_handshake_send_params(gnutls_session_t session,
					  gnutls_buffer_st * extdata);

const hello_ext_entry_st ext_mod_post_handshake = {
	.name = "Post Handshake Auth",
	.tls_id = 49,
	.gid = GNUTLS_EXTENSION_POST_HANDSHAKE,
	.parse_type = GNUTLS_EXT_TLS,
	.validity = GNUTLS_EXT_FLAG_CLIENT_HELLO,

	.recv_func = _gnutls_post_handshake_recv_params,
	.send_func = _gnutls_post_handshake_send_params,
	.pack_func = NULL,
	.unpack_func = NULL,
	.deinit_func = NULL,
	.cannot_be_overriden = 1
};

static int
_gnutls_post_handshake_recv_params(gnutls_session_t session,
			       const uint8_t * data, size_t _data_size)
{
	const version_entry_st *vers;

	if (session->security_parameters.entity == GNUTLS_SERVER) {
		vers = get_version(session);
		if (unlikely(vers == NULL))
			return 0;

		if (vers->post_handshake_auth)
			session->security_parameters.post_handshake_auth = 1;
	}

	return 0;
}

/* returns data_size or a negative number on failure
 */
static int
_gnutls_post_handshake_send_params(gnutls_session_t session,
			       gnutls_buffer_st * extdata)
{
	/* we don't support post-handshake authentication yet */
	return 0;
#if 0

	gnutls_certificate_credentials_t cred;
	const version_entry_st *max;

	if (session->security_parameters.entity != GNUTLS_CLIENT) {
		/* not sent on server side */
		return 0;
	}

	cred = (gnutls_certificate_credentials_t)
	    _gnutls_get_cred(session, GNUTLS_CRD_CERTIFICATE);
	if (cred == NULL)	/* no certificate authentication */
		return gnutls_assert_val(0);

	max = _gnutls_version_max(session);
	if (unlikely(max == NULL))
		return gnutls_assert_val(0);

	if (max->post_handshake_auth && (cred->ncerts || cred->get_cert_callback2 || cred->get_cert_callback))
		return GNUTLS_E_INT_RET_0;
	else
		return 0;
#endif
}