xref: /openssl/test/helpers/ssltestlib.h (revision 7ed6de99)
1 /*
2  * Copyright 2016-2024 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_ssl_objects2(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
32                        SSL **cssl, int sfd, int cfd);
33 int wait_until_sock_readable(int sock);
34 int create_test_sockets(int *cfdp, int *sfdp, int socktype, BIO_ADDR *saddr);
35 int create_ssl_connection(SSL *serverssl, SSL *clientssl, int want);
36 void shutdown_ssl_connection(SSL *serverssl, SSL *clientssl);
37 
38 /* Note: Not thread safe! */
39 const BIO_METHOD *bio_f_tls_dump_filter(void);
40 void bio_f_tls_dump_filter_free(void);
41 
42 const BIO_METHOD *bio_s_mempacket_test(void);
43 void bio_s_mempacket_test_free(void);
44 
45 const BIO_METHOD *bio_s_always_retry(void);
46 void bio_s_always_retry_free(void);
47 void set_always_retry_err_val(int err);
48 
49 /*
50  * Maybe retry BIO ctrls. We make them large enough to not clash with standard
51  * BIO ctrl codes.
52  */
53 #define MAYBE_RETRY_CTRL_SET_RETRY_AFTER_CNT       (1 << 15)
54 
55 const BIO_METHOD *bio_s_maybe_retry(void);
56 void bio_s_maybe_retry_free(void);
57 
58 /* Packet types - value 0 is reserved */
59 #define INJECT_PACKET                   1
60 #define INJECT_PACKET_IGNORE_REC_SEQ    2
61 
62 /*
63  * Mempacket BIO ctrls. We make them large enough to not clash with standard BIO
64  * ctrl codes.
65  */
66 #define MEMPACKET_CTRL_SET_DROP_EPOCH       (1 << 15)
67 #define MEMPACKET_CTRL_SET_DROP_REC         (2 << 15)
68 #define MEMPACKET_CTRL_GET_DROP_REC         (3 << 15)
69 #define MEMPACKET_CTRL_SET_DUPLICATE_REC    (4 << 15)
70 
71 int mempacket_swap_epoch(BIO *bio);
72 int mempacket_move_packet(BIO *bio, int d, int s);
73 int mempacket_test_inject(BIO *bio, const char *in, int inl, int pktnum,
74                           int type);
75 
76 typedef struct mempacket_st MEMPACKET;
77 
78 DEFINE_STACK_OF(MEMPACKET)
79 
80 SSL_SESSION *create_a_psk(SSL *ssl, size_t mdsize);
81 
82 /* Add cert from `cert_file` multiple times to create large extra cert chain */
83 int ssl_ctx_add_large_cert_chain(OSSL_LIB_CTX *libctx, SSL_CTX *sctx,
84                                  const char *cert_file);
85 
86 ENGINE *load_dasync(void);
87 
88 #endif /* OSSL_TEST_SSLTESTLIB_H */
89