ssl_test_ctx.h 8.6 KB

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