blob: 76c024c81b7f85aaa6ebd225c5436bcc95fd2bd5 [file]
/*
* Copyright (C) 2026 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
* You can also choose to distribute this program under the terms of
* the Unmodified Binary Distribution Licence (as given in the file
* COPYING.UBDL), provided that you have satisfied its requirements.
*/
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
* TLS data format tests
*
*/
/* Forcibly enable assertions */
#undef NDEBUG
#include <string.h>
#include <byteswap.h>
#include <ipxe/tls.h>
#include <ipxe/tlsfmt.h>
#include <ipxe/test.h>
/** Known valid TLSv1.3 ServerHello (from RFC 8448) */
static uint8_t tls13_server_hello[] = {
0x03, 0x03, 0xa6, 0xaf, 0x06, 0xa4, 0x12, 0x18, 0x60, 0xdc, 0x5e,
0x6e, 0x60, 0x24, 0x9c, 0xd3, 0x4c, 0x95, 0x93, 0x0c, 0x8a, 0xc5,
0xcb, 0x14, 0x34, 0xda, 0xc1, 0x55, 0x77, 0x2e, 0xd3, 0xe2, 0x69,
0x28, 0x00, 0x13, 0x01, 0x00, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x24,
0x00, 0x1d, 0x00, 0x20, 0xc9, 0x82, 0x88, 0x76, 0x11, 0x20, 0x95,
0xfe, 0x66, 0x76, 0x2b, 0xdb, 0xf7, 0xc6, 0x72, 0xe1, 0x56, 0xd6,
0xcc, 0x25, 0x3b, 0x83, 0x3d, 0xf1, 0xdd, 0x69, 0xb1, 0xb0, 0x4e,
0x75, 0x1f, 0x0f, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04
};
/** TLSv1.3 ServerHello random bytes */
static uint8_t tls13_server_hello_random[] = {
0xa6, 0xaf, 0x06, 0xa4, 0x12, 0x18, 0x60, 0xdc, 0x5e, 0x6e, 0x60,
0x24, 0x9c, 0xd3, 0x4c, 0x95, 0x93, 0x0c, 0x8a, 0xc5, 0xcb, 0x14,
0x34, 0xda, 0xc1, 0x55, 0x77, 0x2e, 0xd3, 0xe2, 0x69, 0x28
};
/** TLSv1.3 ServerHello public key */
static uint8_t tls13_server_hello_public[] = {
0xc9, 0x82, 0x88, 0x76, 0x11, 0x20, 0x95, 0xfe, 0x66, 0x76, 0x2b,
0xdb, 0xf7, 0xc6, 0x72, 0xe1, 0x56, 0xd6, 0xcc, 0x25, 0x3b, 0x83,
0x3d, 0xf1, 0xdd, 0x69, 0xb1, 0xb0, 0x4e, 0x75, 0x1f, 0x0f
};
/** Known valid TLSv1.3 Certificate (from RFC 8448) */
static uint8_t tls13_certificate[] = {
0x00, 0x00, 0x01, 0xb5, 0x00, 0x01, 0xb0, 0x30, 0x82, 0x01, 0xac,
0x30, 0x82, 0x01, 0x15, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01,
0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0e, 0x31, 0x0c, 0x30, 0x0a,
0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x03, 0x72, 0x73, 0x61, 0x30,
0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x37, 0x33, 0x30, 0x30, 0x31,
0x32, 0x33, 0x35, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x37,
0x33, 0x30, 0x30, 0x31, 0x32, 0x33, 0x35, 0x39, 0x5a, 0x30, 0x0e,
0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x03,
0x72, 0x73, 0x61, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a,
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03,
0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xb4,
0xbb, 0x49, 0x8f, 0x82, 0x79, 0x30, 0x3d, 0x98, 0x08, 0x36, 0x39,
0x9b, 0x36, 0xc6, 0x98, 0x8c, 0x0c, 0x68, 0xde, 0x55, 0xe1, 0xbd,
0xb8, 0x26, 0xd3, 0x90, 0x1a, 0x24, 0x61, 0xea, 0xfd, 0x2d, 0xe4,
0x9a, 0x91, 0xd0, 0x15, 0xab, 0xbc, 0x9a, 0x95, 0x13, 0x7a, 0xce,
0x6c, 0x1a, 0xf1, 0x9e, 0xaa, 0x6a, 0xf9, 0x8c, 0x7c, 0xed, 0x43,
0x12, 0x09, 0x98, 0xe1, 0x87, 0xa8, 0x0e, 0xe0, 0xcc, 0xb0, 0x52,
0x4b, 0x1b, 0x01, 0x8c, 0x3e, 0x0b, 0x63, 0x26, 0x4d, 0x44, 0x9a,
0x6d, 0x38, 0xe2, 0x2a, 0x5f, 0xda, 0x43, 0x08, 0x46, 0x74, 0x80,
0x30, 0x53, 0x0e, 0xf0, 0x46, 0x1c, 0x8c, 0xa9, 0xd9, 0xef, 0xbf,
0xae, 0x8e, 0xa6, 0xd1, 0xd0, 0x3e, 0x2b, 0xd1, 0x93, 0xef, 0xf0,
0xab, 0x9a, 0x80, 0x02, 0xc4, 0x74, 0x28, 0xa6, 0xd3, 0x5a, 0x8d,
0x88, 0xd7, 0x9f, 0x7f, 0x1e, 0x3f, 0x02, 0x03, 0x01, 0x00, 0x01,
0xa3, 0x1a, 0x30, 0x18, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13,
0x04, 0x02, 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f,
0x04, 0x04, 0x03, 0x02, 0x05, 0xa0, 0x30, 0x0d, 0x06, 0x09, 0x2a,
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
0x81, 0x81, 0x00, 0x85, 0xaa, 0xd2, 0xa0, 0xe5, 0xb9, 0x27, 0x6b,
0x90, 0x8c, 0x65, 0xf7, 0x3a, 0x72, 0x67, 0x17, 0x06, 0x18, 0xa5,
0x4c, 0x5f, 0x8a, 0x7b, 0x33, 0x7d, 0x2d, 0xf7, 0xa5, 0x94, 0x36,
0x54, 0x17, 0xf2, 0xea, 0xe8, 0xf8, 0xa5, 0x8c, 0x8f, 0x81, 0x72,
0xf9, 0x31, 0x9c, 0xf3, 0x6b, 0x7f, 0xd6, 0xc5, 0x5b, 0x80, 0xf2,
0x1a, 0x03, 0x01, 0x51, 0x56, 0x72, 0x60, 0x96, 0xfd, 0x33, 0x5e,
0x5e, 0x67, 0xf2, 0xdb, 0xf1, 0x02, 0x70, 0x2e, 0x60, 0x8c, 0xca,
0xe6, 0xbe, 0xc1, 0xfc, 0x63, 0xa4, 0x2a, 0x99, 0xbe, 0x5c, 0x3e,
0xb7, 0x10, 0x7c, 0x3c, 0x54, 0xe9, 0xb9, 0xeb, 0x2b, 0xd5, 0x20,
0x3b, 0x1c, 0x3b, 0x84, 0xe0, 0xa8, 0xb2, 0xf7, 0x59, 0x40, 0x9b,
0xa3, 0xea, 0xc9, 0xd9, 0x1d, 0x40, 0x2d, 0xcc, 0x0c, 0xc8, 0xf8,
0x96, 0x12, 0x29, 0xac, 0x91, 0x87, 0xb4, 0x2b, 0x4d, 0xe1, 0x00,
0x00
};
/** TLSv1.2 Certificate (derived from RFC 8448) */
static uint8_t tls12_certificate[] = {
0x00, 0x01, 0xb3, 0x00, 0x01, 0xb0, 0x30, 0x82, 0x01, 0xac, 0x30,
0x82, 0x01, 0x15, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x02,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
0x01, 0x0b, 0x05, 0x00, 0x30, 0x0e, 0x31, 0x0c, 0x30, 0x0a, 0x06,
0x03, 0x55, 0x04, 0x03, 0x13, 0x03, 0x72, 0x73, 0x61, 0x30, 0x1e,
0x17, 0x0d, 0x31, 0x36, 0x30, 0x37, 0x33, 0x30, 0x30, 0x31, 0x32,
0x33, 0x35, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x37, 0x33,
0x30, 0x30, 0x31, 0x32, 0x33, 0x35, 0x39, 0x5a, 0x30, 0x0e, 0x31,
0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x03, 0x72,
0x73, 0x61, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81,
0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xb4, 0xbb,
0x49, 0x8f, 0x82, 0x79, 0x30, 0x3d, 0x98, 0x08, 0x36, 0x39, 0x9b,
0x36, 0xc6, 0x98, 0x8c, 0x0c, 0x68, 0xde, 0x55, 0xe1, 0xbd, 0xb8,
0x26, 0xd3, 0x90, 0x1a, 0x24, 0x61, 0xea, 0xfd, 0x2d, 0xe4, 0x9a,
0x91, 0xd0, 0x15, 0xab, 0xbc, 0x9a, 0x95, 0x13, 0x7a, 0xce, 0x6c,
0x1a, 0xf1, 0x9e, 0xaa, 0x6a, 0xf9, 0x8c, 0x7c, 0xed, 0x43, 0x12,
0x09, 0x98, 0xe1, 0x87, 0xa8, 0x0e, 0xe0, 0xcc, 0xb0, 0x52, 0x4b,
0x1b, 0x01, 0x8c, 0x3e, 0x0b, 0x63, 0x26, 0x4d, 0x44, 0x9a, 0x6d,
0x38, 0xe2, 0x2a, 0x5f, 0xda, 0x43, 0x08, 0x46, 0x74, 0x80, 0x30,
0x53, 0x0e, 0xf0, 0x46, 0x1c, 0x8c, 0xa9, 0xd9, 0xef, 0xbf, 0xae,
0x8e, 0xa6, 0xd1, 0xd0, 0x3e, 0x2b, 0xd1, 0x93, 0xef, 0xf0, 0xab,
0x9a, 0x80, 0x02, 0xc4, 0x74, 0x28, 0xa6, 0xd3, 0x5a, 0x8d, 0x88,
0xd7, 0x9f, 0x7f, 0x1e, 0x3f, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3,
0x1a, 0x30, 0x18, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04,
0x02, 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04,
0x04, 0x03, 0x02, 0x05, 0xa0, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x81,
0x81, 0x00, 0x85, 0xaa, 0xd2, 0xa0, 0xe5, 0xb9, 0x27, 0x6b, 0x90,
0x8c, 0x65, 0xf7, 0x3a, 0x72, 0x67, 0x17, 0x06, 0x18, 0xa5, 0x4c,
0x5f, 0x8a, 0x7b, 0x33, 0x7d, 0x2d, 0xf7, 0xa5, 0x94, 0x36, 0x54,
0x17, 0xf2, 0xea, 0xe8, 0xf8, 0xa5, 0x8c, 0x8f, 0x81, 0x72, 0xf9,
0x31, 0x9c, 0xf3, 0x6b, 0x7f, 0xd6, 0xc5, 0x5b, 0x80, 0xf2, 0x1a,
0x03, 0x01, 0x51, 0x56, 0x72, 0x60, 0x96, 0xfd, 0x33, 0x5e, 0x5e,
0x67, 0xf2, 0xdb, 0xf1, 0x02, 0x70, 0x2e, 0x60, 0x8c, 0xca, 0xe6,
0xbe, 0xc1, 0xfc, 0x63, 0xa4, 0x2a, 0x99, 0xbe, 0x5c, 0x3e, 0xb7,
0x10, 0x7c, 0x3c, 0x54, 0xe9, 0xb9, 0xeb, 0x2b, 0xd5, 0x20, 0x3b,
0x1c, 0x3b, 0x84, 0xe0, 0xa8, 0xb2, 0xf7, 0x59, 0x40, 0x9b, 0xa3,
0xea, 0xc9, 0xd9, 0x1d, 0x40, 0x2d, 0xcc, 0x0c, 0xc8, 0xf8, 0x96,
0x12, 0x29, 0xac, 0x91, 0x87, 0xb4, 0x2b, 0x4d, 0xe1
};
/** TLSv1.1 ServerHello with no extensions */
static uint8_t tls11_server_hello[] = {
0x03, 0x02, 0x1d, 0xd2, 0xbc, 0xd6, 0xce, 0xb4, 0x4b, 0x7c, 0x86,
0xd1, 0xac, 0x69, 0xef, 0x72, 0xf0, 0x97, 0xf7, 0xba, 0x9a, 0x84,
0x8d, 0x7c, 0x43, 0xf0, 0x9b, 0xea, 0x2a, 0xc0, 0x2b, 0xe6, 0xc2,
0xca, 0x00, 0x00, 0x2f, 0x00
};
/** TLSv1.2 ServerKeyExchange with explicit signature hash algorithm */
static uint8_t tls12_server_key_exchange_ecdhe[] = {
0x03, 0x00, 0x1d, 0x20, 0x79, 0xc4, 0x99, 0x60, 0xa2, 0x38, 0xa5,
0x11, 0xe1, 0xd1, 0x88, 0x30, 0x17, 0xb0, 0xbe, 0xef, 0xd3, 0x93,
0x71, 0x1e, 0xc4, 0x76, 0x70, 0x5a, 0xd5, 0x24, 0x94, 0xdb, 0x6a,
0xfa, 0x1c, 0x74, 0x02, 0x01, 0x01, 0x00, 0x4a, 0x8e, 0x81, 0x8b,
0x7f, 0x7c, 0xe0, 0x0f, 0x71, 0xe6, 0xcf, 0x24, 0xce, 0x99, 0xb4,
0x18, 0xf1, 0xb0, 0x68, 0x8b, 0xbf, 0x18, 0xe9, 0xed, 0xf5, 0xb4,
0x61, 0x4a, 0x89, 0x57, 0xa2, 0x30, 0xe8, 0x67, 0xdd, 0x70, 0x85,
0x60, 0xc8, 0x16, 0x4e, 0x6b, 0x0e, 0x7f, 0x8d, 0xa3, 0x5b, 0xd8,
0xbc, 0x2b, 0xc7, 0x81, 0xf2, 0x5f, 0xda, 0xed, 0x25, 0x60, 0x7b,
0x01, 0x8d, 0xaf, 0xad, 0x6b, 0x7e, 0x89, 0x2e, 0x4b, 0x14, 0xa0,
0x17, 0xa9, 0x53, 0xd9, 0x1f, 0xd2, 0x82, 0x88, 0x9c, 0xd9, 0x2e,
0x6e, 0x30, 0x78, 0x07, 0xf1, 0x9f, 0x53, 0x1f, 0xc8, 0xec, 0x2d,
0xf2, 0xf7, 0xdc, 0x19, 0x2b, 0x36, 0xbc, 0xf6, 0xec, 0x73, 0x9a,
0x43, 0xf1, 0x44, 0xa2, 0x9d, 0x80, 0xd5, 0xee, 0x18, 0xf5, 0x76,
0xcd, 0x81, 0xfd, 0x66, 0xb0, 0xf0, 0xa5, 0x23, 0x35, 0x42, 0x4b,
0xc2, 0x36, 0xbc, 0x9f, 0x55, 0x33, 0x0f, 0x64, 0x97, 0xda, 0x67,
0x25, 0xcb, 0x2c, 0xae, 0x78, 0xab, 0xd0, 0xa2, 0xd4, 0xf8, 0xde,
0x88, 0x44, 0x5a, 0x6a, 0x46, 0x1d, 0x69, 0x98, 0x2f, 0x2e, 0xe7,
0xd2, 0xde, 0x87, 0x0b, 0x25, 0xe3, 0x2c, 0xc1, 0x8f, 0xb6, 0xec,
0xf1, 0xb3, 0xba, 0xdc, 0xd7, 0x17, 0xf8, 0xbc, 0x40, 0x8f, 0xa5,
0x76, 0x3a, 0x40, 0xe6, 0x4c, 0x6d, 0x84, 0x76, 0x88, 0xf8, 0x37,
0xf4, 0x53, 0x14, 0xf6, 0x9c, 0x59, 0x39, 0x5f, 0x9b, 0x02, 0xea,
0x22, 0xbf, 0xa3, 0xb2, 0xde, 0x06, 0xc5, 0xba, 0x01, 0xd8, 0x15,
0xdc, 0x02, 0x8c, 0xdb, 0xa5, 0x56, 0x85, 0xa7, 0xbd, 0x8b, 0x9a,
0xdf, 0x8e, 0xbd, 0x7b, 0xac, 0xe4, 0xf3, 0x5a, 0xc4, 0x52, 0xd6,
0xba, 0x32, 0xca, 0xdc, 0x9f, 0x71, 0x0e, 0x00, 0xc9, 0xb0, 0x9a,
0x6e, 0xc6, 0xe3, 0x20, 0xb2, 0x9b, 0xe5, 0x02, 0x07, 0x2e
};
/** TLSv1.1 ServerKeyExchange with implicit signature hash algorithm */
static uint8_t tls11_server_key_exchange_ecdhe[] = {
0x03, 0x00, 0x1d, 0x20, 0x79, 0xc4, 0x99, 0x60, 0xa2, 0x38, 0xa5,
0x11, 0xe1, 0xd1, 0x88, 0x30, 0x17, 0xb0, 0xbe, 0xef, 0xd3, 0x93,
0x71, 0x1e, 0xc4, 0x76, 0x70, 0x5a, 0xd5, 0x24, 0x94, 0xdb, 0x6a,
0xfa, 0x1c, 0x74, 0x01, 0x00, 0x4a, 0x8e, 0x81, 0x8b, 0x7f, 0x7c,
0xe0, 0x0f, 0x71, 0xe6, 0xcf, 0x24, 0xce, 0x99, 0xb4, 0x18, 0xf1,
0xb0, 0x68, 0x8b, 0xbf, 0x18, 0xe9, 0xed, 0xf5, 0xb4, 0x61, 0x4a,
0x89, 0x57, 0xa2, 0x30, 0xe8, 0x67, 0xdd, 0x70, 0x85, 0x60, 0xc8,
0x16, 0x4e, 0x6b, 0x0e, 0x7f, 0x8d, 0xa3, 0x5b, 0xd8, 0xbc, 0x2b,
0xc7, 0x81, 0xf2, 0x5f, 0xda, 0xed, 0x25, 0x60, 0x7b, 0x01, 0x8d,
0xaf, 0xad, 0x6b, 0x7e, 0x89, 0x2e, 0x4b, 0x14, 0xa0, 0x17, 0xa9,
0x53, 0xd9, 0x1f, 0xd2, 0x82, 0x88, 0x9c, 0xd9, 0x2e, 0x6e, 0x30,
0x78, 0x07, 0xf1, 0x9f, 0x53, 0x1f, 0xc8, 0xec, 0x2d, 0xf2, 0xf7,
0xdc, 0x19, 0x2b, 0x36, 0xbc, 0xf6, 0xec, 0x73, 0x9a, 0x43, 0xf1,
0x44, 0xa2, 0x9d, 0x80, 0xd5, 0xee, 0x18, 0xf5, 0x76, 0xcd, 0x81,
0xfd, 0x66, 0xb0, 0xf0, 0xa5, 0x23, 0x35, 0x42, 0x4b, 0xc2, 0x36,
0xbc, 0x9f, 0x55, 0x33, 0x0f, 0x64, 0x97, 0xda, 0x67, 0x25, 0xcb,
0x2c, 0xae, 0x78, 0xab, 0xd0, 0xa2, 0xd4, 0xf8, 0xde, 0x88, 0x44,
0x5a, 0x6a, 0x46, 0x1d, 0x69, 0x98, 0x2f, 0x2e, 0xe7, 0xd2, 0xde,
0x87, 0x0b, 0x25, 0xe3, 0x2c, 0xc1, 0x8f, 0xb6, 0xec, 0xf1, 0xb3,
0xba, 0xdc, 0xd7, 0x17, 0xf8, 0xbc, 0x40, 0x8f, 0xa5, 0x76, 0x3a,
0x40, 0xe6, 0x4c, 0x6d, 0x84, 0x76, 0x88, 0xf8, 0x37, 0xf4, 0x53,
0x14, 0xf6, 0x9c, 0x59, 0x39, 0x5f, 0x9b, 0x02, 0xea, 0x22, 0xbf,
0xa3, 0xb2, 0xde, 0x06, 0xc5, 0xba, 0x01, 0xd8, 0x15, 0xdc, 0x02,
0x8c, 0xdb, 0xa5, 0x56, 0x85, 0xa7, 0xbd, 0x8b, 0x9a, 0xdf, 0x8e,
0xbd, 0x7b, 0xac, 0xe4, 0xf3, 0x5a, 0xc4, 0x52, 0xd6, 0xba, 0x32,
0xca, 0xdc, 0x9f, 0x71, 0x0e, 0x00, 0xc9, 0xb0, 0x9a, 0x6e, 0xc6,
0xe3, 0x20, 0xb2, 0x9b, 0xe5, 0x02, 0x07, 0x2e
};
/** ServerKeyExchange public curve point */
static uint8_t server_key_exchange_point[] = {
0x79, 0xc4, 0x99, 0x60, 0xa2, 0x38, 0xa5, 0x11, 0xe1, 0xd1, 0x88,
0x30, 0x17, 0xb0, 0xbe, 0xef, 0xd3, 0x93, 0x71, 0x1e, 0xc4, 0x76,
0x70, 0x5a, 0xd5, 0x24, 0x94, 0xdb, 0x6a, 0xfa, 0x1c, 0x74
};
/** ServerKeyExchange signature */
static uint8_t server_key_exchange_sig[] = {
0x4a, 0x8e, 0x81, 0x8b, 0x7f, 0x7c, 0xe0, 0x0f, 0x71, 0xe6, 0xcf,
0x24, 0xce, 0x99, 0xb4, 0x18, 0xf1, 0xb0, 0x68, 0x8b, 0xbf, 0x18,
0xe9, 0xed, 0xf5, 0xb4, 0x61, 0x4a, 0x89, 0x57, 0xa2, 0x30, 0xe8,
0x67, 0xdd, 0x70, 0x85, 0x60, 0xc8, 0x16, 0x4e, 0x6b, 0x0e, 0x7f,
0x8d, 0xa3, 0x5b, 0xd8, 0xbc, 0x2b, 0xc7, 0x81, 0xf2, 0x5f, 0xda,
0xed, 0x25, 0x60, 0x7b, 0x01, 0x8d, 0xaf, 0xad, 0x6b, 0x7e, 0x89,
0x2e, 0x4b, 0x14, 0xa0, 0x17, 0xa9, 0x53, 0xd9, 0x1f, 0xd2, 0x82,
0x88, 0x9c, 0xd9, 0x2e, 0x6e, 0x30, 0x78, 0x07, 0xf1, 0x9f, 0x53,
0x1f, 0xc8, 0xec, 0x2d, 0xf2, 0xf7, 0xdc, 0x19, 0x2b, 0x36, 0xbc,
0xf6, 0xec, 0x73, 0x9a, 0x43, 0xf1, 0x44, 0xa2, 0x9d, 0x80, 0xd5,
0xee, 0x18, 0xf5, 0x76, 0xcd, 0x81, 0xfd, 0x66, 0xb0, 0xf0, 0xa5,
0x23, 0x35, 0x42, 0x4b, 0xc2, 0x36, 0xbc, 0x9f, 0x55, 0x33, 0x0f,
0x64, 0x97, 0xda, 0x67, 0x25, 0xcb, 0x2c, 0xae, 0x78, 0xab, 0xd0,
0xa2, 0xd4, 0xf8, 0xde, 0x88, 0x44, 0x5a, 0x6a, 0x46, 0x1d, 0x69,
0x98, 0x2f, 0x2e, 0xe7, 0xd2, 0xde, 0x87, 0x0b, 0x25, 0xe3, 0x2c,
0xc1, 0x8f, 0xb6, 0xec, 0xf1, 0xb3, 0xba, 0xdc, 0xd7, 0x17, 0xf8,
0xbc, 0x40, 0x8f, 0xa5, 0x76, 0x3a, 0x40, 0xe6, 0x4c, 0x6d, 0x84,
0x76, 0x88, 0xf8, 0x37, 0xf4, 0x53, 0x14, 0xf6, 0x9c, 0x59, 0x39,
0x5f, 0x9b, 0x02, 0xea, 0x22, 0xbf, 0xa3, 0xb2, 0xde, 0x06, 0xc5,
0xba, 0x01, 0xd8, 0x15, 0xdc, 0x02, 0x8c, 0xdb, 0xa5, 0x56, 0x85,
0xa7, 0xbd, 0x8b, 0x9a, 0xdf, 0x8e, 0xbd, 0x7b, 0xac, 0xe4, 0xf3,
0x5a, 0xc4, 0x52, 0xd6, 0xba, 0x32, 0xca, 0xdc, 0x9f, 0x71, 0x0e,
0x00, 0xc9, 0xb0, 0x9a, 0x6e, 0xc6, 0xe3, 0x20, 0xb2, 0x9b, 0xe5,
0x02, 0x07, 0x2e
};
/** Reference TLSv1.3 ClientHello (from RFC 8448) */
static uint8_t tls13_client_hello[] = {
0x03, 0x03, 0xcb, 0x34, 0xec, 0xb1, 0xe7, 0x81, 0x63, 0xba, 0x1c,
0x38, 0xc6, 0xda, 0xcb, 0x19, 0x6a, 0x6d, 0xff, 0xa2, 0x1a, 0x8d,
0x99, 0x12, 0xec, 0x18, 0xa2, 0xef, 0x62, 0x83, 0x02, 0x4d, 0xec,
0xe7, 0x00, 0x00, 0x06, 0x13, 0x01, 0x13, 0x03, 0x13, 0x02, 0x01,
0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x09, 0x00, 0x00,
0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0xff, 0x01, 0x00, 0x01,
0x00, 0x00, 0x0a, 0x00, 0x14, 0x00, 0x12, 0x00, 0x1d, 0x00, 0x17,
0x00, 0x18, 0x00, 0x19, 0x01, 0x00, 0x01, 0x01, 0x01, 0x02, 0x01,
0x03, 0x01, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x33, 0x00, 0x26,
0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0x99, 0x38, 0x1d, 0xe5, 0x60,
0xe4, 0xbd, 0x43, 0xd2, 0x3d, 0x8e, 0x43, 0x5a, 0x7d, 0xba, 0xfe,
0xb3, 0xc0, 0x6e, 0x51, 0xc1, 0x3c, 0xae, 0x4d, 0x54, 0x13, 0x69,
0x1e, 0x52, 0x9a, 0xaf, 0x2c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0x03,
0x04, 0x00, 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x04, 0x03, 0x05, 0x03,
0x06, 0x03, 0x02, 0x03, 0x08, 0x04, 0x08, 0x05, 0x08, 0x06, 0x04,
0x01, 0x05, 0x01, 0x06, 0x01, 0x02, 0x01, 0x04, 0x02, 0x05, 0x02,
0x06, 0x02, 0x02, 0x02, 0x00, 0x2d, 0x00, 0x02, 0x01, 0x01, 0x00,
0x1c, 0x00, 0x02, 0x40, 0x01
};
/** TLSv1.3 ClientHello random bytes */
static uint8_t tls13_client_hello_random[] = {
0xcb, 0x34, 0xec, 0xb1, 0xe7, 0x81, 0x63, 0xba, 0x1c, 0x38, 0xc6,
0xda, 0xcb, 0x19, 0x6a, 0x6d, 0xff, 0xa2, 0x1a, 0x8d, 0x99, 0x12,
0xec, 0x18, 0xa2, 0xef, 0x62, 0x83, 0x02, 0x4d, 0xec, 0xe7
};
/** TLSv1.3 ClientHello cipher suites */
static uint8_t tls13_client_hello_suites[] = {
0x13, 0x01, 0x13, 0x03, 0x13, 0x02
};
/** TLSv1.3 ClientHello supported groups */
static uint8_t tls13_client_hello_groups[] = {
0x00, 0x12, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x01,
0x00, 0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04
};
/** TLSv1.3 ClientHello public key */
static uint8_t tls13_client_hello_public[] = {
0x99, 0x38, 0x1d, 0xe5, 0x60, 0xe4, 0xbd, 0x43, 0xd2, 0x3d, 0x8e,
0x43, 0x5a, 0x7d, 0xba, 0xfe, 0xb3, 0xc0, 0x6e, 0x51, 0xc1, 0x3c,
0xae, 0x4d, 0x54, 0x13, 0x69, 0x1e, 0x52, 0x9a, 0xaf, 0x2c
};
/** TLSv1.3 ClientHello signature algorithms */
static uint8_t tls13_client_hello_sigs[] = {
0x00, 0x1e, 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x02, 0x03, 0x08,
0x04, 0x08, 0x05, 0x08, 0x06, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01,
0x02, 0x01, 0x04, 0x02, 0x05, 0x02, 0x06, 0x02, 0x02, 0x02
};
/** TLSv1.3 ClientHello supported version */
static uint8_t tls13_client_hello_supvers[] = { 0x03, 0x04 };
/** TLSv1.3 ClientHello pre-shared key modes */
static uint8_t tls13_client_hello_pskmodes[] = { 0x01 };
/** Space for test data */
union tlsfmt_test_data {
uint8_t tls13_server_hello[ sizeof ( tls13_server_hello ) + 1 ];
uint8_t tls13_certificate[ sizeof ( tls13_certificate ) ];
uint8_t tls12_certificate[ sizeof ( tls12_certificate ) ];
uint8_t tls11_server_hello[ sizeof ( tls11_server_hello ) ];
uint8_t tls12_server_key_exchange_ecdhe
[ sizeof ( tls12_server_key_exchange_ecdhe ) ];
uint8_t tls11_server_key_exchange_ecdhe
[ sizeof ( tls11_server_key_exchange_ecdhe ) ];
uint8_t tls13_client_hello[ sizeof ( tls13_client_hello ) ];
};
/**
* Report a mapping validity test result
*
* @v type Descriptor structure name
* @v version Protocol version
*/
#define map_version_ok( type, version ) do { \
struct tls_cursor cursor; \
struct type desc; \
void *empty; \
\
memset ( &desc, 0, sizeof ( desc ) ); \
ok ( tls_size ( type, version, &desc, &cursor ) == 0 ); \
empty = zalloc ( cursor.len ); \
ok ( empty != NULL ); \
cursor.data = empty; \
ok ( tls_build ( type, version, &desc, &cursor ) == 0 ); \
ok ( tls_parse ( type, version, &cursor, &desc ) == 0 ); \
free ( empty ); \
} while ( 0 )
/**
* Report a mapping validity test result
*
* @v type Descriptor structure name
*/
#define map_ok( type ) do { \
map_version_ok ( type, TLS_VERSION_TLS_1_1 ); \
map_version_ok ( type, TLS_VERSION_TLS_1_2 ); \
map_version_ok ( type, TLS_VERSION_TLS_1_3 ); \
} while ( 0 )
/**
* Report a cursor comparison test result
*
* @v cursor Cursor
* @v reference Reference cursor
* @v file Test code file
* @v line Test code line
*/
static void cursor_okx ( struct tls_cursor *cursor,
struct tls_cursor *reference,
const char *file, unsigned int line ) {
/* Compare cursors */
okx ( cursor->len == reference->len, file, line );
okx ( memcmp ( cursor->data, reference->data, reference->len ) == 0,
file, line );
}
#define cursor_ok( cursor, reference ) \
cursor_okx ( (cursor), (reference), __FILE__, __LINE__ )
/**
* Report a pre-extensions comparison test result
*
* @v data Data
* @v ext Extensions
* @v reference Reference data
* @v reference_ext Reference extensions
* @v file Test code file
* @v line Test code line
*/
static void pre_ext_okx ( const void *data, struct tls_cursor *extensions,
const void *reference,
struct tls_cursor *reference_ext,
const char *file, unsigned int line ) {
size_t reference_len = ( reference_ext->data - reference );
size_t len = ( extensions->data - data );
/* Compare cursors */
okx ( len == reference_len, file, line );
okx ( memcmp ( data, reference, reference_len ) == 0, file, line );
}
#define pre_ext_ok( data, ext, reference, reference_ext ) \
pre_ext_okx ( (data), (ext), (reference), (reference_ext), \
__FILE__, __LINE__ )
/**
* Perform TLS data format self-test
*
*/
static void tlsfmt_test_exec ( void ) {
union tlsfmt_test_data u;
struct tls_cursor cursor;
struct tls_client_hello client_hello;
struct tls_client_hello client_hello_ref;
struct tls_server_hello server_hello;
struct tls_server_hello server_hello_ref;
struct tls_supported_version supported_version;
struct tls_supported_versions supported_versions;
struct tls_key_share_entry key_share_entry;
struct tls_key_share_client_hello key_share_client_hello;
struct tls_certificate certificate;
struct tls_certificate_entry certificate_entry;
struct tls_server_key_exchange_ecdhe server_key_exchange_ecdhe;
struct tls_digitally_signed digitally_signed;
struct tls_server_name server_name;
struct tls_server_name_list server_name_list;
struct tls_psk_key_exchange_modes psk_key_exchange_modes;
struct x509_certificate *tls13_cert;
struct x509_certificate *tls12_cert;
unsigned int offset;
uint16_t __attribute__ (( aligned ( 1 ) )) *tmp16;
uint16_t group;
uint16_t record;
uint8_t empty[0];
/* Check validity of all mappings */
map_ok ( tls_certificate );
map_ok ( tls_certificate_entry );
map_ok ( tls_client_hello );
map_ok ( tls_client_key_exchange_dhe );
map_ok ( tls_client_key_exchange_ecdhe );
map_ok ( tls_client_key_exchange_pubkey );
map_ok ( tls_digitally_signed );
map_ok ( tls_extension );
map_ok ( tls_hello_request );
map_ok ( tls_key_share_client_hello );
map_ok ( tls_key_share_entry );
map_ok ( tls_key_share_hello_retry_request );
map_ok ( tls_key_share_server_hello );
map_ok ( tls_max_fragment_length );
map_ok ( tls_named_group_list );
map_ok ( tls_new_session_ticket );
map_ok ( tls_psk_key_exchange_modes );
map_ok ( tls_renegotiation_info );
map_ok ( tls_server_hello );
map_ok ( tls_server_hello_done );
map_ok ( tls_server_key_exchange_dhe );
map_ok ( tls_server_key_exchange_ecdhe );
map_ok ( tls_server_name );
map_ok ( tls_server_name_list );
map_ok ( tls_signature_scheme_list );
map_ok ( tls_supported_version );
map_ok ( tls_supported_versions );
/* Well-formed TLSv1.3 ServerHello */
memset ( u.tls13_server_hello, 0xaa, sizeof ( u.tls13_server_hello ) );
memcpy ( u.tls13_server_hello, tls13_server_hello,
sizeof ( tls13_server_hello ) );
cursor.data = u.tls13_server_hello;
cursor.len = sizeof ( tls13_server_hello );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) == 0 );
ok ( server_hello.a->version == htons ( TLS_VERSION_TLS_1_2 ) );
ok ( server_hello.session_id.data != NULL );
ok ( server_hello.session_id.len == 0 );
ok ( server_hello.b->suite == htons ( TLS_AES_128_GCM_SHA256 ) );
ok ( server_hello.ext.reneg.data == NULL );
ok ( server_hello.ext.ems.data == NULL );
ok ( server_hello.ext.supver.data != NULL );
ok ( server_hello.ext.key.data != NULL );
ok ( tls_parse ( tls_supported_version, TLS_VERSION_TLS_1_3,
&server_hello.ext.supver, &supported_version ) == 0 );
ok ( *supported_version.selected == htons ( TLS_VERSION_TLS_1_3 ) );
ok ( tls_parse ( tls_key_share_entry, TLS_VERSION_TLS_1_3,
&server_hello.ext.key, &key_share_entry ) == 0 );
ok ( *key_share_entry.group == htons ( TLS_NAMED_GROUP_X25519 ) );
ok ( key_share_entry.public.data != NULL );
ok ( key_share_entry.public.len ==
sizeof ( tls13_server_hello_public ) );
ok ( key_share_entry.next.data != NULL );
ok ( key_share_entry.next.len == 0 );
/* Truncated fixed-length data */
cursor.data = server_hello.ext.supver.data;
cursor.len = server_hello.ext.supver.len;
ok ( tls_parse ( tls_supported_version, TLS_VERSION_TLS_1_3,
&cursor, &supported_version ) == 0 );
cursor.len -= 1;
ok ( tls_parse ( tls_supported_version, TLS_VERSION_TLS_1_3,
&cursor, &supported_version ) != 0 );
/* Truncated variable-length length */
cursor.data = server_hello.ext.key.data;
cursor.len = server_hello.ext.key.len;
ok ( tls_parse ( tls_key_share_entry, TLS_VERSION_TLS_1_3, &cursor,
&key_share_entry ) == 0 );
cursor.len = ( sizeof ( *key_share_entry.group ) + 1 );
ok ( tls_parse ( tls_key_share_entry, TLS_VERSION_TLS_1_3, &cursor,
&key_share_entry ) != 0 );
/* Truncated variable-length data */
cursor.data = u.tls13_server_hello;
cursor.len = sizeof ( tls13_server_hello );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) == 0 );
cursor.len -= 1;
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) != 0 );
/* Excess data */
cursor.data = u.tls13_server_hello;
cursor.len = sizeof ( tls13_server_hello );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) == 0 );
cursor.len += 1;
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) != 0 );
/* Duplicate extension type */
cursor.data = u.tls13_server_hello;
cursor.len = sizeof ( tls13_server_hello );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) == 0 );
offset = ( server_hello.ext.key.data - cursor.data - 4 );
tmp16 = ( ( void * ) &u.tls13_server_hello[offset] );
ok ( *tmp16 == htons ( TLS_KEY_SHARE ) );
*tmp16 = htons ( TLS_RENEGOTIATION_INFO );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) == 0 );
*tmp16 = htons ( TLS_SUPPORTED_VERSIONS );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) != 0 );
*tmp16 = htons ( TLS_KEY_SHARE );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) == 0 );
/* Malformed extension length */
cursor.data = u.tls13_server_hello;
cursor.len = sizeof ( tls13_server_hello );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) == 0 );
offset = ( server_hello.ext.key.data - cursor.data - 2 );
tmp16 = ( ( void * ) &u.tls13_server_hello[offset] );
ok ( *tmp16 == htons ( 36 ) );
*tmp16 = htons ( sizeof ( tls13_server_hello ) );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) != 0 );
*tmp16 = htons ( 36 );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) == 0 );
/* Well-formed TLSv1.3 Certificate */
memcpy ( u.tls13_certificate, tls13_certificate,
sizeof ( tls13_certificate ) );
cursor.data = u.tls13_certificate;
cursor.len = sizeof ( tls13_certificate );
ok ( tls_parse ( tls_certificate, TLS_VERSION_TLS_1_3, &cursor,
&certificate ) == 0 );
ok ( tls_parse ( tls_certificate_entry, TLS_VERSION_TLS_1_3,
&certificate.list, &certificate_entry ) == 0 );
ok ( x509_certificate ( certificate_entry.cert.data,
certificate_entry.cert.len,
&tls13_cert ) == 0 );
ok ( certificate_entry.next.data != NULL );
ok ( certificate_entry.next.len == 0 );
ok ( asn1_compare ( tls_asn1 ( &certificate_entry.cert ),
&tls13_cert->raw ) == 0 );
/* Fields not present in older TLS versions */
ok ( tls_parse ( tls_certificate, TLS_VERSION_TLS_1_3, &cursor,
&certificate ) == 0 );
ok ( tls_parse ( tls_certificate, TLS_VERSION_TLS_1_2, &cursor,
&certificate ) != 0 );
/* Well-formed TLSv1.2 Certificate */
memcpy ( u.tls12_certificate, tls12_certificate,
sizeof ( tls12_certificate ) );
cursor.data = u.tls12_certificate;
cursor.len = sizeof ( tls12_certificate );
ok ( tls_parse ( tls_certificate, TLS_VERSION_TLS_1_2, &cursor,
&certificate ) == 0 );
ok ( tls_parse ( tls_certificate_entry, TLS_VERSION_TLS_1_2,
&certificate.list, &certificate_entry ) == 0 );
ok ( x509_certificate ( certificate_entry.cert.data,
certificate_entry.cert.len,
&tls12_cert ) == 0 );
ok ( certificate_entry.next.data != NULL );
ok ( certificate_entry.next.len == 0 );
ok ( asn1_compare ( tls_asn1 ( &certificate_entry.cert ),
&tls12_cert->raw ) == 0 );
ok ( tls12_cert == tls13_cert );
/* Fields not present in newer TLS versions */
ok ( tls_parse ( tls_certificate, TLS_VERSION_TLS_1_2, &cursor,
&certificate ) == 0 );
ok ( tls_parse ( tls_certificate, TLS_VERSION_TLS_1_3, &cursor,
&certificate ) != 0 );
/* Well-formed TLSv1.1 ServerHello with no extensions */
memcpy ( u.tls11_server_hello, tls11_server_hello,
sizeof ( tls11_server_hello ) );
cursor.data = u.tls11_server_hello;
cursor.len = sizeof ( tls11_server_hello );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_1, &cursor,
&server_hello ) == 0 );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_2, &cursor,
&server_hello ) == 0 );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3, &cursor,
&server_hello ) != 0 );
/* Well-formed TLSv1.2 ServerKeyExchange with explicit algorithm */
memcpy ( u.tls12_server_key_exchange_ecdhe,
tls12_server_key_exchange_ecdhe,
sizeof ( tls12_server_key_exchange_ecdhe ) );
cursor.data = u.tls12_server_key_exchange_ecdhe;
cursor.len = sizeof ( tls12_server_key_exchange_ecdhe );
ok ( tls_parse ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_2,
&cursor, &server_key_exchange_ecdhe ) == 0 );
ok ( server_key_exchange_ecdhe.curve->type == TLS_NAMED_CURVE_TYPE );
ok ( server_key_exchange_ecdhe.curve->group ==
htons ( TLS_NAMED_GROUP_X25519 ) );
ok ( tls_parse ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_1,
&cursor, &server_key_exchange_ecdhe ) == 0 );
ok ( tls_parse ( tls_digitally_signed, TLS_VERSION_TLS_1_2,
&server_key_exchange_ecdhe.dsig,
&digitally_signed ) == 0 );
ok ( digitally_signed.sig_hash != NULL );
ok ( *digitally_signed.sig_hash == htons ( TLS_RSA_SHA1_ALGORITHM ) );
ok ( tls_parse ( tls_digitally_signed, TLS_VERSION_TLS_1_1,
&server_key_exchange_ecdhe.dsig,
&digitally_signed ) != 0 );
/* Well-formed TLSv1.1 ServerKeyExchange with implicit algorithm */
memcpy ( u.tls11_server_key_exchange_ecdhe,
tls11_server_key_exchange_ecdhe,
sizeof ( tls11_server_key_exchange_ecdhe ) );
cursor.data = u.tls11_server_key_exchange_ecdhe;
cursor.len = sizeof ( tls11_server_key_exchange_ecdhe );
ok ( tls_parse ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_1,
&cursor, &server_key_exchange_ecdhe ) == 0 );
ok ( server_key_exchange_ecdhe.curve->type == TLS_NAMED_CURVE_TYPE );
ok ( server_key_exchange_ecdhe.curve->group ==
htons ( TLS_NAMED_GROUP_X25519 ) );
ok ( tls_parse ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_2,
&cursor, &server_key_exchange_ecdhe ) == 0 );
ok ( tls_parse ( tls_digitally_signed, TLS_VERSION_TLS_1_1,
&server_key_exchange_ecdhe.dsig,
&digitally_signed ) == 0 );
ok ( digitally_signed.sig_hash == NULL );
ok ( tls_parse ( tls_digitally_signed, TLS_VERSION_TLS_1_2,
&server_key_exchange_ecdhe.dsig,
&digitally_signed ) != 0 );
/* Build TLSv1.3 ServerHello */
memset ( &supported_version, 0, sizeof ( supported_version ) );
memset ( &key_share_entry, 0, sizeof ( key_share_entry ) );
memset ( &server_hello, 0, sizeof ( server_hello ) );
group = htons ( TLS_NAMED_GROUP_X25519 );
key_share_entry.group = &group;
key_share_entry.public.data = tls13_server_hello_public;
key_share_entry.public.len = sizeof ( tls13_server_hello_public );
ok ( tls_size ( tls_supported_version, TLS_VERSION_TLS_1_3,
&supported_version, &server_hello.ext.supver ) == 0 );
ok ( tls_size ( tls_key_share_entry, TLS_VERSION_TLS_1_3,
&key_share_entry, &server_hello.ext.key ) == 0 );
ok ( tls_size ( tls_server_hello, TLS_VERSION_TLS_1_3,
&server_hello, &cursor ) == 0 );
ok ( cursor.len == sizeof ( tls13_server_hello ) );
cursor.data = u.tls13_server_hello;
ok ( tls_build ( tls_server_hello, TLS_VERSION_TLS_1_3,
&server_hello, &cursor ) == 0 );
server_hello.a->version = htons ( TLS_VERSION_TLS_1_2 );
memcpy ( server_hello.a->random, tls13_server_hello_random,
sizeof ( server_hello.a->random ) );
server_hello.b->suite = htons ( TLS_AES_128_GCM_SHA256 );
ok ( tls_build ( tls_key_share_entry, TLS_VERSION_TLS_1_3,
&key_share_entry, &server_hello.ext.key ) == 0 );
ok ( tls_build ( tls_supported_version, TLS_VERSION_TLS_1_3,
&supported_version, &server_hello.ext.supver ) == 0 );
*supported_version.selected = htons ( TLS_VERSION_TLS_1_3 );
DBGC ( &cursor, "TLSFMT built TLSv1.3 ServerHello:\n" );
DBGC_HDA ( &cursor, 0, cursor.data, cursor.len );
DBGC ( &cursor, "TLSFMT reference TLSv1.3 ServerHello:\n" );
DBGC_HDA ( &cursor, 0, tls13_server_hello,
sizeof ( tls13_server_hello ) );
cursor.data = tls13_server_hello;
cursor.len = sizeof ( tls13_server_hello );
ok ( tls_parse ( tls_server_hello, TLS_VERSION_TLS_1_3,
&cursor, &server_hello_ref ) == 0 );
pre_ext_ok ( u.tls13_server_hello, &server_hello.ext.all,
tls13_server_hello, &server_hello_ref.ext.all );
cursor_ok ( &server_hello.ext.supver, &server_hello_ref.ext.supver );
cursor_ok ( &server_hello.ext.key, &server_hello_ref.ext.key );
/* Build TLSv1.2 ServerKeyExchange */
memset ( &digitally_signed, 0, sizeof ( digitally_signed ) );
memset ( &server_key_exchange_ecdhe, 0,
sizeof ( server_key_exchange_ecdhe ) );
server_key_exchange_ecdhe.point.data = server_key_exchange_point;
server_key_exchange_ecdhe.point.len =
sizeof ( server_key_exchange_point );
digitally_signed.sig.data = server_key_exchange_sig;
digitally_signed.sig.len = sizeof ( server_key_exchange_sig );
ok ( tls_size ( tls_digitally_signed, TLS_VERSION_TLS_1_2,
&digitally_signed,
&server_key_exchange_ecdhe.dsig ) == 0 );
ok ( tls_size ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_2,
&server_key_exchange_ecdhe, &cursor ) == 0 );
ok ( cursor.len == sizeof ( tls12_server_key_exchange_ecdhe ) );
cursor.data = u.tls12_server_key_exchange_ecdhe;
ok ( tls_build ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_2,
&server_key_exchange_ecdhe, &cursor ) == 0 );
ok ( tls_build ( tls_digitally_signed, TLS_VERSION_TLS_1_2,
&digitally_signed,
&server_key_exchange_ecdhe.dsig ) == 0 );
server_key_exchange_ecdhe.curve->type = TLS_NAMED_CURVE_TYPE;
server_key_exchange_ecdhe.curve->group =
htons ( TLS_NAMED_GROUP_X25519 );
ok ( digitally_signed.sig_hash != NULL );
*digitally_signed.sig_hash = htons ( TLS_RSA_SHA1_ALGORITHM );
DBGC ( &cursor, "TLSFMT built TLSv1.2 ServerKeyExchange:\n" );
DBGC_HDA ( &cursor, 0, cursor.data, cursor.len );
DBGC ( &cursor, "TLSFMT reference TLSv1.2 ServerKeyExchange:\n" );
DBGC_HDA ( &cursor, 0, tls12_server_key_exchange_ecdhe,
sizeof ( tls12_server_key_exchange_ecdhe ) );
ok ( memcmp ( u.tls12_server_key_exchange_ecdhe,
tls12_server_key_exchange_ecdhe,
sizeof ( tls12_server_key_exchange_ecdhe ) ) == 0 );
/* Build TLSv1.1 ServerKeyExchange */
memset ( &digitally_signed, 0, sizeof ( digitally_signed ) );
memset ( &server_key_exchange_ecdhe, 0,
sizeof ( server_key_exchange_ecdhe ) );
server_key_exchange_ecdhe.point.data = server_key_exchange_point;
server_key_exchange_ecdhe.point.len =
sizeof ( server_key_exchange_point );
digitally_signed.sig.data = server_key_exchange_sig;
digitally_signed.sig.len = sizeof ( server_key_exchange_sig );
ok ( tls_size ( tls_digitally_signed, TLS_VERSION_TLS_1_1,
&digitally_signed,
&server_key_exchange_ecdhe.dsig ) == 0 );
ok ( tls_size ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_1,
&server_key_exchange_ecdhe, &cursor ) == 0 );
ok ( cursor.len == sizeof ( tls11_server_key_exchange_ecdhe ) );
cursor.data = u.tls11_server_key_exchange_ecdhe;
ok ( tls_build ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_1,
&server_key_exchange_ecdhe, &cursor ) == 0 );
ok ( tls_build ( tls_digitally_signed, TLS_VERSION_TLS_1_1,
&digitally_signed,
&server_key_exchange_ecdhe.dsig ) == 0 );
server_key_exchange_ecdhe.curve->type = TLS_NAMED_CURVE_TYPE;
server_key_exchange_ecdhe.curve->group =
htons ( TLS_NAMED_GROUP_X25519 );
ok ( digitally_signed.sig_hash == NULL );
DBGC ( &cursor, "TLSFMT built TLSv1.1 ServerKeyExchange:\n" );
DBGC_HDA ( &cursor, 0, cursor.data, cursor.len );
DBGC ( &cursor, "TLSFMT reference TLSv1.1 ServerKeyExchange:\n" );
DBGC_HDA ( &cursor, 0, tls11_server_key_exchange_ecdhe,
sizeof ( tls11_server_key_exchange_ecdhe ) );
ok ( memcmp ( u.tls11_server_key_exchange_ecdhe,
tls11_server_key_exchange_ecdhe,
sizeof ( tls11_server_key_exchange_ecdhe ) ) == 0 );
/* Build TLSv1.3 ClientHello */
memset ( &server_name, 0, sizeof ( server_name ) );
memset ( &server_name_list, 0, sizeof ( server_name_list ) );
memset ( &key_share_entry, 0, sizeof ( key_share_entry ) );
memset ( &key_share_client_hello, 0,
sizeof ( key_share_client_hello ) );
memset ( &supported_versions, 0, sizeof ( supported_versions ) );
memset ( &psk_key_exchange_modes, 0,
sizeof ( psk_key_exchange_modes ) );
memset ( &client_hello, 0, sizeof ( client_hello ) );
server_name.name.data = "server";
server_name.name.len = strlen ( server_name.name.data );
ok ( tls_size ( tls_server_name, TLS_VERSION_TLS_1_3,
&server_name, &server_name_list.list ) == 0 );
ok ( tls_size ( tls_server_name_list, TLS_VERSION_TLS_1_3,
&server_name_list, &client_hello.ext.names ) == 0 );
group = htons ( TLS_NAMED_GROUP_X25519 );
key_share_entry.group = &group;
key_share_entry.public.data = tls13_client_hello_public;
key_share_entry.public.len = sizeof ( tls13_client_hello_public );
ok ( tls_size ( tls_key_share_entry, TLS_VERSION_TLS_1_3,
&key_share_entry,
&key_share_client_hello.list ) == 0 );
ok ( tls_size ( tls_key_share_client_hello, TLS_VERSION_TLS_1_3,
&key_share_client_hello,
&client_hello.ext.keys ) == 0 );
supported_versions.list.data = tls13_client_hello_supvers;
supported_versions.list.len = sizeof ( tls13_client_hello_supvers );
ok ( tls_size ( tls_supported_versions, TLS_VERSION_TLS_1_3,
&supported_versions,
&client_hello.ext.supvers ) == 0 );
psk_key_exchange_modes.list.data = tls13_client_hello_pskmodes;
psk_key_exchange_modes.list.len =
sizeof ( tls13_client_hello_pskmodes );
ok ( tls_size ( tls_psk_key_exchange_modes, TLS_VERSION_TLS_1_3,
&psk_key_exchange_modes,
&client_hello.ext.pskmodes ) == 0 );
client_hello.suites.data = tls13_client_hello_suites;
client_hello.suites.len = sizeof ( tls13_client_hello_suites );
client_hello.compression.len = 1;
client_hello.ext.reneg.len = 1;
client_hello.ext.groups.data = tls13_client_hello_groups;
client_hello.ext.groups.len = sizeof ( tls13_client_hello_groups );
client_hello.ext.ticket.data = empty;
client_hello.ext.sigs.data = tls13_client_hello_sigs;
client_hello.ext.sigs.len = sizeof ( tls13_client_hello_sigs );
record = htons ( 0x4001 );
client_hello.ext.record.data = &record;
client_hello.ext.record.len = sizeof ( record );
ok ( tls_size ( tls_client_hello, TLS_VERSION_TLS_1_3,
&client_hello, &cursor ) == 0 );
ok ( cursor.len == sizeof ( tls13_client_hello ) );
cursor.data = u.tls13_client_hello;
ok ( tls_build ( tls_client_hello, TLS_VERSION_TLS_1_3,
&client_hello, &cursor ) == 0 );
client_hello.a->version = htons ( TLS_VERSION_TLS_1_2 );
ok ( tls_build ( tls_server_name_list, TLS_VERSION_TLS_1_3,
&server_name_list, &client_hello.ext.names ) == 0 );
ok ( tls_build ( tls_server_name, TLS_VERSION_TLS_1_3,
&server_name, &server_name_list.list ) == 0 );
ok ( tls_build ( tls_key_share_client_hello, TLS_VERSION_TLS_1_3,
&key_share_client_hello,
&client_hello.ext.keys ) == 0 );
ok ( tls_build ( tls_key_share_entry, TLS_VERSION_TLS_1_3,
&key_share_entry,
&key_share_client_hello.list ) == 0 );
ok ( tls_build ( tls_supported_versions, TLS_VERSION_TLS_1_3,
&supported_versions,
&client_hello.ext.supvers ) == 0 );
ok ( tls_build ( tls_psk_key_exchange_modes, TLS_VERSION_TLS_1_3,
&psk_key_exchange_modes,
&client_hello.ext.pskmodes ) == 0 );
memcpy ( client_hello.a->random, tls13_client_hello_random,
sizeof ( client_hello.a->random ) );
DBGC ( &cursor, "TLSFMT built TLSv1.3 ClientHello:\n" );
DBGC_HDA ( &cursor, 0, cursor.data, cursor.len );
DBGC ( &cursor, "TLSFMT reference TLSv1.3 ClientHello:\n" );
DBGC_HDA ( &cursor, 0, tls13_client_hello,
sizeof ( tls13_client_hello ) );
cursor.data = tls13_client_hello;
cursor.len = sizeof ( tls13_client_hello );
ok ( tls_parse ( tls_client_hello, TLS_VERSION_TLS_1_3,
&cursor, &client_hello_ref ) == 0 );
pre_ext_ok ( u.tls13_client_hello, &client_hello.ext.all,
tls13_client_hello, &client_hello_ref.ext.all );
cursor_ok ( &client_hello.ext.ems, &client_hello_ref.ext.ems );
cursor_ok ( &client_hello.ext.frag, &client_hello_ref.ext.frag );
cursor_ok ( &client_hello.ext.groups, &client_hello_ref.ext.groups );
cursor_ok ( &client_hello.ext.keys, &client_hello_ref.ext.keys );
cursor_ok ( &client_hello.ext.names, &client_hello_ref.ext.names );
cursor_ok ( &client_hello.ext.pskmodes,
&client_hello_ref.ext.pskmodes );
cursor_ok ( &client_hello.ext.record, &client_hello_ref.ext.record );
cursor_ok ( &client_hello.ext.reneg, &client_hello_ref.ext.reneg );
cursor_ok ( &client_hello.ext.sigs, &client_hello_ref.ext.sigs );
cursor_ok ( &client_hello.ext.supvers, &client_hello_ref.ext.supvers );
cursor_ok ( &client_hello.ext.ticket, &client_hello_ref.ext.ticket );
/* Propagation of sizing errors */
memset ( &digitally_signed, 0, sizeof ( digitally_signed ) );
memset ( &server_key_exchange_ecdhe, 0,
sizeof ( server_key_exchange_ecdhe ) );
ok ( tls_size ( tls_digitally_signed, TLS_VERSION_TLS_1_2,
&digitally_signed,
&server_key_exchange_ecdhe.dsig ) == 0 );
ok ( tls_size ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_2,
&server_key_exchange_ecdhe, &cursor ) == 0 );
memset ( &digitally_signed, 0, sizeof ( digitally_signed ) );
memset ( &server_key_exchange_ecdhe, 0,
sizeof ( server_key_exchange_ecdhe ) );
digitally_signed.sig.len = 0x10000;
ok ( tls_size ( tls_digitally_signed, TLS_VERSION_TLS_1_2,
&digitally_signed,
&server_key_exchange_ecdhe.dsig ) != 0 );
ok ( tls_size ( tls_server_key_exchange_ecdhe, TLS_VERSION_TLS_1_2,
&server_key_exchange_ecdhe, &cursor ) != 0 );
/* Drop certificate references */
x509_put ( tls12_cert );
x509_put ( tls13_cert );
}
/** TLS data format self-test */
struct self_test tlsfmt_test __self_test = {
.name = "tlsfmt",
.exec = tlsfmt_test_exec,
};