|
|
@@ -35,72 +35,12 @@ namespace LocalAttestationUntrusted {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- void get_lengths_for_protobuf_serialized_array(extension_to_decryptor_enclosed_msg &protobuf_ext_to_decryptor,
|
|
|
- uint32_t *output_lengths)
|
|
|
- {
|
|
|
- uint32_t number_of_ciphertext_fields, counter, total_length;
|
|
|
- // Didn't use bytesize() or bytesizelong() for getting the lengths of the public key or the ciphertext string
|
|
|
- // as that gives the *serialized* length of the message which should be an upper-bound.
|
|
|
- // Can switch to that if necessary for time performance reasons.
|
|
|
- total_length=protobuf_ext_to_decryptor.ciphertext_client_public_key().length();
|
|
|
- number_of_ciphertext_fields=protobuf_ext_to_decryptor.ciphertext_fields_size();
|
|
|
- for(counter=0; counter<number_of_ciphertext_fields; counter++)
|
|
|
- total_length+=protobuf_ext_to_decryptor.ciphertext_fields(counter).field().length();
|
|
|
- output_lengths[0]=total_length;
|
|
|
- output_lengths[1]=number_of_ciphertext_fields;
|
|
|
- }
|
|
|
-
|
|
|
- void create_array_from_protobuf(extension_to_decryptor_enclosed_msg &protobuf_ext_to_decryptor,
|
|
|
- unsigned char* double_ciphertext_client_data, uint32_t* sizes_array, uint32_t* sizes_array_length)
|
|
|
- {
|
|
|
- uint32_t counter, size_of_field, number_of_fields;
|
|
|
- unsigned char* ptr;
|
|
|
-
|
|
|
- // Set the size of the first element - the public key - and copy it to the output array.
|
|
|
- sizes_array[0] = protobuf_ext_to_decryptor.ciphertext_client_public_key().length();
|
|
|
- ptr=strncpy((char*)double_ciphertext_client_data, protobuf_ext_to_decryptor.ciphertext_client_public_key().c_str(),
|
|
|
- size_of_field);
|
|
|
-
|
|
|
- // Start copying past the length copied above, copy all ciphertext fields to the output string array
|
|
|
- // and set their lengths in the output integers array
|
|
|
- number_of_fields=protobuf_ext_to_decryptor.ciphertext_fields_size();
|
|
|
- for(counter=0;counter<number_of_fields;counter++)
|
|
|
- {
|
|
|
- // First element of the LHS array is the length of the client's public key.
|
|
|
- sizes_array[counter+1] = protobuf_ext_to_decryptor.ciphertext_fields(counter).field().length();
|
|
|
- ptr = strncpy((char*)ptr, protobuf_ext_to_decryptor.ciphertext_fields(counter).field().c_str(), size_of_field);
|
|
|
- }
|
|
|
- sizes_array_length=number_of_fields+1;
|
|
|
- }
|
|
|
-
|
|
|
- void create_protobuf_from_array( unsigned char* ciphertext_client_data, uint32_t* sizes_array, uint32_t sizes_array_length,
|
|
|
- extension_to_decryptor_enclosed_msg protobuf_extension_decryptor_msg)
|
|
|
- {
|
|
|
- uint32_t counter;
|
|
|
- void* ptr;
|
|
|
-
|
|
|
- // Note that we don't care about setting the client public key as we don't include that in the outgoing message
|
|
|
- // to the extension.
|
|
|
- ptr=ciphertext_client_data;
|
|
|
- for(counter=0; counter<sizes_array_length; counter++)
|
|
|
- {
|
|
|
- protobuf_extension_decryptor_msg.mutable_ciphertext_fields(counter).set_field(ptr, sizes_array[counter]);
|
|
|
- ptr+=sizes_array[counter];
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
- uint32_t get_decrypted_client_data(uint8_t* array, uint32_t array_length)
|
|
|
- {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
int decrypt_client_data(uint32_t own_enclave_id, int fd, int time_file_fd) {
|
|
|
- /* extension_to_decryptor_enclosed_msg protobuf_extension_decryptor_msg;
|
|
|
- unsigned char* double_ciphertext_client_data, ciphertext_client_data;
|
|
|
- uint32_t* input_sizes_array, output_sizes_array;
|
|
|
- uint32_t ecall_input_lengths[2];
|
|
|
- uint32_t ecall_output_lengths[2];
|
|
|
+ extension_to_decryptor_enclosed_msg protobuf_extension_decryptor_msg;
|
|
|
+ unsigned char *double_ciphertext, *ciphertext;
|
|
|
+ uint32_t *input_sizes_array, *output_sizes_array;
|
|
|
+ uint32_t double_ciphertext_length;
|
|
|
+ uint32_t number_of_double_ciphertext_fields;
|
|
|
uint32_t sgx_ret;
|
|
|
|
|
|
// Get a message of the type decryptor_to_extension msg
|
|
|
@@ -110,40 +50,44 @@ namespace LocalAttestationUntrusted {
|
|
|
return 0xf3;
|
|
|
}
|
|
|
|
|
|
- get_length_of_protobuf_serialized_array(protobuf_extension_decryptor_msg, lengths);
|
|
|
- double_ciphertext_client_data=(unsigned char*) malloc(ecall_input_lengths[0]);
|
|
|
- ciphertext_client_data = (unsigned char*) malloc(ecall_input_lengths[0]);
|
|
|
+ PostLAProtobufNativeTransforms::get_lengths_for_protobuf_serialized_array(protobuf_extension_decryptor_msg, &double_ciphertext_length,
|
|
|
+ &number_of_double_ciphertext_fields);
|
|
|
|
|
|
- input_sizes_array = (uint32_t*) malloc(ecall_input_lengths[1] * sizeof(uint32_t));
|
|
|
+ double_ciphertext=(unsigned char*) malloc(double_ciphertext_length);
|
|
|
+ ciphertext = (unsigned char*) malloc(double_ciphertext_length);
|
|
|
|
|
|
- create_array_from_protobuf(protobuf_extension_decryptor_msg, double_ciphertext_client_data,
|
|
|
- input_sizes_array, ecall_input_lengths[1]);
|
|
|
+ input_sizes_array = (uint32_t*) malloc(number_of_double_ciphertext_fields * sizeof(uint32_t));
|
|
|
+ output_sizes_array = (uint32_t*) malloc(number_of_double_ciphertext_fields * sizeof(uint32_t));
|
|
|
+ PostLAProtobufNativeTransforms::create_array_from_protobuf(protobuf_extension_decryptor_msg, double_ciphertext,
|
|
|
+ input_sizes_array, &number_of_double_ciphertext_fields);
|
|
|
|
|
|
// Call the enclave's decryption function with these arguments and get back another vector of ciphertexts.
|
|
|
- Decryptor_decrypt_client_data_wrapper(own_enclave_id, &sgx_ret,
|
|
|
- double_ciphertext_client_data,
|
|
|
- ecall_input_lengths[0],
|
|
|
+ Decryptor_process_apache_message_generate_response_wrapper(own_enclave_id, &sgx_ret,
|
|
|
+ double_ciphertext,
|
|
|
+ double_ciphertext_length,
|
|
|
input_sizes_array,
|
|
|
- ecall_input_lengths[1]);
|
|
|
+ number_of_double_ciphertext_fields,
|
|
|
+ ciphertext,
|
|
|
+ output_sizes_array);
|
|
|
|
|
|
- free(double_ciphertext_client_data);
|
|
|
+ free(double_ciphertext);
|
|
|
free(input_sizes_array);
|
|
|
|
|
|
// Error checking
|
|
|
if(!sgx_ret)
|
|
|
{
|
|
|
- free(ciphertext_client_data);
|
|
|
+ free(ciphertext);
|
|
|
free(output_sizes_array);
|
|
|
return 0x32;
|
|
|
}
|
|
|
- output_sizes_array = (uint32_t *) malloc(ecall_input_lengths[1] * sizeof(uint32_t)); // Upper bound: it should be lengths[1]-1.
|
|
|
|
|
|
// Clear the protobuf msg above and reset it with the output arguments of the ecall.
|
|
|
protobuf_extension_decryptor_msg.clear_ciphertext_client_public_key();
|
|
|
protobuf_extension_decryptor_msg.clear_ciphertext_fields();
|
|
|
- create_protobuf_from_array(ciphertext_client_data, output_sizes_array, ecall_output_lengths[1],
|
|
|
- protobuf_extension_decryptor_msg);
|
|
|
- free(ciphertext_client_data);
|
|
|
+ PostLAProtobufNativeTransforms::create_protobuf_from_array(ciphertext, output_sizes_array,
|
|
|
+ number_of_double_ciphertext_fields,
|
|
|
+ protobuf_extension_decryptor_msg);
|
|
|
+ free(ciphertext);
|
|
|
free(output_sizes_array);
|
|
|
|
|
|
// write message to apache extension
|