2 * Copyright 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
10 #include <openssl/opensslconf.h>
11 #include <openssl/bio.h>
12 #include <openssl/crypto.h>
13 #include <openssl/ssl.h>
15 #include "ssltestlib.h"
18 static char *cert = NULL;
19 static char *privkey = NULL;
21 static int test_tlsext_status_type(void)
27 /* Test tlsext_status_type */
28 ctx = SSL_CTX_new(TLS_method());
30 if (SSL_CTX_get_tlsext_status_type(ctx) != -1) {
31 printf("Unexpected initial value for "
32 "SSL_CTX_get_tlsext_status_type()\n");
38 if (SSL_get_tlsext_status_type(con) != -1) {
39 printf("Unexpected initial value for SSL_get_tlsext_status_type()\n");
43 if (!SSL_set_tlsext_status_type(con, TLSEXT_STATUSTYPE_ocsp)) {
44 printf("Unexpected fail for SSL_set_tlsext_status_type()\n");
48 if (SSL_get_tlsext_status_type(con) != TLSEXT_STATUSTYPE_ocsp) {
49 printf("Unexpected result for SSL_get_tlsext_status_type()\n");
56 if (!SSL_CTX_set_tlsext_status_type(ctx, TLSEXT_STATUSTYPE_ocsp)) {
57 printf("Unexpected fail for SSL_CTX_set_tlsext_status_type()\n");
61 if (SSL_CTX_get_tlsext_status_type(ctx) != TLSEXT_STATUSTYPE_ocsp) {
62 printf("Unexpected result for SSL_CTX_get_tlsext_status_type()\n");
68 if (SSL_get_tlsext_status_type(con) != TLSEXT_STATUSTYPE_ocsp) {
69 printf("Unexpected result for SSL_get_tlsext_status_type() (test 2)\n");
82 static int test_session(void)
84 SSL_CTX *sctx = NULL, *cctx = NULL;
85 SSL *serverssl1 = NULL, *clientssl1 = NULL;
86 SSL *serverssl2 = NULL, *clientssl2 = NULL;
87 SSL_SESSION *sess1 = NULL, *sess2 = NULL;
90 if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,
91 &cctx, cert, privkey)) {
92 printf("Unable to create SSL_CTX pair\n");
96 /* Turn on client session cache */
97 SSL_CTX_set_session_cache_mode(cctx, SSL_SESS_CACHE_CLIENT);
99 if (!create_ssl_connection(sctx, cctx, &serverssl1, &clientssl1, NULL,
101 printf("Unable to create SSL connection\n");
105 sess1 = SSL_get1_session(clientssl1);
107 printf("Unexpected NULL session\n");
111 if (SSL_CTX_add_session(cctx, sess1)) {
112 /* Should have failed because it should already be in the cache */
113 printf("Unexpected success adding session to cache\n");
117 if (!create_ssl_connection(sctx, cctx, &serverssl2, &clientssl2, NULL,
119 printf("Unable to create second SSL connection\n");
123 sess2 = SSL_get1_session(clientssl2);
125 printf("Unexpected NULL session from clientssl2\n");
130 * This should clear sess2 from the cache because it is a "bad" session. See
131 * SSL_set_session() documentation.
133 if (!SSL_set_session(clientssl2, sess1)) {
134 printf("Unexpected failure setting session\n");
138 if (SSL_get_session(clientssl2) != sess1) {
139 printf("Unexpected session found\n");
143 if (!SSL_CTX_add_session(cctx, sess2)) {
145 * Should have succeeded because it should not already be in the cache
147 printf("Unexpected failure adding session to cache\n");
151 if (!SSL_CTX_remove_session(cctx, sess2)) {
152 printf("Unexpected failure removing session from cache\n");
156 if (SSL_CTX_remove_session(cctx, sess2)) {
157 printf("Unexpected success removing session from cache\n");
163 SSL_free(serverssl1);
164 SSL_free(clientssl1);
165 SSL_free(serverssl2);
166 SSL_free(clientssl2);
167 SSL_SESSION_free(sess1);
168 SSL_SESSION_free(sess2);
175 int main(int argc, char *argv[])
181 printf("Invalid argument count\n");
188 err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
190 CRYPTO_set_mem_debug(1);
191 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
193 ADD_TEST(test_tlsext_status_type);
194 ADD_TEST(test_session);
196 testresult = run_tests(argv[0]);
198 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
199 if (CRYPTO_mem_leaks(err) <= 0)