summaryrefslogtreecommitdiff
path: root/src/lib/libssl/dtls_locl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/dtls_locl.h')
-rw-r--r--src/lib/libssl/dtls_locl.h251
1 files changed, 251 insertions, 0 deletions
diff --git a/src/lib/libssl/dtls_locl.h b/src/lib/libssl/dtls_locl.h
new file mode 100644
index 0000000000..9bf1fe6661
--- /dev/null
+++ b/src/lib/libssl/dtls_locl.h
@@ -0,0 +1,251 @@
1/* $OpenBSD: dtls_locl.h,v 1.1 2021/05/16 13:56:30 jsing Exp $ */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#ifndef HEADER_DTLS_LOCL_H
61#define HEADER_DTLS_LOCL_H
62
63#include <sys/time.h>
64
65#include <openssl/dtls1.h>
66
67#include "ssl_locl.h"
68
69__BEGIN_HIDDEN_DECLS
70
71typedef struct dtls1_bitmap_st {
72 unsigned long map; /* track 32 packets on 32-bit systems
73 and 64 - on 64-bit systems */
74 unsigned char max_seq_num[8]; /* max record number seen so far,
75 64-bit value in big-endian
76 encoding */
77} DTLS1_BITMAP;
78
79struct dtls1_retransmit_state {
80 EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
81 EVP_MD_CTX *write_hash; /* used for mac generation */
82 SSL_SESSION *session;
83 unsigned short epoch;
84};
85
86struct hm_header_st {
87 unsigned char type;
88 unsigned long msg_len;
89 unsigned short seq;
90 unsigned long frag_off;
91 unsigned long frag_len;
92 unsigned int is_ccs;
93 struct dtls1_retransmit_state saved_retransmit_state;
94};
95
96struct ccs_header_st {
97 unsigned char type;
98 unsigned short seq;
99};
100
101struct dtls1_timeout_st {
102 /* Number of read timeouts so far */
103 unsigned int read_timeouts;
104
105 /* Number of write timeouts so far */
106 unsigned int write_timeouts;
107
108 /* Number of alerts received so far */
109 unsigned int num_alerts;
110};
111
112struct _pqueue;
113
114typedef struct record_pqueue_st {
115 unsigned short epoch;
116 struct _pqueue *q;
117} record_pqueue;
118
119typedef struct hm_fragment_st {
120 struct hm_header_st msg_header;
121 unsigned char *fragment;
122 unsigned char *reassembly;
123} hm_fragment;
124
125typedef struct dtls1_record_data_internal_st {
126 unsigned char *packet;
127 unsigned int packet_length;
128 SSL3_BUFFER_INTERNAL rbuf;
129 SSL3_RECORD_INTERNAL rrec;
130} DTLS1_RECORD_DATA_INTERNAL;
131
132struct dtls1_state_internal_st;
133
134typedef struct dtls1_state_internal_st {
135 unsigned int send_cookie;
136 unsigned char cookie[DTLS1_COOKIE_LENGTH];
137 unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH];
138 unsigned int cookie_len;
139
140 /*
141 * The current data and handshake epoch. This is initially
142 * undefined, and starts at zero once the initial handshake is
143 * completed
144 */
145 unsigned short r_epoch;
146
147 /* records being received in the current epoch */
148 DTLS1_BITMAP bitmap;
149
150 /* renegotiation starts a new set of sequence numbers */
151 DTLS1_BITMAP next_bitmap;
152
153 /* handshake message numbers */
154 unsigned short handshake_write_seq;
155 unsigned short next_handshake_write_seq;
156
157 unsigned short handshake_read_seq;
158
159 /* Received handshake records (processed and unprocessed) */
160 record_pqueue unprocessed_rcds;
161 record_pqueue processed_rcds;
162
163 /* Buffered handshake messages */
164 struct _pqueue *buffered_messages;
165
166 /* Buffered application records.
167 * Only for records between CCS and Finished
168 * to prevent either protocol violation or
169 * unnecessary message loss.
170 */
171 record_pqueue buffered_app_data;
172
173 /* Is set when listening for new connections with dtls1_listen() */
174 unsigned int listen;
175
176 unsigned int mtu; /* max DTLS packet size */
177
178 struct hm_header_st w_msg_hdr;
179 struct hm_header_st r_msg_hdr;
180
181 struct dtls1_timeout_st timeout;
182
183 /* storage for Alert/Handshake protocol data received but not
184 * yet processed by ssl3_read_bytes: */
185 unsigned char alert_fragment[DTLS1_AL_HEADER_LENGTH];
186 unsigned int alert_fragment_len;
187 unsigned char handshake_fragment[DTLS1_HM_HEADER_LENGTH];
188 unsigned int handshake_fragment_len;
189
190 unsigned int retransmitting;
191 unsigned int change_cipher_spec_ok;
192} DTLS1_STATE_INTERNAL;
193#define D1I(s) (s->d1->internal)
194
195typedef struct dtls1_state_st {
196 /* Buffered (sent) handshake records */
197 struct _pqueue *sent_messages;
198
199 /* Indicates when the last handshake msg or heartbeat sent will timeout */
200 struct timeval next_timeout;
201
202 /* Timeout duration */
203 unsigned short timeout_duration;
204
205 struct dtls1_state_internal_st *internal;
206} DTLS1_STATE;
207
208int dtls1_do_write(SSL *s, int type);
209int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
210void dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len,
211 unsigned long frag_off, unsigned long frag_len);
212void dtls1_set_message_header_int(SSL *s, unsigned char mt,
213 unsigned long len, unsigned short seq_num, unsigned long frag_off,
214 unsigned long frag_len);
215
216int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf, int len);
217int dtls1_write_bytes(SSL *s, int type, const void *buf, int len);
218
219int dtls1_read_failed(SSL *s, int code);
220int dtls1_buffer_message(SSL *s, int ccs);
221int dtls1_retransmit_message(SSL *s, unsigned short seq,
222 unsigned long frag_off, int *found);
223int dtls1_get_queue_priority(unsigned short seq, int is_ccs);
224int dtls1_retransmit_buffered_messages(SSL *s);
225void dtls1_clear_record_buffer(SSL *s);
226int dtls1_get_message_header(unsigned char *data,
227 struct hm_header_st *msg_hdr);
228void dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr);
229void dtls1_reset_read_seq_numbers(SSL *s);
230struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft);
231int dtls1_check_timeout_num(SSL *s);
232int dtls1_handle_timeout(SSL *s);
233const SSL_CIPHER *dtls1_get_cipher(unsigned int u);
234void dtls1_start_timer(SSL *s);
235void dtls1_stop_timer(SSL *s);
236int dtls1_is_timer_expired(SSL *s);
237void dtls1_double_timeout(SSL *s);
238unsigned int dtls1_min_mtu(void);
239
240int dtls1_new(SSL *s);
241void dtls1_free(SSL *s);
242void dtls1_clear(SSL *s);
243long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg);
244
245long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
246int dtls1_get_record(SSL *s);
247int dtls1_dispatch_alert(SSL *s);
248
249__END_HIDDEN_DECLS
250
251#endif