Browse Source

temp commit from another major refactoring overhaul

dettanym 2 years ago
parent
commit
dc8cde4c20

+ 95 - 0
DeploymentStageLogic.cpp

@@ -0,0 +1,95 @@
+//
+// Created by miti on 2019-12-24.
+//
+
+#include "DeploymentStageLogic.h"
+
+// Sets up a socket connected to the port passed as input - returns the socket FD on success and -1 on error.
+// Also prints the errno on error.
+int set_up_socket_connect(int port)
+{
+    int sock = 0;
+    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+    {
+        printf("\n Error in socket call - errno is %d \n", errno);
+        return -1;
+    }
+
+    struct sockaddr_in serv_addr;
+    memset(&serv_addr, '0', sizeof(serv_addr));
+
+    serv_addr.sin_family = AF_INET;
+    serv_addr.sin_port = htons(port);
+
+    // Convert IPv4 and IPv6 addresses from text to binary form
+    if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
+    {
+        printf("\nError in inet_pton - errno is %d\n", errno);
+        return -1;
+    }
+
+    if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
+    {
+        printf("\nError in connect - errno is %d \n", errno);
+        return -1;
+    }
+
+    return sock;
+}
+
+uint32_t set_target_hash(uint8_t* given_hash)
+{
+    uint32_t counter;
+    for(counter=0; counter<32; counter++)
+        target_hash[counter] = given_hash[counter];
+}
+
+int main_logic()
+{
+    int decryptor_fd;
+    uint8_t key[16];
+
+    // Set up an IPC channel for local attestation and post-LA messages.
+    decryptor_fd = set_up_socket_connect(port);
+    if(decryptor_fd == -1)
+    {
+        perror("\nCould not set up the socket: had the following error: ");
+        fflush(stderr);
+    }
+
+    // Conduct LA.
+    ret_status = laInitiator.conduct_la(decryptor_fd);
+    if(ret_status != 0)
+        return ret_status;
+
+    // Use the same channel for post-LA messages as the one used above for LA messages.
+    postLAMessaging.set_fd(decryptor_fd);
+
+    // Use the symmetric key from LA to send messages for the rest of the deployment stage.
+    postLAMessaging.set_la_symmetric_key(laInitiator.get_la_symmetric_key(key));
+
+    // Send the target's hash to the decryptor enclave.
+    return send_secure_msg(target_hash, 32);
+}
+
+/*
+uint32_t generate_encrypted_rsa_keypair_hash(uint8_t* op_ciphertext, uint32_t* length)
+{
+
+    uint8_t tag[16];
+    int ciphertext_len;// int plaintext_len=32;
+    uint8_t iv[12];
+    memset(iv, 0, 12);
+    return_status=aes_cipher(1, key, iv, hash, 32, op_ciphertext,  &ciphertext_len, tag);
+    if(return_status == 0)
+    {
+        for(counter=0;counter<12;counter++)
+            op_ciphertext[counter+ ciphertext_len] = iv[counter];
+        for(counter=0;counter<16;counter++)
+            op_ciphertext[counter+ ciphertext_len + 12] = tag[counter];
+        ciphertext_len+=28;
+        *length=ciphertext_len;
+    }
+}
+*/
+

+ 26 - 0
DeploymentStageLogic.h

@@ -0,0 +1,26 @@
+//
+// Created by miti on 2019-12-24.
+//
+
+#ifndef VERIFIER_DEPLOYMENTSTAGELOGIC_H
+#define VERIFIER_DEPLOYMENTSTAGELOGIC_H
+
+
+class DeploymentStageLogic {
+    LAInitiator_Protobuf laInitiator;
+    PostLAMessaging postLaMessaging;
+    uint8_t target_hash[32];
+
+public:
+    //    hash = {0x54,0x24,0x5d,0x63,0x5c,0x8f,0xec,0xcf,0x37,0xb9,0xcf,0x9e,0xb8,0xd3,0x22,0x04,0x57,0x5b,0xb2,0xfc,0xa6,0xd3,0x11,0xfb,0x87,0xb7,0x01,0x06,0x2f,0x18,0x25,0xc1};
+    //	return_status=generate_rsa_keypair_hash(hash);
+    //	if(return_status!=0)
+    //		return return_status;
+
+    uint32_t set_target_hash(uint8_t* given_hash);
+    int set_up_socket_connect(int port);
+    int main_logic();
+};
+
+
+#endif //VERIFIER_DEPLOYMENTSTAGELOGIC_H

+ 365 - 0
Initiator_Transforms.cpp

@@ -0,0 +1,365 @@
+#include "Initiator_Transforms.h"
+int Initiator_Transforms::fit_32_into_uint8_t(google::protobuf::uint32 temp32, uint8_t* temp8)
+    {
+        if(temp32 > UINT8_MAX)
+            return -1;
+        else
+        {
+            //		 *temp8 = *(uint8_t*)&temp32; // Probably works irrespective of endianness but not sure.
+            *temp8 = (uint8_t)temp32;
+            return 0;
+        }
+    }
+
+int Initiator_Transforms::fit_32_into_uint16_t(google::protobuf::uint32 temp32, uint16_t* temp16)
+    {
+        if(temp32 > UINT16_MAX)
+            return -1;
+        else
+        {
+            //              *temp8 = *(uint8_t*)&temp32; // Probably works irrespective of endianness but not sure.
+            *temp16 = (uint16_t)temp32;
+            return 0;
+        }
+    }
+
+void Initiator_Transforms::encode_ec256_public_key_to_protobuf(protobuf_sgx_ec256_public_t* protobuf_g_a , sgx_ec256_public_t* g_a)
+    {
+        printf("\n ec256 public key gx and gy \n");
+        int counter; google::protobuf::uint32 temp32;
+        for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+        {
+            temp32 = g_a->gx[counter];
+            protobuf_g_a->add_gx(temp32);
+            printf("%d ", temp32);
+            temp32 = g_a->gy[counter];
+            protobuf_g_a->add_gy(temp32);
+            printf("%d ", temp32);
+        }
+        printf("\n");
+    }
+
+void Initiator_Transforms::encode_attributes_to_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes)
+    {
+        protobuf_attributes->set_flags(attributes->flags); // 64 bit
+        protobuf_attributes->set_xfrm(attributes->xfrm); // 64 bit
+    }
+
+void Initiator_Transforms::encode_report_to_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report)
+    {
+        printf("\n report \n key id \n");
+        int counter; google::protobuf::uint32 temp32;
+        for(counter=0;counter<SGX_KEYID_SIZE;counter++)
+        {
+            temp32=report->key_id.id[counter];
+            protobuf_report->add_key_id(temp32);
+            printf("%d ",temp32);
+        }
+
+        printf("\n mac \n");
+        for(counter=0;counter<SGX_MAC_SIZE;counter++)
+        {
+            temp32=report->mac[counter];
+            protobuf_report->add_mac(temp32);
+            printf("%d ", temp32);
+        }
+
+        protobuf_report->mutable_body()->set_misc_select(report->body.misc_select); // 32 bit
+        protobuf_report->mutable_body()->set_isv_svn(report->body.isv_svn); // 16 bit
+        protobuf_report->mutable_body()->set_isv_prod_id(report->body.isv_prod_id); // 16 bit
+        encode_attributes_to_protobuf(protobuf_report->mutable_body()->mutable_attributes(), &(report->body.attributes));
+
+        for(counter=0;counter<SGX_CPUSVN_SIZE;counter++)
+        {
+            temp32=report->body.cpu_svn.svn[counter];
+            protobuf_report->mutable_body()->add_cpu_svn(temp32);
+        }
+
+        for(counter=0;counter<SGX_REPORT_BODY_RESERVED1;counter++)
+        {
+            temp32=report->body.reserved1[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+            protobuf_report->mutable_body()->add_reserved1(temp32);
+        }
+
+        for(counter=0;counter<SGX_REPORT_BODY_RESERVED2;counter++)
+        {
+            temp32=report->body.reserved2[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+            protobuf_report->mutable_body()->add_reserved2(temp32);
+        }
+
+        for(counter=0;counter<SGX_REPORT_BODY_RESERVED3;counter++)
+        {
+            temp32=report->body.reserved3[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+            protobuf_report->mutable_body()->add_reserved3(temp32);
+        }
+
+        for(counter=0;counter<SGX_REPORT_BODY_RESERVED4;counter++)
+        {
+            temp32=report->body.reserved4[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
+            protobuf_report->mutable_body()->add_reserved4(temp32);
+        }
+
+        printf("\nmr enclave\n");
+        fflush(stdout);
+        for(counter=0;counter<SGX_HASH_SIZE;counter++)
+        {
+            temp32=report->body.mr_enclave.m[counter];
+            protobuf_report->mutable_body()->add_mr_enclave(temp32);
+            printf("%x ", temp32);
+        }
+
+        printf("\n mr signer\n");  fflush(stdout);
+        for(counter=0;counter<SGX_HASH_SIZE;counter++)
+        {
+            temp32=report->body.mr_signer.m[counter];
+            protobuf_report->mutable_body()->add_mr_signer(temp32);
+            printf("%x ", temp32);
+        }
+
+
+        for(counter=0;counter<SGX_REPORT_DATA_SIZE;counter++)
+        {
+            temp32=report->body.report_data.d[counter];
+            protobuf_report->mutable_body()->add_report_data(temp32);
+        }
+    }
+
+int Initiator_Transforms::decode_attributes_from_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes)
+    {
+        attributes->flags = protobuf_attributes->flags();
+        printf("\n flags %" PRIu64 " \n", attributes->flags);
+        attributes->xfrm = protobuf_attributes->xfrm();
+        printf("\n xfrm %" PRIu64 " \n", attributes->xfrm);
+        return 0;
+    }
+
+int Initiator_Transforms::decode_report_from_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report)
+    {
+        int counter; google::protobuf::uint32 temp32;
+        printf("\n----------------------Decoding received msg3 ------------------------\n");
+        printf("\nreport body keyid\n");
+        for(counter=0;counter<SGX_KEYID_SIZE;counter++)
+        {
+            temp32=protobuf_report->key_id(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->key_id.id[counter]))!=0)
+                return -1;
+            printf("%d ", report->key_id.id[counter]);
+        }
+
+        printf("\nreport mac\n");
+        for(counter=0;counter<SGX_MAC_SIZE;counter++)
+        {
+            temp32=protobuf_report->mac(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->mac[counter]))!=0)
+                return -1;
+            printf("%d ", report->mac[counter]);
+        }
+
+        report->body.misc_select=protobuf_report->mutable_body()->misc_select(); // 32 bit
+        temp32=protobuf_report->mutable_body()->isv_svn();
+        if(fit_32_into_uint16_t(temp32, &(report->body.isv_svn))!=0)
+            return -1;
+        printf("\nmisc select %d \n", report->body.misc_select);
+
+        temp32=protobuf_report->mutable_body()->isv_prod_id();
+        if(fit_32_into_uint16_t(temp32, &(report->body.isv_prod_id))!=0)
+            return -1;
+        printf("\nprod id %d \n", report->body.isv_prod_id);
+
+        decode_attributes_from_protobuf(protobuf_report->mutable_body()->mutable_attributes(), &(report->body.attributes));
+
+        printf("\n cpu svn\n");
+        for(counter=0;counter<SGX_CPUSVN_SIZE;counter++)
+        {
+            temp32=protobuf_report->mutable_body()->cpu_svn(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->body.cpu_svn.svn[counter]))!=0)
+                return -1;
+            printf("%d ", report->body.cpu_svn.svn[counter]);
+
+        }
+
+        printf("\n reserved1 \n");
+        for(counter=0;counter<SGX_REPORT_BODY_RESERVED1;counter++)
+        {
+            temp32=protobuf_report->mutable_body()->reserved1(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->body.reserved1[counter]))!=0)
+                return -1;
+            printf("%d ", report->body.reserved1[counter]);
+        }
+
+        printf("\n reserved2 \n");
+        for(counter=0;counter<SGX_REPORT_BODY_RESERVED2;counter++)
+        {
+            temp32=protobuf_report->mutable_body()->reserved2(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->body.reserved2[counter]))!=0)
+                return -1;
+            printf("%d ", report->body.reserved2[counter]);
+        }
+
+        printf("\n reserved3 \n");
+        for(counter=0;counter<SGX_REPORT_BODY_RESERVED3;counter++)
+        {
+            temp32=protobuf_report->mutable_body()->reserved3(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->body.reserved3[counter]))!=0)
+                return -1;
+            printf("%d ", report->body.reserved3[counter]);
+        }
+
+        printf("\n reserved4 \n");
+        for(counter=0;counter<SGX_REPORT_BODY_RESERVED4;counter++)
+        {
+            temp32=protobuf_report->mutable_body()->reserved4(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->body.reserved4[counter]))!=0)
+                return -1;
+            printf("%d ", report->body.reserved4[counter]);
+
+        }
+
+        printf("\n mrenclave \n");
+        for(counter=0;counter<SGX_HASH_SIZE;counter++)
+        {
+            temp32=protobuf_report->mutable_body()->mr_enclave(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->body.mr_enclave.m[counter]))!=0)
+                return -1;
+            printf("%x ", report->body.mr_enclave.m[counter]);
+        }
+
+        printf("\n mrsigner \n");
+        for(counter=0;counter<SGX_HASH_SIZE;counter++)
+        {
+            temp32=protobuf_report->mutable_body()->mr_signer(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->body.mr_signer.m[counter]))!=0)
+                return -1;
+            printf("%x ", report->body.mr_signer.m[counter]);
+        }
+
+        printf("\n report data\n");
+        for(counter=0;counter<SGX_REPORT_DATA_SIZE;counter++)
+        {
+            temp32=protobuf_report->mutable_body()->report_data(counter);
+            if(fit_32_into_uint8_t(temp32, &(report->body.report_data.d[counter]))!=0)
+                return -1;
+            printf("%d ", report->body.report_data.d[counter]);
+        }
+        printf("\n------------------------ end of msg3 --------------------------\n");
+        return 0;
+    }
+
+int Initiator_Transforms::print_initialized_msg1( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1)
+    {
+        int counter;
+        printf("gx\n");
+        for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+        {
+            printf("%d ", protobuf_dhmsg1.g_a().gx(counter));
+        }
+
+        printf("\ngy\n");
+        for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+        {
+            printf("%d ", protobuf_dhmsg1.g_a().gy(counter));
+        }
+
+        printf("\nmrenclave in target\n");
+        for(counter=0;counter<SGX_HASH_SIZE;counter++)
+        {
+            printf("%" PRIu32 " ", protobuf_dhmsg1.target().mr_enclave(counter));
+        }
+
+        printf("\nreserved1 in target\n");
+        for(counter=0;counter<SGX_TARGET_INFO_RESERVED1_BYTES;counter++)
+        {
+            printf("%" PRIu32 " ", protobuf_dhmsg1.target().reserved1(counter));
+        }
+
+        printf("\nreserved2 in target\n");
+        for(counter=0;counter<SGX_TARGET_INFO_RESERVED2_BYTES;counter++)
+        {
+            printf("%" PRIu32 " ", protobuf_dhmsg1.target().reserved2(counter));
+        }
+
+        printf("\n %" PRIu64 "\n", protobuf_dhmsg1.target().attributes().flags());
+        printf("\n %" PRIu64 "\n", protobuf_dhmsg1.target().attributes().xfrm());
+        printf("\n %" PRIu32 "\n", protobuf_dhmsg1.target().misc_select());
+
+        return 0;
+    }
+
+int Initiator_Transforms::decode_msg1_from_protobuf( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1, sgx_dh_msg1_t* native_dhmsg1)
+    {
+        int counter; google::protobuf::uint32 temp32;// google::protobuf::uint64 temp64;
+
+        for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
+        {
+            temp32 = protobuf_dhmsg1.mutable_g_a()->gx(counter);
+            if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->g_a.gx[counter]))!=0)
+                return -1;
+            temp32 = protobuf_dhmsg1.mutable_g_a()->gy(counter);
+            if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->g_a.gy[counter]))!=0)
+                return -1;
+        }
+
+        for(counter=0;counter<SGX_HASH_SIZE;counter++)
+        {
+            temp32 = protobuf_dhmsg1.mutable_target()->mr_enclave(counter);
+            if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->target.mr_enclave.m[counter]))!=0)
+                return -1;
+        }
+
+        for(counter=0;counter<SGX_TARGET_INFO_RESERVED1_BYTES;counter++)
+        {
+            temp32 = protobuf_dhmsg1.mutable_target()->reserved1(counter);
+            if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->target.reserved1[counter]))!=0)
+                return -1;
+        }
+
+        for(counter=0;counter<SGX_TARGET_INFO_RESERVED2_BYTES;counter++)
+        {
+            temp32 = protobuf_dhmsg1.mutable_target()->reserved2(counter);
+            if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->target.reserved2[counter]))!=0)
+                return -1;
+        }
+
+        native_dhmsg1->target.attributes.flags = protobuf_dhmsg1.mutable_target()->mutable_attributes()->flags();
+        native_dhmsg1->target.attributes.xfrm = protobuf_dhmsg1.mutable_target()->mutable_attributes()->xfrm();
+        native_dhmsg1->target.misc_select = protobuf_dhmsg1.mutable_target()->misc_select();
+        return 0;
+    }
+
+int Initiator_Transforms::decode_msg3_from_protobuf(protobuf_sgx_dh_msg3_t& protobuf_dhmsg3, sgx_dh_msg3_t* native_dhmsg3)
+    {
+        int counter; google::protobuf::uint32 temp32;
+        for(counter=0;counter<SGX_DH_MAC_SIZE;counter++)
+        {
+            temp32=protobuf_dhmsg3.cmac(counter);
+            if(fit_32_into_uint8_t(temp32, &(native_dhmsg3->cmac[counter]))!=0)
+                return -1;
+        }
+
+        if(decode_report_from_protobuf(protobuf_dhmsg3.mutable_msg3_body()->mutable_report(), &(native_dhmsg3->msg3_body.report))==-1)
+            return -1;
+        int max_counter=protobuf_dhmsg3.mutable_msg3_body()->additional_prop_size();
+        native_dhmsg3->msg3_body.additional_prop_length=max_counter;
+        // TODO: Need to assign a variable on the heap and then pass it as an argument to this function - set it to null if protobuf_dhmsg3.mutable_msg3_body()->additional_prop_size() is 0
+        // TODO: And then free it in that function (create_session) when it is done. It is likely that it is 0 in the SGX SDK sample code. And SDK people probably didn't deserialize it - as it may contain a pointer in the general case - to the array of additional_properties.
+        if(max_counter!=0)
+            return -1;
+        return 0;
+    }
+
+void Initiator_Transforms::encode_msg2_to_protobuf( protobuf_sgx_dh_msg2_t& protobuf_dhmsg2, sgx_dh_msg2_t* native_dhmsg2)
+    {
+        int counter; google::protobuf::uint32 temp32; //google::protobuf::uint64 temp64;
+        printf("\n msg2 cmac \n");
+        for(counter=0;counter<SGX_DH_MAC_SIZE;counter++)
+        {
+            temp32=native_dhmsg2->cmac[counter];
+            protobuf_dhmsg2.add_cmac(temp32);
+            printf("%d ", temp32);
+        }
+
+        encode_ec256_public_key_to_protobuf(protobuf_dhmsg2.mutable_g_b(), &(native_dhmsg2->g_b));
+
+        encode_report_to_protobuf(protobuf_dhmsg2.mutable_report(), &(native_dhmsg2->report));
+    }
+

+ 51 - 0
Initiator_Transforms.h

@@ -0,0 +1,51 @@
+//
+// Created by miti on 2019-12-21.
+//
+
+#ifndef VERIFIER_INITIATOR_TRANSFORMS_H
+#define VERIFIER_INITIATOR_TRANSFORMS_H
+#include "sgx_eid.h"
+#include "error_codes.h"
+#include "datatypes.h"
+#include "sgx_urts.h"
+#include "sgx_dh.h"
+
+// For msg1
+#define SGX_TARGET_INFO_RESERVED1_BYTES 4
+#define SGX_TARGET_INFO_RESERVED2_BYTES 456
+#define SGX_ECP256_KEY_SIZE 32
+#define SGX_HASH_SIZE 32 /* SHA256 */
+// For msg2
+#define SGX_REPORT_DATA_SIZE 64
+#define SGX_KEYID_SIZE 32
+#define SGX_DH_MAC_SIZE 16
+#define SGX_REPORT_BODY_RESERVED1 28
+#define SGX_REPORT_BODY_RESERVED2 32
+#define SGX_REPORT_BODY_RESERVED3 96
+#define SGX_REPORT_BODY_RESERVED4 60
+
+
+#include <stdio.h>
+// For google protobufs and deserialization/serialization
+#include "ProtobufLAMessages.h"
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+using namespace google::protobuf::io;
+#include <inttypes.h>
+
+
+class Initiator_Transforms {
+    static int fit_32_into_uint8_t(google::protobuf::uint32 temp32, uint8_t* temp8);
+    static int fit_32_into_uint16_t(google::protobuf::uint32 temp32, uint16_t* temp16);
+    static void  encode_ec256_public_key_to_protobuf(protobuf_sgx_ec256_public_t* protobuf_g_a , sgx_ec256_public_t* g_a);
+    static void  encode_attributes_to_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes);
+    static void  encode_report_to_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report);
+    static int decode_attributes_from_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes);
+    static int decode_report_from_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report);
+    static int print_initialized_msg1( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1);
+public:
+    static int decode_msg1_from_protobuf( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1, sgx_dh_msg1_t* native_dhmsg1);
+    static int decode_msg3_from_protobuf(protobuf_sgx_dh_msg3_t& protobuf_dhmsg3, sgx_dh_msg3_t* native_dhmsg3);
+    static void  encode_msg2_to_protobuf( protobuf_sgx_dh_msg2_t& protobuf_dhmsg2, sgx_dh_msg2_t* native_dhmsg2);
+};
+#endif //VERIFIER_INITIATOR_TRANSFORMS_H

+ 92 - 0
LAInitiator_Protobuf.cpp

@@ -0,0 +1,92 @@
+
+uint32_t process_protobuf_dh_msg1_generate_protobuf_dh_msg2(protobuf_sgx_dh_msg1_t& protobuf_msg1, protobuf_sgx_dh_msg2_t& protobuf_msg2)
+{
+  sgx_dh_msg1_t dh_msg1;            //Diffie-Hellman Message 1
+  sgx_dh_msg2_t dh_msg2;
+  memset(&dh_msg1, 0, sizeof(sgx_dh_msg1_t));
+  uint32_t ret_status;
+
+  if(Initiator_Transforms::decode_msg1_from_protobuf(protobuf_msg1, &dh_msg1)!=0)
+    return -1;
+
+  //Intialize the session as a session initiator
+  ret_status = sgx_dh_init_session(SGX_DH_SESSION_INITIATOR, &sgx_dh_session);
+  if(ret_status != SGX_SUCCESS)
+    return ret_status;
+
+  //Process the message 1 obtained from desination enclave and generate message 2
+  ret_status = sgx_dh_initiator_proc_msg1(&dh_msg1, &dh_msg2, &sgx_dh_session);
+  if(ret_status != SGX_SUCCESS)
+    return ret_status;
+
+  Initiator_Transforms::encode_msg2_to_protobuf(protobuf_msg2, &dh_msg2);
+  return 0;
+}
+
+uint32_t process_protobuf_dh_msg3(protobuf_sgx_dh_msg3_t& protobuf_msg3) {
+
+  uint32_t ret_status;
+  sgx_dh_msg3_t dh_msg3;
+  sgx_key_128bit_t dh_aek;        // Session Key
+  sgx_dh_session_enclave_identity_t responder_identity;
+
+  memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
+
+  if(Initiator_Transforms::decode_msg3_from_protobuf(protobuf_msg3, &dh_msg3)!=0)
+    return -1;
+
+  //Process Message 3 obtained from the destination enclave
+  ret_status = sgx_dh_initiator_proc_msg3(&dh_msg3, &sgx_dh_session, &dh_aek, &responder_identity);
+  if(SGX_SUCCESS != ret_status)
+    return ret_status;
+
+  memcpy(global_session_info.active.AEK, &dh_aek, sizeof(sgx_key_128bit_t));
+  global_session_info.session_id = 1; // TODO: session_id;
+  global_session_info.active.counter = 0;
+  global_session_info.status = ACTIVE;
+  memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
+
+  return 0;
+}
+
+uint32_t conduct_la(int decryptor_fd) {
+    // declare msg1, msg2, msg3 protobuf objects
+    protobuf_sgx_dh_msg1_t protobuf_msg1;
+    protobuf_sgx_dh_msg2_t protobuf_msg2;
+    protobuf_sgx_dh_msg3_t protobuf_msg3;
+    uint32_t protobuf_sgx_ret;
+
+    setbuf(stdout,NULL);
+
+    protobufReaderWriter.set_fd(decryptor_fd);
+
+    if(protobufReaderWriter.read_msg(protobuf_msg1)!=0)
+        return -1;
+
+    protobuf_sgx_ret = process_protobuf_dh_msg1_generate_protobuf_dh_msg2(protobuf_msg1, protobuf_msg2);
+    if(protobuf_sgx_ret != 0)
+    {
+        printf("Error in process_protobuf_dh_msg1_generate_protobuf_dh_msg2: 0x%x", protobuf_sgx_ret); fflush(stdout); return protobuf_sgx_ret;
+    }
+
+    if(protobufReaderWriter.write_msg(protobuf_msg2)!=0)
+        return -1;
+
+    if(protobufReaderWriter.read_msg(protobuf_msg3)!=0)
+        return -1;
+
+    protobuf_sgx_ret = process_protobuf_dh_msg3(protobuf_msg3);
+    if(protobuf_sgx_ret != 0)
+    {
+        printf("Error in process_protobuf_dh_msg3: 0x%x", protobuf_sgx_ret); fflush(stdout); return protobuf_sgx_ret;
+    }
+    return 0;
+}
+
+uint32_t get_la_symmetric_key(uint8_t* op_key)
+{
+    uint32_t counter;
+    for(counter=0; counter<32; counter++)
+        op_key[counter] = key[counter];
+    // TODO: Fix this code - there is no attribute called key - it's in one of the existing attributes.
+}

+ 48 - 0
LAInitiator_Protobuf.h

@@ -0,0 +1,48 @@
+//
+// Created by miti on 2019-12-21.
+//
+
+#ifndef VERIFIER_LAINITIATOR_PROTOBUFINTERFACE_H
+#define VERIFIER_LAINITIATOR_PROTOBUFINTERFACE_H
+#include "sgx_eid.h"
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#include "ProtobufLAMessages.h"
+#include <stdio.h>
+
+#include "sgx_trts.h"
+#include "sgx_utils.h"
+#include "error_codes.h"
+#include "sgx_ecp_types.h"
+#include "sgx_thread.h"
+#include <map>
+#include "sgx_dh.h"
+#include "dh_session_protocol.h"
+#include "sgx_tcrypto.h"
+#include "datatypes.h"
+#include "Initiator_Transforms.h"
+#define MAX_SESSION_COUNT  16
+#define SGX_CAST(type, item) ((type)(item))
+#include <string.h>
+#include "crypto.h"
+#include "stdio.h"
+
+// For socket programming
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+class LAInitiator_Protobuf {
+    sgx_dh_session_t sgx_dh_session;
+    dh_session_t global_session_info;
+    ProtobufMessageRW protobufReaderWriter;
+    uint32_t process_protobuf_dh_msg3(protobuf_sgx_dh_msg3_t& protobuf_msg3, uint32_t* session_id);
+    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);
+public:
+    uint32_t conduct_la();
+    uint32_t get_la_symmetric_key(uint8_t* key);
+};
+// TODO: Get them to take in lists as inputs and change verifier's code too to put in elements into a list.
+// TODO: Revert php code back by two commits (before rollback) and edit from there.
+// TODO: Also get the decryptor codebase in sync with this format of sgx/protobuf files.
+#endif //LAINITIATOR_PROTOBUFINTERFACE_H

+ 109 - 0
PostLAMessaging.cpp

@@ -0,0 +1,109 @@
+//
+// Created by miti on 2019-12-24.
+//
+
+#include "PostLAMessaging.h"
+
+// The verifier doesn't receive any messages (in the deployment stage or at all)
+uint32_t send_secure_msg(uint8_t* input, uint32_t input_size)
+{
+    uint8_t* output;
+    uint32_t output_size, ret;
+    google::protobuf::MessageLite protobuf_msg;
+
+    output = (unsigned char*) malloc(output, input_size + 28); // 16 for tag, 12 for IV
+    // TODO: Make sure this is the same as in the PHP extension code.
+    ret = aes_gcm_wrapper(1, input, input_size, output, output_size );
+    if(ret != 0)
+        return ret;
+
+    // TODO: Conversion logic to protobuf. Set msg or whatever.
+    if(!protobufReaderWriter.write_msg(protobuf_msg))
+        return 0x3;
+    return 0;
+}
+
+void set_la_symmetric_key(uint8_t* given_key) {
+    uint32_t counter;
+    for(counter=0; counter<32; counter++)
+    {
+        key[counter] = given_key[counter];
+    }
+}
+
+void set_fd(int given_fd)
+{
+    protobufReaderWriter.set_fd(given_fd);
+}
+
+/*
+int encrypt_decrypt_msgs(int encrypt_decrypt, std::vector<std::string> &input_msgs,
+                         std::vector<std::string> &output_msgs)
+{
+    unsigned char *input; unsigned char *output;
+    uint32_t input_size, output_size, ret;
+    output=NULL;
+
+    for (std::string msg:input_msgs)
+    {
+        input_size = msg.length();
+        input = (unsigned char*) msg.c_str();
+        output = (unsigned char*) realloc(output, input_size + 28); // 16 for tag, 12 for IV
+        ret = aes_gcm_wrapper(encrypt_decrypt, input, input_size, output, &output_size );
+        if(ret!=0)
+        {
+            free(output);
+            printf("Failed to encrypt an input field.\n"); fflush(stdout);
+            return 0x2;
+        }
+        output_msgs.push_back(std::string(reinterpret_cast<const char *> (output), output_size));
+    }
+    free(output);
+
+    return 0;
+}
+*/
+
+/*
+ * virtual void create_vector_from_protobuf(google::protobuf::MessageLite& protobuf_msg,
+                                         std::vector<std::string> &native_msg_list) {}
+
+uint32_t receive_secure_msgs(std::vector<std::string> &plaintext_msg_list) {
+    std::vector<std::string> ciphertext_msg_list;
+    google::protobuf::MessageLite protobuf_msg;
+
+    // read encrypted data
+    if(!protobufReaderWriter.read_msg(protobuf_msg))
+    {
+        printf("Not all of the decryptor's message was read\n"); fflush(stdout);
+        return 0xf3;
+    }
+
+    create_vector_from_protobuf(protobuf_msg, ciphertext_msg_list);
+
+    return encrypt_decrypt_ciphertexts(0, &ciphertext_msg_list, plaintext_msg_list);
+}
+*/
+
+/*
+uint32_t send_secure_msgs(std::vector<std::string> &plaintext_msg_list)
+{
+    uint32_t ret;
+    std::vector<std::string> ciphertext_msg_list;
+    google::protobuf::MessageLite protobuf_msg;
+
+    ret=encrypt_decrypt_msgs(1, plaintext_msg_list, &ciphertext_msg_list);
+    if(ret!=0)
+        return ret;
+
+    create_protobuf_from_vector(ciphertext_msg_list, protobuf_msg);
+
+    // write message to decryptor
+    if(!protobufReaderWriter.write_msg(protobuf_msg))
+    {
+        printf("Not all of the client's pub key and ciphertext data was written\n"); fflush(stdout);
+        return 0xfe;
+    }
+    return 0;
+}
+*/

+ 18 - 0
PostLAMessaging.h

@@ -0,0 +1,18 @@
+//
+// Created by miti on 2019-12-24.
+//
+
+#ifndef VERIFIER_POSTLAMESSAGING_H
+#define VERIFIER_POSTLAMESSAGING_H
+
+class PostLAMessaging {
+    uint8_t key[16];
+    ProtobufMessageRW protobufReaderWriter;
+public:
+    void set_la_symmetric_key(uint8_t* given_key);
+    void set_fd(uint8_t* given_fd);
+    uint32_t send_secure_msg(uint8_t* input, uint32_t input_size);
+};
+
+
+#endif

+ 0 - 168
ProtobufLAInitiator.cpp

@@ -1,168 +0,0 @@
-// Knows only protobuf_sgx objects, protobuf header.
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include<unistd.h>
-#include <stdio.h>
-#include "ProtobufLAMessages.h"
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/io/zero_copy_stream_impl.h>
-using namespace google::protobuf::io;
-#include "SgxProtobufLAInitiator.h"
-
-// For socket programming
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-
-// TODO: Make these private functions
-int read_protobuf_msg_from_fd(int accept_fd, google::protobuf::MessageLite& message)
-{
-  ZeroCopyInputStream* raw_input;
-  CodedInputStream* coded_input;
-  uint32_t size;
-  CodedInputStream::Limit limit;
-  raw_input = new FileInputStream(accept_fd);
-  coded_input = new CodedInputStream(raw_input);
-  if(!coded_input->ReadVarint32(&size))
-  {
-    printf("Error in reading size of msg");
-    fflush(stdout);
-    return -1;
-  }
-  //printf("size of msg was read to be %" PRIu32 " \n", size);
-  fflush(stdout);
-  limit = coded_input->PushLimit(size);
-  if(!message.ParseFromCodedStream(coded_input))
-  {
-    printf("Error in parsing msg");
-    fflush(stdout);
-    return -1;
-  }
-  coded_input->PopLimit(limit);
-  return 0;
-}
-
-// TODO: private functions
-int write_protobuf_msg_to_fd(int accept_fd, google::protobuf::MessageLite& message)
-{
-  ZeroCopyOutputStream* raw_output = new FileOutputStream(accept_fd);
-  CodedOutputStream* coded_output  = new CodedOutputStream(raw_output);
-  coded_output->WriteVarint32(message.ByteSize());
-  if(!message.SerializeToCodedStream(coded_output))
-  {
-    printf("SerializeToCodedStream failed");
-    fflush(stdout);
-    return -1;
-  }
-  // As per this - https://stackoverflow.com/questions/22881876/protocol-buffers-how-to-serialize-and-deserialize-multiple-messages-into-a-file?noredirect=1&lq=1
-  // TODO: There may be a better way to do this - 1) this happens with every accept now and 2) make it happen on the stack vs heap - destructor will be called on return from this function (main) and the items will then be written out. (We probably don't want that, actually)
-  delete coded_output;
-  delete raw_output;
-  fflush(stdout);
-  return 0;
-}
-
-// Sets up a socket connected to the port passed as input - returns the socket FD on success and -1 on error.
-// Also prints the errno on error.
-int set_up_socket_connect(int port)
-{
-  int sock = 0;
-  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
-  {
-    printf("\n Error in socket call - errno is %d \n", errno);
-    return -1;
-  }
-
-  struct sockaddr_in serv_addr;
-  memset(&serv_addr, '0', sizeof(serv_addr));
-
-  serv_addr.sin_family = AF_INET;
-  serv_addr.sin_port = htons(port);
-
-  // Convert IPv4 and IPv6 addresses from text to binary form
-  if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
-  {
-    printf("\nError in inet_pton - errno is %d\n", errno);
-    return -1;
-  }
-
-  if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
-  {
-    printf("\nError in connect - errno is %d \n", errno);
-    return -1;
-  }
-
-  return sock;
-}
-
-int local_attestation_initiator(int port)
-{
-  // declare msg1, msg2, msg3 protobuf objects
-  protobuf_sgx_dh_msg1_t protobuf_msg1;
-  protobuf_sgx_dh_msg2_t protobuf_msg2;
-  protobuf_sgx_dh_msg3_t protobuf_msg3;
-  uint32_t protobuf_sgx_ret;
-  uint8_t encrypted_hash_and_tag[150];// uint8_t encrypted_tag[16]; 
-  uint32_t total_length;
-size_t post_la_bytes_written;
-  // For socket to listen to the Apache enclave.
-
-  uint32_t session_id;
-  //  int counter;
-
-  int decryptor_fd;
-  setbuf(stdout,NULL);
-  decryptor_fd=set_up_socket_connect(port);
-  if(decryptor_fd == -1)
-  {
-    perror("\nCould not set up the socket: had the following error: ");
-    fflush(stderr);
-  }
-//  printf("");
-  if(read_protobuf_msg_from_fd(decryptor_fd, protobuf_msg1)!=0)
-    return -1;
-
-  protobuf_sgx_ret = process_protobuf_dh_msg1_generate_protobuf_dh_msg2(protobuf_msg1, protobuf_msg2, &session_id);
-  if(protobuf_sgx_ret != 0)
-  {
-    printf("Error in process_protobuf_dh_msg1_generate_protobuf_dh_msg2: 0x%x", protobuf_sgx_ret); fflush(stdout); return protobuf_sgx_ret;
-  }
-
-  if(write_protobuf_msg_to_fd(decryptor_fd, protobuf_msg2)!=0)
-    return -1;
-
-  if(read_protobuf_msg_from_fd(decryptor_fd, protobuf_msg3)!=0)
-    return -1;
-
-  protobuf_sgx_ret = process_protobuf_dh_msg3(protobuf_msg3, &session_id);
-  if(protobuf_sgx_ret != 0)
-  {
-      printf("Error in process_protobuf_dh_msg3: 0x%x", protobuf_sgx_ret); fflush(stdout); return protobuf_sgx_ret;
-  }
-  memset(encrypted_hash_and_tag, 0, 150); 
-  protobuf_sgx_ret=generate_encrypted_rsa_keypair_hash(encrypted_hash_and_tag, &total_length); 
-  if(protobuf_sgx_ret==0)
-  {
-	printf("Done encryption of hash.\n"); fflush(stdout); 
-  }
-  else 
-	{
-		printf("Error in enc/dec of hash: 0x%x", protobuf_sgx_ret); fflush(stdout); return protobuf_sgx_ret; 
-	}
-  
-
-   post_la_bytes_written = write(decryptor_fd, encrypted_hash_and_tag, total_length);
-   printf("Wrote the hash and the tag to the decryptor socket.\n Wrote this many bytes: %d\n", post_la_bytes_written); fflush(stdout); 
-
-   if(close(decryptor_fd)!= 0)
-   {
-	printf("Error in closing the socket connection.\n"); fflush(stdout); return 0xfd; 
-   } 
-  
-
-	printf("Successfully done Local attestation\n");
-	fflush(stdout);
-	return 0;
-}

+ 66 - 0
ProtobufMessageRW.cpp

@@ -0,0 +1,66 @@
+//
+// Created by miti on 2019-12-24.
+//
+
+#include "ProtobufMessageRW.h"
+int ProtobufMessageRW::read_msg(google::protobuf::MessageLite& message)
+{
+    if(fd < 0)
+    {
+        printf("Need to call set_fd on this object first, to set the fd to a non-negative number.\n");
+        fflush(stdout);
+        return 0x2;
+    }
+    ZeroCopyInputStream* raw_input;
+    CodedInputStream* coded_input;
+    uint32_t size;
+    CodedInputStream::Limit limit;
+    raw_input = new FileInputStream(fd);
+    coded_input = new CodedInputStream(raw_input);
+    if(!coded_input->ReadVarint32(&size))
+    {
+        printf("Error in reading size of msg");
+        fflush(stdout);
+        return -1;
+    }
+    //printf("size of msg was read to be %" PRIu32 " \n", size);
+    fflush(stdout);
+    limit = coded_input->PushLimit(size);
+    if(!message.ParseFromCodedStream(coded_input))
+    {
+        printf("Error in parsing msg");
+        fflush(stdout);
+        return -1;
+    }
+    coded_input->PopLimit(limit);
+    return 0;
+}
+
+int ProtobufMessageRW::write_msg(google::protobuf::MessageLite& message)
+{
+    if(fd < 0)
+    {
+        printf("Need to call set_fd on this object first, to set the fd to a non-negative number.\n");
+        fflush(stdout);
+        return 0x2;
+    }
+    ZeroCopyOutputStream* raw_output = new FileOutputStream(fd);
+    CodedOutputStream* coded_output  = new CodedOutputStream(raw_output);
+    coded_output->WriteVarint32(message.ByteSize());
+    if(!message.SerializeToCodedStream(coded_output))
+    {
+        printf("SerializeToCodedStream failed");
+        fflush(stdout);
+        return -1;
+    }
+    // As per this - https://stackoverflow.com/questions/22881876/protocol-buffers-how-to-serialize-and-deserialize-multiple-messages-into-a-file?noredirect=1&lq=1
+    // TODO: There may be a better way to do this - 1) this happens with every accept now and 2) make it happen on the stack vs heap - destructor will be called on return from this function (main) and the items will then be written out. (We probably don't want that, actually)
+    delete coded_output;
+    delete raw_output;
+    fflush(stdout);
+    return 0;
+}
+
+uint32_t ProtobufMessageRW::set_fd(int given_fd) {
+    fd = given_fd;
+}

+ 17 - 0
ProtobufMessageRW.h

@@ -0,0 +1,17 @@
+//
+// Created by miti on 2019-12-24.
+//
+
+#ifndef VERIFIER_PROTOBUFMESSAGERW_H
+#define VERIFIER_PROTOBUFMESSAGERW_H
+
+class ProtobufMessageRW {
+    int fd;
+public:
+    int read_msg(google::protobuf::MessageLite& message);
+    int write_msg(google::protobuf::MessageLite& message);
+    uint32_t set_fd(fd);
+};
+
+
+#endif //VERIFIER_PROTOBUFMESSAGERW_H

+ 0 - 160
SgxProtobufLAInitiator.cpp

@@ -1,160 +0,0 @@
-#include "sgx_eid.h"
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
-#include "ProtobufLAMessages.h"
-#include <stdio.h>
-
-#include "sgx_trts.h"
-#include "sgx_utils.h"
-#include "error_codes.h"
-#include "sgx_ecp_types.h"
-#include "sgx_thread.h"
-#include <map>
-#include "sgx_dh.h"
-#include "dh_session_protocol.h"
-#include "sgx_tcrypto.h"
-#include "datatypes.h"
-#include "SgxProtobufLAInitiator_Transforms.h"
-#define MAX_SESSION_COUNT  16
-#define SGX_CAST(type, item) ((type)(item))
-#include <string.h>
-#include "crypto.h"
-#include "stdio.h"
-
-dh_session_t global_session_info;
-
-sgx_dh_session_t sgx_dh_session;
-//  sgx_key_128bit_t dh_aek;        // Session Key
-
-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);
-
-
-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)
-{
-  sgx_dh_msg1_t dh_msg1;            //Diffie-Hellman Message 1
-  sgx_dh_msg2_t dh_msg2;
-  memset(&dh_msg1, 0, sizeof(sgx_dh_msg1_t));
-  uint32_t ret_status;
-
-  if(decode_msg1_from_protobuf(protobuf_msg1, &dh_msg1)!=0)
-    return -1;
-
-  //Intialize the session as a session initiator
-  ret_status = sgx_dh_init_session(SGX_DH_SESSION_INITIATOR, &sgx_dh_session);
-  if(ret_status != SGX_SUCCESS)
-    return ret_status;
-
-  //Process the message 1 obtained from desination enclave and generate message 2
-  ret_status = sgx_dh_initiator_proc_msg1(&dh_msg1, &dh_msg2, &sgx_dh_session);
-  if(SGX_SUCCESS != ret_status)
-    return ret_status;
-
-  encode_msg2_to_protobuf(protobuf_msg2, &dh_msg2);
-  return 0;
-}
-
-uint32_t process_protobuf_dh_msg3(protobuf_sgx_dh_msg3_t& protobuf_msg3, uint32_t* session_id) {
-
-  uint32_t ret_status;
-  sgx_dh_msg3_t dh_msg3;
-  sgx_key_128bit_t dh_aek;        // Session Key
-  sgx_dh_session_enclave_identity_t responder_identity;
-
-  memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
-
-  if(decode_msg3_from_protobuf(protobuf_msg3, &dh_msg3)!=0)
-    return -1;
-
-  //Process Message 3 obtained from the destination enclave
-  ret_status = sgx_dh_initiator_proc_msg3(&dh_msg3, &sgx_dh_session, &dh_aek, &responder_identity);
-  if(SGX_SUCCESS != ret_status)
-    return ret_status;
-
-  // Verify the identity of the destination enclave
-  ret_status = verify_peer_enclave_trust(&responder_identity, NULL, NULL);
-  if(ret_status != 0)
-    return ret_status;
-
-  memcpy(global_session_info.active.AEK, &dh_aek, sizeof(sgx_key_128bit_t));
-  global_session_info.session_id = 1; // TODO: session_id;
-  global_session_info.active.counter = 0;
-  global_session_info.status = ACTIVE;
-  memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
-
-  return 0;
-}
-
-uint32_t generate_encrypted_rsa_keypair_hash(uint8_t* op_ciphertext, uint32_t* length)
-{
-	uint8_t hash[32]={0x54,0x24,0x5d,0x63,0x5c,0x8f,0xec,0xcf,0x37,0xb9,0xcf,0x9e,0xb8,0xd3,0x22,0x04,0x57,0x5b,0xb2,0xfc,0xa6,0xd3,0x11,0xfb,0x87,0xb7,0x01,0x06,0x2f,0x18,0x25,0xc1};
-	uint32_t return_status;
-	unsigned char key[16]; uint32_t counter;
-	for(counter=0;counter<16;counter++)
-		key[counter]=global_session_info.active.AEK[counter]; 
-//	return_status=generate_rsa_keypair_hash(hash); 
-//	if(return_status!=0)
-//		return return_status; 
-
-	uint8_t tag[16]; 
-	int ciphertext_len;// int plaintext_len=32;
-	uint8_t iv[12];  
-	memset(iv, 0, 12);  
-	return_status=aes_cipher(1, key, iv, hash, 32, op_ciphertext,  &ciphertext_len, tag);
-	if(return_status == 0)
-	{
-		for(counter=0;counter<12;counter++)
-			op_ciphertext[counter+ ciphertext_len] = iv[counter];
-                for(counter=0;counter<16;counter++)
-                        op_ciphertext[counter+ ciphertext_len + 12] = tag[counter];
-		ciphertext_len+=28;
-		*length=ciphertext_len;
-	}
-	for(counter=0;counter<32;counter++)
-	{
-		printf("0x%02x ", op_ciphertext[counter]); 
-	}
-	printf("IV:\n"); 
-	        for(counter=32;counter<44;counter++)
-        {
-                printf("0x%02x ", op_ciphertext[counter]); 
-        }
-	printf("Tag:\n"); 
-
-        for(counter=44;counter<60;counter++)
-        {
-                printf("0x%02x ", op_ciphertext[counter]); 
-        }
-	printf("\n");
-	fflush(stdout);
-	return return_status;
-}
-
-// TODO: Private function
-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; // TODO: Different error here.
-		}
-	}
-
-  return SUCCESS;
-}

+ 0 - 450
SgxProtobufLAInitiator_Transforms.cpp

@@ -1,450 +0,0 @@
-#include "sgx_eid.h"
-#include "error_codes.h"
-#include "datatypes.h"
-#include "sgx_urts.h"
-#include "sgx_dh.h"
-
-// For msg1
-#define SGX_TARGET_INFO_RESERVED1_BYTES 4
-#define SGX_TARGET_INFO_RESERVED2_BYTES 456
-#define SGX_ECP256_KEY_SIZE 32
-#define SGX_HASH_SIZE 32 /* SHA256 */
-// For msg2
-#define SGX_REPORT_DATA_SIZE 64
-#define SGX_KEYID_SIZE 32
-#define SGX_DH_MAC_SIZE 16
-#define SGX_REPORT_BODY_RESERVED1 28
-#define SGX_REPORT_BODY_RESERVED2 32
-#define SGX_REPORT_BODY_RESERVED3 96
-#define SGX_REPORT_BODY_RESERVED4 60
-
-
-#include <stdio.h>
-// For google protobufs and deserialization/serialization
-#include "ProtobufLAMessages.h"
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/io/zero_copy_stream_impl.h>
-using namespace google::protobuf::io;
-#include <inttypes.h>
-
-// TODO: PRIVATE
-int fit_32_into_uint8_t(google::protobuf::uint32 temp32, uint8_t* temp8)
-{
- if(temp32 > UINT8_MAX)
-	 return -1;
- else
- {
-	 //		 *temp8 = *(uint8_t*)&temp32; // Probably works irrespective of endianness but not sure.
-	 *temp8 = (uint8_t)temp32;
-	 return 0;
- }
-}
-
-// TODO: PRIVATE
-int fit_32_into_uint16_t(google::protobuf::uint32 temp32, uint16_t* temp16)
-{
- if(temp32 > UINT16_MAX)
-         return -1;
- else
- {
-         //              *temp8 = *(uint8_t*)&temp32; // Probably works irrespective of endianness but not sure.
-         *temp16 = (uint16_t)temp32;
-         return 0;
- }
-}
-
-// TODO: PRIVATE
-void encode_ec256_public_key_to_protobuf(protobuf_sgx_ec256_public_t* protobuf_g_a , sgx_ec256_public_t* g_a)
-{
-	printf("\n ec256 public key gx and gy \n");
-	int counter; google::protobuf::uint32 temp32;
-	for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
-	{
-		temp32 = g_a->gx[counter];
-		protobuf_g_a->add_gx(temp32);
-		printf("%d ", temp32);
-		temp32 = g_a->gy[counter];
-		protobuf_g_a->add_gy(temp32);
-		printf("%d ", temp32);
-	}
-	printf("\n");
-}
-
-// TODO: PRIVATE
-void encode_attributes_to_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes)
-{
-	protobuf_attributes->set_flags(attributes->flags); // 64 bit
-	protobuf_attributes->set_xfrm(attributes->xfrm); // 64 bit
-}
-
-// TODO: PRIVATE
-void encode_report_to_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report)
-{
-	printf("\n report \n key id \n");
-	int counter; google::protobuf::uint32 temp32;
-	for(counter=0;counter<SGX_KEYID_SIZE;counter++)
-	{
-		temp32=report->key_id.id[counter];
-		protobuf_report->add_key_id(temp32);
-		printf("%d ",temp32);
-	}
-
-	printf("\n mac \n");
-	for(counter=0;counter<SGX_MAC_SIZE;counter++)
-	{
-		temp32=report->mac[counter];
-		protobuf_report->add_mac(temp32);
-		printf("%d ", temp32);
-	}
-
-	protobuf_report->mutable_body()->set_misc_select(report->body.misc_select); // 32 bit
-	protobuf_report->mutable_body()->set_isv_svn(report->body.isv_svn); // 16 bit
-	protobuf_report->mutable_body()->set_isv_prod_id(report->body.isv_prod_id); // 16 bit
-	encode_attributes_to_protobuf(protobuf_report->mutable_body()->mutable_attributes(), &(report->body.attributes));
-
-	for(counter=0;counter<SGX_CPUSVN_SIZE;counter++)
-	{
-		temp32=report->body.cpu_svn.svn[counter];
-		protobuf_report->mutable_body()->add_cpu_svn(temp32);
-	}
-
-	for(counter=0;counter<SGX_REPORT_BODY_RESERVED1;counter++)
-	{
-		temp32=report->body.reserved1[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
-		protobuf_report->mutable_body()->add_reserved1(temp32);
- 	}
-
-	for(counter=0;counter<SGX_REPORT_BODY_RESERVED2;counter++)
-	{
-		temp32=report->body.reserved2[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
-		protobuf_report->mutable_body()->add_reserved2(temp32);
-	}
-
-	for(counter=0;counter<SGX_REPORT_BODY_RESERVED3;counter++)
-	{
-		temp32=report->body.reserved3[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
-		protobuf_report->mutable_body()->add_reserved3(temp32);
- 	}
-
-	for(counter=0;counter<SGX_REPORT_BODY_RESERVED4;counter++)
-	{
-		temp32=report->body.reserved4[counter]; // TODO: Could be optimized out - if these are determined to be 0s.
-		protobuf_report->mutable_body()->add_reserved4(temp32);
- 	}
-
-	printf("\nmr enclave\n");
-	fflush(stdout);
-	for(counter=0;counter<SGX_HASH_SIZE;counter++)
-	{
-		temp32=report->body.mr_enclave.m[counter];
-		protobuf_report->mutable_body()->add_mr_enclave(temp32);
-		printf("%x ", temp32);
- 	}
-
-	printf("\n mr signer\n");  fflush(stdout);
-	for(counter=0;counter<SGX_HASH_SIZE;counter++)
-	{
-		temp32=report->body.mr_signer.m[counter];
-		protobuf_report->mutable_body()->add_mr_signer(temp32);
-		printf("%x ", temp32);
- 	}
-
-
-	for(counter=0;counter<SGX_REPORT_DATA_SIZE;counter++)
-	{
-		temp32=report->body.report_data.d[counter];
-		protobuf_report->mutable_body()->add_report_data(temp32);
- 	}
-}
-
-// TODO: PRIVATE
-int decode_attributes_from_protobuf(protobuf_sgx_attributes_t* protobuf_attributes, sgx_attributes_t* attributes)
-{
-        attributes->flags = protobuf_attributes->flags();
-  printf("\n flags %" PRIu64 " \n", attributes->flags);
-        attributes->xfrm = protobuf_attributes->xfrm();
-  printf("\n xfrm %" PRIu64 " \n", attributes->xfrm);
-        return 0;
-}
-
-// TODO: PRIVATE
-int decode_report_from_protobuf(protobuf_sgx_report_t* protobuf_report, sgx_report_t* report)
-{
-  int counter; google::protobuf::uint32 temp32;
-  printf("\n----------------------Decoding received msg3 ------------------------\n");
-  printf("\nreport body keyid\n");
-  for(counter=0;counter<SGX_KEYID_SIZE;counter++)
-  {
-    temp32=protobuf_report->key_id(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->key_id.id[counter]))!=0)
-		  return -1;
-    printf("%d ", report->key_id.id[counter]);
-  }
-
-  printf("\nreport mac\n");
-  for(counter=0;counter<SGX_MAC_SIZE;counter++)
-  {
-    temp32=protobuf_report->mac(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->mac[counter]))!=0)
-      return -1;
-    printf("%d ", report->mac[counter]);
-  }
-
-  report->body.misc_select=protobuf_report->mutable_body()->misc_select(); // 32 bit
-  temp32=protobuf_report->mutable_body()->isv_svn();
-  if(fit_32_into_uint16_t(temp32, &(report->body.isv_svn))!=0)
-   return -1;
-  printf("\nmisc select %d \n", report->body.misc_select);
-
-  temp32=protobuf_report->mutable_body()->isv_prod_id();
-   if(fit_32_into_uint16_t(temp32, &(report->body.isv_prod_id))!=0)
-    return -1;
-  printf("\nprod id %d \n", report->body.isv_prod_id);
-
-  decode_attributes_from_protobuf(protobuf_report->mutable_body()->mutable_attributes(), &(report->body.attributes));
-
-  printf("\n cpu svn\n");
-  for(counter=0;counter<SGX_CPUSVN_SIZE;counter++)
-  {
-    temp32=protobuf_report->mutable_body()->cpu_svn(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->body.cpu_svn.svn[counter]))!=0)
-      return -1;
-    printf("%d ", report->body.cpu_svn.svn[counter]);
-
-  }
-
-  printf("\n reserved1 \n");
-  for(counter=0;counter<SGX_REPORT_BODY_RESERVED1;counter++)
-  {
-    temp32=protobuf_report->mutable_body()->reserved1(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->body.reserved1[counter]))!=0)
-      return -1;
-    printf("%d ", report->body.reserved1[counter]);
-  }
-
-  printf("\n reserved2 \n");
-  for(counter=0;counter<SGX_REPORT_BODY_RESERVED2;counter++)
-  {
-    temp32=protobuf_report->mutable_body()->reserved2(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->body.reserved2[counter]))!=0)
-      return -1;
-    printf("%d ", report->body.reserved2[counter]);
-  }
-
-  printf("\n reserved3 \n");
-  for(counter=0;counter<SGX_REPORT_BODY_RESERVED3;counter++)
-  {
-    temp32=protobuf_report->mutable_body()->reserved3(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->body.reserved3[counter]))!=0)
-      return -1;
-    printf("%d ", report->body.reserved3[counter]);
-  }
-
-  printf("\n reserved4 \n");
-  for(counter=0;counter<SGX_REPORT_BODY_RESERVED4;counter++)
-  {
-    temp32=protobuf_report->mutable_body()->reserved4(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->body.reserved4[counter]))!=0)
-      return -1;
-    printf("%d ", report->body.reserved4[counter]);
-
-  }
-
-  printf("\n mrenclave \n");
-  for(counter=0;counter<SGX_HASH_SIZE;counter++)
-  {
-    temp32=protobuf_report->mutable_body()->mr_enclave(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->body.mr_enclave.m[counter]))!=0)
-      return -1;
-    printf("%x ", report->body.mr_enclave.m[counter]);
-  }
-
-  printf("\n mrsigner \n");
-  for(counter=0;counter<SGX_HASH_SIZE;counter++)
-  {
-    temp32=protobuf_report->mutable_body()->mr_signer(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->body.mr_signer.m[counter]))!=0)
-      return -1;
-    printf("%x ", report->body.mr_signer.m[counter]);
-  }
-
-  printf("\n report data\n");
-  for(counter=0;counter<SGX_REPORT_DATA_SIZE;counter++)
-  {
-    temp32=protobuf_report->mutable_body()->report_data(counter);
-    if(fit_32_into_uint8_t(temp32, &(report->body.report_data.d[counter]))!=0)
-      return -1;
-    printf("%d ", report->body.report_data.d[counter]);
-  }
-  printf("\n------------------------ end of msg3 --------------------------\n");
-	return 0;
-}
-
-int decode_msg1_from_protobuf( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1, sgx_dh_msg1_t* native_dhmsg1)
-{
-	int counter; google::protobuf::uint32 temp32;// google::protobuf::uint64 temp64;
-
-	for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
-	{
-		temp32 = protobuf_dhmsg1.mutable_g_a()->gx(counter);
-		if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->g_a.gx[counter]))!=0)
-		 return -1;
-		temp32 = protobuf_dhmsg1.mutable_g_a()->gy(counter);
-		if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->g_a.gy[counter]))!=0)
-		 return -1;
-	}
-
-	for(counter=0;counter<SGX_HASH_SIZE;counter++)
-	{
-		temp32 = protobuf_dhmsg1.mutable_target()->mr_enclave(counter);
-		if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->target.mr_enclave.m[counter]))!=0)
-		 return -1;
-	}
-
-	for(counter=0;counter<SGX_TARGET_INFO_RESERVED1_BYTES;counter++)
-	{
-		temp32 = protobuf_dhmsg1.mutable_target()->reserved1(counter);
-		if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->target.reserved1[counter]))!=0)
-		 return -1;
-	}
-
-	for(counter=0;counter<SGX_TARGET_INFO_RESERVED2_BYTES;counter++)
-	{
-		temp32 = protobuf_dhmsg1.mutable_target()->reserved2(counter);
-		if(fit_32_into_uint8_t(temp32, &(native_dhmsg1->target.reserved2[counter]))!=0)
-		 return -1;
-	}
-
-	native_dhmsg1->target.attributes.flags = protobuf_dhmsg1.mutable_target()->mutable_attributes()->flags();
-	native_dhmsg1->target.attributes.xfrm = protobuf_dhmsg1.mutable_target()->mutable_attributes()->xfrm();
-	native_dhmsg1->target.misc_select = protobuf_dhmsg1.mutable_target()->misc_select();
-	return 0;
-}
-
-int decode_msg3_from_protobuf(protobuf_sgx_dh_msg3_t& protobuf_dhmsg3, sgx_dh_msg3_t* native_dhmsg3)
-{
-  int counter; google::protobuf::uint32 temp32;
-  for(counter=0;counter<SGX_DH_MAC_SIZE;counter++)
-  {
-		temp32=protobuf_dhmsg3.cmac(counter);
-    if(fit_32_into_uint8_t(temp32, &(native_dhmsg3->cmac[counter]))!=0)
-      return -1;
-  }
-
-  if(decode_report_from_protobuf(protobuf_dhmsg3.mutable_msg3_body()->mutable_report(), &(native_dhmsg3->msg3_body.report))==-1)
-    return -1;
-  int max_counter=protobuf_dhmsg3.mutable_msg3_body()->additional_prop_size();
-  native_dhmsg3->msg3_body.additional_prop_length=max_counter;
-  // TODO: Need to assign a variable on the heap and then pass it as an argument to this function - set it to null if protobuf_dhmsg3.mutable_msg3_body()->additional_prop_size() is 0
-  // TODO: And then free it in that function (create_session) when it is done. It is likely that it is 0 in the SGX SDK sample code. And SDK people probably didn't deserialize it - as it may contain a pointer in the general case - to the array of additional_properties.
-  if(max_counter!=0)
-    return -1;
-  return 0;
-}
-
-// TODO: PRIVATE - OR EVEN GET RID OF IT
-int print_initialized_msg1( protobuf_sgx_dh_msg1_t& protobuf_dhmsg1 /*, sgx_dh_msg1_t* native_dhmsg1*/)
-{
-	int counter;
-	printf("gx\n");
-	for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
-	{
-		 printf("%d ", protobuf_dhmsg1.g_a().gx(counter));
-	}
-
-	printf("\ngy\n");
-	for(counter=0;counter<SGX_ECP256_KEY_SIZE;counter++)
-	{
-		 printf("%d ", protobuf_dhmsg1.g_a().gy(counter));
-	}
-
-	printf("\nmrenclave in target\n");
-	for(counter=0;counter<SGX_HASH_SIZE;counter++)
-	{
-		 printf("%" PRIu32 " ", protobuf_dhmsg1.target().mr_enclave(counter));
-	}
-
-	printf("\nreserved1 in target\n");
-	for(counter=0;counter<SGX_TARGET_INFO_RESERVED1_BYTES;counter++)
-	{
-		 printf("%" PRIu32 " ", protobuf_dhmsg1.target().reserved1(counter));
-	}
-
-	printf("\nreserved2 in target\n");
-	for(counter=0;counter<SGX_TARGET_INFO_RESERVED2_BYTES;counter++)
-	{
-		 printf("%" PRIu32 " ", protobuf_dhmsg1.target().reserved2(counter));
-	}
-
-	printf("\n %" PRIu64 "\n", protobuf_dhmsg1.target().attributes().flags());
-	printf("\n %" PRIu64 "\n", protobuf_dhmsg1.target().attributes().xfrm());
-	printf("\n %" PRIu32 "\n", protobuf_dhmsg1.target().misc_select());
-
-	return 0;
-}
-
-void encode_msg2_to_protobuf( protobuf_sgx_dh_msg2_t& protobuf_dhmsg2, sgx_dh_msg2_t* native_dhmsg2)
-{
-	int counter; google::protobuf::uint32 temp32; //google::protobuf::uint64 temp64;
-	printf("\n msg2 cmac \n");
-	for(counter=0;counter<SGX_DH_MAC_SIZE;counter++)
-	{
-		temp32=native_dhmsg2->cmac[counter];
-		protobuf_dhmsg2.add_cmac(temp32);
-		printf("%d ", temp32);
-	}
-
-	encode_ec256_public_key_to_protobuf(protobuf_dhmsg2.mutable_g_b(), &(native_dhmsg2->g_b));
-
-	encode_report_to_protobuf(protobuf_dhmsg2.mutable_report(), &(native_dhmsg2->report));
-}
-/*
-// Got rid of the session ID - figure out its role.
-//message1 from the destination enclave through a socket set up before.
-// TODO: What do we do about session id?
-int session_request_call(int fd, sgx_dh_msg1_t* dh_msg1) //, uint32_t* session_id)
-{
-	protobuf_sgx_dh_msg1_t protobuf_msg1;
-	printf("reading msg1\n");
-	fflush(stdout);
-	if(read_protobuf_msg_from_fd(fd, protobuf_msg1)!=0)
-		return -1;
-	print_initialized_msg1(protobuf_msg1);
-	printf("\n done reading msg1 --------------------\n");
-	fflush(stdout);
-  if(decode_msg1_from_protobuf(protobuf_msg1, dh_msg1)!=0)
-    return -1;
-  return 0;
-}
-
-// Source enclave for exchange_report_ocall (like other ocalls) will be the PHP enclave and the destination enclave will be the decryptor one.
-//Makes an sgx_ecall to the destination enclave sends message2 from the source enclave and gets message 3 from the destination enclave
-// TODO: What do we do about session id?
-int exchange_report_call(int fd, sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *dh_msg3) // , uint32_t* session_id)
-{
-	protobuf_sgx_dh_msg2_t protobuf_msg2;
-  protobuf_sgx_dh_msg3_t protobuf_msg3;
-	printf("\n------------------------------------- generating msg2 --------\n");
-	// Fill protobuf class for dhmsg2 with contents from its native C struct.
-	encode_msg2_to_protobuf(protobuf_msg2, dh_msg2);
-	// Write msg length and then write the raw msg.
-	if(write_protobuf_msg_to_fd(fd, protobuf_msg2)!=0)
-		return -1;
-	printf("Wrote msg2 to protobuf ------------------------------------------\n");
-	fflush(stdout);
-	// Read from socket dh_msg3
-	if(read_protobuf_msg_from_fd(fd, protobuf_msg3)!=0)
-		return -1;
- 	// Decode msg3 from protobuf to native structs
-	if(decode_msg3_from_protobuf(protobuf_msg3, dh_msg3)!=0)
-		return -1;
- 	return 0;
-
-}
-
-//Make an sgx_ecall to the destination enclave to close the session
-int end_session_ocall()
-{
-  return SGX_SUCCESS;
-}
-*/

+ 6 - 20
systemMain.cpp

@@ -119,9 +119,6 @@ int main(int argc, char** argv)
   std::string apache_public_key;
   std::string apache_private_key2; 
 //  generate_rsa_keypair(apache_public_key, apache_private_key2); 
-
-//  uint8_t decryptor_mr_enclave[SGX_HASH_SIZE] = {0x1};
-//  uint8_t decryptor_mr_signer[SGX_HASH_SIZE] = {0x2};
   uint32_t return_sgx; uint32_t return_internal;
   std::string recovered_plaintext;
   uint32_t expected_sealed_msg_size=0;
@@ -165,23 +162,12 @@ int main(int argc, char** argv)
   printf("\nSuccessfully sealed the plaintext %s to length 0x%x.\n", apache_signature_keypair_private.c_str(), expected_sealed_msg_size);
   fflush(stdout);
 
-
-
-  return_sgx = local_attestation_initiator(DECRYPTOR_PORT);
-  if(return_sgx != 0)
-  {
-    if(return_sgx== 0xFFFFFFFF)
-    {
-      perror("\nCould not set up the socket: had the following error: ");
-      fflush(stderr);
-    }
-    else
-    {
-      printf("\nHad the following error in SGX local attestation: 0x%x", return_sgx);
-      fflush(stdout);
-    }
-    return return_sgx;
-  }
+    uint8_t hash[32] = {0x54,0x24,0x5d,0x63,0x5c,0x8f,0xec,0xcf,0x37,0xb9,0xcf,0x9e,0xb8,0xd3,0x22,0x04,0x57,0x5b,0xb2,0xfc,0xa6,0xd3,0x11,0xfb,0x87,0xb7,0x01,0x06,0x2f,0x18,0x25,0xc1};
+    // TODO: Error conditions.
+    DeploymentStageLogic deploymentStage;
+    deploymentStage.set_target_hash(hash);
+    deploymentStage.set_up_socket_connect(DECRYPTOR_PORT);
+    deploymentStage.main_logic();
   printf("\nSuccessful LA with port %d.\n", DECRYPTOR_PORT);
   fflush(stdout);
 /*