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