2 * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 #include <openssl/opensslconf.h>
13 #include <openssl/bio.h>
14 #include <openssl/crypto.h>
15 #include <openssl/evp.h>
16 #include <openssl/ssl.h>
17 #include <openssl/err.h>
19 #include "../ssl/packet_locl.h"
21 #define CLIENT_VERSION_LEN 2
24 #define TOTAL_NUM_TESTS 1
27 * Test that explicitly setting ticket data results in it appearing in the
28 * ClientHello for a negotiated SSL/TLS version
30 #define TEST_SET_SESSION_TICK_DATA_VER_NEG 0
32 int main(int argc, char *argv[])
41 PACKET pkt, pkt2, pkt3;
42 char *dummytick = "Hello World!";
47 err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
49 CRYPTO_set_mem_debug(1);
50 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
53 * For each test set up an SSL_CTX and SSL and see what ClientHello gets
54 * produced when we try to connect
56 for (; currtest < TOTAL_NUM_TESTS; currtest++) {
58 ctx = SSL_CTX_new(TLS_method());
60 /* Testing for session tickets <= TLS1.2; not relevant for 1.3 */
61 if (ctx == NULL || !SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION))
68 rbio = BIO_new(BIO_s_mem());
69 wbio = BIO_new(BIO_s_mem());
70 if (rbio == NULL || wbio == NULL) {
76 SSL_set_bio(con, rbio, wbio);
77 SSL_set_connect_state(con);
79 if (currtest == TEST_SET_SESSION_TICK_DATA_VER_NEG) {
80 if (!SSL_set_session_ticket_ext(con, dummytick, strlen(dummytick)))
84 if (SSL_connect(con) > 0) {
85 /* This shouldn't succeed because we don't have a server! */
89 len = BIO_get_mem_data(wbio, (char **)&data);
90 if (!PACKET_buf_init(&pkt, data, len))
93 /* Skip the record header */
94 if (!PACKET_forward(&pkt, SSL3_RT_HEADER_LENGTH))
97 /* Skip the handshake message header */
98 if (!PACKET_forward(&pkt, SSL3_HM_HEADER_LENGTH))
101 /* Skip client version and random */
102 if (!PACKET_forward(&pkt, CLIENT_VERSION_LEN + SSL3_RANDOM_SIZE))
105 /* Skip session id */
106 if (!PACKET_get_length_prefixed_1(&pkt, &pkt2))
110 if (!PACKET_get_length_prefixed_2(&pkt, &pkt2))
113 /* Skip compression */
114 if (!PACKET_get_length_prefixed_1(&pkt, &pkt2))
118 if (!PACKET_as_length_prefixed_2(&pkt, &pkt2))
121 /* Loop through all extensions */
122 while (PACKET_remaining(&pkt2)) {
124 if (!PACKET_get_net_2(&pkt2, &type) ||
125 !PACKET_get_length_prefixed_2(&pkt2, &pkt3))
128 if (type == TLSEXT_TYPE_session_ticket) {
129 if (currtest == TEST_SET_SESSION_TICK_DATA_VER_NEG) {
130 if (PACKET_equal(&pkt3, dummytick, strlen(dummytick))) {
131 /* Ticket data is as we expected */
134 printf("Received session ticket is not as expected\n");
146 printf("ClientHello test: FAILED (Test %d)\n", currtest);
151 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
152 if (CRYPTO_mem_leaks(err) <= 0)
157 return testresult?0:1;