Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/ssl/s3_lib.cc

raw
1 // Copyright (C) 1995-1998 Eric Young ([email protected])
2 // Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
3 // Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 // Copyright 2005 Nokia. All rights reserved.
5 //
6 // ECC cipher suite support in OpenSSL originally developed by
7 // SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
8 //
9 // The Contribution, originally written by Mika Kousa and Pasi Eronen of
10 // Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
11 // support (see RFC 4279) to OpenSSL.
12 //
13 // SPDX-License-Identifier: Apache-2.0
14
15 #include <openssl/ssl.h>
16
17 #include <assert.h>
18 #include <string.h>
19
20 #include <openssl/digest.h>
21 #include <openssl/err.h>
22 #include <openssl/md5.h>
23 #include <openssl/mem.h>
24 #include <openssl/nid.h>
25
26 #include "../crypto/internal.h"
27 #include "internal.h"
28
29
30 BSSL_NAMESPACE_BEGIN
31
32 SSL3_STATE::SSL3_STATE()
33 : skip_early_data(false),
34 have_version(false),
35 v2_hello_done(false),
36 is_v2_hello(false),
37 has_message(false),
38 initial_handshake_complete(false),
39 session_reused(false),
40 delegated_credential_used(false),
41 send_connection_binding(false),
42 channel_id_valid(false),
43 early_data_accepted(false),
44 alert_dispatch(false),
45 renegotiate_pending(false),
46 used_hello_retry_request(false),
47 was_key_usage_invalid(false) {}
48
49 SSL3_STATE::~SSL3_STATE() {
50 sk_X509_NAME_pop_free(cached_x509_peer_ca_names, X509_NAME_free);
51 }
52
53 bool tls_new(SSL *ssl) {
54 UniquePtr<SSL3_STATE> s3 = MakeUnique<SSL3_STATE>();
55 if (!s3) {
56 return false;
57 }
58
59 s3->aead_read_ctx = SSLAEADContext::CreateNullCipher(SSL_is_dtls(ssl));
60 s3->aead_write_ctx = SSLAEADContext::CreateNullCipher(SSL_is_dtls(ssl));
61 s3->hs = ssl_handshake_new(ssl);
62 if (!s3->aead_read_ctx || !s3->aead_write_ctx || !s3->hs) {
63 return false;
64 }
65
66 ssl->s3 = s3.release();
67
68 // Set the version to the highest supported version.
69 //
70 // TODO(davidben): Move this field into |s3|, have it store the normalized
71 // protocol version, and implement this pre-negotiation quirk in |SSL_version|
72 // at the API boundary rather than in internal state.
73 ssl->version = TLS1_2_VERSION;
74 return true;
75 }
76
77 void tls_free(SSL *ssl) {
78 if (ssl == NULL || ssl->s3 == NULL) {
79 return;
80 }
81
82 Delete(ssl->s3);
83 ssl->s3 = NULL;
84 }
85
86 BSSL_NAMESPACE_END