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>
20 #define CLIENT_VERSION_LEN 2
21 #define SESSION_ID_LEN_LEN 1
22 #define CIPHERS_LEN_LEN 2
23 #define COMPRESSION_LEN_LEN 1
24 #define EXTENSIONS_LEN_LEN 2
25 #define EXTENSION_TYPE_LEN 2
26 #define EXTENSION_SIZE_LEN 2
29 #define TOTAL_NUM_TESTS 1
32 * Test that explicitly setting ticket data results in it appearing in the
33 * ClientHello for a negotiated SSL/TLS version
35 #define TEST_SET_SESSION_TICK_DATA_VER_NEG 0
37 int main(int argc
, char *argv
[])
46 unsigned char *dataend
;
47 char *dummytick
= "Hello World!";
54 err
= BIO_new_fp(stderr
, BIO_NOCLOSE
| BIO_FP_TEXT
);
56 CRYPTO_set_mem_debug(1);
57 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON
);
60 * For each test set up an SSL_CTX and SSL and see what ClientHello gets
61 * produced when we try to connect
63 for (; currtest
< TOTAL_NUM_TESTS
; currtest
++) {
65 ctx
= SSL_CTX_new(TLS_method());
68 rbio
= BIO_new(BIO_s_mem());
69 wbio
= BIO_new(BIO_s_mem());
70 SSL_set_bio(con
, rbio
, wbio
);
71 SSL_set_connect_state(con
);
73 if (currtest
== TEST_SET_SESSION_TICK_DATA_VER_NEG
) {
74 if (!SSL_set_session_ticket_ext(con
, dummytick
, strlen(dummytick
)))
78 if (SSL_connect(con
) > 0) {
79 /* This shouldn't succeed because we don't have a server! */
83 len
= BIO_get_mem_data(wbio
, (char **)&data
);
86 /* Skip the record header */
87 data
+= SSL3_RT_HEADER_LENGTH
;
88 /* Skip the handshake message header */
89 data
+= SSL3_HM_HEADER_LENGTH
;
90 /* Skip client version and random */
91 data
+= CLIENT_VERSION_LEN
+ SSL3_RANDOM_SIZE
;
92 if (data
+ SESSION_ID_LEN_LEN
> dataend
)
96 data
+= SESSION_ID_LEN_LEN
+ tmplen
;
97 if (data
+ CIPHERS_LEN_LEN
> dataend
)
100 tmplen
= ((*data
) << 8) | *(data
+ 1);
101 data
+= CIPHERS_LEN_LEN
+ tmplen
;
102 if (data
+ COMPRESSION_LEN_LEN
> dataend
)
104 /* Skip compression */
106 data
+= COMPRESSION_LEN_LEN
+ tmplen
;
107 if (data
+ EXTENSIONS_LEN_LEN
> dataend
)
110 tmplen
= ((*data
) << 8) | *(data
+ 1);
111 data
+= EXTENSIONS_LEN_LEN
;
112 if (data
+ tmplen
> dataend
)
115 /* Loop through all extensions */
116 while (tmplen
> EXTENSION_TYPE_LEN
+ EXTENSION_SIZE_LEN
) {
117 type
= ((*data
) << 8) | *(data
+ 1);
118 data
+= EXTENSION_TYPE_LEN
;
119 size
= ((*data
) << 8) | *(data
+ 1);
120 data
+= EXTENSION_SIZE_LEN
;
121 if (data
+ size
> dataend
)
124 if (type
== TLSEXT_TYPE_session_ticket
) {
125 if (currtest
== TEST_SET_SESSION_TICK_DATA_VER_NEG
) {
126 if (size
== strlen(dummytick
)
127 && memcmp(data
, dummytick
, size
) == 0) {
128 /* Ticket data is as we expected */
131 printf("Received session ticket is not as expected\n");
137 tmplen
-= EXTENSION_TYPE_LEN
+ EXTENSION_SIZE_LEN
+ size
;
145 printf("ClientHello test: FAILED (Test %d)\n", currtest
);
150 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
151 if (CRYPTO_mem_leaks(err
) <= 0)
156 return testresult
?0:1;