2014-06-20 20:00:00 +01:00
|
|
|
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This package is an SSL implementation written
|
|
|
|
* by Eric Young (eay@cryptsoft.com).
|
|
|
|
* 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 (tjh@cryptsoft.com).
|
|
|
|
*
|
|
|
|
* 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 (eay@cryptsoft.com)"
|
|
|
|
* 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 (tjh@cryptsoft.com)"
|
|
|
|
*
|
|
|
|
* 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.]
|
|
|
|
*/
|
|
|
|
/* ====================================================================
|
|
|
|
* Copyright 2005 Nokia. All rights reserved.
|
|
|
|
*
|
|
|
|
* The portions of the attached software ("Contribution") is developed by
|
|
|
|
* Nokia Corporation and is licensed pursuant to the OpenSSL open source
|
|
|
|
* license.
|
|
|
|
*
|
|
|
|
* The Contribution, originally written by Mika Kousa and Pasi Eronen of
|
|
|
|
* Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
|
|
|
|
* support (see RFC 4279) to OpenSSL.
|
|
|
|
*
|
|
|
|
* No patent licenses or other rights except those expressly stated in
|
|
|
|
* the OpenSSL open source license shall be deemed granted or received
|
|
|
|
* expressly, by implication, estoppel, or otherwise.
|
|
|
|
*
|
|
|
|
* No assurances are provided by Nokia that the Contribution does not
|
|
|
|
* infringe the patent or other intellectual property rights of any third
|
|
|
|
* party or that the license provides you with all the necessary rights
|
|
|
|
* to make use of the Contribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
|
|
|
|
* ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
|
|
|
|
* SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
|
|
|
|
* OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
|
|
|
|
* OTHERWISE. */
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Per C99, various stdint.h macros are unavailable in C++ unless some macros
|
|
|
|
// are defined. C++11 overruled this decision, but older Android NDKs still
|
|
|
|
// require it.
|
2017-07-09 21:17:55 +01:00
|
|
|
#if !defined(__STDC_LIMIT_MACROS)
|
|
|
|
#define __STDC_LIMIT_MACROS
|
|
|
|
#endif
|
|
|
|
|
2015-09-15 06:48:04 +01:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
2014-10-19 09:33:38 +01:00
|
|
|
#include <limits.h>
|
2014-10-19 18:50:18 +01:00
|
|
|
#include <string.h>
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2017-07-26 03:36:00 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2016-08-25 21:30:58 +01:00
|
|
|
#include <openssl/buf.h>
|
2014-10-19 09:33:38 +01:00
|
|
|
#include <openssl/bytestring.h>
|
2014-06-20 20:00:00 +01:00
|
|
|
#include <openssl/err.h>
|
2015-03-28 07:12:01 +00:00
|
|
|
#include <openssl/mem.h>
|
2014-06-20 20:00:00 +01:00
|
|
|
#include <openssl/x509.h>
|
|
|
|
|
2016-12-13 06:07:13 +00:00
|
|
|
#include "../crypto/internal.h"
|
2015-04-08 03:38:30 +01:00
|
|
|
#include "internal.h"
|
2014-06-20 20:00:00 +01:00
|
|
|
|
|
|
|
|
Move libssl's internals into the bssl namespace.
This is horrible, but everything else I tried was worse. The goal with
this CL is to take the extern "C" out of ssl/internal.h and move most
symbols to namespace bssl, so we can start using C++ helpers and
destructors without worry.
Complications:
- Public API functions must be extern "C" and match their declaration in
ssl.h, which is unnamespaced. C++ really does not want you to
interleave namespaced and unnamespaced things. One can actually write
a namespaced extern "C" function, but this means, from C++'s
perspective, the function is namespaced. Trying to namespace the
public header would worked but ended up too deep a rabbithole.
- Our STACK_OF macros do not work right in namespaces.
- The typedefs for our exposed but opaque types are visible in the
header files and copied into consuming projects as forward
declarations. We ultimately want to give SSL a destructor, but
clobbering an unnamespaced ssl_st::~ssl_st seems bad manners.
- MSVC complains about ambiguous names if one typedefs SSL to bssl::SSL.
This CL opts for:
- ssl/*.cc must begin with #define BORINGSSL_INTERNAL_CXX_TYPES. This
informs the public headers to create forward declarations which are
compatible with our namespaces.
- For now, C++-defined type FOO ends up at bssl::FOO with a typedef
outside. Later I imagine we'll rename many of them.
- Internal functions get namespace bssl, so we stop worrying about
stomping the tls1_prf symbol. Exported C functions are stuck as they
are. Rather than try anything weird, bite the bullet and reorder files
which have a mix of public and private functions. I expect that over
time, the public functions will become fairly small as we move logic
to more idiomatic C++.
Files without any public C functions can just be written normally.
- To avoid MSVC troubles, some bssl types are renamed to CPlusPlusStyle
in advance of them being made idiomatic C++.
Bug: 132
Change-Id: Ic931895e117c38b14ff8d6e5a273e868796c7581
Reviewed-on: https://boringssl-review.googlesource.com/18124
Reviewed-by: David Benjamin <davidben@google.com>
2017-07-18 21:34:25 +01:00
|
|
|
namespace bssl {
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// An SSL_SESSION is serialized as the following ASN.1 structure:
|
|
|
|
//
|
|
|
|
// SSLSession ::= SEQUENCE {
|
|
|
|
// version INTEGER (1), -- session structure version
|
|
|
|
// sslVersion INTEGER, -- protocol version number
|
|
|
|
// cipher OCTET STRING, -- two bytes long
|
|
|
|
// sessionID OCTET STRING,
|
|
|
|
// masterKey OCTET STRING,
|
|
|
|
// time [1] INTEGER, -- seconds since UNIX epoch
|
|
|
|
// timeout [2] INTEGER, -- in seconds
|
|
|
|
// peer [3] Certificate OPTIONAL,
|
|
|
|
// sessionIDContext [4] OCTET STRING OPTIONAL,
|
|
|
|
// verifyResult [5] INTEGER OPTIONAL, -- one of X509_V_* codes
|
|
|
|
// pskIdentity [8] OCTET STRING OPTIONAL,
|
|
|
|
// ticketLifetimeHint [9] INTEGER OPTIONAL, -- client-only
|
|
|
|
// ticket [10] OCTET STRING OPTIONAL, -- client-only
|
|
|
|
// peerSHA256 [13] OCTET STRING OPTIONAL,
|
|
|
|
// originalHandshakeHash [14] OCTET STRING OPTIONAL,
|
|
|
|
// signedCertTimestampList [15] OCTET STRING OPTIONAL,
|
|
|
|
// -- contents of SCT extension
|
|
|
|
// ocspResponse [16] OCTET STRING OPTIONAL,
|
|
|
|
// -- stapled OCSP response from the server
|
|
|
|
// extendedMasterSecret [17] BOOLEAN OPTIONAL,
|
|
|
|
// groupID [18] INTEGER OPTIONAL,
|
|
|
|
// certChain [19] SEQUENCE OF Certificate OPTIONAL,
|
|
|
|
// ticketAgeAdd [21] OCTET STRING OPTIONAL,
|
|
|
|
// isServer [22] BOOLEAN DEFAULT TRUE,
|
|
|
|
// peerSignatureAlgorithm [23] INTEGER OPTIONAL,
|
|
|
|
// ticketMaxEarlyData [24] INTEGER OPTIONAL,
|
|
|
|
// authTimeout [25] INTEGER OPTIONAL, -- defaults to timeout
|
|
|
|
// earlyALPN [26] OCTET STRING OPTIONAL,
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// Note: historically this serialization has included other optional
|
2017-09-06 20:40:19 +01:00
|
|
|
// fields. Their presence is currently treated as a parse error, except for
|
|
|
|
// hostName, which is ignored.
|
2017-08-29 21:33:21 +01:00
|
|
|
//
|
|
|
|
// keyArg [0] IMPLICIT OCTET STRING OPTIONAL,
|
2017-09-06 20:40:19 +01:00
|
|
|
// hostName [6] OCTET STRING OPTIONAL,
|
2017-08-29 21:33:21 +01:00
|
|
|
// pskIdentityHint [7] OCTET STRING OPTIONAL,
|
|
|
|
// compressionMethod [11] OCTET STRING OPTIONAL,
|
|
|
|
// srpUsername [12] OCTET STRING OPTIONAL,
|
|
|
|
// ticketFlags [20] INTEGER OPTIONAL,
|
2014-10-19 09:33:38 +01:00
|
|
|
|
2015-06-02 22:16:44 +01:00
|
|
|
static const unsigned kVersion = 1;
|
2015-10-17 17:36:12 +01:00
|
|
|
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kTimeTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 1;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kTimeoutTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 2;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kPeerTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 3;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kSessionIDContextTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 4;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kVerifyResultTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 5;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kHostNameTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 6;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kPSKIdentityTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 8;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kTicketLifetimeHintTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 9;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kTicketTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 10;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kPeerSHA256Tag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 13;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kOriginalHandshakeHashTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 14;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kSignedCertTimestampListTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 15;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kOCSPResponseTag =
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 16;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kExtendedMasterSecretTag =
|
2014-10-11 00:23:43 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 17;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kGroupIDTag =
|
2015-06-29 14:07:26 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 18;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kCertChainTag =
|
2015-08-22 21:04:17 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 19;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kTicketAgeAddTag =
|
2016-07-27 16:10:52 +01:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 21;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kIsServerTag =
|
2016-12-12 18:51:00 +00:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 22;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kPeerSignatureAlgorithmTag =
|
2016-12-14 01:05:36 +00:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 23;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kTicketMaxEarlyDataTag =
|
2016-12-07 20:29:45 +00:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 24;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kAuthTimeoutTag =
|
2017-01-28 19:00:32 +00:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 25;
|
2017-11-21 21:25:12 +00:00
|
|
|
static const unsigned kEarlyALPNTag =
|
2017-02-14 18:20:40 +00:00
|
|
|
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 26;
|
2015-08-22 21:04:17 +01:00
|
|
|
|
2018-01-25 23:49:37 +00:00
|
|
|
static int SSL_SESSION_to_bytes_full(const SSL_SESSION *in, CBB *cbb,
|
|
|
|
int for_ticket) {
|
2014-12-26 04:11:49 +00:00
|
|
|
if (in == NULL || in->cipher == NULL) {
|
2014-10-19 18:50:18 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2017-07-20 04:57:40 +01:00
|
|
|
CBB session, child, child2;
|
2018-01-25 23:49:37 +00:00
|
|
|
if (!CBB_add_asn1(cbb, &session, CBS_ASN1_SEQUENCE) ||
|
2015-10-17 17:36:12 +01:00
|
|
|
!CBB_add_asn1_uint64(&session, kVersion) ||
|
2014-10-19 18:50:18 +01:00
|
|
|
!CBB_add_asn1_uint64(&session, in->ssl_version) ||
|
|
|
|
!CBB_add_asn1(&session, &child, CBS_ASN1_OCTETSTRING) ||
|
2014-12-26 04:11:49 +00:00
|
|
|
!CBB_add_u16(&child, (uint16_t)(in->cipher->id & 0xffff)) ||
|
2017-08-29 21:33:21 +01:00
|
|
|
// The session ID is irrelevant for a session ticket.
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_octet_string(&session, in->session_id,
|
|
|
|
for_ticket ? 0 : in->session_id_length) ||
|
|
|
|
!CBB_add_asn1_octet_string(&session, in->master_key,
|
|
|
|
in->master_key_length) ||
|
2017-02-20 22:00:20 +00:00
|
|
|
!CBB_add_asn1(&session, &child, kTimeTag) ||
|
|
|
|
!CBB_add_asn1_uint64(&child, in->time) ||
|
|
|
|
!CBB_add_asn1(&session, &child, kTimeoutTag) ||
|
2016-11-04 00:32:10 +00:00
|
|
|
!CBB_add_asn1_uint64(&child, in->timeout)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// The peer certificate is only serialized if the SHA-256 isn't
|
|
|
|
// serialized instead.
|
2016-12-12 19:06:16 +00:00
|
|
|
if (sk_CRYPTO_BUFFER_num(in->certs) > 0 && !in->peer_sha256_valid) {
|
|
|
|
const CRYPTO_BUFFER *buffer = sk_CRYPTO_BUFFER_value(in->certs, 0);
|
|
|
|
if (!CBB_add_asn1(&session, &child, kPeerTag) ||
|
|
|
|
!CBB_add_bytes(&child, CRYPTO_BUFFER_data(buffer),
|
|
|
|
CRYPTO_BUFFER_len(buffer))) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Although it is OPTIONAL and usually empty, OpenSSL has
|
|
|
|
// historically always encoded the sid_ctx.
|
2014-10-19 18:50:18 +01:00
|
|
|
if (!CBB_add_asn1(&session, &child, kSessionIDContextTag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_octet_string(&child, in->sid_ctx, in->sid_ctx_length)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2014-10-19 18:50:18 +01:00
|
|
|
if (in->verify_result != X509_V_OK) {
|
|
|
|
if (!CBB_add_asn1(&session, &child, kVerifyResultTag) ||
|
|
|
|
!CBB_add_asn1_uint64(&child, in->verify_result)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2014-10-19 18:50:18 +01:00
|
|
|
if (in->psk_identity) {
|
|
|
|
if (!CBB_add_asn1(&session, &child, kPSKIdentityTag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_octet_string(&child, (const uint8_t *)in->psk_identity,
|
|
|
|
strlen(in->psk_identity))) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2016-08-09 18:18:40 +01:00
|
|
|
if (in->tlsext_tick_lifetime_hint > 0) {
|
2014-10-19 18:50:18 +01:00
|
|
|
if (!CBB_add_asn1(&session, &child, kTicketLifetimeHintTag) ||
|
2016-08-09 18:18:40 +01:00
|
|
|
!CBB_add_asn1_uint64(&child, in->tlsext_tick_lifetime_hint)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2015-06-16 00:53:32 +01:00
|
|
|
if (in->tlsext_tick && !for_ticket) {
|
2014-10-19 18:50:18 +01:00
|
|
|
if (!CBB_add_asn1(&session, &child, kTicketTag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_octet_string(&child, in->tlsext_tick,
|
|
|
|
in->tlsext_ticklen)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2014-10-19 18:50:18 +01:00
|
|
|
if (in->peer_sha256_valid) {
|
|
|
|
if (!CBB_add_asn1(&session, &child, kPeerSHA256Tag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_octet_string(&child, in->peer_sha256,
|
|
|
|
sizeof(in->peer_sha256))) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2014-10-19 18:50:18 +01:00
|
|
|
if (in->original_handshake_hash_len > 0) {
|
|
|
|
if (!CBB_add_asn1(&session, &child, kOriginalHandshakeHashTag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_octet_string(&child, in->original_handshake_hash,
|
|
|
|
in->original_handshake_hash_len)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2017-08-22 23:07:51 +01:00
|
|
|
if (in->signed_cert_timestamp_list != nullptr) {
|
2014-10-19 18:50:18 +01:00
|
|
|
if (!CBB_add_asn1(&session, &child, kSignedCertTimestampListTag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_octet_string(
|
|
|
|
&child, CRYPTO_BUFFER_data(in->signed_cert_timestamp_list),
|
|
|
|
CRYPTO_BUFFER_len(in->signed_cert_timestamp_list))) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-14 13:42:37 +01:00
|
|
|
|
2017-08-22 23:07:51 +01:00
|
|
|
if (in->ocsp_response != nullptr) {
|
2014-10-19 18:50:18 +01:00
|
|
|
if (!CBB_add_asn1(&session, &child, kOCSPResponseTag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_octet_string(&child,
|
|
|
|
CRYPTO_BUFFER_data(in->ocsp_response),
|
|
|
|
CRYPTO_BUFFER_len(in->ocsp_response))) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-19 18:50:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-27 21:42:38 +01:00
|
|
|
|
2014-10-11 00:23:43 +01:00
|
|
|
if (in->extended_master_secret) {
|
|
|
|
if (!CBB_add_asn1(&session, &child, kExtendedMasterSecretTag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_bool(&child, true)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2014-10-11 00:23:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 07:48:12 +00:00
|
|
|
if (in->group_id > 0 &&
|
|
|
|
(!CBB_add_asn1(&session, &child, kGroupIDTag) ||
|
|
|
|
!CBB_add_asn1_uint64(&child, in->group_id))) {
|
2015-06-29 14:07:26 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2015-06-29 14:07:26 +01:00
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// The certificate chain is only serialized if the leaf's SHA-256 isn't
|
|
|
|
// serialized instead.
|
2016-12-12 19:06:16 +00:00
|
|
|
if (in->certs != NULL &&
|
|
|
|
!in->peer_sha256_valid &&
|
|
|
|
sk_CRYPTO_BUFFER_num(in->certs) >= 2) {
|
2015-08-22 21:04:17 +01:00
|
|
|
if (!CBB_add_asn1(&session, &child, kCertChainTag)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2015-08-22 21:04:17 +01:00
|
|
|
}
|
2016-12-12 19:06:16 +00:00
|
|
|
for (size_t i = 1; i < sk_CRYPTO_BUFFER_num(in->certs); i++) {
|
|
|
|
const CRYPTO_BUFFER *buffer = sk_CRYPTO_BUFFER_value(in->certs, i);
|
|
|
|
if (!CBB_add_bytes(&child, CRYPTO_BUFFER_data(buffer),
|
|
|
|
CRYPTO_BUFFER_len(buffer))) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2015-08-22 21:04:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 16:10:52 +01:00
|
|
|
if (in->ticket_age_add_valid) {
|
|
|
|
if (!CBB_add_asn1(&session, &child, kTicketAgeAddTag) ||
|
|
|
|
!CBB_add_asn1(&child, &child2, CBS_ASN1_OCTETSTRING) ||
|
|
|
|
!CBB_add_u32(&child2, in->ticket_age_add)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2016-07-27 16:10:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 18:51:00 +00:00
|
|
|
if (!in->is_server) {
|
|
|
|
if (!CBB_add_asn1(&session, &child, kIsServerTag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_bool(&child, false)) {
|
2016-12-12 18:51:00 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2016-12-12 18:51:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-14 01:05:36 +00:00
|
|
|
if (in->peer_signature_algorithm != 0 &&
|
|
|
|
(!CBB_add_asn1(&session, &child, kPeerSignatureAlgorithmTag) ||
|
|
|
|
!CBB_add_asn1_uint64(&child, in->peer_signature_algorithm))) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2016-12-14 01:05:36 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 20:29:45 +00:00
|
|
|
if (in->ticket_max_early_data != 0 &&
|
|
|
|
(!CBB_add_asn1(&session, &child, kTicketMaxEarlyDataTag) ||
|
|
|
|
!CBB_add_asn1_uint64(&child, in->ticket_max_early_data))) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2016-12-07 20:29:45 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 19:00:32 +00:00
|
|
|
if (in->timeout != in->auth_timeout &&
|
|
|
|
(!CBB_add_asn1(&session, &child, kAuthTimeoutTag) ||
|
|
|
|
!CBB_add_asn1_uint64(&child, in->auth_timeout))) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2017-01-28 19:00:32 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 18:20:40 +00:00
|
|
|
if (in->early_alpn) {
|
|
|
|
if (!CBB_add_asn1(&session, &child, kEarlyALPNTag) ||
|
2018-01-25 23:37:46 +00:00
|
|
|
!CBB_add_asn1_octet_string(&child, (const uint8_t *)in->early_alpn,
|
|
|
|
in->early_alpn_len)) {
|
2017-02-14 18:20:40 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 04:57:40 +01:00
|
|
|
return 0;
|
2017-02-14 18:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-25 23:49:37 +00:00
|
|
|
return CBB_flush(cbb);
|
2014-10-21 06:46:30 +01:00
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// SSL_SESSION_parse_string gets an optional ASN.1 OCTET STRING
|
|
|
|
// explicitly tagged with |tag| from |cbs| and saves it in |*out|. On
|
|
|
|
// entry, if |*out| is not NULL, it frees the existing contents. If
|
|
|
|
// the element was not found, it sets |*out| to NULL. It returns one
|
|
|
|
// on success, whether or not the element was found, and zero on
|
|
|
|
// decode error.
|
2015-06-16 00:41:48 +01:00
|
|
|
static int SSL_SESSION_parse_string(CBS *cbs, char **out, unsigned tag) {
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS value;
|
|
|
|
int present;
|
|
|
|
if (!CBS_get_optional_asn1_octet_string(cbs, &value, &present, tag)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2014-10-19 09:33:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (present) {
|
|
|
|
if (CBS_contains_zero_byte(&value)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2014-10-19 09:33:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!CBS_strdup(&value, out)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2014-10-19 09:33:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-22 21:17:58 +01:00
|
|
|
} else {
|
2014-10-19 09:33:38 +01:00
|
|
|
OPENSSL_free(*out);
|
|
|
|
*out = NULL;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// SSL_SESSION_parse_string gets an optional ASN.1 OCTET STRING
|
|
|
|
// explicitly tagged with |tag| from |cbs| and stows it in |*out_ptr|
|
|
|
|
// and |*out_len|. If |*out_ptr| is not NULL, it frees the existing
|
|
|
|
// contents. On entry, if the element was not found, it sets
|
|
|
|
// |*out_ptr| to NULL. It returns one on success, whether or not the
|
|
|
|
// element was found, and zero on decode error.
|
2015-06-16 00:41:48 +01:00
|
|
|
static int SSL_SESSION_parse_octet_string(CBS *cbs, uint8_t **out_ptr,
|
2015-08-23 06:37:36 +01:00
|
|
|
size_t *out_len, unsigned tag) {
|
2014-10-19 09:33:38 +01:00
|
|
|
CBS value;
|
|
|
|
if (!CBS_get_optional_asn1_octet_string(cbs, &value, NULL, tag)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2014-10-19 09:33:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!CBS_stow(&value, out_ptr, out_len)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2014-10-19 09:33:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-08-22 23:07:51 +01:00
|
|
|
static int SSL_SESSION_parse_crypto_buffer(CBS *cbs, CRYPTO_BUFFER **out,
|
|
|
|
unsigned tag,
|
|
|
|
CRYPTO_BUFFER_POOL *pool) {
|
|
|
|
if (!CBS_peek_asn1_tag(cbs, tag)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBS child, value;
|
|
|
|
if (!CBS_get_asn1(cbs, &child, tag) ||
|
|
|
|
!CBS_get_asn1(&child, &value, CBS_ASN1_OCTETSTRING) ||
|
|
|
|
CBS_len(&child) != 0) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
CRYPTO_BUFFER_free(*out);
|
|
|
|
*out = CRYPTO_BUFFER_new_from_CBS(&value, pool);
|
|
|
|
if (*out == nullptr) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// SSL_SESSION_parse_bounded_octet_string parses an optional ASN.1 OCTET STRING
|
|
|
|
// explicitly tagged with |tag| of size at most |max_out|.
|
2015-08-23 06:37:36 +01:00
|
|
|
static int SSL_SESSION_parse_bounded_octet_string(
|
2016-12-08 03:35:24 +00:00
|
|
|
CBS *cbs, uint8_t *out, uint8_t *out_len, uint8_t max_out, unsigned tag) {
|
2015-08-23 06:37:36 +01:00
|
|
|
CBS value;
|
|
|
|
if (!CBS_get_optional_asn1_octet_string(cbs, &value, NULL, tag) ||
|
|
|
|
CBS_len(&value) > max_out) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2015-08-23 06:37:36 +01:00
|
|
|
return 0;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
2016-12-13 06:07:13 +00:00
|
|
|
OPENSSL_memcpy(out, CBS_data(&value), CBS_len(&value));
|
2016-12-08 03:35:24 +00:00
|
|
|
*out_len = (uint8_t)CBS_len(&value);
|
2015-08-23 06:37:36 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SSL_SESSION_parse_long(CBS *cbs, long *out, unsigned tag,
|
|
|
|
long default_value) {
|
|
|
|
uint64_t value;
|
|
|
|
if (!CBS_get_optional_asn1_uint64(cbs, &value, tag,
|
|
|
|
(uint64_t)default_value) ||
|
|
|
|
value > LONG_MAX) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2015-08-23 06:37:36 +01:00
|
|
|
return 0;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
2015-08-23 06:37:36 +01:00
|
|
|
*out = (long)value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SSL_SESSION_parse_u32(CBS *cbs, uint32_t *out, unsigned tag,
|
|
|
|
uint32_t default_value) {
|
|
|
|
uint64_t value;
|
|
|
|
if (!CBS_get_optional_asn1_uint64(cbs, &value, tag,
|
|
|
|
(uint64_t)default_value) ||
|
|
|
|
value > 0xffffffff) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2015-08-23 06:37:36 +01:00
|
|
|
return 0;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
2015-08-23 06:37:36 +01:00
|
|
|
*out = (uint32_t)value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-12-14 01:05:36 +00:00
|
|
|
static int SSL_SESSION_parse_u16(CBS *cbs, uint16_t *out, unsigned tag,
|
|
|
|
uint16_t default_value) {
|
|
|
|
uint64_t value;
|
|
|
|
if (!CBS_get_optional_asn1_uint64(cbs, &value, tag,
|
|
|
|
(uint64_t)default_value) ||
|
|
|
|
value > 0xffff) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*out = (uint16_t)value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-07-20 19:49:15 +01:00
|
|
|
UniquePtr<SSL_SESSION> SSL_SESSION_parse(CBS *cbs,
|
|
|
|
const SSL_X509_METHOD *x509_method,
|
|
|
|
CRYPTO_BUFFER_POOL *pool) {
|
|
|
|
UniquePtr<SSL_SESSION> ret = ssl_session_new(x509_method);
|
|
|
|
if (!ret) {
|
|
|
|
return nullptr;
|
2015-06-29 14:07:26 +01:00
|
|
|
}
|
|
|
|
|
2015-08-23 06:37:36 +01:00
|
|
|
CBS session;
|
|
|
|
uint64_t version, ssl_version;
|
2017-06-20 15:55:02 +01:00
|
|
|
uint16_t unused;
|
2015-08-23 06:37:36 +01:00
|
|
|
if (!CBS_get_asn1(cbs, &session, CBS_ASN1_SEQUENCE) ||
|
|
|
|
!CBS_get_asn1_uint64(&session, &version) ||
|
2015-10-17 17:36:12 +01:00
|
|
|
version != kVersion ||
|
2017-06-20 15:55:02 +01:00
|
|
|
!CBS_get_asn1_uint64(&session, &ssl_version) ||
|
2017-08-29 21:33:21 +01:00
|
|
|
// Require sessions have versions valid in either TLS or DTLS. The session
|
|
|
|
// will not be used by the handshake if not applicable, but, for
|
|
|
|
// simplicity, never parse a session that does not pass
|
|
|
|
// |ssl_protocol_version_from_wire|.
|
2017-06-20 15:55:02 +01:00
|
|
|
ssl_version > UINT16_MAX ||
|
|
|
|
!ssl_protocol_version_from_wire(&unused, ssl_version)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2015-05-29 01:00:08 +01:00
|
|
|
}
|
2014-10-19 09:33:38 +01:00
|
|
|
ret->ssl_version = ssl_version;
|
|
|
|
|
2015-08-23 06:37:36 +01:00
|
|
|
CBS cipher;
|
2014-12-26 04:11:49 +00:00
|
|
|
uint16_t cipher_value;
|
2015-08-23 06:37:36 +01:00
|
|
|
if (!CBS_get_asn1(&session, &cipher, CBS_ASN1_OCTETSTRING) ||
|
|
|
|
!CBS_get_u16(&cipher, &cipher_value) ||
|
|
|
|
CBS_len(&cipher) != 0) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
2015-05-30 22:03:14 +01:00
|
|
|
ret->cipher = SSL_get_cipher_by_value(cipher_value);
|
2014-10-19 09:33:38 +01:00
|
|
|
if (ret->cipher == NULL) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_CIPHER);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
|
|
|
|
2015-08-23 06:37:36 +01:00
|
|
|
CBS session_id, master_key;
|
|
|
|
if (!CBS_get_asn1(&session, &session_id, CBS_ASN1_OCTETSTRING) ||
|
|
|
|
CBS_len(&session_id) > SSL3_MAX_SSL_SESSION_ID_LENGTH ||
|
|
|
|
!CBS_get_asn1(&session, &master_key, CBS_ASN1_OCTETSTRING) ||
|
|
|
|
CBS_len(&master_key) > SSL_MAX_MASTER_KEY_LENGTH) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
2016-12-13 06:07:13 +00:00
|
|
|
OPENSSL_memcpy(ret->session_id, CBS_data(&session_id), CBS_len(&session_id));
|
2014-10-19 09:33:38 +01:00
|
|
|
ret->session_id_length = CBS_len(&session_id);
|
2016-12-13 06:07:13 +00:00
|
|
|
OPENSSL_memcpy(ret->master_key, CBS_data(&master_key), CBS_len(&master_key));
|
2015-08-23 06:37:36 +01:00
|
|
|
ret->master_key_length = CBS_len(&master_key);
|
2014-10-19 09:33:38 +01:00
|
|
|
|
2016-11-04 00:32:10 +00:00
|
|
|
CBS child;
|
2017-02-20 22:00:20 +00:00
|
|
|
uint64_t timeout;
|
2016-11-04 00:32:10 +00:00
|
|
|
if (!CBS_get_asn1(&session, &child, kTimeTag) ||
|
2017-02-20 22:00:20 +00:00
|
|
|
!CBS_get_asn1_uint64(&child, &ret->time) ||
|
2016-11-04 00:32:10 +00:00
|
|
|
!CBS_get_asn1(&session, &child, kTimeoutTag) ||
|
|
|
|
!CBS_get_asn1_uint64(&child, &timeout) ||
|
2017-02-20 22:00:20 +00:00
|
|
|
timeout > UINT32_MAX) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
|
|
|
|
2017-02-20 22:00:20 +00:00
|
|
|
ret->timeout = (uint32_t)timeout;
|
2016-11-04 00:32:10 +00:00
|
|
|
|
2015-08-23 06:37:36 +01:00
|
|
|
CBS peer;
|
|
|
|
int has_peer;
|
2016-12-12 19:06:16 +00:00
|
|
|
if (!CBS_get_optional_asn1(&session, &peer, &has_peer, kPeerTag) ||
|
|
|
|
(has_peer && CBS_len(&peer) == 0)) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
2017-08-29 21:33:21 +01:00
|
|
|
// |peer| is processed with the certificate chain.
|
2014-10-19 09:33:38 +01:00
|
|
|
|
2015-08-23 06:37:36 +01:00
|
|
|
if (!SSL_SESSION_parse_bounded_octet_string(
|
|
|
|
&session, ret->sid_ctx, &ret->sid_ctx_length, sizeof(ret->sid_ctx),
|
|
|
|
kSessionIDContextTag) ||
|
|
|
|
!SSL_SESSION_parse_long(&session, &ret->verify_result, kVerifyResultTag,
|
2017-09-06 20:40:19 +01:00
|
|
|
X509_V_OK)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip the historical hostName field.
|
|
|
|
CBS unused_hostname;
|
|
|
|
if (!CBS_get_optional_asn1(&session, &unused_hostname, nullptr,
|
|
|
|
kHostNameTag)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SSL_SESSION_parse_string(&session, &ret->psk_identity,
|
2015-08-23 06:37:36 +01:00
|
|
|
kPSKIdentityTag) ||
|
2016-08-09 18:18:40 +01:00
|
|
|
!SSL_SESSION_parse_u32(&session, &ret->tlsext_tick_lifetime_hint,
|
2015-08-23 06:37:36 +01:00
|
|
|
kTicketLifetimeHintTag, 0) ||
|
|
|
|
!SSL_SESSION_parse_octet_string(&session, &ret->tlsext_tick,
|
|
|
|
&ret->tlsext_ticklen, kTicketTag)) {
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
|
|
|
|
2015-08-23 06:37:36 +01:00
|
|
|
if (CBS_peek_asn1_tag(&session, kPeerSHA256Tag)) {
|
2016-11-04 00:32:10 +00:00
|
|
|
CBS peer_sha256;
|
2015-08-23 06:37:36 +01:00
|
|
|
if (!CBS_get_asn1(&session, &child, kPeerSHA256Tag) ||
|
|
|
|
!CBS_get_asn1(&child, &peer_sha256, CBS_ASN1_OCTETSTRING) ||
|
|
|
|
CBS_len(&peer_sha256) != sizeof(ret->peer_sha256) ||
|
|
|
|
CBS_len(&child) != 0) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
2016-12-13 06:07:13 +00:00
|
|
|
OPENSSL_memcpy(ret->peer_sha256, CBS_data(&peer_sha256),
|
|
|
|
sizeof(ret->peer_sha256));
|
2014-10-19 09:33:38 +01:00
|
|
|
ret->peer_sha256_valid = 1;
|
|
|
|
} else {
|
|
|
|
ret->peer_sha256_valid = 0;
|
|
|
|
}
|
|
|
|
|
2015-08-23 06:37:36 +01:00
|
|
|
if (!SSL_SESSION_parse_bounded_octet_string(
|
|
|
|
&session, ret->original_handshake_hash,
|
|
|
|
&ret->original_handshake_hash_len,
|
|
|
|
sizeof(ret->original_handshake_hash), kOriginalHandshakeHashTag) ||
|
2017-08-22 23:07:51 +01:00
|
|
|
!SSL_SESSION_parse_crypto_buffer(&session,
|
|
|
|
&ret->signed_cert_timestamp_list,
|
|
|
|
kSignedCertTimestampListTag, pool) ||
|
|
|
|
!SSL_SESSION_parse_crypto_buffer(&session, &ret->ocsp_response,
|
|
|
|
kOCSPResponseTag, pool)) {
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2015-08-23 06:37:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int extended_master_secret;
|
|
|
|
if (!CBS_get_optional_asn1_bool(&session, &extended_master_secret,
|
|
|
|
kExtendedMasterSecretTag,
|
|
|
|
0 /* default to false */)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2015-08-23 06:37:36 +01:00
|
|
|
}
|
|
|
|
ret->extended_master_secret = !!extended_master_secret;
|
|
|
|
|
2017-04-12 03:13:45 +01:00
|
|
|
if (!SSL_SESSION_parse_u16(&session, &ret->group_id, kGroupIDTag, 0)) {
|
2015-08-22 21:04:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2015-08-22 21:04:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CBS cert_chain;
|
2016-12-12 19:06:16 +00:00
|
|
|
CBS_init(&cert_chain, NULL, 0);
|
2015-08-22 21:04:17 +01:00
|
|
|
int has_cert_chain;
|
|
|
|
if (!CBS_get_optional_asn1(&session, &cert_chain, &has_cert_chain,
|
2016-12-12 19:06:16 +00:00
|
|
|
kCertChainTag) ||
|
|
|
|
(has_cert_chain && CBS_len(&cert_chain) == 0)) {
|
2015-08-22 21:04:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2015-08-22 21:04:17 +01:00
|
|
|
}
|
2016-12-12 19:06:16 +00:00
|
|
|
if (has_cert_chain && !has_peer) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2016-12-12 18:51:00 +00:00
|
|
|
}
|
2016-12-12 19:06:16 +00:00
|
|
|
if (has_peer || has_cert_chain) {
|
|
|
|
ret->certs = sk_CRYPTO_BUFFER_new_null();
|
|
|
|
if (ret->certs == NULL) {
|
2015-08-22 21:04:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2015-08-22 21:04:17 +01:00
|
|
|
}
|
2016-12-12 19:06:16 +00:00
|
|
|
|
|
|
|
if (has_peer) {
|
2017-07-26 03:36:00 +01:00
|
|
|
UniquePtr<CRYPTO_BUFFER> buffer(CRYPTO_BUFFER_new_from_CBS(&peer, pool));
|
|
|
|
if (!buffer ||
|
|
|
|
!PushToStack(ret->certs, std::move(buffer))) {
|
2016-12-12 19:06:16 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2016-12-12 19:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-22 21:04:17 +01:00
|
|
|
while (CBS_len(&cert_chain) > 0) {
|
2016-12-12 19:06:16 +00:00
|
|
|
CBS cert;
|
|
|
|
if (!CBS_get_any_asn1_element(&cert_chain, &cert, NULL, NULL) ||
|
|
|
|
CBS_len(&cert) == 0) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2015-08-22 21:04:17 +01:00
|
|
|
}
|
2016-12-12 19:06:16 +00:00
|
|
|
|
2018-06-29 22:46:42 +01:00
|
|
|
UniquePtr<CRYPTO_BUFFER> buffer(CRYPTO_BUFFER_new_from_CBS(&cert, pool));
|
|
|
|
if (buffer == nullptr ||
|
|
|
|
!PushToStack(ret->certs, std::move(buffer))) {
|
2015-08-22 21:04:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2015-08-22 21:04:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 19:49:15 +01:00
|
|
|
if (!x509_method->session_cache_objects(ret.get())) {
|
2016-12-12 19:06:16 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2016-12-12 19:06:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 16:10:52 +01:00
|
|
|
CBS age_add;
|
|
|
|
int age_add_present;
|
2016-09-01 17:29:49 +01:00
|
|
|
if (!CBS_get_optional_asn1_octet_string(&session, &age_add, &age_add_present,
|
2016-07-27 16:10:52 +01:00
|
|
|
kTicketAgeAddTag) ||
|
|
|
|
(age_add_present &&
|
|
|
|
!CBS_get_u32(&age_add, &ret->ticket_age_add)) ||
|
|
|
|
CBS_len(&age_add) != 0) {
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2016-07-27 16:10:52 +01:00
|
|
|
}
|
2018-06-29 18:24:45 +01:00
|
|
|
ret->ticket_age_add_valid = age_add_present != 0;
|
2016-07-27 16:10:52 +01:00
|
|
|
|
2016-12-12 18:51:00 +00:00
|
|
|
int is_server;
|
|
|
|
if (!CBS_get_optional_asn1_bool(&session, &is_server, kIsServerTag,
|
|
|
|
1 /* default to true */)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2016-12-12 18:51:00 +00:00
|
|
|
}
|
|
|
|
/* TODO: in time we can include |is_server| for servers too, then we can
|
|
|
|
enforce that client and server sessions are never mixed up. */
|
|
|
|
|
|
|
|
ret->is_server = is_server;
|
|
|
|
|
2016-12-14 01:05:36 +00:00
|
|
|
if (!SSL_SESSION_parse_u16(&session, &ret->peer_signature_algorithm,
|
|
|
|
kPeerSignatureAlgorithmTag, 0) ||
|
2016-12-07 20:29:45 +00:00
|
|
|
!SSL_SESSION_parse_u32(&session, &ret->ticket_max_early_data,
|
|
|
|
kTicketMaxEarlyDataTag, 0) ||
|
2017-02-20 22:00:20 +00:00
|
|
|
!SSL_SESSION_parse_u32(&session, &ret->auth_timeout, kAuthTimeoutTag,
|
|
|
|
ret->timeout) ||
|
2017-02-14 18:20:40 +00:00
|
|
|
!SSL_SESSION_parse_octet_string(&session, &ret->early_alpn,
|
|
|
|
&ret->early_alpn_len, kEarlyALPNTag) ||
|
2016-12-14 01:05:36 +00:00
|
|
|
CBS_len(&session) != 0) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2017-07-20 19:49:15 +01:00
|
|
|
return nullptr;
|
2014-10-19 09:33:38 +01:00
|
|
|
}
|
|
|
|
|
2015-06-16 00:41:48 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-25 23:49:37 +00:00
|
|
|
int ssl_session_serialize(const SSL_SESSION *in, CBB *cbb) {
|
|
|
|
return SSL_SESSION_to_bytes_full(in, cbb, 0);
|
|
|
|
}
|
|
|
|
|
Move libssl's internals into the bssl namespace.
This is horrible, but everything else I tried was worse. The goal with
this CL is to take the extern "C" out of ssl/internal.h and move most
symbols to namespace bssl, so we can start using C++ helpers and
destructors without worry.
Complications:
- Public API functions must be extern "C" and match their declaration in
ssl.h, which is unnamespaced. C++ really does not want you to
interleave namespaced and unnamespaced things. One can actually write
a namespaced extern "C" function, but this means, from C++'s
perspective, the function is namespaced. Trying to namespace the
public header would worked but ended up too deep a rabbithole.
- Our STACK_OF macros do not work right in namespaces.
- The typedefs for our exposed but opaque types are visible in the
header files and copied into consuming projects as forward
declarations. We ultimately want to give SSL a destructor, but
clobbering an unnamespaced ssl_st::~ssl_st seems bad manners.
- MSVC complains about ambiguous names if one typedefs SSL to bssl::SSL.
This CL opts for:
- ssl/*.cc must begin with #define BORINGSSL_INTERNAL_CXX_TYPES. This
informs the public headers to create forward declarations which are
compatible with our namespaces.
- For now, C++-defined type FOO ends up at bssl::FOO with a typedef
outside. Later I imagine we'll rename many of them.
- Internal functions get namespace bssl, so we stop worrying about
stomping the tls1_prf symbol. Exported C functions are stuck as they
are. Rather than try anything weird, bite the bullet and reorder files
which have a mix of public and private functions. I expect that over
time, the public functions will become fairly small as we move logic
to more idiomatic C++.
Files without any public C functions can just be written normally.
- To avoid MSVC troubles, some bssl types are renamed to CPlusPlusStyle
in advance of them being made idiomatic C++.
Bug: 132
Change-Id: Ic931895e117c38b14ff8d6e5a273e868796c7581
Reviewed-on: https://boringssl-review.googlesource.com/18124
Reviewed-by: David Benjamin <davidben@google.com>
2017-07-18 21:34:25 +01:00
|
|
|
} // namespace bssl
|
|
|
|
|
|
|
|
using namespace bssl;
|
|
|
|
|
|
|
|
int SSL_SESSION_to_bytes(const SSL_SESSION *in, uint8_t **out_data,
|
|
|
|
size_t *out_len) {
|
|
|
|
if (in->not_resumable) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// If the caller has an unresumable session, e.g. if |SSL_get_session| were
|
|
|
|
// called on a TLS 1.3 or False Started connection, serialize with a
|
|
|
|
// placeholder value so it is not accidentally deserialized into a resumable
|
|
|
|
// one.
|
Move libssl's internals into the bssl namespace.
This is horrible, but everything else I tried was worse. The goal with
this CL is to take the extern "C" out of ssl/internal.h and move most
symbols to namespace bssl, so we can start using C++ helpers and
destructors without worry.
Complications:
- Public API functions must be extern "C" and match their declaration in
ssl.h, which is unnamespaced. C++ really does not want you to
interleave namespaced and unnamespaced things. One can actually write
a namespaced extern "C" function, but this means, from C++'s
perspective, the function is namespaced. Trying to namespace the
public header would worked but ended up too deep a rabbithole.
- Our STACK_OF macros do not work right in namespaces.
- The typedefs for our exposed but opaque types are visible in the
header files and copied into consuming projects as forward
declarations. We ultimately want to give SSL a destructor, but
clobbering an unnamespaced ssl_st::~ssl_st seems bad manners.
- MSVC complains about ambiguous names if one typedefs SSL to bssl::SSL.
This CL opts for:
- ssl/*.cc must begin with #define BORINGSSL_INTERNAL_CXX_TYPES. This
informs the public headers to create forward declarations which are
compatible with our namespaces.
- For now, C++-defined type FOO ends up at bssl::FOO with a typedef
outside. Later I imagine we'll rename many of them.
- Internal functions get namespace bssl, so we stop worrying about
stomping the tls1_prf symbol. Exported C functions are stuck as they
are. Rather than try anything weird, bite the bullet and reorder files
which have a mix of public and private functions. I expect that over
time, the public functions will become fairly small as we move logic
to more idiomatic C++.
Files without any public C functions can just be written normally.
- To avoid MSVC troubles, some bssl types are renamed to CPlusPlusStyle
in advance of them being made idiomatic C++.
Bug: 132
Change-Id: Ic931895e117c38b14ff8d6e5a273e868796c7581
Reviewed-on: https://boringssl-review.googlesource.com/18124
Reviewed-by: David Benjamin <davidben@google.com>
2017-07-18 21:34:25 +01:00
|
|
|
static const char kNotResumableSession[] = "NOT RESUMABLE";
|
|
|
|
|
|
|
|
*out_len = strlen(kNotResumableSession);
|
|
|
|
*out_data = (uint8_t *)BUF_memdup(kNotResumableSession, *out_len);
|
|
|
|
if (*out_data == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-01-25 23:49:37 +00:00
|
|
|
ScopedCBB cbb;
|
|
|
|
if (!CBB_init(cbb.get(), 256) ||
|
|
|
|
!SSL_SESSION_to_bytes_full(in, cbb.get(), 0) ||
|
|
|
|
!CBB_finish(cbb.get(), out_data, out_len)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
Move libssl's internals into the bssl namespace.
This is horrible, but everything else I tried was worse. The goal with
this CL is to take the extern "C" out of ssl/internal.h and move most
symbols to namespace bssl, so we can start using C++ helpers and
destructors without worry.
Complications:
- Public API functions must be extern "C" and match their declaration in
ssl.h, which is unnamespaced. C++ really does not want you to
interleave namespaced and unnamespaced things. One can actually write
a namespaced extern "C" function, but this means, from C++'s
perspective, the function is namespaced. Trying to namespace the
public header would worked but ended up too deep a rabbithole.
- Our STACK_OF macros do not work right in namespaces.
- The typedefs for our exposed but opaque types are visible in the
header files and copied into consuming projects as forward
declarations. We ultimately want to give SSL a destructor, but
clobbering an unnamespaced ssl_st::~ssl_st seems bad manners.
- MSVC complains about ambiguous names if one typedefs SSL to bssl::SSL.
This CL opts for:
- ssl/*.cc must begin with #define BORINGSSL_INTERNAL_CXX_TYPES. This
informs the public headers to create forward declarations which are
compatible with our namespaces.
- For now, C++-defined type FOO ends up at bssl::FOO with a typedef
outside. Later I imagine we'll rename many of them.
- Internal functions get namespace bssl, so we stop worrying about
stomping the tls1_prf symbol. Exported C functions are stuck as they
are. Rather than try anything weird, bite the bullet and reorder files
which have a mix of public and private functions. I expect that over
time, the public functions will become fairly small as we move logic
to more idiomatic C++.
Files without any public C functions can just be written normally.
- To avoid MSVC troubles, some bssl types are renamed to CPlusPlusStyle
in advance of them being made idiomatic C++.
Bug: 132
Change-Id: Ic931895e117c38b14ff8d6e5a273e868796c7581
Reviewed-on: https://boringssl-review.googlesource.com/18124
Reviewed-by: David Benjamin <davidben@google.com>
2017-07-18 21:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int SSL_SESSION_to_bytes_for_ticket(const SSL_SESSION *in, uint8_t **out_data,
|
|
|
|
size_t *out_len) {
|
2018-01-25 23:49:37 +00:00
|
|
|
ScopedCBB cbb;
|
|
|
|
if (!CBB_init(cbb.get(), 256) ||
|
|
|
|
!SSL_SESSION_to_bytes_full(in, cbb.get(), 1) ||
|
|
|
|
!CBB_finish(cbb.get(), out_data, out_len)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
Move libssl's internals into the bssl namespace.
This is horrible, but everything else I tried was worse. The goal with
this CL is to take the extern "C" out of ssl/internal.h and move most
symbols to namespace bssl, so we can start using C++ helpers and
destructors without worry.
Complications:
- Public API functions must be extern "C" and match their declaration in
ssl.h, which is unnamespaced. C++ really does not want you to
interleave namespaced and unnamespaced things. One can actually write
a namespaced extern "C" function, but this means, from C++'s
perspective, the function is namespaced. Trying to namespace the
public header would worked but ended up too deep a rabbithole.
- Our STACK_OF macros do not work right in namespaces.
- The typedefs for our exposed but opaque types are visible in the
header files and copied into consuming projects as forward
declarations. We ultimately want to give SSL a destructor, but
clobbering an unnamespaced ssl_st::~ssl_st seems bad manners.
- MSVC complains about ambiguous names if one typedefs SSL to bssl::SSL.
This CL opts for:
- ssl/*.cc must begin with #define BORINGSSL_INTERNAL_CXX_TYPES. This
informs the public headers to create forward declarations which are
compatible with our namespaces.
- For now, C++-defined type FOO ends up at bssl::FOO with a typedef
outside. Later I imagine we'll rename many of them.
- Internal functions get namespace bssl, so we stop worrying about
stomping the tls1_prf symbol. Exported C functions are stuck as they
are. Rather than try anything weird, bite the bullet and reorder files
which have a mix of public and private functions. I expect that over
time, the public functions will become fairly small as we move logic
to more idiomatic C++.
Files without any public C functions can just be written normally.
- To avoid MSVC troubles, some bssl types are renamed to CPlusPlusStyle
in advance of them being made idiomatic C++.
Bug: 132
Change-Id: Ic931895e117c38b14ff8d6e5a273e868796c7581
Reviewed-on: https://boringssl-review.googlesource.com/18124
Reviewed-by: David Benjamin <davidben@google.com>
2017-07-18 21:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int i2d_SSL_SESSION(SSL_SESSION *in, uint8_t **pp) {
|
|
|
|
uint8_t *out;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (!SSL_SESSION_to_bytes(in, &out, &len)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > INT_MAX) {
|
|
|
|
OPENSSL_free(out);
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_OVERFLOW);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pp) {
|
|
|
|
OPENSSL_memcpy(*pp, out, len);
|
|
|
|
*pp += len;
|
|
|
|
}
|
|
|
|
OPENSSL_free(out);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2017-02-01 23:49:37 +00:00
|
|
|
SSL_SESSION *SSL_SESSION_from_bytes(const uint8_t *in, size_t in_len,
|
|
|
|
const SSL_CTX *ctx) {
|
2015-06-16 00:41:48 +01:00
|
|
|
CBS cbs;
|
|
|
|
CBS_init(&cbs, in, in_len);
|
2017-07-20 19:49:15 +01:00
|
|
|
UniquePtr<SSL_SESSION> ret =
|
|
|
|
SSL_SESSION_parse(&cbs, ctx->x509_method, ctx->pool);
|
|
|
|
if (!ret) {
|
2015-06-16 00:41:48 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (CBS_len(&cbs) != 0) {
|
2015-06-29 05:28:17 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
|
2015-06-16 00:41:48 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-07-20 19:49:15 +01:00
|
|
|
return ret.release();
|
2015-06-16 00:41:48 +01:00
|
|
|
}
|