Switch ssl_aead_ctx, ssl_file, and ssl_lib to C++.
Bug: 132
Change-Id: I0b83bb05082aa6dad8c15f906cebc2d4f2d5216b
Reviewed-on: https://boringssl-review.googlesource.com/17764
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Steven Valdez <svaldez@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
diff --git a/ssl/CMakeLists.txt b/ssl/CMakeLists.txt
index c7b4a3b..d825827 100644
--- a/ssl/CMakeLists.txt
+++ b/ssl/CMakeLists.txt
@@ -16,14 +16,14 @@
s3_both.cc
s3_lib.cc
s3_pkt.cc
- ssl_aead_ctx.c
+ ssl_aead_ctx.cc
ssl_asn1.cc
ssl_buffer.cc
ssl_cert.cc
ssl_cipher.cc
ssl_ecdh.cc
- ssl_file.c
- ssl_lib.c
+ ssl_file.cc
+ ssl_lib.cc
ssl_privkey.c
ssl_privkey_cc.cc
ssl_session.c
diff --git a/ssl/ssl_aead_ctx.c b/ssl/ssl_aead_ctx.cc
similarity index 98%
rename from ssl/ssl_aead_ctx.c
rename to ssl/ssl_aead_ctx.cc
index 1b9dcd2..0cdf717 100644
--- a/ssl/ssl_aead_ctx.c
+++ b/ssl/ssl_aead_ctx.cc
@@ -61,7 +61,7 @@
enc_key_len += fixed_iv_len;
}
- SSL_AEAD_CTX *aead_ctx = OPENSSL_malloc(sizeof(SSL_AEAD_CTX));
+ SSL_AEAD_CTX *aead_ctx = (SSL_AEAD_CTX *)OPENSSL_malloc(sizeof(SSL_AEAD_CTX));
if (aead_ctx == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/ssl/ssl_file.c b/ssl/ssl_file.cc
similarity index 100%
rename from ssl/ssl_file.c
rename to ssl/ssl_file.cc
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.cc
similarity index 98%
rename from ssl/ssl_lib.c
rename to ssl/ssl_lib.cc
index d88427a..346f2c1 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.cc
@@ -234,7 +234,7 @@
return NULL;
}
- ret = OPENSSL_malloc(sizeof(SSL_CTX));
+ ret = (SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));
if (ret == NULL) {
goto err;
}
@@ -365,7 +365,7 @@
return NULL;
}
- SSL *ssl = OPENSSL_malloc(sizeof(SSL));
+ SSL *ssl = (SSL *)OPENSSL_malloc(sizeof(SSL));
if (ssl == NULL) {
goto err;
}
@@ -408,8 +408,8 @@
}
if (ctx->supported_group_list) {
- ssl->supported_group_list = BUF_memdup(ctx->supported_group_list,
- ctx->supported_group_list_len * 2);
+ ssl->supported_group_list = (uint16_t *)BUF_memdup(
+ ctx->supported_group_list, ctx->supported_group_list_len * 2);
if (!ssl->supported_group_list) {
goto err;
}
@@ -417,8 +417,8 @@
}
if (ctx->alpn_client_proto_list) {
- ssl->alpn_client_proto_list = BUF_memdup(ctx->alpn_client_proto_list,
- ctx->alpn_client_proto_list_len);
+ ssl->alpn_client_proto_list = (uint8_t *)BUF_memdup(
+ ctx->alpn_client_proto_list, ctx->alpn_client_proto_list_len);
if (ssl->alpn_client_proto_list == NULL) {
goto err;
}
@@ -720,7 +720,8 @@
}
int got_handshake;
- int ret = ssl->method->read_app_data(ssl, &got_handshake, buf, num, peek);
+ int ret = ssl->method->read_app_data(ssl, &got_handshake, (uint8_t *)buf,
+ num, peek);
if (ret > 0 || !got_handshake) {
ssl->s3->key_update_count = 0;
return ret;
@@ -775,7 +776,8 @@
}
}
- ret = ssl->method->write_app_data(ssl, &needs_handshake, buf, num);
+ ret = ssl->method->write_app_data(ssl, &needs_handshake,
+ (const uint8_t *)buf, num);
} while (needs_handshake);
return ret;
}
@@ -1041,11 +1043,14 @@
int SSL_get_tls_unique(const SSL *ssl, uint8_t *out, size_t *out_len,
size_t max_out) {
+ *out_len = 0;
+ OPENSSL_memset(out, 0, max_out);
+
/* tls-unique is not defined for SSL 3.0 or TLS 1.3. */
if (!ssl->s3->initial_handshake_complete ||
ssl3_protocol_version(ssl) < TLS1_VERSION ||
ssl3_protocol_version(ssl) >= TLS1_3_VERSION) {
- goto err;
+ return 0;
}
/* The tls-unique value is the first Finished message in the handshake, which
@@ -1056,7 +1061,7 @@
if (ssl->session != NULL) {
/* tls-unique is broken for resumed sessions unless EMS is used. */
if (!ssl->session->extended_master_secret) {
- goto err;
+ return 0;
}
finished = ssl->s3->previous_server_finished;
finished_len = ssl->s3->previous_server_finished_len;
@@ -1069,11 +1074,6 @@
OPENSSL_memcpy(out, finished, *out_len);
return 1;
-
-err:
- *out_len = 0;
- OPENSSL_memset(out, 0, max_out);
- return 0;
}
static int set_session_id_context(CERT *cert, const uint8_t *sid_ctx,
@@ -1392,7 +1392,7 @@
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_TICKET_KEYS_LENGTH);
return 0;
}
- uint8_t *out_bytes = out;
+ uint8_t *out_bytes = reinterpret_cast<uint8_t *>(out);
OPENSSL_memcpy(out_bytes, ctx->tlsext_tick_key_name, 16);
OPENSSL_memcpy(out_bytes + 16, ctx->tlsext_tick_hmac_key, 16);
OPENSSL_memcpy(out_bytes + 32, ctx->tlsext_tick_aes_key, 16);
@@ -1407,7 +1407,7 @@
OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_TICKET_KEYS_LENGTH);
return 0;
}
- const uint8_t *in_bytes = in;
+ const uint8_t *in_bytes = reinterpret_cast<const uint8_t *>(in);
OPENSSL_memcpy(ctx->tlsext_tick_key_name, in_bytes, 16);
OPENSSL_memcpy(ctx->tlsext_tick_hmac_key, in_bytes + 16, 16);
OPENSSL_memcpy(ctx->tlsext_tick_aes_key, in_bytes + 32, 16);
@@ -1691,7 +1691,7 @@
int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const uint8_t *protos,
unsigned protos_len) {
OPENSSL_free(ctx->alpn_client_proto_list);
- ctx->alpn_client_proto_list = BUF_memdup(protos, protos_len);
+ ctx->alpn_client_proto_list = (uint8_t *)BUF_memdup(protos, protos_len);
if (!ctx->alpn_client_proto_list) {
return 1;
}
@@ -1702,7 +1702,7 @@
int SSL_set_alpn_protos(SSL *ssl, const uint8_t *protos, unsigned protos_len) {
OPENSSL_free(ssl->alpn_client_proto_list);
- ssl->alpn_client_proto_list = BUF_memdup(protos, protos_len);
+ ssl->alpn_client_proto_list = (uint8_t *)BUF_memdup(protos, protos_len);
if (!ssl->alpn_client_proto_list) {
return 1;
}