]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/internal/statem.h
Implement the QUIC Fault injector support for TLS handshake messages
[thirdparty/openssl.git] / include / internal / statem.h
CommitLineData
846e33c7 1/*
4333b89f 2 * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
8ba708e5 3 *
2c18d164 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
846e33c7
RS
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
8ba708e5
MC
8 */
9
10/*****************************************************************************
11 * *
8483a003 12 * These enums should be considered PRIVATE to the state machine. No *
8ba708e5
MC
13 * non-state machine code should need to use these *
14 * *
15 *****************************************************************************/
16/*
17 * Valid return codes used for functions performing work prior to or after
18 * sending or receiving a message
19 */
be3583fa 20typedef enum {
8ba708e5
MC
21 /* Something went wrong */
22 WORK_ERROR,
23 /* We're done working and there shouldn't be anything else to do after */
24 WORK_FINISHED_STOP,
25 /* We're done working move onto the next thing */
26 WORK_FINISHED_CONTINUE,
27 /* We're working on phase A */
28 WORK_MORE_A,
29 /* We're working on phase B */
ddf97258
BK
30 WORK_MORE_B,
31 /* We're working on phase C */
32 WORK_MORE_C
be3583fa 33} WORK_STATE;
8ba708e5
MC
34
35/* Write transition return codes */
be3583fa 36typedef enum {
8ba708e5
MC
37 /* Something went wrong */
38 WRITE_TRAN_ERROR,
39 /* A transition was successfully completed and we should continue */
40 WRITE_TRAN_CONTINUE,
41 /* There is no more write work to be done */
42 WRITE_TRAN_FINISHED
be3583fa 43} WRITE_TRAN;
8ba708e5 44
8ba708e5 45/* Message flow states */
be3583fa 46typedef enum {
8ba708e5
MC
47 /* No handshake in progress */
48 MSG_FLOW_UNINITED,
49 /* A permanent error with this connection */
50 MSG_FLOW_ERROR,
8ba708e5
MC
51 /* We are reading messages */
52 MSG_FLOW_READING,
53 /* We are writing messages */
54 MSG_FLOW_WRITING,
55 /* Handshake has finished */
56 MSG_FLOW_FINISHED
be3583fa 57} MSG_FLOW_STATE;
8ba708e5
MC
58
59/* Read states */
be3583fa 60typedef enum {
8ba708e5
MC
61 READ_STATE_HEADER,
62 READ_STATE_BODY,
63 READ_STATE_POST_PROCESS
be3583fa 64} READ_STATE;
8ba708e5
MC
65
66/* Write states */
be3583fa 67typedef enum {
8ba708e5
MC
68 WRITE_STATE_TRANSITION,
69 WRITE_STATE_PRE_WORK,
70 WRITE_STATE_SEND,
71 WRITE_STATE_POST_WORK
be3583fa 72} WRITE_STATE;
8ba708e5 73
67ec6d2b
MC
74typedef enum {
75 CON_FUNC_ERROR = 0,
76 CON_FUNC_SUCCESS,
77 CON_FUNC_DONT_SEND
78} CON_FUNC_RETURN;
79
6d1f6933 80typedef int (*ossl_statem_mutate_handshake_cb)(const unsigned char *msgin,
d03fe5de
MC
81 size_t inlen,
82 unsigned char **msgout,
83 size_t *outlen,
84 void *arg);
85
86typedef void (*ossl_statem_finish_mutate_handshake_cb)(void *arg);
87
8ba708e5
MC
88/*****************************************************************************
89 * *
90 * This structure should be considered "opaque" to anything outside of the *
91 * state machine. No non-state machine code should be accessing the members *
92 * of this structure. *
93 * *
94 *****************************************************************************/
95
d6f1a6e9 96struct ossl_statem_st {
be3583fa
MC
97 MSG_FLOW_STATE state;
98 WRITE_STATE write_state;
99 WORK_STATE write_state_work;
100 READ_STATE read_state;
101 WORK_STATE read_state_work;
35bf6e05 102 OSSL_HANDSHAKE_STATE hand_state;
0386aad1
MC
103 /* The handshake state requested by an API call (e.g. HelloRequest) */
104 OSSL_HANDSHAKE_STATE request_state;
8ba708e5
MC
105 int in_init;
106 int read_state_first_init;
024f543c
MC
107 /* true when we are actually in SSL_accept() or SSL_connect() */
108 int in_handshake;
c7f47786
MC
109 /*
110 * True when are processing a "real" handshake that needs cleaning up (not
111 * just a HelloRequest or similar).
112 */
113 int cleanuphand;
a71a4966
MC
114 /* Should we skip the CertificateVerify message? */
115 unsigned int no_cert_verify;
8ba708e5 116 int use_timer;
d03fe5de
MC
117
118 /* Test harness message mutator callbacks */
119 ossl_statem_mutate_handshake_cb mutate_handshake_cb;
120 ossl_statem_finish_mutate_handshake_cb finish_mutate_handshake_cb;
121 void *mutatearg;
122 unsigned int write_in_progress : 1;
8ba708e5 123};
d6f1a6e9 124typedef struct ossl_statem_st OSSL_STATEM;
8ba708e5 125
8ba708e5
MC
126/*****************************************************************************
127 * *
128 * The following macros/functions represent the libssl internal API to the *
129 * state machine. Any libssl code may call these functions/macros *
130 * *
131 *****************************************************************************/
132
d03fe5de
MC
133typedef struct ssl_connection_st SSL_CONNECTION;
134
fe3a3291
MC
135__owur int ossl_statem_accept(SSL *s);
136__owur int ossl_statem_connect(SSL *s);
846975f3 137OSSL_HANDSHAKE_STATE ossl_statem_get_state(SSL_CONNECTION *s);
38b051a1
TM
138void ossl_statem_clear(SSL_CONNECTION *s);
139void ossl_statem_set_renegotiate(SSL_CONNECTION *s);
140void ossl_statem_send_fatal(SSL_CONNECTION *s, int al);
141void ossl_statem_fatal(SSL_CONNECTION *s, int al, int reason,
142 const char *fmt, ...);
5a2d0ef3 143# define SSLfatal_alert(s, al) ossl_statem_send_fatal((s), (al))
e92519b5
RL
144# define SSLfatal(s, al, r) SSLfatal_data((s), (al), (r), NULL)
145# define SSLfatal_data \
146 (ERR_new(), \
147 ERR_set_debug(OPENSSL_FILE, OPENSSL_LINE, OPENSSL_FUNC), \
148 ossl_statem_fatal)
1f359471 149
38b051a1
TM
150int ossl_statem_in_error(const SSL_CONNECTION *s);
151void ossl_statem_set_in_init(SSL_CONNECTION *s, int init);
152int ossl_statem_get_in_handshake(SSL_CONNECTION *s);
153void ossl_statem_set_in_handshake(SSL_CONNECTION *s, int inhand);
154__owur int ossl_statem_skip_early_data(SSL_CONNECTION *s);
155void ossl_statem_check_finish_init(SSL_CONNECTION *s, int send);
156void ossl_statem_set_hello_verify_done(SSL_CONNECTION *s);
157__owur int ossl_statem_app_data_allowed(SSL_CONNECTION *s);
158__owur int ossl_statem_export_allowed(SSL_CONNECTION *s);
159__owur int ossl_statem_export_early_allowed(SSL_CONNECTION *s);
2a8db717
MC
160
161/* Flush the write BIO */
38b051a1 162int statem_flush(SSL_CONNECTION *s);
d03fe5de
MC
163
164int ossl_statem_set_mutator(SSL *s,
165 ossl_statem_mutate_handshake_cb mutate_handshake_cb,
166 ossl_statem_finish_mutate_handshake_cb finish_mutate_handshake_cb,
167 void *mutatearg);