12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- //#include "ProtobufSgxTransforms.h"
- #include "sgx_tae_service.h"
- #include "ProtobufSealerMessages.pb.h"
- #include <string>
- namespace ProtobufSgxTransforms {
- namespace {
- void encode_counter_id_and_value_to_protobuf(sgx_mc_uuid_t* sgx_monotonic_counter_id, uint32_t* sgx_monotonic_counter_value, protobuf_plaintext_seal_message& protobuf_plaintext) {
- protobuf_plaintext.mutable_monotonic_counter_id()->set_nonce(sgx_monotonic_counter_id->nonce, SGX_MC_UUID_NONCE_SIZE);
- protobuf_plaintext.mutable_monotonic_counter_id()->set_counter_id(sgx_monotonic_counter_id->counter_id, SGX_MC_UUID_COUNTER_ID_SIZE);
- protobuf_plaintext.set_monotonic_counter_value(*sgx_monotonic_counter_value);
- }
- void encode_message_to_protobuf(std::string& plaintext, protobuf_plaintext_seal_message& protobuf_plaintext) {
- protobuf_plaintext.set_message(plaintext);
- }
- void encode_message_and_counter_to_protobuf(std::string& plaintext, sgx_mc_uuid_t* sgx_counter_id, uint32_t* sgx_counter_value, protobuf_plaintext_seal_message& protobuf_plaintext) {
- encode_counter_id_and_value_to_protobuf(sgx_counter_id, sgx_counter_value, protobuf_plaintext);
- encode_message_to_protobuf(plaintext, protobuf_plaintext);
- }
- }
- uint32_t encode_message_and_counter_to_protobuf_string(std::string& plaintext, sgx_mc_uuid_t* sgx_counter_id, uint32_t* sgx_counter_value, std::string& serialized_plaintext) {
- uint32_t ret;
- protobuf_plaintext_seal_message protobuf_plaintext;
- uint32_t total_plaintext_length;
- encode_message_and_counter_to_protobuf(plaintext, sgx_counter_id, sgx_counter_value, protobuf_plaintext);
- total_plaintext_length = protobuf_plaintext.ByteSize(); // TODO: This assignment could be problematic on platforms where the max. positive value for signed int is greater than that for unsigned int?
- if(total_plaintext_length<=0)
- return 1;
- if(!protobuf_plaintext.SerializeToString(&serialized_plaintext))
- return 1;
- return 0;
- }
- void decode_protobuf_message_to_counter_id_and_value(std::string& temp_plaintext_str, sgx_mc_uuid_t* sgx_counter_id, uint32_t* sgx_counter_value) {
- /* protobuf_plaintext_seal_message protobuf_encoded_msg; protobuf_encoded_msg.ParseFromString(temp_plaintext_str);
- std::string protobuf_nonce = protobuf_encoded_msg.mutable_monotonic_counter_id()->nonce();
- std::vector<uint8_t> sgx_nonce_vector(protobuf_nonce.begin(), protobuf_nonce.end());
- uint8_t* id_char = &sgx_nonce_vector[0]; int counter;
- for(counter=0; counter<SGX_MC_UUID_NONCE_SIZE; counter++)
- {
- sgx_counter_id->nonce[counter]=*id_char; id_char++;
- }
- std::string protobuf_counter_id = protobuf_encoded_msg.mutable_monotonic_counter_id()->counter_id();
- std::vector<uint8_t> sgx_counter_id_vector(protobuf_counter_id.begin(), protobuf_counter_id.end());
- id_char = &sgx_counter_id_vector[0];
- for(counter=0; counter<SGX_MC_UUID_COUNTER_ID_SIZE; counter++)
- {
- sgx_counter_id->counter_id[counter]=*id_char; id_char++;
- }
- *sgx_counter_value=protobuf_encoded_msg.monotonic_counter_value();
- */
- }
- void decode_protobuf_message_to_plaintext(std::string& temp_plaintext_str , std::string& plaintext) {
- protobuf_plaintext_seal_message protobuf_encoded_msg; protobuf_encoded_msg.ParseFromString(temp_plaintext_str);
- plaintext = protobuf_encoded_msg.message();
- }
- /* namespace {
- void encode_counter_id_and_value_to_protobuf(sgx_mc_uuid_t* sgx_monotonic_counter_id, uint32_t* sgx_monotonic_counter_value, protobuf_plaintext_seal_message& protobuf_plaintext) {
- protobuf_plaintext->mutable_monotonic_counter_id()->set_nonce(sgx_monotonic_counter_id->nonce, SGX_MC_UUID_NONCE_SIZE);
- protobuf_plaintext->mutable_monotonic_counter_id()->set_counter_id(sgx_monotonic_counter_id->counter_id, SGX_MC_UUID_COUNTER_ID_SIZE);
- protobuf_plaintext->set_monotonic_counter_value(*sgx_monotonic_counter_value);
- }
- void encode_message_to_protobuf(string& plaintext, protobuf_plaintext_seal_message& protobuf_plaintext) {
- protobuf_plaintext->set_message(plaintext);
- }
- void encode_message_and_counter_to_protobuf(std::string& plaintext, sgx_mc_uuid_t* sgx_monotonic_counter_id, uint32_t* sgx_monotonic_counter_value, protobuf_plaintext_seal_message& protobuf_plaintext) {
- encode_counter_id_and_value_to_protobuf(&sgx_counter_id, &sgx_counter_value, protobuf_plaintext);
- encode_message_to_protobuf(plaintext, protobuf_plaintext);
- }
- }*/
- }
|