|
@@ -29,6 +29,9 @@
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
#include "Decryptor.h"
|
|
|
#include "sgx_tseal.h"
|
|
|
#include "sgx_tcrypto.h"
|
|
@@ -37,15 +40,18 @@
|
|
|
#include "error_codes.h"
|
|
|
|
|
|
|
|
|
- ECDSASignatureBox Decryptor::signatureBox;
|
|
|
- HybridEncryptionBox Decryptor::hybridEncryptionBoxClient;
|
|
|
- SymmetricEncryptionBox Decryptor::symmetricEncryptionBoxApache;
|
|
|
+ ECDSASignatureBox Decryptor::signatureBox;
|
|
|
+ HybridEncryptionBox Decryptor::hybridEncryptionBoxClient;
|
|
|
+ SymmetricEncryptionBox Decryptor::symmetricEncryptionBoxApache;
|
|
|
SymmetricEncryptionBox Decryptor::symmetricEncryptionBoxVerifier;
|
|
|
- uint8_t Decryptor::verifier_mr_enclave[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
- uint8_t Decryptor::apache_mr_signer[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
+ uint8_t Decryptor::verifier_mr_enclave[32] = {0};
|
|
|
+ uint8_t Decryptor::apache_mr_signer[32] = {0};
|
|
|
+ unsigned int successful_la_count;
|
|
|
+ uint8_t Decryptor::plaintext_mitigator_header_H[ECDH_PUBLIC_KEY_SIZE + 32 + 64]={0};
|
|
|
|
|
|
|
|
|
- uint32_t Decryptor::create_mitigator_token_M(uint8_t* token)
|
|
|
+
|
|
|
+ uint32_t Decryptor::create_mitigator_token_M(uint8_t* token)
|
|
|
{
|
|
|
uint32_t internal_return_status;
|
|
|
uint32_t counter;
|
|
@@ -62,30 +68,50 @@
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- uint32_t Decryptor::create_mitigator_header_H(uint8_t* signature_data, uint8_t* signature)
|
|
|
+
|
|
|
+ uint32_t Decryptor::create_mitigator_header_H(uint8_t* signature_data_and_signature)
|
|
|
{
|
|
|
uint32_t internal_return_status;
|
|
|
- uint8_t local_signature[64];
|
|
|
- uint8_t local_signature_data[ECDH_PUBLIC_KEY_SIZE + 32];
|
|
|
+ uint8_t local_signature_data_and_signature[ECDH_PUBLIC_KEY_SIZE + 32 + 64];
|
|
|
uint32_t counter;
|
|
|
-
|
|
|
- if(LocalAttestationTrusted::get_one_successful_la_done() < 1)
|
|
|
- return 0xde;
|
|
|
- internal_return_status = Decryptor::create_mitigator_token_M(local_signature_data);
|
|
|
+ internal_return_status = Decryptor::create_mitigator_token_M(local_signature_data_and_signature);
|
|
|
if(internal_return_status != 0x0)
|
|
|
return internal_return_status;
|
|
|
|
|
|
- internal_return_status = signatureBox.sign(local_signature_data, ECDH_PUBLIC_KEY_SIZE + 32, local_signature);
|
|
|
+ internal_return_status = signatureBox.sign(local_signature_data_and_signature, ECDH_PUBLIC_KEY_SIZE + 32, local_signature_and_signature + ECDH_PUBLIC_KEY_SIZE + 32);
|
|
|
if(internal_return_status != 0x0)
|
|
|
return internal_return_status;
|
|
|
- for(counter=0;counter<ECDH_PUBLIC_KEY_SIZE + 32;counter++)
|
|
|
- signature_data[counter] = local_signature_data[counter];
|
|
|
- for(counter=0;counter<64;counter++)
|
|
|
- signature[counter] = local_signature[counter];
|
|
|
+ for(counter=0;counter<ECDH_PUBLIC_KEY_SIZE + 32 + 64;counter++)
|
|
|
+ signature_data_and_signature[counter] = local_signature_data_and_signature[counter];
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ uint32_t Decryptor::encrypt_mitigator_header_H_to_apache(uint8_t* ciphertext_token_H_plus_tag)
|
|
|
+ {
|
|
|
+ uint32_t counter;
|
|
|
+ uint8_t sign_data_and_sign[ECDH_PUBLIC_KEY_SIZE + 32 + 64 + 10];
|
|
|
+ uint8_t temp_tag[16];
|
|
|
+ uint32_t temp_ciphertext_token_H_length;
|
|
|
+ uint32_t internal_return_status;
|
|
|
+
|
|
|
+ if(successful_la_count != 2)
|
|
|
+ return 0x33;
|
|
|
+
|
|
|
+ internal_return_status = create_mitigator_header_H(plaintext_mitigator_header_H);
|
|
|
+ if(internal_return_status != 0)
|
|
|
+ return internal_return_status;
|
|
|
+
|
|
|
+ internal_return_status = symmetricEncryptionBoxApache.encrypt_decrypt(1, plaintext_mitigator_header_H, ECDH_PUBLIC_KEY_SIZE + 32 + 64, ciphertext_token_H_plus_tag, &temp_ciphertext_token_H_length);
|
|
|
+ if(internal_return_status != 0)
|
|
|
+ return internal_return_status;
|
|
|
+
|
|
|
+ if(temp_ciphertext_token_H_length != 160)
|
|
|
+ return 0x45;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
uint32_t Decryptor::create_long_term_signing_keypair(uint8_t* private_public_key_string)
|
|
|
{
|
|
|
uint32_t internal_return_status;
|
|
@@ -97,11 +123,11 @@
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
uint32_t Decryptor::initialize_symmetric_key_decrypt_client_data(uint8_t* plaintext_client_public_key_plus_encrypted_data_plus_tag, uint32_t total_length, uint8_t* plaintext_client_data, uint32_t* plaintext_client_data_length)
|
|
|
{
|
|
|
uint8_t* ciphertext;
|
|
|
uint32_t ciphertext_length;
|
|
|
- uint8_t* tag;
|
|
|
uint32_t internal_return_status;
|
|
|
|
|
|
internal_return_status = hybridEncryptionBoxClient.initialize_symmetric_key(plaintext_client_public_key_plus_encrypted_data_plus_tag);
|
|
@@ -111,91 +137,53 @@
|
|
|
|
|
|
ciphertext = plaintext_client_public_key_plus_encrypted_data_plus_tag + ECDH_PUBLIC_KEY_SIZE;
|
|
|
ciphertext_length = total_length - ECDH_PUBLIC_KEY_SIZE - 16;
|
|
|
- tag = ciphertext + ciphertext_length;
|
|
|
|
|
|
- internal_return_status = hybridEncryptionBoxClient.encrypt_decrypt(0, ciphertext, ciphertext_length, plaintext_client_data, plaintext_client_data_length, tag);
|
|
|
+ internal_return_status = hybridEncryptionBoxClient.encrypt_decrypt(0, ciphertext, ciphertext_length, plaintext_client_data, plaintext_client_data_length);
|
|
|
return internal_return_status;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- uint32_t Decryptor::create_and_seal_long_term_signing_key_pair(uint32_t* sealed_data_length, uint8_t* sealed_data)
|
|
|
- {
|
|
|
+
|
|
|
+ uint32_t Decryptor::create_and_seal_long_term_signing_key_pair(uint32_t* sealed_data_length, uint8_t* sealed_data)
|
|
|
+ {
|
|
|
uint32_t sgx_libcall_status;
|
|
|
uint32_t internal_return_status;
|
|
|
uint32_t temp_sealed_data_length;
|
|
|
uint8_t* temp_sealed_data;
|
|
|
uint8_t private_public_key_string[ECDH_PUBLIC_KEY_SIZE + ECDH_PRIVATE_KEY_SIZE];
|
|
|
uint32_t counter;
|
|
|
-
|
|
|
+
|
|
|
temp_sealed_data_length = sgx_calc_sealed_data_size(0, ECDH_PUBLIC_KEY_SIZE + ECDH_PRIVATE_KEY_SIZE);
|
|
|
if(temp_sealed_data_length == 0xFFFFFFFF)
|
|
|
return 0x01;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
temp_sealed_data = (uint8_t*) malloc(temp_sealed_data_length);
|
|
|
-
|
|
|
+
|
|
|
internal_return_status = create_long_term_signing_keypair(private_public_key_string);
|
|
|
- if(internal_return_status != 0)
|
|
|
- {
|
|
|
- free(temp_sealed_data);
|
|
|
- return internal_return_status;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- temp_sealed_data[counter]=counter;
|
|
|
- */
|
|
|
+ if(internal_return_status != 0)
|
|
|
+ {
|
|
|
+ free(temp_sealed_data);
|
|
|
+ return internal_return_status;
|
|
|
+ }
|
|
|
+
|
|
|
sgx_libcall_status = sgx_seal_data(0, NULL, 3*SGX_ECP256_KEY_SIZE, private_public_key_string, temp_sealed_data_length, (sgx_sealed_data_t*) temp_sealed_data);
|
|
|
if(sgx_libcall_status != SGX_SUCCESS)
|
|
|
{
|
|
|
free(temp_sealed_data);
|
|
|
return sgx_libcall_status;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for(counter=0;counter<temp_sealed_data_length;counter++)
|
|
|
*(sealed_data + counter)= *(temp_sealed_data + counter);
|
|
|
- *sealed_data_length = temp_sealed_data_length;
|
|
|
+ *sealed_data_length = temp_sealed_data_length;
|
|
|
free(temp_sealed_data);
|
|
|
-
|
|
|
- return 0;
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- uint32_t Decryptor::create_and_encrypt_mitigator_header_H(uint8_t* ciphertext_token_H_plus_tag)
|
|
|
- {
|
|
|
- uint32_t counter;
|
|
|
- uint8_t sign_data_and_sign[ECDH_PUBLIC_KEY_SIZE + 32 + 64];
|
|
|
- uint8_t temp_ciphertext_token_H[ECDH_PUBLIC_KEY_SIZE + 32 + 64 + 10];
|
|
|
- uint8_t temp_tag[16];
|
|
|
- uint32_t temp_ciphertext_token_H_length;
|
|
|
- uint32_t internal_return_status;
|
|
|
-
|
|
|
- internal_return_status = create_mitigator_header_H(sign_data_and_sign, sign_data_and_sign + ECDH_PUBLIC_KEY_SIZE + 32);
|
|
|
- if(internal_return_status != 0)
|
|
|
- return internal_return_status;
|
|
|
-
|
|
|
- internal_return_status = symmetricEncryptionBoxApache.encrypt_decrypt(1, sign_data_and_sign, ECDH_PUBLIC_KEY_SIZE + 32 + 64, temp_ciphertext_token_H, &temp_ciphertext_token_H_length, temp_tag);
|
|
|
- if(internal_return_status != 0)
|
|
|
- return internal_return_status;
|
|
|
-
|
|
|
- if(temp_ciphertext_token_H_length != 160)
|
|
|
- return 0x45;
|
|
|
-
|
|
|
- for(counter=0; counter<160; counter++)
|
|
|
- {
|
|
|
- *(ciphertext_token_H_plus_tag + counter) = *(temp_ciphertext_token_H + counter);
|
|
|
- }
|
|
|
- for(counter=0; counter<16; counter++)
|
|
|
- {
|
|
|
- *(ciphertext_token_H_plus_tag + counter) = *(temp_tag + counter);
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- uint32_t Decryptor::unseal_and_restore_long_term_signing_key_pair(uint8_t* sealed_data, uint32_t* sgx_sealed_data_length)
|
|
|
- {
|
|
|
+
|
|
|
+ uint32_t Decryptor::unseal_and_restore_long_term_signing_key_pair(uint8_t* sealed_data, uint32_t* sgx_sealed_data_length)
|
|
|
+ {
|
|
|
uint32_t temp_plaintext_length;
|
|
|
uint8_t* temp_plaintext;
|
|
|
uint32_t counter;
|
|
@@ -224,39 +212,45 @@
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- uint32_t Decryptor::decrypt_verifiers_message_set_apache_mrsigner(uint8_t* ciphertext_plus_tag)
|
|
|
- {
|
|
|
- uint8_t temp_apache_mrsigner[32+10];
|
|
|
- uint32_t temp_apache_mrsigner_length;
|
|
|
- uint32_t internal_return_status;
|
|
|
- uint32_t counter;
|
|
|
- uint8_t* tag;
|
|
|
-
|
|
|
- tag = ciphertext_plus_tag + 32;
|
|
|
- internal_return_status = symmetricEncryptionBoxVerifier.encrypt_decrypt(0, ciphertext_plus_tag, 32, temp_apache_mrsigner, &temp_apache_mrsigner_length, tag);
|
|
|
- if(internal_return_status != 0)
|
|
|
- return internal_return_status;
|
|
|
- if(temp_apache_mrsigner_length != 32)
|
|
|
- return 0x33;
|
|
|
+ uint32_t Decryptor::process_verifiers_message(uint8_t* input_ciphertext, uint32_t input_ciphertext_plus_tag_length)
|
|
|
+ {
|
|
|
+ uint8_t *first_decryption_output, *plaintext_client_data, *temp_output_ciphertext;
|
|
|
+ uint32_t first_decryption_output_length, plaintext_client_data_length;
|
|
|
+ uint32_t temp_output_ciphertext_length, internal_return_status;
|
|
|
+ uint8_t temp_output_tag[16]; uint32_t counter;
|
|
|
+ if(successful_la_count != 1)
|
|
|
+ return 0x23;
|
|
|
+
|
|
|
+ first_decryption_output = (uint8_t*) malloc(input_ciphertext_plus_tag_length);
|
|
|
+ internal_return_status = symmetricEncryptionBoxVerifier.encrypt_decrypt(0, input_ciphertext, input_ciphertext_plus_tag_length - 16, first_decryption_output, &first_decryption_output_length);
|
|
|
+ if(internal_return_status != 0)
|
|
|
+ {
|
|
|
+ free(first_decryption_output);
|
|
|
+ return internal_return_status;
|
|
|
+ }
|
|
|
|
|
|
- for(counter=0; counter<32; counter++)
|
|
|
- {
|
|
|
- apache_mr_signer[counter] = *(temp_apache_mrsigner + counter);
|
|
|
- }
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ if(first_decryption_output_length != 32)
|
|
|
+ {
|
|
|
+ free(first_decryption_output);
|
|
|
+ return 0x33;
|
|
|
+ }
|
|
|
+ for(counter=0; counter<32; counter++)
|
|
|
+ {
|
|
|
+ apache_mr_signer[counter] = *(first_decryption_output + counter);
|
|
|
+ }
|
|
|
+ free(first_decryption_output);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- uint32_t Decryptor::process_apache_message_generate_response(uint8_t* input_ciphertext, uint32_t input_ciphertext_plus_tag_length, uint8_t* output_ciphertext_plus_tag, uint32_t* output_ciphertext_plus_tag_length)
|
|
|
- {
|
|
|
- uint8_t *first_decryption_output, *plaintext_client_data, *temp_output_ciphertext;
|
|
|
+
|
|
|
+ uint32_t Decryptor::process_apache_message_generate_response(uint8_t* input_ciphertext, uint32_t input_ciphertext_plus_tag_length, uint8_t* output_ciphertext_plus_tag, uint32_t* output_ciphertext_plus_tag_length)
|
|
|
+ {
|
|
|
+ uint8_t *first_decryption_output, *plaintext_client_data;
|
|
|
uint32_t first_decryption_output_length, plaintext_client_data_length;
|
|
|
- uint32_t temp_output_ciphertext_length, internal_return_status;
|
|
|
- uint8_t temp_output_tag[16]; uint32_t counter;
|
|
|
+ uint32_t internal_return_status;
|
|
|
|
|
|
first_decryption_output = (uint8_t*) malloc(input_ciphertext_plus_tag_length);
|
|
|
- internal_return_status = symmetricEncryptionBoxApache.encrypt_decrypt(0, input_ciphertext, input_ciphertext_plus_tag_length, first_decryption_output, &first_decryption_output_length, input_ciphertext + input_ciphertext_plus_tag_length - 16);
|
|
|
+ internal_return_status = symmetricEncryptionBoxApache.encrypt_decrypt(0, input_ciphertext, input_ciphertext_plus_tag_length - 16, first_decryption_output, &first_decryption_output_length);
|
|
|
if(internal_return_status != 0)
|
|
|
{
|
|
|
free(first_decryption_output);
|
|
@@ -269,33 +263,24 @@
|
|
|
if(internal_return_status != 0)
|
|
|
return internal_return_status;
|
|
|
|
|
|
- temp_output_ciphertext = (uint8_t*) malloc(plaintext_client_data_length + 20);
|
|
|
|
|
|
- internal_return_status = symmetricEncryptionBoxApache.encrypt_decrypt(1, plaintext_client_data, plaintext_client_data_length, temp_output_ciphertext, &temp_output_ciphertext_length, temp_output_tag);
|
|
|
+ internal_return_status = symmetricEncryptionBoxApache.encrypt_decrypt(1, plaintext_client_data, plaintext_client_data_length, output_ciphertext_plus_tag, output_ciphertext_plus_tag_length);
|
|
|
free(plaintext_client_data);
|
|
|
if(internal_return_status != 0)
|
|
|
- {
|
|
|
- free(temp_output_ciphertext);
|
|
|
return internal_return_status;
|
|
|
- }
|
|
|
-
|
|
|
- for(counter=0; counter<temp_output_ciphertext_length; counter++)
|
|
|
- output_ciphertext_plus_tag[counter] = temp_output_ciphertext[counter];
|
|
|
- free(temp_output_ciphertext);
|
|
|
- for(counter=0; counter<16;counter++)
|
|
|
- output_ciphertext_plus_tag[counter] = temp_output_tag[counter];
|
|
|
- *output_ciphertext_plus_tag_length = temp_output_ciphertext_length + 16;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-uint32_t Decryptor::verify_peer_enclave_trust(uint8_t* given_mr_enclave, uint8_t* given_mr_signer, uint8_t* dhaek)
|
|
|
-{
|
|
|
- uint32_t count;
|
|
|
- if(LocalAttestationTrusted::get_one_successful_la_done() == 0)
|
|
|
+
|
|
|
+ uint32_t Decryptor::verify_peer_enclave_trust(uint8_t* given_mr_enclave, uint8_t* given_mr_signer, uint8_t* dhaek)
|
|
|
+ {
|
|
|
+ uint32_t count;
|
|
|
+ uint32_t internal_return_status;
|
|
|
+ if(successful_la_count == 0)
|
|
|
{
|
|
|
for(count=0; count<SGX_HASH_SIZE; count++)
|
|
|
verifier_mr_enclave[count] = given_mr_enclave[count];
|
|
|
- symmetricEncryptionBoxVerifier.set_symmetric_key(dhaek);
|
|
|
+ symmetricEncryptionBoxVerifier.set_symmetric_key(dhaek);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -304,12 +289,13 @@ uint32_t Decryptor::verify_peer_enclave_trust(uint8_t* given_mr_enclave, uint8_t
|
|
|
if( given_mr_signer[count] != apache_mr_signer[count] )
|
|
|
return ENCLAVE_TRUST_ERROR;
|
|
|
}
|
|
|
- symmetricEncryptionBoxApache.set_symmetric_key(dhaek);
|
|
|
+ symmetricEncryptionBoxApache.set_symmetric_key(dhaek);
|
|
|
}
|
|
|
+ successful_la_count ++;
|
|
|
return SGX_SUCCESS;
|
|
|
}
|
|
|
|
|
|
-void Decryptor::calculate_sealed_keypair_size(uint32_t* output_length)
|
|
|
-{
|
|
|
- *output_length = sgx_calc_sealed_data_size(0, ECDH_PUBLIC_KEY_SIZE + ECDH_PRIVATE_KEY_SIZE);
|
|
|
-}
|
|
|
+ void Decryptor::calculate_sealed_keypair_size(uint32_t* output_length)
|
|
|
+ {
|
|
|
+ *output_length = sgx_calc_sealed_data_size(0, ECDH_PUBLIC_KEY_SIZE + ECDH_PRIVATE_KEY_SIZE);
|
|
|
+}
|