|
@@ -22,16 +22,8 @@
|
|
|
#include "stdio.h"
|
|
|
|
|
|
dh_session_t global_session_info;
|
|
|
-
|
|
|
sgx_dh_session_t sgx_dh_session;
|
|
|
-
|
|
|
- uint8_t iv[12];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity, uint8_t* expected_mr_enclave, uint8_t* expected_mr_signer);
|
|
|
-
|
|
|
+uint8_t iv[12];
|
|
|
|
|
|
uint32_t process_protobuf_dh_msg1_generate_protobuf_dh_msg2(protobuf_sgx_dh_msg1_t& protobuf_msg1, protobuf_sgx_dh_msg2_t& protobuf_msg2, uint32_t* session_id)
|
|
|
{
|
|
@@ -74,11 +66,8 @@ uint32_t process_protobuf_dh_msg3(protobuf_sgx_dh_msg3_t& protobuf_msg3, uint32_
|
|
|
if(SGX_SUCCESS != ret_status)
|
|
|
return ret_status;
|
|
|
|
|
|
-
|
|
|
- ret_status = verify_peer_enclave_trust(&responder_identity, NULL, NULL);
|
|
|
- if(ret_status != 0)
|
|
|
- return ret_status;
|
|
|
- memset(iv, 0, 12);
|
|
|
+
|
|
|
+ memset(iv, 0, 12);
|
|
|
memcpy(global_session_info.active.AEK, &dh_aek, sizeof(sgx_key_128bit_t));
|
|
|
global_session_info.session_id = 1;
|
|
|
global_session_info.active.counter = 0;
|
|
@@ -87,91 +76,14 @@ uint32_t process_protobuf_dh_msg3(protobuf_sgx_dh_msg3_t& protobuf_msg3, uint32_
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
-uint32_t generate_encrypted_rsa_keypair_hash(uint8_t* op_ciphertext, uint8_t* op_encrypted_tag)
|
|
|
-{
|
|
|
- uint8_t hash[32]; uint32_t return_status;
|
|
|
- unsigned char key[16]; uint32_t count;
|
|
|
- for(count=0;count<16;count++)
|
|
|
- key[count]=global_session_info.active.AEK[count];
|
|
|
- return_status=generate_rsa_keypair_hash(hash);
|
|
|
- if(return_status!=0)
|
|
|
- return return_status;
|
|
|
-
|
|
|
- uint8_t ciphertext[32];
|
|
|
- uint8_t encryption_tag[16];
|
|
|
- int ciphertext_len=32;
|
|
|
- uint8_t iv[12];
|
|
|
- memset(iv, 0, 12);
|
|
|
- return_status=aes_cipher(1, key, iv, hash, 32, op_ciphertext, &ciphertext_len, op_encrypted_tag);
|
|
|
- for(count=0;count<32;count++)
|
|
|
- {
|
|
|
- printf("0x%02x ", op_ciphertext[count]);
|
|
|
- }
|
|
|
- printf("\n");
|
|
|
- fflush(stdout);
|
|
|
- for(count=0;count<16;count++)
|
|
|
- {
|
|
|
- printf("0x%02x ", op_encrypted_tag[count]);
|
|
|
- }
|
|
|
- printf("\n"); fflush(stdout);
|
|
|
- return return_status;
|
|
|
-}
|
|
|
-*/
|
|
|
|
|
|
uint32_t decrypt_wrapper(uint8_t* ciphertext, int ciphertext_len, uint8_t* op_plaintext, int* op_plaintext_len, uint8_t* ip_encrypted_tag)
|
|
|
{
|
|
|
- uint8_t hash[32]; uint32_t return_status;
|
|
|
+ uint32_t return_status;
|
|
|
unsigned char key[16]; uint32_t count;
|
|
|
for(count=0;count<16;count++)
|
|
|
key[count]=global_session_info.active.AEK[count];
|
|
|
printf("Doing decryption\n"); fflush(stdout);
|
|
|
-
|
|
|
-
|
|
|
return_status=aes_cipher(0, key, iv, ciphertext, ciphertext_len, op_plaintext, op_plaintext_len, ip_encrypted_tag);
|
|
|
-
|
|
|
- for(count=0;count<*op_plaintext_len;count++)
|
|
|
- {
|
|
|
- printf("0x%02x ", op_plaintext[count]);
|
|
|
- }
|
|
|
- printf("\n");
|
|
|
- fflush(stdout);
|
|
|
- for(count=0;count<16;count++)
|
|
|
- {
|
|
|
- printf("0x%02x ", ip_encrypted_tag[count]);
|
|
|
- }
|
|
|
- printf("\n"); fflush(stdout);
|
|
|
-*/ return return_status;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity, uint8_t* expected_mr_enclave, uint8_t* expected_mr_signer)
|
|
|
-{
|
|
|
- int count=0;
|
|
|
- if(!peer_enclave_identity)
|
|
|
- return INVALID_PARAMETER_ERROR;
|
|
|
-
|
|
|
- sgx_measurement_t actual_mr_enclave = peer_enclave_identity->mr_enclave;
|
|
|
- sgx_measurement_t actual_mr_signer = peer_enclave_identity->mr_signer;
|
|
|
-
|
|
|
- if(expected_mr_enclave != NULL)
|
|
|
- {
|
|
|
- for(count=0; count<SGX_HASH_SIZE; count++)
|
|
|
- {
|
|
|
- if( actual_mr_enclave.m[count] != expected_mr_enclave[count] )
|
|
|
- return ENCLAVE_TRUST_ERROR;
|
|
|
- }
|
|
|
- }
|
|
|
- if(expected_mr_signer !=NULL)
|
|
|
- {
|
|
|
- for(count=0; count<SGX_HASH_SIZE; count++)
|
|
|
- {
|
|
|
- if( actual_mr_signer.m[count] != expected_mr_signer[count] )
|
|
|
- return ENCLAVE_TRUST_ERROR;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return SUCCESS;
|
|
|
+ return return_status;
|
|
|
}
|