ssl_test_ctx.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Copyright 2016-2021 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. #ifndef OSSL_TEST_SSL_TEST_CTX_H
  10. #define OSSL_TEST_SSL_TEST_CTX_H
  11. #include <openssl/conf.h>
  12. #include <openssl/ssl.h>
  13. typedef enum {
  14. SSL_TEST_SUCCESS = 0, /* Default */
  15. SSL_TEST_SERVER_FAIL,
  16. SSL_TEST_CLIENT_FAIL,
  17. SSL_TEST_INTERNAL_ERROR,
  18. /* Couldn't test resumption/renegotiation: original handshake failed. */
  19. SSL_TEST_FIRST_HANDSHAKE_FAILED
  20. } ssl_test_result_t;
  21. typedef enum {
  22. SSL_TEST_VERIFY_NONE = 0, /* Default */
  23. SSL_TEST_VERIFY_ACCEPT_ALL,
  24. SSL_TEST_VERIFY_RETRY_ONCE,
  25. SSL_TEST_VERIFY_REJECT_ALL
  26. } ssl_verify_callback_t;
  27. typedef enum {
  28. SSL_TEST_SERVERNAME_NONE = 0, /* Default */
  29. SSL_TEST_SERVERNAME_SERVER1,
  30. SSL_TEST_SERVERNAME_SERVER2,
  31. SSL_TEST_SERVERNAME_INVALID
  32. } ssl_servername_t;
  33. typedef enum {
  34. SSL_TEST_SERVERNAME_CB_NONE = 0, /* Default */
  35. SSL_TEST_SERVERNAME_IGNORE_MISMATCH,
  36. SSL_TEST_SERVERNAME_REJECT_MISMATCH,
  37. SSL_TEST_SERVERNAME_CLIENT_HELLO_IGNORE_MISMATCH,
  38. SSL_TEST_SERVERNAME_CLIENT_HELLO_REJECT_MISMATCH,
  39. SSL_TEST_SERVERNAME_CLIENT_HELLO_NO_V12
  40. } ssl_servername_callback_t;
  41. typedef enum {
  42. SSL_TEST_SESSION_TICKET_IGNORE = 0, /* Default */
  43. SSL_TEST_SESSION_TICKET_YES,
  44. SSL_TEST_SESSION_TICKET_NO,
  45. SSL_TEST_SESSION_TICKET_BROKEN /* Special test */
  46. } ssl_session_ticket_t;
  47. typedef enum {
  48. SSL_TEST_COMPRESSION_NO = 0, /* Default */
  49. SSL_TEST_COMPRESSION_YES
  50. } ssl_compression_t;
  51. typedef enum {
  52. SSL_TEST_SESSION_ID_IGNORE = 0, /* Default */
  53. SSL_TEST_SESSION_ID_YES,
  54. SSL_TEST_SESSION_ID_NO
  55. } ssl_session_id_t;
  56. typedef enum {
  57. SSL_TEST_METHOD_TLS = 0, /* Default */
  58. SSL_TEST_METHOD_DTLS
  59. } ssl_test_method_t;
  60. typedef enum {
  61. SSL_TEST_HANDSHAKE_SIMPLE = 0, /* Default */
  62. SSL_TEST_HANDSHAKE_RESUME,
  63. SSL_TEST_HANDSHAKE_RENEG_SERVER,
  64. SSL_TEST_HANDSHAKE_RENEG_CLIENT,
  65. SSL_TEST_HANDSHAKE_KEY_UPDATE_SERVER,
  66. SSL_TEST_HANDSHAKE_KEY_UPDATE_CLIENT,
  67. SSL_TEST_HANDSHAKE_POST_HANDSHAKE_AUTH
  68. } ssl_handshake_mode_t;
  69. typedef enum {
  70. SSL_TEST_CT_VALIDATION_NONE = 0, /* Default */
  71. SSL_TEST_CT_VALIDATION_PERMISSIVE,
  72. SSL_TEST_CT_VALIDATION_STRICT
  73. } ssl_ct_validation_t;
  74. typedef enum {
  75. SSL_TEST_CERT_STATUS_NONE = 0, /* Default */
  76. SSL_TEST_CERT_STATUS_GOOD_RESPONSE,
  77. SSL_TEST_CERT_STATUS_BAD_RESPONSE
  78. } ssl_cert_status_t;
  79. /*
  80. * Server/client settings that aren't supported by the SSL CONF library,
  81. * such as callbacks.
  82. */
  83. typedef struct {
  84. /* One of a number of predefined custom callbacks. */
  85. ssl_verify_callback_t verify_callback;
  86. /* One of a number of predefined server names use by the client */
  87. ssl_servername_t servername;
  88. /* Maximum Fragment Length extension mode */
  89. int max_fragment_len_mode;
  90. /* Supported NPN and ALPN protocols. A comma-separated list. */
  91. char *npn_protocols;
  92. char *alpn_protocols;
  93. ssl_ct_validation_t ct_validation;
  94. /* Ciphersuites to set on a renegotiation */
  95. char *reneg_ciphers;
  96. char *srp_user;
  97. char *srp_password;
  98. /* PHA enabled */
  99. int enable_pha;
  100. /* Do not send extms on renegotiation */
  101. int no_extms_on_reneg;
  102. } SSL_TEST_CLIENT_CONF;
  103. typedef struct {
  104. /* SNI callback (server-side). */
  105. ssl_servername_callback_t servername_callback;
  106. /* Supported NPN and ALPN protocols. A comma-separated list. */
  107. char *npn_protocols;
  108. char *alpn_protocols;
  109. /* Whether to set a broken session ticket callback. */
  110. int broken_session_ticket;
  111. /* Should we send a CertStatus message? */
  112. ssl_cert_status_t cert_status;
  113. /* An SRP user known to the server. */
  114. char *srp_user;
  115. char *srp_password;
  116. /* Forced PHA */
  117. int force_pha;
  118. char *session_ticket_app_data;
  119. } SSL_TEST_SERVER_CONF;
  120. typedef struct {
  121. SSL_TEST_CLIENT_CONF client;
  122. SSL_TEST_SERVER_CONF server;
  123. SSL_TEST_SERVER_CONF server2;
  124. } SSL_TEST_EXTRA_CONF;
  125. typedef struct {
  126. /*
  127. * Global test configuration. Does not change between handshakes.
  128. */
  129. /* Whether the server/client CTX should use DTLS or TLS. */
  130. ssl_test_method_t method;
  131. /* Whether to test a resumed/renegotiated handshake. */
  132. ssl_handshake_mode_t handshake_mode;
  133. /*
  134. * How much application data to exchange (default is 256 bytes).
  135. * Both peers will send |app_data_size| bytes interleaved.
  136. */
  137. int app_data_size;
  138. /* Maximum send fragment size. */
  139. int max_fragment_size;
  140. /* KeyUpdate type */
  141. int key_update_type;
  142. /*
  143. * Extra server/client configurations. Per-handshake.
  144. */
  145. /* First handshake. */
  146. SSL_TEST_EXTRA_CONF extra;
  147. /* Resumed handshake. */
  148. SSL_TEST_EXTRA_CONF resume_extra;
  149. /*
  150. * Test expectations. These apply to the LAST handshake.
  151. */
  152. /* Defaults to SUCCESS. */
  153. ssl_test_result_t expected_result;
  154. /* Alerts. 0 if no expectation. */
  155. /* See ssl.h for alert codes. */
  156. /* Alert sent by the client / received by the server. */
  157. int expected_client_alert;
  158. /* Alert sent by the server / received by the client. */
  159. int expected_server_alert;
  160. /* Negotiated protocol version. 0 if no expectation. */
  161. /* See ssl.h for protocol versions. */
  162. int expected_protocol;
  163. /*
  164. * The expected SNI context to use.
  165. * We test server-side that the server switched to the expected context.
  166. * Set by the callback upon success, so if the callback wasn't called or
  167. * terminated with an alert, the servername will match with
  168. * SSL_TEST_SERVERNAME_NONE.
  169. * Note: in the event that the servername was accepted, the client should
  170. * also receive an empty SNI extension back but we have no way of probing
  171. * client-side via the API that this was the case.
  172. */
  173. ssl_servername_t expected_servername;
  174. ssl_session_ticket_t session_ticket_expected;
  175. int compression_expected;
  176. /* The expected NPN/ALPN protocol to negotiate. */
  177. char *expected_npn_protocol;
  178. char *expected_alpn_protocol;
  179. /* Whether the second handshake is resumed or a full handshake (boolean). */
  180. int resumption_expected;
  181. /* Expected temporary key type */
  182. int expected_tmp_key_type;
  183. /* Expected server certificate key type */
  184. int expected_server_cert_type;
  185. /* Expected server signing hash */
  186. int expected_server_sign_hash;
  187. /* Expected server signature type */
  188. int expected_server_sign_type;
  189. /* Expected server CA names */
  190. STACK_OF(X509_NAME) *expected_server_ca_names;
  191. /* Expected client certificate key type */
  192. int expected_client_cert_type;
  193. /* Expected client signing hash */
  194. int expected_client_sign_hash;
  195. /* Expected client signature type */
  196. int expected_client_sign_type;
  197. /* Expected CA names for client auth */
  198. STACK_OF(X509_NAME) *expected_client_ca_names;
  199. /* Whether to use SCTP for the transport */
  200. int use_sctp;
  201. /* Enable SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG on client side */
  202. int enable_client_sctp_label_bug;
  203. /* Enable SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG on server side */
  204. int enable_server_sctp_label_bug;
  205. /* Whether to expect a session id from the server */
  206. ssl_session_id_t session_id_expected;
  207. char *expected_cipher;
  208. /* Expected Session Ticket Application Data */
  209. char *expected_session_ticket_app_data;
  210. OSSL_LIB_CTX *libctx;
  211. } SSL_TEST_CTX;
  212. const char *ssl_test_result_name(ssl_test_result_t result);
  213. const char *ssl_alert_name(int alert);
  214. const char *ssl_protocol_name(int protocol);
  215. const char *ssl_verify_callback_name(ssl_verify_callback_t verify_callback);
  216. const char *ssl_servername_name(ssl_servername_t server);
  217. const char *ssl_servername_callback_name(ssl_servername_callback_t
  218. servername_callback);
  219. const char *ssl_session_ticket_name(ssl_session_ticket_t server);
  220. const char *ssl_session_id_name(ssl_session_id_t server);
  221. const char *ssl_test_method_name(ssl_test_method_t method);
  222. const char *ssl_handshake_mode_name(ssl_handshake_mode_t mode);
  223. const char *ssl_ct_validation_name(ssl_ct_validation_t mode);
  224. const char *ssl_certstatus_name(ssl_cert_status_t cert_status);
  225. const char *ssl_max_fragment_len_name(int MFL_mode);
  226. /*
  227. * Load the test case context from |conf|.
  228. * See test/README.ssltest.md for details on the conf file format.
  229. */
  230. SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section,
  231. OSSL_LIB_CTX *libctx);
  232. SSL_TEST_CTX *SSL_TEST_CTX_new(OSSL_LIB_CTX *libctx);
  233. void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx);
  234. #endif /* OSSL_TEST_SSL_TEST_CTX_H */