1*bbf5c0e5Stb /* $OpenBSD: exportertest.c,v 1.4 2024/03/01 03:46:54 tb Exp $ */
24cf748f3Sjsing /*
34cf748f3Sjsing * Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
44cf748f3Sjsing *
54cf748f3Sjsing * Permission to use, copy, modify, and distribute this software for any
64cf748f3Sjsing * purpose with or without fee is hereby granted, provided that the above
74cf748f3Sjsing * copyright notice and this permission notice appear in all copies.
84cf748f3Sjsing *
94cf748f3Sjsing * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
104cf748f3Sjsing * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
114cf748f3Sjsing * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
124cf748f3Sjsing * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
134cf748f3Sjsing * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
144cf748f3Sjsing * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
154cf748f3Sjsing * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
164cf748f3Sjsing */
174cf748f3Sjsing
184cf748f3Sjsing #include <openssl/err.h>
194cf748f3Sjsing #include <openssl/ssl.h>
204cf748f3Sjsing
214cf748f3Sjsing #include <err.h>
224cf748f3Sjsing #include <stdio.h>
234cf748f3Sjsing #include <string.h>
244cf748f3Sjsing
25c9675a23Stb #include "ssl_local.h"
264cf748f3Sjsing
274cf748f3Sjsing static void
hexdump(const unsigned char * buf,size_t len)284cf748f3Sjsing hexdump(const unsigned char *buf, size_t len)
294cf748f3Sjsing {
304cf748f3Sjsing size_t i;
314cf748f3Sjsing
324cf748f3Sjsing for (i = 1; i <= len; i++)
334cf748f3Sjsing fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n");
344cf748f3Sjsing
354cf748f3Sjsing fprintf(stderr, "\n");
364cf748f3Sjsing }
374cf748f3Sjsing
384cf748f3Sjsing struct exporter_test {
394cf748f3Sjsing uint16_t tls_version;
404cf748f3Sjsing unsigned int cipher_id;
414cf748f3Sjsing const uint8_t *label;
424cf748f3Sjsing size_t label_len;
434cf748f3Sjsing const uint8_t context_value[64];
444cf748f3Sjsing size_t context_value_len;
454cf748f3Sjsing int use_context;
464cf748f3Sjsing const uint8_t client_random[SSL3_RANDOM_SIZE];
474cf748f3Sjsing const uint8_t server_random[SSL3_RANDOM_SIZE];
484cf748f3Sjsing const uint8_t master_key[SSL_MAX_MASTER_KEY_LENGTH];
494cf748f3Sjsing const uint8_t shared_key[64];
504cf748f3Sjsing size_t shared_key_len;
514cf748f3Sjsing const uint8_t export[64];
524cf748f3Sjsing size_t export_len;
534cf748f3Sjsing int want_error;
544cf748f3Sjsing };
554cf748f3Sjsing
564cf748f3Sjsing static const struct exporter_test exporter_tests[] = {
574cf748f3Sjsing {
584cf748f3Sjsing /* Valid export, no context - 32 bytes. */
594cf748f3Sjsing .tls_version = TLS1_2_VERSION,
604cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
614cf748f3Sjsing .label = "EXPERIMENTAL testing",
624cf748f3Sjsing .label_len = 20,
634cf748f3Sjsing .use_context = 0,
644cf748f3Sjsing .client_random = {
654cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
664cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
674cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
684cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
694cf748f3Sjsing },
704cf748f3Sjsing .server_random = {
714cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
724cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
734cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
744cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
754cf748f3Sjsing },
764cf748f3Sjsing .master_key = {
774cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
784cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
794cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
804cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
814cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
824cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
834cf748f3Sjsing },
844cf748f3Sjsing .export = {
854cf748f3Sjsing 0x14, 0x08, 0x00, 0x9e, 0x6a, 0x67, 0x75, 0x4c,
864cf748f3Sjsing 0xc4, 0xf3, 0x51, 0x57, 0x2f, 0x75, 0x0b, 0xf8,
874cf748f3Sjsing 0x16, 0xfa, 0x61, 0x74, 0xd2, 0x12, 0x8f, 0x78,
884cf748f3Sjsing 0x77, 0xf9, 0x8a, 0x3e, 0x58, 0x70, 0xf3, 0xd8,
894cf748f3Sjsing },
904cf748f3Sjsing .export_len = 32,
914cf748f3Sjsing },
924cf748f3Sjsing {
934cf748f3Sjsing /* Valid export, no context - 32 bytes. */
944cf748f3Sjsing .tls_version = TLS1_3_VERSION,
954cf748f3Sjsing .label = "EXPERIMENTAL testing",
964cf748f3Sjsing .label_len = 20,
974cf748f3Sjsing .use_context = 0,
984cf748f3Sjsing .shared_key = {
994cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1004cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1014cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1024cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1034cf748f3Sjsing },
1044cf748f3Sjsing .shared_key_len = 32,
1054cf748f3Sjsing .export = {
1064cf748f3Sjsing 0x69, 0xf4, 0xac, 0xec, 0x80, 0x67, 0xac, 0x5c,
1074cf748f3Sjsing 0xa6, 0x24, 0x47, 0xb1, 0x0f, 0xc8, 0xa1, 0x13,
1084cf748f3Sjsing 0x3b, 0x91, 0x33, 0x82, 0x97, 0x0a, 0xc0, 0xbf,
1094cf748f3Sjsing 0xac, 0x6d, 0x6b, 0x34, 0x20, 0xd3, 0x3a, 0x02,
1104cf748f3Sjsing },
1114cf748f3Sjsing .export_len = 32,
1124cf748f3Sjsing },
1134cf748f3Sjsing {
1144cf748f3Sjsing /* Valid export, no context - 64 bytes. */
1154cf748f3Sjsing .tls_version = TLS1_2_VERSION,
1164cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
1174cf748f3Sjsing .label = "EXPERIMENTAL testing",
1184cf748f3Sjsing .label_len = 20,
1194cf748f3Sjsing .use_context = 0,
1204cf748f3Sjsing .client_random = {
1214cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1224cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1234cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1244cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1254cf748f3Sjsing },
1264cf748f3Sjsing .server_random = {
1274cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1284cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1294cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1304cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1314cf748f3Sjsing },
1324cf748f3Sjsing .master_key = {
1334cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1344cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1354cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1364cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1374cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
1384cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
1394cf748f3Sjsing },
1404cf748f3Sjsing .export = {
1414cf748f3Sjsing 0x14, 0x08, 0x00, 0x9e, 0x6a, 0x67, 0x75, 0x4c,
1424cf748f3Sjsing 0xc4, 0xf3, 0x51, 0x57, 0x2f, 0x75, 0x0b, 0xf8,
1434cf748f3Sjsing 0x16, 0xfa, 0x61, 0x74, 0xd2, 0x12, 0x8f, 0x78,
1444cf748f3Sjsing 0x77, 0xf9, 0x8a, 0x3e, 0x58, 0x70, 0xf3, 0xd8,
1454cf748f3Sjsing 0xe8, 0xd2, 0xb7, 0xcd, 0xbc, 0x37, 0xdf, 0x16,
1464cf748f3Sjsing 0x12, 0xf1, 0xe8, 0xb2, 0x62, 0x79, 0x91, 0x45,
1474cf748f3Sjsing 0x77, 0xe0, 0x68, 0x6d, 0xd5, 0x31, 0x54, 0x55,
1484cf748f3Sjsing 0x22, 0x63, 0xc0, 0x36, 0x31, 0x07, 0xda, 0x33,
1494cf748f3Sjsing },
1504cf748f3Sjsing .export_len = 64,
1514cf748f3Sjsing },
1524cf748f3Sjsing {
1534cf748f3Sjsing /* Valid export, no context - 64 bytes. */
1544cf748f3Sjsing .tls_version = TLS1_3_VERSION,
1554cf748f3Sjsing .label = "EXPERIMENTAL testing",
1564cf748f3Sjsing .label_len = 20,
1574cf748f3Sjsing .use_context = 0,
1584cf748f3Sjsing .shared_key = {
1594cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1604cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1614cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1624cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1634cf748f3Sjsing },
1644cf748f3Sjsing .shared_key_len = 32,
1654cf748f3Sjsing .export = {
1664cf748f3Sjsing 0x77, 0x15, 0xe2, 0x07, 0x65, 0x64, 0x3b, 0x14,
1674cf748f3Sjsing 0x38, 0xcb, 0x73, 0x93, 0xda, 0x70, 0xfa, 0x86,
1684cf748f3Sjsing 0x2c, 0x34, 0xcc, 0x94, 0x52, 0xc2, 0xd3, 0xb4,
1694cf748f3Sjsing 0x59, 0x2c, 0xc8, 0x05, 0x70, 0xfe, 0x48, 0x61,
1704cf748f3Sjsing 0xd3, 0xea, 0x57, 0x66, 0xa9, 0x66, 0x2f, 0x4a,
1714cf748f3Sjsing 0x35, 0xc9, 0x88, 0x86, 0x28, 0x52, 0xe3, 0x64,
1724cf748f3Sjsing 0x5e, 0xf9, 0x28, 0x53, 0x8a, 0x3a, 0x92, 0x92,
1734cf748f3Sjsing 0x40, 0x8c, 0x89, 0x17, 0x59, 0xd0, 0xd0, 0x82,
1744cf748f3Sjsing },
1754cf748f3Sjsing .export_len = 64,
1764cf748f3Sjsing },
1774cf748f3Sjsing {
1784cf748f3Sjsing /* Valid export, zero length context - 32 bytes. */
1794cf748f3Sjsing .tls_version = TLS1_2_VERSION,
1804cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
1814cf748f3Sjsing .label = "EXPERIMENTAL testing",
1824cf748f3Sjsing .label_len = 20,
1834cf748f3Sjsing .context_value_len = 0,
1844cf748f3Sjsing .use_context = 1,
1854cf748f3Sjsing .client_random = {
1864cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1874cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1884cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1894cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1904cf748f3Sjsing },
1914cf748f3Sjsing .server_random = {
1924cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1934cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1944cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1954cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1964cf748f3Sjsing },
1974cf748f3Sjsing .master_key = {
1984cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1994cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2004cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2014cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2024cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
2034cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
2044cf748f3Sjsing },
2054cf748f3Sjsing .export = {
2064cf748f3Sjsing 0xdb, 0xc9, 0xdf, 0x7c, 0x04, 0x39, 0xdd, 0x23,
2074cf748f3Sjsing 0xc3, 0x68, 0xdc, 0xf3, 0x04, 0xcf, 0x4c, 0x4d,
2084cf748f3Sjsing 0x86, 0x5b, 0xe6, 0x48, 0xc5, 0x6d, 0xe5, 0x1e,
2094cf748f3Sjsing 0xea, 0xc5, 0xe4, 0x00, 0x27, 0x72, 0xda, 0xb6,
2104cf748f3Sjsing },
2114cf748f3Sjsing .export_len = 32,
2124cf748f3Sjsing },
2134cf748f3Sjsing {
2144cf748f3Sjsing /* Valid export, zero length context - 32 bytes. */
2154cf748f3Sjsing .tls_version = TLS1_3_VERSION,
2164cf748f3Sjsing .label = "EXPERIMENTAL testing",
2174cf748f3Sjsing .label_len = 20,
2184cf748f3Sjsing .context_value_len = 0,
2194cf748f3Sjsing .use_context = 1,
2204cf748f3Sjsing .shared_key = {
2214cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2224cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2234cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2244cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2254cf748f3Sjsing },
2264cf748f3Sjsing .shared_key_len = 32,
2274cf748f3Sjsing .export = {
2284cf748f3Sjsing 0x69, 0xf4, 0xac, 0xec, 0x80, 0x67, 0xac, 0x5c,
2294cf748f3Sjsing 0xa6, 0x24, 0x47, 0xb1, 0x0f, 0xc8, 0xa1, 0x13,
2304cf748f3Sjsing 0x3b, 0x91, 0x33, 0x82, 0x97, 0x0a, 0xc0, 0xbf,
2314cf748f3Sjsing 0xac, 0x6d, 0x6b, 0x34, 0x20, 0xd3, 0x3a, 0x02,
2324cf748f3Sjsing },
2334cf748f3Sjsing .export_len = 32,
2344cf748f3Sjsing },
2354cf748f3Sjsing {
2364cf748f3Sjsing /* Valid export, with context value - 32 bytes. */
2374cf748f3Sjsing .tls_version = TLS1_2_VERSION,
2384cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
2394cf748f3Sjsing .label = "EXPERIMENTAL testing",
2404cf748f3Sjsing .label_len = 20,
2414cf748f3Sjsing .context_value = {
2424cf748f3Sjsing 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
2434cf748f3Sjsing 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0,
2444cf748f3Sjsing },
2454cf748f3Sjsing .context_value_len = 16,
2464cf748f3Sjsing .use_context = 1,
2474cf748f3Sjsing .client_random = {
2484cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2494cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2504cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2514cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2524cf748f3Sjsing },
2534cf748f3Sjsing .server_random = {
2544cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2554cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2564cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2574cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2584cf748f3Sjsing },
2594cf748f3Sjsing .master_key = {
2604cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2614cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2624cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2634cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2644cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
2654cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
2664cf748f3Sjsing },
2674cf748f3Sjsing .export = {
2684cf748f3Sjsing 0x0e, 0xb4, 0xd1, 0x3a, 0x0e, 0x24, 0xab, 0x0d,
2694cf748f3Sjsing 0x4c, 0x48, 0x35, 0x25, 0xf6, 0x4d, 0xa2, 0x9b,
2704cf748f3Sjsing 0xaa, 0x1d, 0xbc, 0x54, 0x7e, 0xb0, 0x3c, 0x4b,
2714cf748f3Sjsing 0x07, 0x04, 0x9c, 0x7c, 0x06, 0xa7, 0xea, 0x70,
2724cf748f3Sjsing },
2734cf748f3Sjsing .export_len = 32,
2744cf748f3Sjsing },
2754cf748f3Sjsing {
2764cf748f3Sjsing /* Valid export, with context value - 32 bytes. */
2774cf748f3Sjsing .tls_version = TLS1_3_VERSION,
2784cf748f3Sjsing .label = "EXPERIMENTAL testing",
2794cf748f3Sjsing .label_len = 20,
2804cf748f3Sjsing .context_value = {
2814cf748f3Sjsing 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
2824cf748f3Sjsing 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0,
2834cf748f3Sjsing },
2844cf748f3Sjsing .context_value_len = 16,
2854cf748f3Sjsing .use_context = 1,
2864cf748f3Sjsing .shared_key = {
2874cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2884cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2894cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2904cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2914cf748f3Sjsing },
2924cf748f3Sjsing .shared_key_len = 32,
2934cf748f3Sjsing .export = {
2944cf748f3Sjsing 0x34, 0xb8, 0x00, 0x6a, 0xb2, 0x62, 0xab, 0xea,
2954cf748f3Sjsing 0xc7, 0x2b, 0x15, 0xa0, 0x85, 0xda, 0xaa, 0xa5,
2964cf748f3Sjsing 0x12, 0x85, 0xbf, 0x4a, 0xa4, 0x71, 0x42, 0xc8,
2974cf748f3Sjsing 0xd4, 0xa6, 0x66, 0x18, 0xc6, 0xc9, 0x26, 0x6f,
2984cf748f3Sjsing },
2994cf748f3Sjsing .export_len = 32,
3004cf748f3Sjsing },
3014cf748f3Sjsing {
3024cf748f3Sjsing /* Valid export, with different label - 32 bytes. */
3034cf748f3Sjsing .tls_version = TLS1_2_VERSION,
3044cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
3054cf748f3Sjsing .label = "EXPERIMENTAL more testing",
3064cf748f3Sjsing .label_len = 20,
3074cf748f3Sjsing .context_value = {
3084cf748f3Sjsing 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
3094cf748f3Sjsing 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0,
3104cf748f3Sjsing },
3114cf748f3Sjsing .context_value_len = 16,
3124cf748f3Sjsing .use_context = 1,
3134cf748f3Sjsing .client_random = {
3144cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3154cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3164cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3174cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3184cf748f3Sjsing },
3194cf748f3Sjsing .server_random = {
3204cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3214cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3224cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3234cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3244cf748f3Sjsing },
3254cf748f3Sjsing .master_key = {
3264cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3274cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3284cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3294cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3304cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
3314cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
3324cf748f3Sjsing },
3334cf748f3Sjsing .export = {
3344cf748f3Sjsing 0xb0, 0xb6, 0x45, 0xdd, 0x30, 0x76, 0xf0, 0x57,
3354cf748f3Sjsing 0x22, 0x31, 0xbb, 0x8d, 0xe1, 0xf9, 0xe3, 0xed,
3364cf748f3Sjsing 0xae, 0x74, 0x6f, 0x40, 0x94, 0xf6, 0xc2, 0xfc,
3374cf748f3Sjsing 0x21, 0xff, 0xf7, 0x00, 0x86, 0x54, 0xb6, 0x06,
3384cf748f3Sjsing },
3394cf748f3Sjsing .export_len = 32,
3404cf748f3Sjsing },
3414cf748f3Sjsing {
3424cf748f3Sjsing /* Valid export, with different label - 32 bytes. */
3434cf748f3Sjsing .tls_version = TLS1_3_VERSION,
3444cf748f3Sjsing .label = "EXPERIMENTAL more testing",
3454cf748f3Sjsing .label_len = 20,
3464cf748f3Sjsing .context_value = {
3474cf748f3Sjsing 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
3484cf748f3Sjsing 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0,
3494cf748f3Sjsing },
3504cf748f3Sjsing .context_value_len = 16,
3514cf748f3Sjsing .use_context = 1,
3524cf748f3Sjsing .shared_key = {
3534cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3544cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3554cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3564cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3574cf748f3Sjsing },
3584cf748f3Sjsing .shared_key_len = 32,
3594cf748f3Sjsing .export = {
3604cf748f3Sjsing 0x18, 0x4e, 0x65, 0x3c, 0x91, 0x5d, 0x6a, 0xc3,
3614cf748f3Sjsing 0x25, 0x38, 0xbe, 0x6e, 0xca, 0x12, 0x54, 0x76,
3624cf748f3Sjsing 0x5a, 0x84, 0xf7, 0x19, 0x44, 0x78, 0xec, 0xc0,
3634cf748f3Sjsing 0x83, 0xf6, 0x22, 0xb8, 0x86, 0x31, 0xe9, 0x2e,
3644cf748f3Sjsing },
3654cf748f3Sjsing .export_len = 32,
3664cf748f3Sjsing },
3674cf748f3Sjsing {
3684cf748f3Sjsing /* Invalid - illegal label. */
3694cf748f3Sjsing .tls_version = TLS1_2_VERSION,
3704cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
3714cf748f3Sjsing .label = TLS_MD_CLIENT_FINISH_CONST,
3724cf748f3Sjsing .label_len = TLS_MD_CLIENT_FINISH_CONST_SIZE,
3734cf748f3Sjsing .use_context = 0,
3744cf748f3Sjsing .client_random = {
3754cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3764cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3774cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3784cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3794cf748f3Sjsing },
3804cf748f3Sjsing .server_random = {
3814cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3824cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3834cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3844cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3854cf748f3Sjsing },
3864cf748f3Sjsing .master_key = {
3874cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3884cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3894cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3904cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3914cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
3924cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
3934cf748f3Sjsing },
3944cf748f3Sjsing .export_len = 32,
3954cf748f3Sjsing .want_error = SSL_R_TLS_ILLEGAL_EXPORTER_LABEL,
3964cf748f3Sjsing },
3974cf748f3Sjsing {
3984cf748f3Sjsing /* Invalid - illegal label. */
3994cf748f3Sjsing .tls_version = TLS1_2_VERSION,
4004cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
4014cf748f3Sjsing .label = TLS_MD_SERVER_FINISH_CONST,
4024cf748f3Sjsing .label_len = TLS_MD_SERVER_FINISH_CONST_SIZE,
4034cf748f3Sjsing .use_context = 0,
4044cf748f3Sjsing .client_random = {
4054cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4064cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4074cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4084cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4094cf748f3Sjsing },
4104cf748f3Sjsing .server_random = {
4114cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4124cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4134cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4144cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4154cf748f3Sjsing },
4164cf748f3Sjsing .master_key = {
4174cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4184cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4194cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4204cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4214cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
4224cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
4234cf748f3Sjsing },
4244cf748f3Sjsing .export_len = 32,
4254cf748f3Sjsing .want_error = SSL_R_TLS_ILLEGAL_EXPORTER_LABEL,
4264cf748f3Sjsing },
4274cf748f3Sjsing {
4284cf748f3Sjsing /* Invalid - illegal label. */
4294cf748f3Sjsing .tls_version = TLS1_2_VERSION,
4304cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
4314cf748f3Sjsing .label = TLS_MD_KEY_EXPANSION_CONST,
4324cf748f3Sjsing .label_len = TLS_MD_KEY_EXPANSION_CONST_SIZE,
4334cf748f3Sjsing .use_context = 0,
4344cf748f3Sjsing .client_random = {
4354cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4364cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4374cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4384cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4394cf748f3Sjsing },
4404cf748f3Sjsing .server_random = {
4414cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4424cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4434cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4444cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4454cf748f3Sjsing },
4464cf748f3Sjsing .master_key = {
4474cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4484cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4494cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4504cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4514cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
4524cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
4534cf748f3Sjsing },
4544cf748f3Sjsing .export_len = 32,
4554cf748f3Sjsing .want_error = SSL_R_TLS_ILLEGAL_EXPORTER_LABEL,
4564cf748f3Sjsing },
4574cf748f3Sjsing {
4584cf748f3Sjsing /* Invalid - illegal label. */
4594cf748f3Sjsing .tls_version = TLS1_2_VERSION,
4604cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
4614cf748f3Sjsing .label = TLS_MD_MASTER_SECRET_CONST,
4624cf748f3Sjsing .label_len = TLS_MD_MASTER_SECRET_CONST_SIZE,
4634cf748f3Sjsing .use_context = 0,
4644cf748f3Sjsing .client_random = {
4654cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4664cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4674cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4684cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4694cf748f3Sjsing },
4704cf748f3Sjsing .server_random = {
4714cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4724cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4734cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4744cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4754cf748f3Sjsing },
4764cf748f3Sjsing .master_key = {
4774cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4784cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4794cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4804cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4814cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
4824cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
4834cf748f3Sjsing },
4844cf748f3Sjsing .export_len = 32,
4854cf748f3Sjsing .want_error = SSL_R_TLS_ILLEGAL_EXPORTER_LABEL,
4864cf748f3Sjsing },
4874cf748f3Sjsing {
4884cf748f3Sjsing /* Invalid - illegal label, split over label and seed. */
4894cf748f3Sjsing .tls_version = TLS1_2_VERSION,
4904cf748f3Sjsing .cipher_id = TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305,
4914cf748f3Sjsing .label = "master ",
4924cf748f3Sjsing .label_len = 7,
4934cf748f3Sjsing .use_context = 0,
4944cf748f3Sjsing .client_random = {
4954cf748f3Sjsing 's', 'e', 'c', 'r', 'e', 't', 0x06, 0x07,
4964cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4974cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4984cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
4994cf748f3Sjsing },
5004cf748f3Sjsing .server_random = {
5014cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5024cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5034cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
5044cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
5054cf748f3Sjsing },
5064cf748f3Sjsing .master_key = {
5074cf748f3Sjsing 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5084cf748f3Sjsing 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5094cf748f3Sjsing 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
5104cf748f3Sjsing 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
5114cf748f3Sjsing 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
5124cf748f3Sjsing 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
5134cf748f3Sjsing },
5144cf748f3Sjsing .export = {
5154cf748f3Sjsing 0x40, 0x70, 0xba, 0xfa, 0xba, 0x44, 0x74, 0x93,
5164cf748f3Sjsing 0xa2, 0x43, 0x18, 0x07, 0xa4, 0x4f, 0x3f, 0xda,
5174cf748f3Sjsing 0x88, 0x7b, 0x0e, 0x79, 0x70, 0xcf, 0xdb, 0x91,
5184cf748f3Sjsing 0xfc, 0x3f, 0x96, 0x78, 0x6b, 0x50, 0xe3, 0xa6,
5194cf748f3Sjsing },
5204cf748f3Sjsing .export_len = 32,
5214cf748f3Sjsing .want_error = SSL_R_TLS_ILLEGAL_EXPORTER_LABEL,
5224cf748f3Sjsing },
5234cf748f3Sjsing };
5244cf748f3Sjsing
5254cf748f3Sjsing #define N_EXPORTER_TESTS (sizeof(exporter_tests) / sizeof(exporter_tests[0]))
5264cf748f3Sjsing
5274cf748f3Sjsing static int
exporter_test(size_t test_no,const struct exporter_test * et)5284cf748f3Sjsing exporter_test(size_t test_no, const struct exporter_test *et)
5294cf748f3Sjsing {
5304cf748f3Sjsing struct tls13_secret tls13_context = { .data = "", .len = 0 };
5314cf748f3Sjsing struct tls13_ctx *tls13_ctx;
5324cf748f3Sjsing struct tls13_secrets *tls13_secrets;
5334cf748f3Sjsing SSL_SESSION *ssl_session = NULL;
5344cf748f3Sjsing SSL_CTX *ssl_ctx = NULL;
5354cf748f3Sjsing SSL *ssl = NULL;
5364cf748f3Sjsing uint8_t export[256];
537*bbf5c0e5Stb unsigned char id[2];
5384cf748f3Sjsing int err, ret;
5394cf748f3Sjsing int failed = 1;
5404cf748f3Sjsing
5414cf748f3Sjsing memset(export, 0, sizeof(export));
5424cf748f3Sjsing
5434cf748f3Sjsing if ((ssl_ctx = SSL_CTX_new(TLS_method())) == NULL) {
5444cf748f3Sjsing fprintf(stderr, "FAIL: SSL_CTX_new\n");
5454cf748f3Sjsing goto failure;
5464cf748f3Sjsing }
5474cf748f3Sjsing if ((ssl = SSL_new(ssl_ctx)) == NULL) {
5484cf748f3Sjsing fprintf(stderr, "FAIL: SSL_new\n");
5494cf748f3Sjsing goto failure;
5504cf748f3Sjsing }
5514cf748f3Sjsing if ((ssl_session = SSL_SESSION_new()) == NULL) {
5524cf748f3Sjsing fprintf(stderr, "FAIL: SSL_SESSION_new\n");
5534cf748f3Sjsing goto failure;
5544cf748f3Sjsing }
5554cf748f3Sjsing
5564cf748f3Sjsing ssl_session->ssl_version = et->tls_version;
5574cf748f3Sjsing
5584cf748f3Sjsing if (!SSL_set_session(ssl, ssl_session)) {
5594cf748f3Sjsing fprintf(stderr, "FAIL: SSL_set_session\n");
5604cf748f3Sjsing goto failure;
5614cf748f3Sjsing }
5624cf748f3Sjsing
5634cf748f3Sjsing memcpy(ssl_session->master_key, et->master_key,
5644cf748f3Sjsing sizeof(ssl_session->master_key));
5654cf748f3Sjsing memcpy(ssl->s3->client_random, et->client_random,
5664cf748f3Sjsing sizeof(ssl->s3->client_random));
5674cf748f3Sjsing memcpy(ssl->s3->server_random, et->server_random,
5684cf748f3Sjsing sizeof(ssl->s3->server_random));
5694cf748f3Sjsing
5704cf748f3Sjsing if (et->tls_version >= TLS1_3_VERSION) {
5714cf748f3Sjsing if ((tls13_ctx = tls13_ctx_new(TLS13_HS_CLIENT, ssl)) == NULL) {
5724cf748f3Sjsing fprintf(stderr, "FAIL: tls13_ctx_new\n");
5734cf748f3Sjsing goto failure;
5744cf748f3Sjsing }
5754cf748f3Sjsing ssl->tls13 = tls13_ctx;
5764cf748f3Sjsing
5774cf748f3Sjsing if ((tls13_secrets = tls13_secrets_create(EVP_sha384(),
5784cf748f3Sjsing 0)) == NULL) {
5794cf748f3Sjsing fprintf(stderr, "FAIL: tls13_secrets_create\n");
5804cf748f3Sjsing goto failure;
5814cf748f3Sjsing }
5824cf748f3Sjsing ssl->s3->hs.tls13.secrets = tls13_secrets;
5834cf748f3Sjsing
5844cf748f3Sjsing if (!tls13_derive_early_secrets(tls13_secrets,
5854cf748f3Sjsing tls13_secrets->zeros.data, tls13_secrets->zeros.len,
5864cf748f3Sjsing &tls13_context)) {
5874cf748f3Sjsing fprintf(stderr, "FAIL: tls13_derive_early_secrets\n");
5884cf748f3Sjsing goto failure;
5894cf748f3Sjsing }
5904cf748f3Sjsing if (!tls13_derive_handshake_secrets(tls13_secrets, et->shared_key,
5914cf748f3Sjsing et->shared_key_len, &tls13_context)) {
5924cf748f3Sjsing fprintf(stderr, "FAIL: tls13_derive_handshake_secrets\n");
5934cf748f3Sjsing goto failure;
5944cf748f3Sjsing }
5954cf748f3Sjsing if (!tls13_derive_application_secrets(tls13_secrets,
5964cf748f3Sjsing &tls13_context)) {
5974cf748f3Sjsing fprintf(stderr, "FAIL: tls13_derive_early_secrets\n");
5984cf748f3Sjsing goto failure;
5994cf748f3Sjsing }
6004cf748f3Sjsing
6014cf748f3Sjsing tls13_ctx->handshake_completed = 1;
6024cf748f3Sjsing }
6034cf748f3Sjsing
6044cf748f3Sjsing ssl->s3->hs.state = SSL_ST_OK;
6054cf748f3Sjsing ssl->s3->hs.negotiated_tls_version = et->tls_version;
606*bbf5c0e5Stb id[0] = (et->cipher_id >> 8) & 0xff;
607*bbf5c0e5Stb id[1] = et->cipher_id & 0xff;
608*bbf5c0e5Stb ssl->s3->hs.cipher = SSL_CIPHER_find(ssl, id);
6094cf748f3Sjsing
6104cf748f3Sjsing ret = SSL_export_keying_material(ssl, export, et->export_len, et->label,
6114cf748f3Sjsing et->label_len, et->context_value, et->context_value_len,
6124cf748f3Sjsing et->use_context);
6134cf748f3Sjsing
6144cf748f3Sjsing if (et->want_error != 0) {
6154cf748f3Sjsing if (ret) {
6164cf748f3Sjsing fprintf(stderr, "FAIL: test %zu - "
6174cf748f3Sjsing "SSL_export_keying_material() succeeded, want "
6184cf748f3Sjsing "error\n", test_no);
6194cf748f3Sjsing goto failure;
6204cf748f3Sjsing }
6214cf748f3Sjsing
6224cf748f3Sjsing err = ERR_peek_error();
6234cf748f3Sjsing if (ERR_GET_REASON(err) != et->want_error) {
6244cf748f3Sjsing fprintf(stderr, "FAIL: %zu - got error reason %d, "
6254cf748f3Sjsing "want %d\n", test_no, ERR_GET_REASON(err),
6264cf748f3Sjsing et->want_error);
6274cf748f3Sjsing goto failure;
6284cf748f3Sjsing }
6294cf748f3Sjsing } else {
6304cf748f3Sjsing if (!ret) {
6314cf748f3Sjsing fprintf(stderr, "FAIL: test %zu - "
6324cf748f3Sjsing "SSL_export_keying_material() failed\n", test_no);
6334cf748f3Sjsing ERR_print_errors_fp(stderr);
6344cf748f3Sjsing goto failure;
6354cf748f3Sjsing }
6364cf748f3Sjsing
6374cf748f3Sjsing if (memcmp(et->export, export, et->export_len) != 0) {
6384cf748f3Sjsing fprintf(stderr, "FAIL: test %zu\n", test_no);
6394cf748f3Sjsing fprintf(stderr, "Got export:\n");
6404cf748f3Sjsing hexdump(export, et->export_len);
6414cf748f3Sjsing fprintf(stderr, "Want export:\n");
6424cf748f3Sjsing hexdump(et->export, et->export_len);
6434cf748f3Sjsing goto failure;
6444cf748f3Sjsing }
6454cf748f3Sjsing }
6464cf748f3Sjsing
6474cf748f3Sjsing failed = 0;
6484cf748f3Sjsing
6494cf748f3Sjsing failure:
6504cf748f3Sjsing SSL_SESSION_free(ssl_session);
6514cf748f3Sjsing SSL_CTX_free(ssl_ctx);
6524cf748f3Sjsing SSL_free(ssl);
6534cf748f3Sjsing
6544cf748f3Sjsing return failed;
6554cf748f3Sjsing }
6564cf748f3Sjsing
6574cf748f3Sjsing int
main(int argc,char ** argv)6584cf748f3Sjsing main(int argc, char **argv)
6594cf748f3Sjsing {
6604cf748f3Sjsing int failed = 0;
6614cf748f3Sjsing size_t i;
6624cf748f3Sjsing
6634cf748f3Sjsing for (i = 0; i < N_EXPORTER_TESTS; i++)
6644cf748f3Sjsing failed |= exporter_test(i, &exporter_tests[i]);
6654cf748f3Sjsing
6664cf748f3Sjsing return (failed);
6674cf748f3Sjsing }
668