• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
4  * Copyright 2005 Nokia. All rights reserved.
5  *
6  * Licensed under the OpenSSL license (the "License").  You may not use
7  * this file except in compliance with the License.  You can obtain a copy
8  * in the file LICENSE in the source distribution or at
9  * https://www.openssl.org/source/license.html
10  */
11 
12 #include <openssl/ssl.h>
13 
14 #include <assert.h>
15 #include <string.h>
16 
17 #include <openssl/digest.h>
18 #include <openssl/err.h>
19 #include <openssl/md5.h>
20 #include <openssl/mem.h>
21 #include <openssl/nid.h>
22 
23 #include "../crypto/internal.h"
24 #include "internal.h"
25 
26 
27 BSSL_NAMESPACE_BEGIN
28 
SSL3_STATE()29 SSL3_STATE::SSL3_STATE()
30     : skip_early_data(false),
31       v2_hello_done(false),
32       is_v2_hello(false),
33       has_message(false),
34       initial_handshake_complete(false),
35       session_reused(false),
36       send_connection_binding(false),
37       channel_id_valid(false),
38       key_update_pending(false),
39       early_data_accepted(false),
40       alert_dispatch(false),
41       renegotiate_pending(false),
42       used_hello_retry_request(false),
43       was_key_usage_invalid(false) {}
44 
~SSL3_STATE()45 SSL3_STATE::~SSL3_STATE() {}
46 
tls_new(SSL * ssl)47 bool tls_new(SSL *ssl) {
48   UniquePtr<SSL3_STATE> s3 = MakeUnique<SSL3_STATE>();
49   if (!s3) {
50     return false;
51   }
52 
53   // TODO(crbug.com/368805255): Fields that aren't used in DTLS should not be
54   // allocated at all.
55   // TODO(crbug.com/371998381): Don't create these in QUIC either, once the
56   // placeholder QUIC ones for subsequent epochs are removed.
57   if (!SSL_is_dtls(ssl)) {
58     s3->aead_read_ctx = SSLAEADContext::CreateNullCipher();
59     s3->aead_write_ctx = SSLAEADContext::CreateNullCipher();
60     if (!s3->aead_read_ctx || !s3->aead_write_ctx) {
61       return false;
62     }
63   }
64 
65   s3->hs = ssl_handshake_new(ssl);
66   if (!s3->hs) {
67     return false;
68   }
69 
70   ssl->s3 = s3.release();
71   return true;
72 }
73 
tls_free(SSL * ssl)74 void tls_free(SSL *ssl) {
75   if (ssl->s3 == NULL) {
76     return;
77   }
78 
79   Delete(ssl->s3);
80   ssl->s3 = NULL;
81 }
82 
83 BSSL_NAMESPACE_END
84