You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

180 rivejä
5.9 KiB

  1. /* ssl/dtls1.h */
  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. #ifndef OPENSSL_HEADER_DTLS1_H
  58. #define OPENSSL_HEADER_DTLS1_H
  59. #include <openssl/base.h>
  60. #include <openssl/buf.h>
  61. #include <openssl/pqueue.h>
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65. #define DTLS1_VERSION 0xFEFF
  66. #define DTLS1_2_VERSION 0xFEFD
  67. /* lengths of messages */
  68. #define DTLS1_COOKIE_LENGTH 256
  69. #define DTLS1_RT_HEADER_LENGTH 13
  70. #define DTLS1_HM_HEADER_LENGTH 12
  71. #define DTLS1_CCS_HEADER_LENGTH 1
  72. #define DTLS1_AL_HEADER_LENGTH 2
  73. typedef struct dtls1_bitmap_st {
  74. /* map is a bit mask of the last 64 sequence numbers. Bit
  75. * |1<<i| corresponds to |max_seq_num - i|. */
  76. uint64_t map;
  77. /* max_seq_num is the largest sequence number seen so far. It
  78. * is a 64-bit value in big-endian encoding. */
  79. uint8_t max_seq_num[8];
  80. } DTLS1_BITMAP;
  81. /* TODO(davidben): This structure is used for both incoming messages and
  82. * outgoing messages. |is_ccs| and |epoch| are only used in the latter and
  83. * should be moved elsewhere. */
  84. struct hm_header_st {
  85. uint8_t type;
  86. uint32_t msg_len;
  87. uint16_t seq;
  88. uint32_t frag_off;
  89. uint32_t frag_len;
  90. int is_ccs;
  91. /* epoch, for buffered outgoing messages, is the epoch the message was
  92. * originally sent in. */
  93. uint16_t epoch;
  94. };
  95. /* TODO(davidben): This structure is used for both incoming messages and
  96. * outgoing messages. |fragment| and |reassembly| are only used in the former
  97. * and should be moved elsewhere. */
  98. typedef struct hm_fragment_st {
  99. struct hm_header_st msg_header;
  100. uint8_t *fragment;
  101. uint8_t *reassembly;
  102. } hm_fragment;
  103. typedef struct dtls1_state_st {
  104. /* send_cookie is true if we are resending the ClientHello
  105. * with a cookie from a HelloVerifyRequest. */
  106. unsigned int send_cookie;
  107. uint8_t cookie[DTLS1_COOKIE_LENGTH];
  108. size_t cookie_len;
  109. /* The current data and handshake epoch. This is initially undefined, and
  110. * starts at zero once the initial handshake is completed. */
  111. uint16_t r_epoch;
  112. uint16_t w_epoch;
  113. /* records being received in the current epoch */
  114. DTLS1_BITMAP bitmap;
  115. /* handshake message numbers */
  116. uint16_t handshake_write_seq;
  117. uint16_t next_handshake_write_seq;
  118. uint16_t handshake_read_seq;
  119. /* save last sequence number for retransmissions */
  120. uint8_t last_write_sequence[8];
  121. /* buffered_messages is a priority queue of incoming handshake messages that
  122. * have yet to be processed.
  123. *
  124. * TODO(davidben): This data structure may as well be a ring buffer of fixed
  125. * size. */
  126. pqueue buffered_messages;
  127. /* send_messages is a priority queue of outgoing handshake messages sent in
  128. * the most recent handshake flight.
  129. *
  130. * TODO(davidben): This data structure may as well be a STACK_OF(T). */
  131. pqueue sent_messages;
  132. unsigned int mtu; /* max DTLS packet size */
  133. struct hm_header_st w_msg_hdr;
  134. /* num_timeouts is the number of times the retransmit timer has fired since
  135. * the last time it was reset. */
  136. unsigned int num_timeouts;
  137. /* Indicates when the last handshake msg or heartbeat sent will
  138. * timeout. Because of header issues on Windows, this cannot actually be a
  139. * struct timeval. */
  140. OPENSSL_timeval next_timeout;
  141. /* Timeout duration */
  142. unsigned short timeout_duration;
  143. unsigned int change_cipher_spec_ok;
  144. } DTLS1_STATE;
  145. #ifdef __cplusplus
  146. } /* extern C */
  147. #endif
  148. #endif /* OPENSSL_HEADER_DTLS1_H */