Updates for SGX 2.18 reproducible build.

Signed-off-by: Zhang Lili <lili.z.zhang@intel.com>
This commit is contained in:
Zhang Lili
2022-11-24 13:42:20 +08:00
parent 1deb73848a
commit 30012305f3
560 changed files with 63548 additions and 31923 deletions
+13 -4
View File
@@ -41,7 +41,7 @@
// put common files here in a definition of Macro to reduce
// redundancy code
#ifdef CLIENT_UNTRUSTED
#ifdef CLIENT_USE_QVL
#include "sgx_utls.h"
#define PRINT printf
#define GETCURRTIME time
@@ -49,9 +49,18 @@
#define FREE_SUPDATA tee_free_supplemental_data_host
#else
#include "sgx_ttls.h"
extern void t_print(const char* fmt, ...);
#define PRINT t_print
#define GETCURRTIME t_time
#define PRINT T_PRINT
#define GETCURRTIME T_TIME
#define VERIFY_CALLBACK tee_verify_certificate_with_evidence
#define FREE_SUPDATA tee_free_supplemental_data
#endif
#ifdef TDX_ENV
#define T_PRINT printf
#define T_TIME time
#else
extern void t_print(const char* fmt, ...);
extern void t_time(time_t *c_time);
#define T_PRINT t_print
#define T_TIME t_time
#endif
@@ -41,11 +41,11 @@ sgx_status_t generate_certificate_and_pkey(X509*& certificate, EVP_PKEY*& pkey)
int key_type = RSA_TYPE;
if (key_type) {
t_print(" generating keys by EC P-384\n");
PRINT(" generating keys by EC P-384\n");
}
else
{
t_print(" generating keys by RSA 3072\n");
PRINT(" generating keys by RSA 3072\n");
}
result = generate_key_pair(
key_type, &public_key_buffer,
@@ -54,14 +54,14 @@ sgx_status_t generate_certificate_and_pkey(X509*& certificate, EVP_PKEY*& pkey)
&private_key_buffer_size);
if (result != SGX_SUCCESS)
{
t_print(" failed to generate RSA key pair\n");
PRINT(" failed to generate RSA key pair\n");
goto done;
}
t_print("public_key_buf_size:[%ld]\n", public_key_buffer_size);
t_print("%s\n", public_key_buffer);
t_print("private_key_buf_size:[%ld]\n", private_key_buffer_size);
t_print("%s\n", private_key_buffer);
PRINT("public_key_buf_size:[%ld]\n", public_key_buffer_size);
PRINT("%s\n", public_key_buffer);
PRINT("private_key_buf_size:[%ld]\n", private_key_buffer_size);
PRINT("%s\n", private_key_buffer);
qresult = tee_get_certificate_with_evidence(
certificate_subject_name,
private_key_buffer,
@@ -74,7 +74,7 @@ sgx_status_t generate_certificate_and_pkey(X509*& certificate, EVP_PKEY*& pkey)
if (qresult != SGX_QL_SUCCESS || output_certificate == nullptr)
{
if (output_certificate == nullptr)
t_print(" null certificate\n");
PRINT(" null certificate\n");
p_sgx_tls_qe_err_msg(qresult);
goto done;
}
@@ -91,18 +91,18 @@ sgx_status_t generate_certificate_and_pkey(X509*& certificate, EVP_PKEY*& pkey)
&certificate_buffer_ptr,
(long)output_certificate_size)) == nullptr)
{
t_print("Failed to convert DER format certificate to X509 structure\n");
PRINT("Failed to convert DER format certificate to X509 structure\n");
goto done;
}
mem = BIO_new_mem_buf((void*)private_key_buffer, -1);
if (!mem)
{
t_print("Failed to convert private key buf into BIO_mem\n");
PRINT("Failed to convert private key buf into BIO_mem\n");
goto done;
}
if ((pkey = PEM_read_bio_PrivateKey(mem, nullptr, 0, nullptr)) == nullptr)
{
t_print("Failed to convert private key buffer into EVP_KEY format\n");
PRINT("Failed to convert private key buffer into EVP_KEY format\n");
goto done;
}
@@ -130,32 +130,32 @@ sgx_status_t load_tls_certificates_and_keys(
if (generate_certificate_and_pkey(certificate, pkey) != SGX_SUCCESS)
{
t_print("Cannot generate certificate and pkey\n");
PRINT("Cannot generate certificate and pkey\n");
goto exit;
}
if (certificate == nullptr)
{
t_print("null cert\n");
PRINT("null cert\n");
goto exit;
}
if (!SSL_CTX_use_certificate(ctx, certificate))
{
t_print("Cannot load certificate on the server\n");
PRINT("Cannot load certificate on the server\n");
goto exit;
}
if (!SSL_CTX_use_PrivateKey(ctx, pkey))
{
t_print("Cannot load private key on the server\n");
PRINT("Cannot load private key on the server\n");
goto exit;
}
/* verify private key */
if (!SSL_CTX_check_private_key(ctx))
{
t_print("Private key does not match the public certificate\n");
PRINT("Private key does not match the public certificate\n");
goto exit;
}
result = SGX_SUCCESS;
@@ -185,7 +185,7 @@ sgx_status_t initalize_ssl_context(SSL_CONF_CTX*& ssl_conf_ctx, SSL_CTX*& ctx)
if ((ssl_conf_return_value =
SSL_CONF_cmd(ssl_conf_ctx, "MinProtocol", "TLSv1.2")) < 0)
{
t_print(
PRINT(
"Setting MinProtocol for ssl context configuration failed with "
"error %d \n",
ssl_conf_return_value);
@@ -194,7 +194,7 @@ sgx_status_t initalize_ssl_context(SSL_CONF_CTX*& ssl_conf_ctx, SSL_CTX*& ctx)
if ((ssl_conf_return_value =
SSL_CONF_cmd(ssl_conf_ctx, "MaxProtocol", "TLSv1.3")) < 0)
{
t_print(
PRINT(
"Setting MaxProtocol for ssl context configuration failed with "
"error %d \n",
ssl_conf_return_value);
@@ -203,7 +203,7 @@ sgx_status_t initalize_ssl_context(SSL_CONF_CTX*& ssl_conf_ctx, SSL_CTX*& ctx)
if ((ssl_conf_return_value = SSL_CONF_cmd(
ssl_conf_ctx, "CipherString", cipher_list_tlsv12_below)) < 0)
{
t_print(
PRINT(
"Setting CipherString for ssl context configuration failed with "
"error %d \n",
ssl_conf_return_value);
@@ -212,7 +212,7 @@ sgx_status_t initalize_ssl_context(SSL_CONF_CTX*& ssl_conf_ctx, SSL_CTX*& ctx)
if ((ssl_conf_return_value = SSL_CONF_cmd(
ssl_conf_ctx, "Ciphersuites", cipher_list_tlsv13)) < 0)
{
t_print(
PRINT(
"Setting Ciphersuites for ssl context configuration failed with "
"error %d \n",
ssl_conf_return_value);
@@ -221,7 +221,7 @@ sgx_status_t initalize_ssl_context(SSL_CONF_CTX*& ssl_conf_ctx, SSL_CTX*& ctx)
if ((ssl_conf_return_value =
SSL_CONF_cmd(ssl_conf_ctx, "Curves", supported_curves)) < 0)
{
t_print(
PRINT(
"Setting Curves for ssl context configuration failed with error %d "
"\n",
ssl_conf_return_value);
@@ -229,7 +229,7 @@ sgx_status_t initalize_ssl_context(SSL_CONF_CTX*& ssl_conf_ctx, SSL_CTX*& ctx)
}
if (!SSL_CONF_CTX_finish(ssl_conf_ctx))
{
t_print("Error finishing ssl context configuration \n");
PRINT("Error finishing ssl context configuration \n");
goto exit;
}
ret = SGX_SUCCESS;
@@ -258,18 +258,18 @@ int read_from_session_peer(
if (error == SSL_ERROR_WANT_READ)
continue;
t_print("Failed! SSL_read returned error=%d\n", error);
PRINT("Failed! SSL_read returned error=%d\n", error);
ret = bytes_read;
break;
}
t_print(" %d bytes read from session peer\n", bytes_read);
PRINT(" %d bytes read from session peer\n", bytes_read);
// check to see if received payload is expected
if ((bytes_read != payload_length) ||
(memcmp(payload, buffer, bytes_read) != 0))
{
t_print(
PRINT(
"ERROR: expected reading %lu bytes but only "
"received %d bytes\n",
payload_length,
@@ -279,7 +279,7 @@ int read_from_session_peer(
}
else
{
t_print(" received all the expected data from the session peer\n\n");
PRINT(" received all the expected data from the session peer\n\n");
ret = 0;
break;
}
@@ -303,12 +303,12 @@ int write_to_session_peer(
int error = SSL_get_error(ssl_session, bytes_written);
if (error == SSL_ERROR_WANT_WRITE)
continue;
t_print("Failed! SSL_write returned %d\n", error);
PRINT("Failed! SSL_write returned %d\n", error);
ret = bytes_written;
goto exit;
}
t_print("%lu bytes written to session peer\n\n", payload_length);
PRINT("%lu bytes written to session peer\n\n", payload_length);
exit:
return ret;
}
+18 -18
View File
@@ -52,19 +52,19 @@ int get_pkey_by_rsa(EVP_PKEY *pk)
e = BN_new();
if (!e) {
t_print("BN_new failed\n");
PRINT("BN_new failed\n");
return res;
}
res = BN_set_word(e, (BN_ULONG)RSA_F4);
if (!res) {
t_print("BN_set_word failed (%d)\n", res);
PRINT("BN_set_word failed (%d)\n", res);
return res;
}
rsa = RSA_new();
if (!rsa) {
t_print("RSA_new failed\n");
PRINT("RSA_new failed\n");
res = -1;
return res;
}
@@ -78,7 +78,7 @@ int get_pkey_by_rsa(EVP_PKEY *pk)
if (!res)
{
t_print("RSA_generate_key failed (%d)\n", res);
PRINT("RSA_generate_key failed (%d)\n", res);
return res;
}
@@ -99,14 +99,14 @@ int get_pkey_by_ec(EVP_PKEY *pk)
res = EVP_PKEY_keygen_init(ctx);
if (res <= 0)
{
t_print("EC_generate_key failed (%d)\n", res);
PRINT("EC_generate_key failed (%d)\n", res);
return res;
}
res = EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, NID_secp384r1);
if (res <= 0)
{
t_print("EC_generate_key failed (%d)\n", res);
PRINT("EC_generate_key failed (%d)\n", res);
return res;
}
@@ -114,7 +114,7 @@ int get_pkey_by_ec(EVP_PKEY *pk)
res = EVP_PKEY_keygen(ctx, &pk);
if (res <= 0)
{
t_print("EC_generate_key failed (%d)\n", res);
PRINT("EC_generate_key failed (%d)\n", res);
return res;
}
@@ -141,7 +141,7 @@ sgx_status_t generate_key_pair(
pkey = EVP_PKEY_new();
if (!pkey)
{
t_print("EVP_PKEY_new failed\n");
PRINT("EVP_PKEY_new failed\n");
result = SGX_ERROR_UNEXPECTED;
goto done;
}
@@ -163,7 +163,7 @@ sgx_status_t generate_key_pair(
if (res <= 0)
{
t_print("get_pkey failed (%d)\n", res);
PRINT("get_pkey failed (%d)\n", res);
result = SGX_ERROR_UNEXPECTED;
goto done;
}
@@ -172,7 +172,7 @@ sgx_status_t generate_key_pair(
local_public_key = (uint8_t*)malloc(RSA_3072_PUBLIC_KEY_SIZE);
if (!local_public_key)
{
t_print("out-of-memory:calloc(local_public_key failed\n");
PRINT("out-of-memory:calloc(local_public_key failed\n");
result = SGX_ERROR_OUT_OF_EPC;
goto done;
}
@@ -181,7 +181,7 @@ sgx_status_t generate_key_pair(
local_private_key = (uint8_t*)malloc(RSA_3072_PRIVATE_KEY_SIZE);
if (!local_private_key)
{
t_print("out-of-memory: calloc(local_private_key) failed\n");
PRINT("out-of-memory: calloc(local_private_key) failed\n");
result = SGX_ERROR_OUT_OF_EPC;
goto done;
}
@@ -192,21 +192,21 @@ sgx_status_t generate_key_pair(
bio = BIO_new(BIO_s_mem());
if (!bio)
{
t_print("BIO_new for local_public_key failed\n");
PRINT("BIO_new for local_public_key failed\n");
goto done;
}
res = PEM_write_bio_PUBKEY(bio, pkey);
if (!res)
{
t_print("PEM_write_bio_PUBKEY failed (%d)\n", res);
PRINT("PEM_write_bio_PUBKEY failed (%d)\n", res);
goto done;
}
res = BIO_read(bio, local_public_key, RSA_3072_PUBLIC_KEY_SIZE);
if (!res)
{
t_print("BIO_read public key failed (%d)\n", res);
PRINT("BIO_read public key failed (%d)\n", res);
goto done;
}
BIO_free(bio);
@@ -215,7 +215,7 @@ sgx_status_t generate_key_pair(
bio = BIO_new(BIO_s_mem());
if (!bio)
{
t_print("BIO_new for local_public_key failed\n");
PRINT("BIO_new for local_public_key failed\n");
goto done;
}
@@ -223,14 +223,14 @@ sgx_status_t generate_key_pair(
bio, pkey, nullptr, nullptr, 0, nullptr, nullptr);
if (!res)
{
t_print("PEM_write_bio_PrivateKey failed (%d)\n", res);
PRINT("PEM_write_bio_PrivateKey failed (%d)\n", res);
goto done;
}
res = BIO_read(bio, local_private_key, RSA_3072_PRIVATE_KEY_SIZE);
if (!res)
{
t_print("BIO_read private key failed (%d)\n", res);
PRINT("BIO_read private key failed (%d)\n", res);
goto done;
}
@@ -243,7 +243,7 @@ sgx_status_t generate_key_pair(
*public_key_size = strlen(reinterpret_cast<const char *>(local_public_key)) + 1;
*private_key_size = strlen(reinterpret_cast<const char *>(local_private_key)) + 1;
t_print("public_key_size %d, private_key_size %d\n", *public_key_size, *private_key_size);
PRINT("public_key_size %d, private_key_size %d\n", *public_key_size, *private_key_size);
result = SGX_SUCCESS;
done:
@@ -47,10 +47,6 @@
const unsigned char certificate_subject_name[] =
"CN=Intel SGX Enclave, O=Intel Corporation,C=US";
void t_time(time_t *c_time);
void t_print(const char* fmt, ...);
sgx_status_t generate_key_pair(
int type,
uint8_t** public_key,