1 /* 2 * Copyright 2016-2025 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the Apache License 2.0 (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 8 */ 9 10 #ifndef OSSL_TEST_SSLTESTLIB_H 11 # define OSSL_TEST_SSLTESTLIB_H 12 13 # include <openssl/ssl.h> 14 15 #define TLS13_AES_128_GCM_SHA256_BYTES ((const unsigned char *)"\x13\x01") 16 #define TLS13_AES_256_GCM_SHA384_BYTES ((const unsigned char *)"\x13\x02") 17 #define TLS13_CHACHA20_POLY1305_SHA256_BYTES ((const unsigned char *)"\x13\x03") 18 #define TLS13_AES_128_CCM_SHA256_BYTES ((const unsigned char *)"\x13\x04") 19 #define TLS13_AES_128_CCM_8_SHA256_BYTES ((const unsigned char *)"\x13\05") 20 #define TLS13_SHA256_SHA256_BYTES ((const unsigned char *)"\xC0\xB4") 21 #define TLS13_SHA384_SHA384_BYTES ((const unsigned char *)"\xC0\xB5") 22 23 int create_ssl_ctx_pair(OSSL_LIB_CTX *libctx, const SSL_METHOD *sm, 24 const SSL_METHOD *cm, int min_proto_version, 25 int max_proto_version, SSL_CTX **sctx, SSL_CTX **cctx, 26 char *certfile, char *privkeyfile); 27 int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl, 28 SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio); 29 int create_bare_ssl_connection(SSL *serverssl, SSL *clientssl, int want, 30 int read, int listen); 31 int create_bare_ssl_connection_ex(SSL *serverssl, SSL *clientssl, int want, 32 int read, int listen, int *cm_count, int *sm_count); 33 int create_ssl_objects2(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl, 34 SSL **cssl, int sfd, int cfd); 35 int wait_until_sock_readable(int sock); 36 int create_test_sockets(int *cfdp, int *sfdp, int socktype, BIO_ADDR *saddr); 37 int create_ssl_connection(SSL *serverssl, SSL *clientssl, int want); 38 int create_ssl_connection_ex(SSL *serverssl, SSL *clientssl, int want, 39 int *cm_count, int *sm_count); 40 void shutdown_ssl_connection(SSL *serverssl, SSL *clientssl); 41 42 /* Note: Not thread safe! */ 43 const BIO_METHOD *bio_f_tls_dump_filter(void); 44 void bio_f_tls_dump_filter_free(void); 45 46 const BIO_METHOD *bio_s_mempacket_test(void); 47 void bio_s_mempacket_test_free(void); 48 49 const BIO_METHOD *bio_s_always_retry(void); 50 void bio_s_always_retry_free(void); 51 void set_always_retry_err_val(int err); 52 53 /* 54 * Maybe retry BIO ctrls. We make them large enough to not clash with standard 55 * BIO ctrl codes. 56 */ 57 #define MAYBE_RETRY_CTRL_SET_RETRY_AFTER_CNT (1 << 15) 58 59 const BIO_METHOD *bio_s_maybe_retry(void); 60 void bio_s_maybe_retry_free(void); 61 62 /* Packet types - value 0 is reserved */ 63 #define INJECT_PACKET 1 64 #define INJECT_PACKET_IGNORE_REC_SEQ 2 65 66 /* 67 * Mempacket BIO ctrls. We make them large enough to not clash with standard BIO 68 * ctrl codes. 69 */ 70 #define MEMPACKET_CTRL_SET_DROP_EPOCH (1 << 15) 71 #define MEMPACKET_CTRL_SET_DROP_REC (2 << 15) 72 #define MEMPACKET_CTRL_GET_DROP_REC (3 << 15) 73 #define MEMPACKET_CTRL_SET_DUPLICATE_REC (4 << 15) 74 75 int mempacket_swap_epoch(BIO *bio); 76 int mempacket_move_packet(BIO *bio, int d, int s); 77 int mempacket_dup_last_packet(BIO *bio); 78 int mempacket_test_inject(BIO *bio, const char *in, int inl, int pktnum, 79 int type); 80 81 typedef struct mempacket_st MEMPACKET; 82 83 DEFINE_STACK_OF(MEMPACKET) 84 85 SSL_SESSION *create_a_psk(SSL *ssl, size_t mdsize); 86 87 /* Add cert from `cert_file` multiple times to create large extra cert chain */ 88 int ssl_ctx_add_large_cert_chain(OSSL_LIB_CTX *libctx, SSL_CTX *sctx, 89 const char *cert_file); 90 91 ENGINE *load_dasync(void); 92 93 #endif /* OSSL_TEST_SSLTESTLIB_H */ 94