]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
handshake: parse new session ticket message
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 15 Sep 2017 11:54:25 +0000 (13:54 +0200)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Mon, 19 Feb 2018 14:29:34 +0000 (15:29 +0100)
That does not include extension handling.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
lib/Makefile.am
lib/handshake-tls13.c
lib/handshake.h
lib/record.c
lib/tls13/session_ticket.c [new file with mode: 0644]
lib/tls13/session_ticket.h [new file with mode: 0644]

index 54bb8690f0dbf9f9e3048d324c052b7a23c05769..fe5c9236af87aa85f9e7cf845f4443461ac7c44f 100644 (file)
@@ -92,6 +92,7 @@ COBJECTS += tls13/encrypted_extensions.c tls13/encrypted_extensions.h \
        tls13/certificate_verify.c tls13/certificate_verify.h \
        tls13-sig.c tls13-sig.h \
        tls13/finished.c tls13/finished.h \
+       tls13/session_ticket.c tls13/session_ticket.h \
        tls13/certificate.c tls13/certificate.h
 
 if ENABLE_PKCS11
index 456442e3e91ced54202092aa0f313518d780b5e8..4cce3d631d151b51c82e61918e6f453c1d5be30b 100644 (file)
@@ -52,6 +52,7 @@
 #include "tls13/certificate_verify.h"
 #include "tls13/certificate.h"
 #include "tls13/finished.h"
+#include "tls13/session_ticket.h"
 
 static int generate_hs_traffic_keys(gnutls_session_t session);
 static int generate_ap_traffic_keys(gnutls_session_t session);
@@ -256,3 +257,43 @@ int _gnutls13_handshake_server(gnutls_session_t session)
        return 0;
 }
 
+int
+_gnutls13_recv_async_handshake(gnutls_session_t session, gnutls_buffer_st *buf)
+{
+       uint8_t type;
+       int ret;
+       size_t handshake_header_size = HANDSHAKE_HEADER_SIZE(session);
+       size_t length;
+
+       if (buf->length < handshake_header_size) {
+               gnutls_assert();
+               return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
+       }
+
+       if (session->security_parameters.entity == GNUTLS_CLIENT) {
+               ret = _gnutls_buffer_pop_prefix8(buf, &type, 0);
+               if (ret < 0)
+                       return gnutls_assert_val(ret);
+
+               ret = _gnutls_buffer_pop_prefix24(buf, &length, 1);
+               if (ret < 0)
+                       return gnutls_assert_val(ret);
+
+               switch(type) {
+                       case GNUTLS_HANDSHAKE_NEW_SESSION_TICKET:
+                               ret = _gnutls13_recv_session_ticket(session, buf);
+                               if (ret < 0)
+                                       return gnutls_assert_val(ret);
+                               break;
+                       default:
+                               gnutls_assert();
+                               return GNUTLS_E_UNEXPECTED_PACKET;
+               }
+
+       } else {
+               gnutls_assert();
+               return GNUTLS_E_UNEXPECTED_PACKET;
+       }
+
+       return 0;
+}
index 90d82b8e9c750e10e05d9a49652fd5541f76c52d..0e63ee39b48a23f0969a295ca37652b38e0bd7d2 100644 (file)
@@ -123,4 +123,7 @@ int _gnutls_send_finished(gnutls_session_t session, int again);
 int _gnutls13_handshake_client(gnutls_session_t session);
 int _gnutls13_handshake_server(gnutls_session_t session);
 
+int
+_gnutls13_recv_async_handshake(gnutls_session_t session, gnutls_buffer_st *buf);
+
 #endif
index 5be4ba3094e3dc240320005dc5b394fcc99319fe..44585078f9ec7c0ff8e7bd1f08f4a50811c9d661 100644 (file)
@@ -756,6 +756,7 @@ record_add_to_buffers(gnutls_session_t session,
 {
 
        int ret;
+       const version_entry_st *ver = get_version(session);
 
        if ((recv->type == type)
            && (type == GNUTLS_APPLICATION_DATA ||
@@ -912,6 +913,22 @@ record_add_to_buffers(gnutls_session_t session,
                                }
                        }
 
+                       /* retrieve async handshake messages */
+                       if (ver->tls13_sem) {
+                               gnutls_buffer_st buf;
+
+                               _gnutls_ro_buffer_from_datum(&buf, &bufel->msg);
+                               ret = _gnutls13_recv_async_handshake(session,
+                                                                    &buf);
+                               if (ret < 0) {
+                                       gnutls_assert();
+                               } else {
+                                       ret = GNUTLS_E_AGAIN;
+                               }
+
+                               goto cleanup;
+                       }
+
                        /* This is legal if HELLO_REQUEST is received - and we are a client.
                         * If we are a server, a client may initiate a renegotiation at any time.
                         */
diff --git a/lib/tls13/session_ticket.c b/lib/tls13/session_ticket.c
new file mode 100644 (file)
index 0000000..3dbec92
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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/>
+ *
+ */
+
+#include "gnutls_int.h"
+#include "errors.h"
+#include "extv.h"
+#include "handshake.h"
+#include "tls13/session_ticket.h"
+#include "auth/cert.h"
+
+static int parse_nst_extension(void *ctx, uint16_t tls_id, const uint8_t *data, int data_size);
+
+int _gnutls13_recv_session_ticket(gnutls_session_t session, gnutls_buffer_st *buf)
+{
+       int ret;
+       size_t val;
+       gnutls_datum_t nonce;
+       gnutls_datum_t ticket;
+
+       _gnutls_handshake_log("HSK[%p]: parsing session ticket message\n", session);
+
+       /* ticket_lifetime */
+       ret = _gnutls_buffer_pop_prefix32(buf, &val, 0);
+       if (ret < 0) {
+               gnutls_assert();
+               goto cleanup;
+       }
+
+       /* ticket_age_add */
+       ret = _gnutls_buffer_pop_prefix32(buf, &val, 0);
+       if (ret < 0) {
+               gnutls_assert();
+               goto cleanup;
+       }
+
+       ret = _gnutls_buffer_pop_datum_prefix8(buf, &nonce);
+       if (ret < 0) {
+               gnutls_assert();
+               goto cleanup;
+       }
+
+       ret = _gnutls_buffer_pop_datum_prefix16(buf, &ticket);
+       if (ret < 0) {
+               gnutls_assert();
+               goto cleanup;
+       }
+
+       ret = _gnutls_extv_parse(NULL, parse_nst_extension, buf->data, buf->length);
+       if (ret < 0) {
+               gnutls_assert();
+               goto cleanup;
+       }
+
+       ret = 0;
+cleanup:
+
+       return ret;
+}
+
+static int parse_nst_extension(void *ctx, uint16_t tls_id, const uint8_t *data, int data_size)
+{
+       /* ignore all extensions */
+       return 0;
+}
diff --git a/lib/tls13/session_ticket.h b/lib/tls13/session_ticket.h
new file mode 100644 (file)
index 0000000..1c31589
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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/>
+ *
+ */
+
+int _gnutls13_recv_session_ticket(gnutls_session_t session, gnutls_buffer_st *buf);