/* * DTLS implementation written by Nagendra Modadugu * ([email protected]) for the OpenSSL project 2005. */ /* ==================================================================== * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * [email protected]. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.openssl.org/)" * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This product includes cryptographic software written by Eric Young * ([email protected]). This product includes software written by Tim * Hudson ([email protected]). * */ /* Copyright (C) 1995-1998 Eric Young ([email protected]) * All rights reserved. * * This package is an SSL implementation written * by Eric Young ([email protected]). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson ([email protected]). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by * Eric Young ([email protected])" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson ([email protected])" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */ #include <openssl/ssl.h> #include <assert.h> #include <limits.h> #include <string.h> #include <openssl/err.h> #include <openssl/evp.h> #include <openssl/mem.h> #include <openssl/rand.h> #include "../crypto/internal.h" #include "internal.h" BSSL_NAMESPACE_BEGIN // TODO(davidben): 28 comes from the size of IP + UDP header. Is this reasonable // for these values? Notably, why is kMinMTU a function of the transport // protocol's overhead rather than, say, what's needed to hold a minimally-sized // handshake fragment plus protocol overhead. // kMinMTU is the minimum acceptable MTU value. static const unsigned int kMinMTU = …; // kDefaultMTU is the default MTU value to use if neither the user nor // the underlying BIO supplies one. static const unsigned int kDefaultMTU = …; // Receiving handshake messages. hm_fragment::~hm_fragment() { … } static UniquePtr<hm_fragment> dtls1_hm_fragment_new( const struct hm_header_st *msg_hdr) { … } // bit_range returns a |uint8_t| with bits |start|, inclusive, to |end|, // exclusive, set. static uint8_t bit_range(size_t start, size_t end) { … } // dtls1_hm_fragment_mark marks bytes |start|, inclusive, to |end|, exclusive, // as received in |frag|. If |frag| becomes complete, it clears // |frag->reassembly|. The range must be within the bounds of |frag|'s message // and |frag->reassembly| must not be NULL. static void dtls1_hm_fragment_mark(hm_fragment *frag, size_t start, size_t end) { … } // dtls1_is_current_message_complete returns whether the current handshake // message is complete. static bool dtls1_is_current_message_complete(const SSL *ssl) { … } // dtls1_get_incoming_message returns the incoming message corresponding to // |msg_hdr|. If none exists, it creates a new one and inserts it in the // queue. Otherwise, it checks |msg_hdr| is consistent with the existing one. It // returns NULL on failure. The caller does not take ownership of the result. static hm_fragment *dtls1_get_incoming_message( SSL *ssl, uint8_t *out_alert, const struct hm_header_st *msg_hdr) { … } ssl_open_record_t dtls1_open_handshake(SSL *ssl, size_t *out_consumed, uint8_t *out_alert, Span<uint8_t> in) { … } bool dtls1_get_message(const SSL *ssl, SSLMessage *out) { … } void dtls1_next_message(SSL *ssl) { … } bool dtls_has_unprocessed_handshake_data(const SSL *ssl) { … } bool dtls1_parse_fragment(CBS *cbs, struct hm_header_st *out_hdr, CBS *out_body) { … } ssl_open_record_t dtls1_open_change_cipher_spec(SSL *ssl, size_t *out_consumed, uint8_t *out_alert, Span<uint8_t> in) { … } // Sending handshake messages. void DTLS_OUTGOING_MESSAGE::Clear() { … } void dtls_clear_outgoing_messages(SSL *ssl) { … } bool dtls1_init_message(const SSL *ssl, CBB *cbb, CBB *body, uint8_t type) { … } bool dtls1_finish_message(const SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg) { … } // ssl_size_t_greater_than_32_bits returns whether |v| exceeds the bounds of a // 32-bit value. The obvious thing doesn't work because, in some 32-bit build // configurations, the compiler warns that the test is always false and breaks // the build. static bool ssl_size_t_greater_than_32_bits(size_t v) { … } // add_outgoing adds a new handshake message or ChangeCipherSpec to the current // outgoing flight. It returns true on success and false on error. static bool add_outgoing(SSL *ssl, bool is_ccs, Array<uint8_t> data) { … } bool dtls1_add_message(SSL *ssl, Array<uint8_t> data) { … } bool dtls1_add_change_cipher_spec(SSL *ssl) { … } // dtls1_update_mtu updates the current MTU from the BIO, ensuring it is above // the minimum. static void dtls1_update_mtu(SSL *ssl) { … } enum seal_result_t { … }; // seal_next_message seals |msg|, which must be the next message, to |out|. If // progress was made, it returns |seal_partial| or |seal_success| and sets // |*out_len| to the number of bytes written. static enum seal_result_t seal_next_message(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out, const DTLS_OUTGOING_MESSAGE *msg) { … } // seal_next_packet writes as much of the next flight as possible to |out| and // advances |ssl->d1->outgoing_written| and |ssl->d1->outgoing_offset| as // appropriate. static bool seal_next_packet(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out) { … } static int send_flight(SSL *ssl) { … } int dtls1_flush_flight(SSL *ssl) { … } int dtls1_retransmit_outgoing_messages(SSL *ssl) { … } unsigned int dtls1_min_mtu(void) { … } BSSL_NAMESPACE_END