Blame SOURCES/gnutls-3.7.8-clear-session-ticket.patch

a74aed
diff --color -ruNp a/lib/ext/session_ticket.c b/lib/ext/session_ticket.c
a74aed
--- a/lib/ext/session_ticket.c	2022-05-10 13:55:00.000000000 +0200
a74aed
+++ b/lib/ext/session_ticket.c	2022-11-15 13:30:20.491830382 +0100
a74aed
@@ -624,6 +624,12 @@ gnutls_session_ticket_enable_server(gnut
a74aed
 	return 0;
a74aed
 }
a74aed
 
a74aed
+void
a74aed
+_gnutls_session_ticket_disable_server(gnutls_session_t session)
a74aed
+{
a74aed
+	session->internals.flags |= GNUTLS_NO_TICKETS;
a74aed
+}
a74aed
+
a74aed
 /*
a74aed
  * Return zero if session tickets haven't been enabled.
a74aed
  */
a74aed
diff --color -ruNp a/lib/ext/session_ticket.h b/lib/ext/session_ticket.h
a74aed
--- a/lib/ext/session_ticket.h	2022-02-22 15:34:48.000000000 +0100
a74aed
+++ b/lib/ext/session_ticket.h	2022-11-15 13:30:20.491830382 +0100
a74aed
@@ -36,5 +36,6 @@ int _gnutls_encrypt_session_ticket(gnutl
a74aed
 int _gnutls_decrypt_session_ticket(gnutls_session_t session,
a74aed
 				   const gnutls_datum_t *ticket_data,
a74aed
 				   gnutls_datum_t *state);
a74aed
+void _gnutls_session_ticket_disable_server(gnutls_session_t session);
a74aed
 
a74aed
 #endif /* GNUTLS_LIB_EXT_SESSION_TICKET_H */
a74aed
diff --color -ruNp a/lib/libgnutls.map b/lib/libgnutls.map
a74aed
--- a/lib/libgnutls.map	2022-11-15 13:12:57.781688194 +0100
a74aed
+++ b/lib/libgnutls.map	2022-11-15 13:30:20.492830401 +0100
a74aed
@@ -1510,4 +1510,6 @@ GNUTLS_PRIVATE_3_4 {
a74aed
 	_gnutls_buffer_clear;
a74aed
 	# needed by tests/cipher-alignment
a74aed
 	_gnutls_crypto_register_cipher;
a74aed
+	# needed by tests/tls12-rehandshake-cert-ticket
a74aed
+	_gnutls_session_ticket_disable_server;
a74aed
 } GNUTLS_3_4;
a74aed
diff --color -ruNp a/lib/state.c b/lib/state.c
a74aed
--- a/lib/state.c	2022-05-16 17:10:08.000000000 +0200
a74aed
+++ b/lib/state.c	2022-11-15 13:30:20.493830420 +0100
a74aed
@@ -545,6 +545,7 @@ void _gnutls_handshake_internal_state_cl
a74aed
 	session->internals.tfo.connect_addrlen = 0;
a74aed
 	session->internals.tfo.connect_only = 0;
a74aed
 	session->internals.early_data_received = 0;
a74aed
+	session->internals.session_ticket_renew = 0;
a74aed
 }
a74aed
 
a74aed
 /**
a74aed
diff --color -ruNp a/tests/Makefile.am b/tests/Makefile.am
a74aed
--- a/tests/Makefile.am	2022-11-15 13:12:58.209696462 +0100
a74aed
+++ b/tests/Makefile.am	2022-11-15 13:30:20.494830440 +0100
a74aed
@@ -234,7 +234,7 @@ ctests += mini-record-2 simple gnutls_hm
a74aed
 	 set_x509_ocsp_multi_cli kdf-api keylog-func handshake-write \
a74aed
 	 x509cert-dntypes id-on-xmppAddr tls13-compat-mode ciphersuite-name \
a74aed
 	 x509-upnconstraint xts-key-check pkcs7-verify-double-free \
a74aed
-	 fips-rsa-sizes
a74aed
+	 fips-rsa-sizes tls12-rehandshake-ticket
a74aed
 
a74aed
 ctests += tls-channel-binding
a74aed
 
a74aed
diff --color -ruNp a/tests/tls12-rehandshake-ticket.c b/tests/tls12-rehandshake-ticket.c
a74aed
--- a/tests/tls12-rehandshake-ticket.c	1970-01-01 01:00:00.000000000 +0100
a74aed
+++ b/tests/tls12-rehandshake-ticket.c	2022-11-15 13:30:20.495830459 +0100
a74aed
@@ -0,0 +1,152 @@
a74aed
+/*
a74aed
+ * Copyright (C) 2022 Red Hat, Inc.
a74aed
+ *
a74aed
+ * Author: Daiki Ueno
a74aed
+ *
a74aed
+ * This file is part of GnuTLS.
a74aed
+ *
a74aed
+ * GnuTLS is free software; you can redistribute it and/or modify it
a74aed
+ * under the terms of the GNU General Public License as published by
a74aed
+ * the Free Software Foundation; either version 3 of the License, or
a74aed
+ * (at your option) any later version.
a74aed
+ *
a74aed
+ * GnuTLS is distributed in the hope that it will be useful, but
a74aed
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
a74aed
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a74aed
+ * General Public License for more details.
a74aed
+ *
a74aed
+ * You should have received a copy of the GNU Lesser General Public License
a74aed
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>
a74aed
+ */
a74aed
+
a74aed
+#ifdef HAVE_CONFIG_H
a74aed
+#include <config.h>
a74aed
+#endif
a74aed
+
a74aed
+#include <gnutls/gnutls.h>
a74aed
+#include <assert.h>
a74aed
+#include "cert-common.h"
a74aed
+
a74aed
+#include "utils.h"
a74aed
+#include "eagain-common.h"
a74aed
+
a74aed
+const char *side = "";
a74aed
+
a74aed
+static void tls_log_func(int level, const char *str)
a74aed
+{
a74aed
+	fprintf(stderr, "%s|<%d>| %s", side, level, str);
a74aed
+}
a74aed
+
a74aed
+#define MAX_BUF 1024
a74aed
+
a74aed
+void _gnutls_session_ticket_disable_server(gnutls_session_t session);
a74aed
+
a74aed
+static void run(void)
a74aed
+{
a74aed
+	char buffer[MAX_BUF + 1];
a74aed
+	/* Server stuff. */
a74aed
+	gnutls_certificate_credentials_t scred;
a74aed
+	gnutls_session_t server;
a74aed
+	gnutls_datum_t session_ticket_key = { NULL, 0 };
a74aed
+	int sret;
a74aed
+	/* Client stuff. */
a74aed
+	gnutls_certificate_credentials_t ccred;
a74aed
+	gnutls_session_t client;
a74aed
+	int cret;
a74aed
+
a74aed
+	/* General init. */
a74aed
+	global_init();
a74aed
+	gnutls_global_set_log_function(tls_log_func);
a74aed
+	if (debug)
a74aed
+		gnutls_global_set_log_level(9);
a74aed
+
a74aed
+	/* Init server */
a74aed
+	assert(gnutls_certificate_allocate_credentials(&scred) >= 0);
a74aed
+	assert(gnutls_certificate_set_x509_key_mem(scred,
a74aed
+						   &server_ca3_localhost_cert,
a74aed
+						   &server_ca3_key,
a74aed
+						   GNUTLS_X509_FMT_PEM) >= 0);
a74aed
+	assert(gnutls_certificate_set_x509_trust_mem(scred,
a74aed
+						     &ca3_cert,
a74aed
+						     GNUTLS_X509_FMT_PEM) >= 0);
a74aed
+
a74aed
+	assert(gnutls_init(&server, GNUTLS_SERVER) >= 0);
a74aed
+	gnutls_certificate_server_set_request(server, GNUTLS_CERT_REQUEST);
a74aed
+	assert(gnutls_priority_set_direct(server,
a74aed
+					  "NORMAL:-VERS-TLS-ALL:+VERS-TLS1.1:+VERS-TLS1.2",
a74aed
+					  NULL) >= 0);
a74aed
+
a74aed
+	gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE, scred);
a74aed
+	gnutls_transport_set_push_function(server, server_push);
a74aed
+	gnutls_transport_set_pull_function(server, server_pull);
a74aed
+	gnutls_transport_set_ptr(server, server);
a74aed
+
a74aed
+	gnutls_session_ticket_key_generate(&session_ticket_key);
a74aed
+	gnutls_session_ticket_enable_server(server, &session_ticket_key);
a74aed
+
a74aed
+	/* Init client */
a74aed
+	assert(gnutls_certificate_allocate_credentials(&ccred) >= 0);
a74aed
+	assert(gnutls_certificate_set_x509_key_mem
a74aed
+	       (ccred, &cli_ca3_cert_chain, &cli_ca3_key, GNUTLS_X509_FMT_PEM) >= 0);
a74aed
+	assert(gnutls_certificate_set_x509_trust_mem
a74aed
+	       (ccred, &ca3_cert, GNUTLS_X509_FMT_PEM) >= 0);
a74aed
+
a74aed
+	gnutls_init(&client, GNUTLS_CLIENT);
a74aed
+	assert(gnutls_priority_set_direct(client,
a74aed
+					  "NORMAL:-VERS-TLS-ALL:+VERS-TLS1.1:+VERS-TLS1.2",
a74aed
+					  NULL) >= 0);
a74aed
+
a74aed
+	assert(gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE, ccred) >= 0);
a74aed
+
a74aed
+	gnutls_transport_set_push_function(client, client_push);
a74aed
+	gnutls_transport_set_pull_function(client, client_pull);
a74aed
+	gnutls_transport_set_ptr(client, client);
a74aed
+
a74aed
+	HANDSHAKE(client, server);
a74aed
+
a74aed
+	/* Server initiates rehandshake */
a74aed
+	switch_side("server");
a74aed
+	sret = gnutls_rehandshake(server);
a74aed
+	if (sret < 0) {
a74aed
+		fail("Error sending %d byte packet: %s\n",
a74aed
+		     (int)sizeof(buffer), gnutls_strerror(sret));
a74aed
+	} else if (debug)
a74aed
+		success("server: starting rehandshake\n");
a74aed
+
a74aed
+	/* Stop sending session ticket */
a74aed
+	_gnutls_session_ticket_disable_server(server);
a74aed
+
a74aed
+	/* Client gets notified with rehandshake */
a74aed
+	switch_side("client");
a74aed
+	do {
a74aed
+		do {
a74aed
+			cret = gnutls_record_recv(client, buffer, MAX_BUF);
a74aed
+		} while (cret == GNUTLS_E_AGAIN || cret == GNUTLS_E_INTERRUPTED);
a74aed
+	} while (cret > 0);
a74aed
+
a74aed
+	if (cret != GNUTLS_E_REHANDSHAKE) {
a74aed
+		fail("client: Error receiving rehandshake: %s\n",
a74aed
+		     gnutls_strerror(cret));
a74aed
+	}
a74aed
+
a74aed
+	HANDSHAKE(client, server);
a74aed
+
a74aed
+	gnutls_bye(client, GNUTLS_SHUT_WR);
a74aed
+	gnutls_bye(server, GNUTLS_SHUT_WR);
a74aed
+
a74aed
+	gnutls_deinit(client);
a74aed
+	gnutls_deinit(server);
a74aed
+
a74aed
+	gnutls_certificate_free_credentials(scred);
a74aed
+	gnutls_certificate_free_credentials(ccred);
a74aed
+
a74aed
+	gnutls_free(session_ticket_key.data);
a74aed
+
a74aed
+	gnutls_global_deinit();
a74aed
+	reset_buffers();
a74aed
+}
a74aed
+
a74aed
+void doit(void)
a74aed
+{
a74aed
+	run();
a74aed
+}