|
@@ -48,13 +48,13 @@
|
|
extern "C" {
|
|
extern "C" {
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity, sgx_measurement_t* measurement);
|
|
|
|
|
|
+uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity);
|
|
#ifdef __cplusplus
|
|
#ifdef __cplusplus
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
-uint32_t create_ecdsa_key_pair(sgx_ec256_public_t* pub_key, sgx_ec256_private_t* priv_key);
|
|
|
|
-void serialize_key_pair_to_string( sgx_ec256_public_t* pub_key, sgx_ec256_private_t* signing_priv_key, uint8_t* private_public_key_string);
|
|
|
|
-void deserialize_string_to_key_pair(uint8_t* private_public_key_string, sgx_ec256_public_t* pub_key, sgx_ec256_private_t* priv_key);
|
|
|
|
|
|
+//uint32_t create_ecdsa_key_pair(sgx_ec256_public_t* pub_key, sgx_ec256_private_t* priv_key);
|
|
|
|
+//void serialize_key_pair_to_string( sgx_ec256_public_t* pub_key, sgx_ec256_private_t* signing_priv_key, uint8_t* private_public_key_string);
|
|
|
|
+//void deserialize_string_to_key_pair(uint8_t* private_public_key_string, sgx_ec256_public_t* pub_key, sgx_ec256_private_t* priv_key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -66,12 +66,8 @@ void deserialize_string_to_key_pair(uint8_t* private_public_key_string, sgx_ec25
|
|
|
|
|
|
ATTESTATION_STATUS generate_session_id(uint32_t *session_id);
|
|
ATTESTATION_STATUS generate_session_id(uint32_t *session_id);
|
|
ATTESTATION_STATUS end_session();
|
|
ATTESTATION_STATUS end_session();
|
|
-sgx_ec256_private_t signing_priv_key;
|
|
|
|
-sgx_ec256_private_t short_term_priv_key;
|
|
|
|
-sgx_ec256_public_t short_term_pub_key; // for testing only: to test verification of signature
|
|
|
|
-uint32_t one_la_done;
|
|
|
|
-sgx_measurement_t verifier_mr_enclave;
|
|
|
|
-sgx_measurement_t apache_mr_signer;
|
|
|
|
|
|
+//sgx_ec256_private_t signing_priv_key;
|
|
|
|
+uint32_t one_successful_la_done;
|
|
sgx_ecc_state_handle_t ecc_state;
|
|
sgx_ecc_state_handle_t ecc_state;
|
|
|
|
|
|
|
|
|
|
@@ -129,7 +125,7 @@ ATTESTATION_STATUS session_request(sgx_dh_msg1_t *dh_msg1,
|
|
ATTESTATION_STATUS exchange_report(
|
|
ATTESTATION_STATUS exchange_report(
|
|
sgx_dh_msg2_t *dh_msg2,
|
|
sgx_dh_msg2_t *dh_msg2,
|
|
sgx_dh_msg3_t *dh_msg3,
|
|
sgx_dh_msg3_t *dh_msg3,
|
|
- uint32_t* session_id, uint8_t* read)
|
|
|
|
|
|
+ uint32_t* session_id, uint8_t* read_or_write)
|
|
{
|
|
{
|
|
|
|
|
|
sgx_key_128bit_t dh_aek; // Session key
|
|
sgx_key_128bit_t dh_aek; // Session key
|
|
@@ -173,28 +169,17 @@ ATTESTATION_STATUS exchange_report(
|
|
uint32_t hash_count;
|
|
uint32_t hash_count;
|
|
// THIS IS WHERE THE DECRYPTOR VERIFIES THE APACHE'S MRSIGNER IS THE PUBLIC KEY GIVEN AFTER THE LOCAL ATTESTATION WITH THE VERIFIER.
|
|
// THIS IS WHERE THE DECRYPTOR VERIFIES THE APACHE'S MRSIGNER IS THE PUBLIC KEY GIVEN AFTER THE LOCAL ATTESTATION WITH THE VERIFIER.
|
|
//Verify source enclave's trust
|
|
//Verify source enclave's trust
|
|
- if(one_la_done == 0)
|
|
|
|
|
|
+ uint32_t verify_return=verify_peer_enclave_trust(&initiator_identity);
|
|
|
|
+ if(verify_return!=0)
|
|
|
|
+ return verify_return;
|
|
|
|
+ if(one_successful_la_done == 0)
|
|
{
|
|
{
|
|
- one_la_done = 1; *read=1;
|
|
|
|
- uint32_t ret = verify_peer_enclave_trust(&initiator_identity, NULL);
|
|
|
|
- if(ret != SUCCESS)
|
|
|
|
- {
|
|
|
|
- return ret; //INVALID_SESSION;
|
|
|
|
- }
|
|
|
|
- for(hash_count=0; hash_count<32; hash_count++)
|
|
|
|
- verifier_mr_enclave.m[hash_count] = initiator_identity.mr_signer.m[hash_count];
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- one_la_done=0; return 0xFFFFFFFF;
|
|
|
|
- /*
|
|
|
|
- uint32_t ret = verify_peer_enclave_trust(&initiator_identity, &apache_mrsigner);
|
|
|
|
- if(ret != SUCCESS)
|
|
|
|
- {
|
|
|
|
- return ret; //INVALID_SESSION;
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
|
|
+ one_successful_la_done = 1; *read_or_write=1;
|
|
}
|
|
}
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ one_successful_la_done=2; *read_or_write=0;
|
|
|
|
+ }
|
|
|
|
|
|
// TODO: Verify that these changes will be lost on update.
|
|
// TODO: Verify that these changes will be lost on update.
|
|
//save the session ID, status and initialize the session nonce
|
|
//save the session ID, status and initialize the session nonce
|
|
@@ -209,7 +194,7 @@ ATTESTATION_STATUS exchange_report(
|
|
|
|
|
|
return status;
|
|
return status;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+/*
|
|
ATTESTATION_STATUS encrypt(__attribute__((unused)) uint8_t *plaintext, __attribute__((unused)) size_t plaintext_length, __attribute__((unused)) uint8_t* payload_tag, __attribute__((unused)) uint8_t* ciphertext, __attribute__((unused)) uint32_t* active_counter)
|
|
ATTESTATION_STATUS encrypt(__attribute__((unused)) uint8_t *plaintext, __attribute__((unused)) size_t plaintext_length, __attribute__((unused)) uint8_t* payload_tag, __attribute__((unused)) uint8_t* ciphertext, __attribute__((unused)) uint32_t* active_counter)
|
|
{
|
|
{
|
|
// return 0;
|
|
// return 0;
|
|
@@ -271,7 +256,7 @@ free(shared_key); free(temp_plaintext); free(temp_req_message);
|
|
//return global_session_info.active.counter-1;
|
|
//return global_session_info.active.counter-1;
|
|
|
|
|
|
}
|
|
}
|
|
-/*
|
|
|
|
|
|
+
|
|
uint32_t decrypt(__attribute__((unused)) uint8_t* ciphertext, __attribute__((unused)) size_t ciphertext_length, __attribute__((unused)) uint8_t* payload_tag, __attribute__((unused)) uint8_t* plaintext, __attribute__((unused)) size_t plaintext_length)
|
|
uint32_t decrypt(__attribute__((unused)) uint8_t* ciphertext, __attribute__((unused)) size_t ciphertext_length, __attribute__((unused)) uint8_t* payload_tag, __attribute__((unused)) uint8_t* plaintext, __attribute__((unused)) size_t plaintext_length)
|
|
{
|
|
{
|
|
uint32_t count; sgx_status_t status;
|
|
uint32_t count; sgx_status_t status;
|
|
@@ -323,7 +308,7 @@ temp_plaintext, iv, 0xc, NULL, 0, &(temp_req_message->message_aes_gcm_data.paylo
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
|
|
|
|
-
|
|
|
|
|
|
+/*
|
|
uint32_t create_ecdsa_key_pair(sgx_ec256_public_t* pub_key, sgx_ec256_private_t* priv_key)
|
|
uint32_t create_ecdsa_key_pair(sgx_ec256_public_t* pub_key, sgx_ec256_private_t* priv_key)
|
|
{
|
|
{
|
|
sgx_status_t se_ret; sgx_status_t se_ret2;
|
|
sgx_status_t se_ret; sgx_status_t se_ret2;
|
|
@@ -362,16 +347,7 @@ void serialize_key_pair_to_string(sgx_ec256_public_t* pub_key, sgx_ec256_private
|
|
{
|
|
{
|
|
for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++)
|
|
for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++)
|
|
*(private_public_key_string+counter)=signing_priv_key->r[counter - 2*SGX_ECP256_KEY_SIZE];
|
|
*(private_public_key_string+counter)=signing_priv_key->r[counter - 2*SGX_ECP256_KEY_SIZE];
|
|
- }
|
|
|
|
-/*
|
|
|
|
- if(pub_key != NULL) // public key to serialize
|
|
|
|
- {
|
|
|
|
- for(counter=SGX_ECP256_KEY_SIZE;counter<2*SGX_ECP256_KEY_SIZE; counter++)
|
|
|
|
- *(private_public_key_string+counter)=pub_key->gx[counter-SGX_ECP256_KEY_SIZE];
|
|
|
|
-
|
|
|
|
- for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++)
|
|
|
|
- *(private_public_key_string+counter)=pub_key->gy[counter-2*SGX_ECP256_KEY_SIZE];
|
|
|
|
- }*/
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -428,12 +404,12 @@ uint32_t create_and_seal_ecdsa_signing_key_pair(__attribute__((unused)) sgx_ec
|
|
return ret_status; // SGX_SUCCESS;
|
|
return ret_status; // SGX_SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
|
|
+
|
|
uint32_t unseal_and_restore_sealed_signing_key_pair(__attribute__((unused)) sgx_ec256_public_t* pub_key, __attribute__((unused)) uint8_t* sealed_data, __attribute__((unused)) uint32_t* sgx_sealed_data_length)
|
|
uint32_t unseal_and_restore_sealed_signing_key_pair(__attribute__((unused)) sgx_ec256_public_t* pub_key, __attribute__((unused)) uint8_t* sealed_data, __attribute__((unused)) uint32_t* sgx_sealed_data_length)
|
|
{
|
|
{
|
|
return SGX_SUCCESS;
|
|
return SGX_SUCCESS;
|
|
|
|
|
|
-}*/
|
|
|
|
|
|
+}
|
|
|
|
|
|
uint32_t unseal_and_restore_sealed_signing_key_pair(__attribute__((unused)) sgx_ec256_public_t* pub_key, uint8_t* sealed_data, size_t* sgx_sealed_data_length)
|
|
uint32_t unseal_and_restore_sealed_signing_key_pair(__attribute__((unused)) sgx_ec256_public_t* pub_key, uint8_t* sealed_data, size_t* sgx_sealed_data_length)
|
|
{
|
|
{
|
|
@@ -488,7 +464,7 @@ uint32_t create_and_sign_client_side_pub_key(sgx_measurement_t* mr_enclave, sgx
|
|
// create key pair
|
|
// create key pair
|
|
uint32_t ret_status = create_ecdsa_key_pair(&short_term_pub_key, &short_term_priv_key); uint32_t counter;
|
|
uint32_t ret_status = create_ecdsa_key_pair(&short_term_pub_key, &short_term_priv_key); uint32_t counter;
|
|
uint32_t ret_status2;
|
|
uint32_t ret_status2;
|
|
- if(ret_status!=SGX_SUCCESS)
|
|
|
|
|
|
+ if(ret_status!=SGX_SUCCESS)
|
|
return ret_status;
|
|
return ret_status;
|
|
// serialize public key, append mr_enclave
|
|
// serialize public key, append mr_enclave
|
|
uint8_t* public_key_string = (uint8_t*) malloc(3*SGX_ECP256_KEY_SIZE); // for .edl file - size parameter for serialize is 96 and this fits coz we need to append the mr_enclave to the pub key
|
|
uint8_t* public_key_string = (uint8_t*) malloc(3*SGX_ECP256_KEY_SIZE); // for .edl file - size parameter for serialize is 96 and this fits coz we need to append the mr_enclave to the pub key
|
|
@@ -522,7 +498,7 @@ uint32_t create_and_sign_client_side_pub_key(sgx_measurement_t* mr_enclave, sgx
|
|
return 0xFFFFFFFF;
|
|
return 0xFFFFFFFF;
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+*/
|
|
|
|
|
|
|
|
|
|
uint32_t calculate_sealed_data_size( uint32_t input_size)
|
|
uint32_t calculate_sealed_data_size( uint32_t input_size)
|
|
@@ -578,8 +554,9 @@ ATTESTATION_STATUS generate_session_id(uint32_t *session_id)
|
|
|
|
|
|
uint32_t decrypt(uint8_t* ip_ciphertext, uint32_t ciphertext_len, uint8_t* ip_tag, uint8_t* op_plaintext)
|
|
uint32_t decrypt(uint8_t* ip_ciphertext, uint32_t ciphertext_len, uint8_t* ip_tag, uint8_t* op_plaintext)
|
|
{
|
|
{
|
|
|
|
+// if(one_successful_la_done < 2) // doesn't matter as confidentiality of the signer is not a problem - changing it in memory so that the decryptor accepts another mrsigner is a problem.
|
|
|
|
+// return 0xfe; // will not return plaintext to the caller as this is the apache's mrsigner, sent to the verifier (value 1) or no LA done yet (value 0)
|
|
uint32_t return_status2; uint32_t count;
|
|
uint32_t return_status2; uint32_t count;
|
|
-// unsigned char key[16]; uint32_t count;
|
|
|
|
unsigned char key[16];
|
|
unsigned char key[16];
|
|
// copying key to within the enclave as apparently it can't operate on it // TODO: Check if it works now.
|
|
// copying key to within the enclave as apparently it can't operate on it // TODO: Check if it works now.
|
|
for(count=0;count<16;count++)
|
|
for(count=0;count<16;count++)
|
|
@@ -595,41 +572,72 @@ uint32_t decrypt(uint8_t* ip_ciphertext, uint32_t ciphertext_len, uint8_t* ip_ta
|
|
*(tag+count)=*(ip_tag+count);
|
|
*(tag+count)=*(ip_tag+count);
|
|
|
|
|
|
uint8_t* plaintext = (uint8_t*) malloc(ciphertext_len);
|
|
uint8_t* plaintext = (uint8_t*) malloc(ciphertext_len);
|
|
-// uint8_t encryption_tag[16]; uint8_t decryption_tag[16];
|
|
|
|
-
|
|
|
|
-// int ciphertext_len=48; int plaintext_len=32;
|
|
|
|
uint8_t iv[12];
|
|
uint8_t iv[12];
|
|
- // memset(ciphertext, 0, 48); memset(expected_plaintext, 0, 48);
|
|
|
|
|
|
+
|
|
memset(iv, 0, 12); //memcpy(iv, &global_session_info.active.counter, 4);
|
|
memset(iv, 0, 12); //memcpy(iv, &global_session_info.active.counter, 4);
|
|
return_status2=sgx_rijndael128GCM_decrypt((sgx_key_128bit_t*) key, ciphertext, ciphertext_len, plaintext, iv, 0xc, NULL, 0, (sgx_aes_gcm_128bit_tag_t*)tag);
|
|
return_status2=sgx_rijndael128GCM_decrypt((sgx_key_128bit_t*) key, ciphertext, ciphertext_len, plaintext, iv, 0xc, NULL, 0, (sgx_aes_gcm_128bit_tag_t*)tag);
|
|
-/*
|
|
|
|
- // memset(expected_plaintext, 0, 32); memset(encryption_tag, 0, 16); memset(decryption_tag, 0, 16);
|
|
|
|
- return_status=sgx_rijndael128GCM_encrypt((sgx_key_128bit_t*) key, hash, 32, ciphertext, iv, 0xc, NULL, 0, (sgx_aes_gcm_128bit_tag_t*)encryption_tag);
|
|
|
|
- for(count=0;count<32;count++)
|
|
|
|
- *(op_ciphertext+count)=ciphertext[count];
|
|
|
|
-
|
|
|
|
- if(return_status == 0)
|
|
|
|
-return_status2=sgx_rijndael128GCM_decrypt((sgx_key_128bit_t*) key, ciphertext, 32, expected_plaintext, iv, 0xc, NULL, 0, (sgx_aes_gcm_128bit_tag_t*)encryption_tag);
|
|
|
|
- else
|
|
|
|
- return 0xffffffff;*/
|
|
|
|
for(count=0;count<ciphertext_len;count++)
|
|
for(count=0;count<ciphertext_len;count++)
|
|
*(op_plaintext+count)=plaintext[count];
|
|
*(op_plaintext+count)=plaintext[count];
|
|
-
|
|
|
|
|
|
+ free(plaintext); free (ciphertext); free(tag);
|
|
return return_status2;
|
|
return return_status2;
|
|
}
|
|
}
|
|
|
|
|
|
-uint32_t encrypt()
|
|
|
|
|
|
+uint32_t encrypt(uint8_t* ip_ciphertext, uint32_t ciphertext_len, uint8_t* ip_tag, uint8_t* op_plaintext)
|
|
{
|
|
{
|
|
|
|
+ uint32_t return_status2; uint32_t count;
|
|
|
|
+ unsigned char key[16];
|
|
|
|
+ // copying key to within the enclave as apparently it can't operate on it // TODO: Check if it works now.
|
|
|
|
+ for(count=0;count<16;count++)
|
|
|
|
+ key[count]=global_session_info.active.AEK[count];
|
|
|
|
|
|
|
|
+ // copying ciphertext to within the enclave (otherwise it crashes with NOT enclave signal)
|
|
|
|
+ uint8_t* ciphertext = (uint8_t*) malloc(ciphertext_len);
|
|
|
|
+ for(count=0;count<ciphertext_len;count++)
|
|
|
|
+ *(ciphertext+count)=*(ip_ciphertext+count);
|
|
|
|
|
|
|
|
+ uint8_t* tag = (uint8_t*) malloc(16);
|
|
|
|
+ for(count=0;count<16;count++)
|
|
|
|
+ *(tag+count)=*(ip_tag+count);
|
|
|
|
|
|
-return 0;
|
|
|
|
|
|
+ uint8_t* plaintext = (uint8_t*) malloc(ciphertext_len);
|
|
|
|
+ uint8_t iv[12];
|
|
|
|
|
|
|
|
+ memset(iv, 0, 12); //memcpy(iv, &global_session_info.active.counter, 4);
|
|
|
|
+ return_status2=sgx_rijndael128GCM_encrypt((sgx_key_128bit_t*) key, ciphertext, ciphertext_len, plaintext, iv, 0xc, NULL, 0, (sgx_aes_gcm_128bit_tag_t*)tag);
|
|
|
|
+ for(count=0;count<ciphertext_len;count++)
|
|
|
|
+ *(op_plaintext+count)=plaintext[count];
|
|
|
|
+ free(plaintext); free (ciphertext); free(tag);
|
|
|
|
+ return return_status2;
|
|
|
|
+}
|
|
|
|
|
|
|
|
+uint32_t encrypt_internal(uint8_t* ip_ciphertext, uint32_t ciphertext_len, uint8_t* op_tag, uint8_t* op_plaintext)
|
|
|
|
+{
|
|
|
|
+//return encrypt(ip_ciphertext, ciphertext_len, ip_tag, op_plaintext);
|
|
|
|
+ uint32_t return_status2; uint32_t count;
|
|
|
|
+ unsigned char key[16];
|
|
|
|
+ // copying key to within the enclave as apparently it can't operate on it // TODO: Check if it works now.
|
|
|
|
+ for(count=0;count<16;count++)
|
|
|
|
+ key[count]=global_session_info.active.AEK[count];
|
|
|
|
|
|
|
|
+ // copying ciphertext to within the enclave (otherwise it crashes with NOT enclave signal)
|
|
|
|
+ uint8_t* ciphertext = (uint8_t*) malloc(ciphertext_len);
|
|
|
|
+ for(count=0;count<ciphertext_len;count++)
|
|
|
|
+ *(ciphertext+count)=*(ip_ciphertext+count);
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ uint8_t tag[16];
|
|
|
|
+ uint8_t* plaintext = (uint8_t*) malloc(ciphertext_len);
|
|
|
|
+ uint8_t iv[12];
|
|
|
|
+
|
|
|
|
+ memset(iv, 0, 12); //memcpy(iv, &global_session_info.active.counter, 4);
|
|
|
|
+ return_status2=sgx_rijndael128GCM_encrypt((sgx_key_128bit_t*) key, ciphertext, ciphertext_len, plaintext, iv, 0xc, NULL, 0, (sgx_aes_gcm_128bit_tag_t*)tag);
|
|
|
|
+ for(count=0;count<ciphertext_len;count++)
|
|
|
|
+ *(op_plaintext+count)=plaintext[count];
|
|
|
|
+ for(count=0;count<16;count++)
|
|
|
|
+ op_tag[count]=tag[count];
|
|
|
|
+ free(plaintext); free (ciphertext);
|
|
|
|
+ return return_status2;
|
|
|
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
|
|