Commit 36e8c398 authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Add conditional unit testing interface.



Don't call internal functions directly call them through
SSL_test_functions(). This also makes unit testing work on
Windows and platforms that don't export internal functions
from shared libraries.

By default unit testing is not enabled: it requires the compile
time option "enable-unit-test".
Reviewed-by: default avatarGeoff Thorpe <geoff@openssl.org>
(cherry picked from commit e0fc7961)

Conflicts:

	ssl/Makefile
	util/mkdef.pl
parent e3f009c5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -720,6 +720,7 @@ my %disabled = ( # "what" => "comment" [or special keyword "experimental
		 "sctp"       => "default",
		 "shared"         => "default",
		 "store"	  => "experimental",
		 "unit-test"	  => "default",
		 "zlib"           => "default",
		 "zlib-dynamic"   => "default"
	       );
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ LIBSRC= \
	ssl_lib.c ssl_err2.c ssl_cert.c ssl_sess.c \
	ssl_ciph.c ssl_stat.c ssl_rsa.c \
	ssl_asn1.c ssl_txt.c ssl_algs.c \
	bio_ssl.c ssl_err.c kssl.c tls_srp.c t1_reneg.c
	bio_ssl.c ssl_err.c kssl.c tls_srp.c t1_reneg.c ssl_utst.c
LIBOBJ= \
	s2_meth.o  s2_srvr.o  s2_clnt.o  s2_lib.o  s2_enc.o s2_pkt.o \
	s3_meth.o  s3_srvr.o  s3_clnt.o  s3_lib.o  s3_enc.o s3_pkt.o s3_both.o s3_cbc.o \
@@ -41,7 +41,7 @@ LIBOBJ= \
	ssl_lib.o ssl_err2.o ssl_cert.o ssl_sess.o \
	ssl_ciph.o ssl_stat.o ssl_rsa.o \
	ssl_asn1.o ssl_txt.o ssl_algs.o \
	bio_ssl.o ssl_err.o kssl.o tls_srp.o t1_reneg.o
	bio_ssl.o ssl_err.o kssl.o tls_srp.o t1_reneg.o ssl_utst.o

SRC= $(LIBSRC)

+4 −1
Original line number Diff line number Diff line
@@ -38,14 +38,17 @@
 * http://mike-bland.com/tags/heartbleed.html
 */

#define OPENSSL_UNIT_TEST

#include "../test/testutil.h"

#include "../ssl/ssl_locl.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if !defined(OPENSSL_NO_HEARTBEATS) && !defined(OPENSSL_SYS_WINDOWS)
#if !defined(OPENSSL_NO_HEARTBEATS) && !defined(OPENSSL_NO_UNIT_TEST)

/* As per https://tools.ietf.org/html/rfc6520#section-4 */
#define MIN_PADDING_SIZE	16
+4 −0
Original line number Diff line number Diff line
@@ -2056,6 +2056,10 @@ int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secre
void SSL_set_debug(SSL *s, int debug);
int SSL_cache_hit(SSL *s);

#ifndef OPENSSL_NO_UNIT_TEST
const struct openssl_ssl_test_functions *SSL_test_functions(void);
#endif

/* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes
 * made after this point may be overwritten when the script is next run.
+17 −0
Original line number Diff line number Diff line
@@ -810,6 +810,16 @@ const SSL_METHOD *func_name(void) \
	return &func_name##_data; \
	}

struct openssl_ssl_test_functions
	{
	int (*p_ssl_init_wbio_buffer)(SSL *s, int push);
	int (*p_ssl3_setup_buffers)(SSL *s);
	int (*p_tls1_process_heartbeat)(SSL *s);
	int (*p_dtls1_process_heartbeat)(SSL *s);
	};

#ifndef OPENSSL_UNIT_TEST

void ssl_clear_cipher_ctx(SSL *s);
int ssl_clear_bad_session(SSL *s);
CERT *ssl_cert_new(void);
@@ -1174,5 +1184,12 @@ void ssl3_cbc_digest_record(
void tls_fips_digest_extra(
	const EVP_CIPHER_CTX *cipher_ctx, EVP_MD_CTX *mac_ctx,
	const unsigned char *data, size_t data_len, size_t orig_len);
#else

#define ssl_init_wbio_buffer SSL_test_functions()->p_ssl_init_wbio_buffer
#define ssl3_setup_buffers SSL_test_functions()->p_ssl3_setup_buffers
#define tls1_process_heartbeat SSL_test_functions()->p_tls1_process_heartbeat
#define dtls1_process_heartbeat SSL_test_functions()->p_dtls1_process_heartbeat

#endif
#endif
Loading