Browse Source

Added in postLA protobufs. It works!

dettanym 4 years ago
parent
commit
24148e3363
6 changed files with 283 additions and 118 deletions
  1. 94 42
      MainLogic.cpp
  2. 3 3
      Makefile
  3. 132 49
      PostLA/PostLAMessaging.cpp
  4. 4 4
      include/MainLogic.h
  5. 27 10
      include/PostLAMessaging.h
  6. 23 10
      systemMain.cpp

+ 94 - 42
MainLogic.cpp

@@ -14,7 +14,7 @@
 #include <netinet/in.h>
 
 #define DECRYPTOR_PORT_DATA 3825
-#define DECRYPTOR_PORT_HEADERS 3830
+#define DECRYPTOR_PORT_HEADERS 3826
 
 // 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.
@@ -49,10 +49,20 @@ int MainLogic::set_up_socket_connect(int port)
     return sock;
 }
 
-int MainLogic::conduct_la_get_initial_header(int data_fd, int headers_fd)
+int MainLogic::conduct_la()
 {
     uint8_t key[16];
     uint32_t ret_status;
+    int data_fd;
+
+    data_fd = set_up_socket_connect(DECRYPTOR_PORT_DATA);
+    printf("About to setup socket.\n");
+    if(data_fd <= 0)
+    {
+        printf("Could not set up a socket with port %d\n", DECRYPTOR_PORT_DATA);
+        fflush(stdout);
+        return 0x1;
+    }
 
     // Conduct LA.
     ret_status = laInitiator.conduct_la(data_fd);
@@ -67,69 +77,93 @@ int MainLogic::conduct_la_get_initial_header(int data_fd, int headers_fd)
     printf("Setting up fds for post LA messaging.\n");
     fflush(stdout);
     // Use the same channel for sending client data as the one used above for LA messages.
-    postLaMessagingData.set_fd(data_fd);
-    // Use a different channel for receiving headers asynchronously.
-    postLaMessagingHeaders.set_fd(headers_fd);
+    postLaMessaging.set_data_fd(data_fd);
 
     // Use the symmetric key from LA to send messages for the rest of the deployment stage.
-    printf("Retrieving key from LA inititator.\n ");
+    printf("Retrieving key from LA inititator.\n");
     fflush(stdout);
     laInitiator.get_la_symmetric_key(key);
-    printf("Setting key for post LA messaging for both data and headers channels.\n ");
+    printf("Setting key for post LA messaging for both data and headers channels.\n");
     fflush(stdout);
-    postLaMessagingData.set_la_symmetric_key(key);
-    postLaMessagingHeaders.set_la_symmetric_key(key);
+    postLaMessaging.set_la_symmetric_key(key);
 
-    //     Mitigator-Public-Key:
-    return postLaMessagingHeaders.receive_secure_msg(last_header_value);
+    return 0;
+}
+
+int MainLogic::get_initial_headers()
+{
+    int headers_fd, ret_status;
+
+    headers_fd = set_up_socket_connect(DECRYPTOR_PORT_HEADERS);
+    if(headers_fd <= 0)
+    {
+        // TODO: Proper error handling.
+        printf("Could not set up a socket with port %d\n", DECRYPTOR_PORT_HEADERS);
+        fflush(stdout);
+        return 0x1;
+    }
+    printf("Set up a socket to receive headers from the decryptor.\n"); fflush(stdout);
+
+    // Use a different channel for receiving headers asynchronously.
+    postLaMessaging.set_headers_fd(headers_fd);
+
+    ret_status = postLaMessaging.receive_header_from_decryptor(last_header_value);
+    if(ret_status != 0)
+    {
+        printf("Could not receive the header from the decryptor. Had error %d\n", ret_status);
+        fflush(stdout);
+    }
+    return 0;
 }
 
-int MainLogic::decode_base64_fields_list(std::vector <std::string> &base64_fields_list, std::vector <std::string> &binary_fields_list)
+int MainLogic::decode_base64_fields_list(std::vector <std::string> &base64_fields_list, std::vector <std::vector<unsigned char>> &binary_fields_list)
 {
-    uint32_t binary_field_size, base64_field_size;
+    int binary_field_size, base64_field_size, counter;
     const char* base64_field_ptr;
     unsigned char* binary_field_ptr = NULL;
 
+    printf("In the base64 decode list function.\n"); fflush(stdout);
     for (auto &base64_field : base64_fields_list)
     {
         base64_field_size = base64_field.size();
         base64_field_ptr = base64_field.c_str();
         // upper limit - the binary data will always be smaller than this (base64 length ~= 4/3 * binary length)
         binary_field_ptr = (unsigned char*) realloc(binary_field_ptr, base64_field_size);
+        printf("About to call the decoder on the following field:%s of the following size%d\n", base64_field_ptr, base64_field_size); fflush(stdout);
         binary_field_size = base64_decoding_wrapper(base64_field_ptr, base64_field_size, binary_field_ptr);
+        printf("Called the decoder and got the following size: %d.\n", binary_field_size );
         if(binary_field_size <= 0)
         {
+            printf("Had an error in decoding.\n"); fflush(stdout);
             free(binary_field_ptr);
             return 0x1;
         }
-        binary_fields_list.push_back(std::string(reinterpret_cast<const char*> (binary_field_ptr), binary_field_size));
+        std::vector<unsigned char> binary_field(binary_field_ptr, binary_field_ptr + binary_field_size);
+        binary_fields_list.push_back(binary_field);
+    }
+    free(binary_field_ptr);
+    for (auto binaryField : binary_fields_list)
+    {
+        for(auto myByte : binaryField)
+            printf("%02x ", myByte);
+        printf("\n");
     }
+
     return 0;
 }
 
 void MainLogic::deployment_stage() {
-    setbuf(stdout,NULL);
-    int data_fd = set_up_socket_connect(DECRYPTOR_PORT_DATA);
-    if(data_fd <= 0)
-    {
-        // TODO: Proper error handling.
-        printf("Could not set up a socket with port %d\n", DECRYPTOR_PORT_DATA);
+    int ret_status = conduct_la();
+    if(ret_status != 0) {
+        printf("Error in conducting LA: %d.\n", ret_status);
         fflush(stdout);
         return;
     }
 
-    int headers_fd = set_up_socket_connect(DECRYPTOR_PORT_HEADERS);
-    if(headers_fd <= 0)
+    ret_status = get_initial_headers();
+    if(ret_status !=0 )
     {
-        // TODO: Proper error handling.
-        printf("Could not set up a socket with port %d\n", DECRYPTOR_PORT_HEADERS);
-        fflush(stdout);
-        return;
-    }
-
-    int ret_status = conduct_la_get_initial_header(data_fd, headers_fd);
-    if(ret_status != 0) {
-        printf("Error in deployment stage: %d.\n", ret_status);
+        printf("Error in getting initial headers: %d.\n", ret_status);
         fflush(stdout);
         return;
     }
@@ -138,21 +172,31 @@ void MainLogic::deployment_stage() {
 }
 
 Php::Value MainLogic::php_decrypt_wrapper(Php::Parameters &params  ) {
-    std::vector <std::string> base64_fields_list, binary_fields_list, plaintext_fields_list;
-    uint32_t ret_status;
+    std::vector <std::string> base64_fields_list;
+    std::vector <std::vector<unsigned char>> binary_fields_list, plaintext_fields_list;
+    uint32_t ret_status, no_of_fields, counter, counter2;
     Php::Object ret_object;
     ret_object["success"]="false";
 
-    base64_fields_list = Php::array_values(params);
+    no_of_fields = params[0].size();
+    printf("Received client's ciphertext fields, performing base 64 decoding.\n"); fflush(stdout);
+    base64_fields_list = params[0]; //Php::array_values(Php::array_values(params)[0]);
+    printf("In the base64 decode list function.\n"); fflush(stdout);
+    /*
+        printf("Field: \n");
+        for(counter2=0; counter2<base64_fields_list[counter].length(); counter2++)
+            printf("%02x ", base64_fields_list[counter][counter2]);
+    */
     ret_status = decode_base64_fields_list(base64_fields_list, binary_fields_list);
-    if(ret_status != 0)
-    {
-        printf("Could not perform base64 decoding correctly."); fflush(stdout);
-        ret_object["error"]="Could not perform base64 decoding correctly.";
+    if (ret_status != 0) {
+        printf("Could not perform base64 decoding correctly.");
+        fflush(stdout);
+        ret_object["error"] = "Could not perform base64 decoding correctly.";
         return ret_object;
     }
 
-    ret_status = postLaMessagingData.send_secure_msgs(binary_fields_list);
+    printf("Sending data to the decryptor.\n"); fflush(stdout);
+    ret_status = postLaMessaging.send_data_to_decryptor(binary_fields_list);
     if(ret_status != 0)
     {
         printf("Cannot send messages to the decryptor.\n"); fflush(stdout);
@@ -160,7 +204,8 @@ Php::Value MainLogic::php_decrypt_wrapper(Php::Parameters &params  ) {
         return ret_object;
     }
 
-    ret_status = postLaMessagingData.receive_secure_msgs(plaintext_fields_list);
+    printf("Receiving data from the decryptor.\n"); fflush(stdout);
+    ret_status = postLaMessaging.receive_data_from_decryptor(plaintext_fields_list);
     if(ret_status != 0)
     {
         printf("Cannot receive messages from the decryptor.\n"); fflush(stdout);
@@ -169,7 +214,13 @@ Php::Value MainLogic::php_decrypt_wrapper(Php::Parameters &params  ) {
     }
     ret_object["success"]="true";
     ret_object["fields"]=Php::Array(plaintext_fields_list);
-
+    printf("Returning back to good old php.\n"); fflush(stdout);
+    for (auto binaryField : plaintext_fields_list)
+    {
+        for(auto myByte : binaryField)
+            printf("%c", myByte);
+        printf("\n");
+    }
     return ret_object;
 }
 
@@ -183,7 +234,7 @@ Php::Value MainLogic::get_mitigator_header() {
     }
     else
     {
-        ret_status = postLaMessagingHeaders.receive_secure_msg(header_value);
+        ret_status = postLaMessaging.receive_header_from_decryptor(header_value);
         if(ret_status != 0)
         {
             printf(" Cannot obtain a header from the decryptor.\n"); fflush(stdout);
@@ -191,5 +242,6 @@ Php::Value MainLogic::get_mitigator_header() {
         }
         header_refresh_counter = 0;
     }
+    printf("Returning this header value:%s\n", header_value.c_str()); fflush(stdout);
     return header_value;
 }

+ 3 - 3
Makefile

@@ -18,7 +18,7 @@ Openssl_Path := /home/m2mazmud/plain-openssl
 
 Uae_Library_Name := sgx_uae_service
 
-all: localattestation_decryption.so ${OBJECTS}
+all: localattestation_decryption.so #${OBJECTS}
 
 clean:
 	${RM} *.obj *~* ${OBJECTS} localattestation_decryption.so
@@ -47,9 +47,9 @@ ProtobufMessageRW.o: ProtobufMessageRW.cpp
 crypto.o: crypto.cpp 
 	g++ -I${Openssl_Path}/include ${CXX_FLAGS} -c $^ -o $@
 
-localattestation_decryption.so: systemMain.o MainLogic.o PostLA/PostLAMessaging.o LAInitiator/LA.o LAInitiator/Tramsforms.o ProtobufMessageRW.o  ProtobufLAMessages.pb.o crypto.o
+localattestation_decryption.so: systemMain.o MainLogic.o LAInitiator/LA.o LAInitiator/Tramsforms.o  ProtobufLAMessages.pb.o PostLA/PostLAMessaging.o PostLA/PostLAMessages.pb.o ProtobufMessageRW.o crypto.o
 #systemMain.o ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o PostLAMessages.pb.o crypto.o
-	${CXX} ${LD_FLAGS} systemMain.o MainLogic.o PostLA/PostLAMessaging.o LAInitiator/LA.o LAInitiator/Tramsforms.o ProtobufMessageRW.o  ProtobufLAMessages.pb.o crypto.o  -lphpcpp -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc -lprotobuf -Wl,--rpath /home/m2mazmud/plain-openssl/lib    -L${Openssl_Path}/lib -lssl -lcrypto   -Wl,-Bsymbolic -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  -o $@
+	${CXX} ${LD_FLAGS} systemMain.o MainLogic.o LAInitiator/LA.o LAInitiator/Tramsforms.o  ProtobufLAMessages.pb.o PostLA/PostLAMessaging.o PostLA/PostLAMessages.pb.o ProtobufMessageRW.o crypto.o  -lphpcpp -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc -lprotobuf -Wl,--rpath /home/m2mazmud/plain-openssl/lib    -L${Openssl_Path}/lib -lssl -lcrypto   -Wl,-Bsymbolic -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  -o $@
 #ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o 
 # -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc -lprotobuf -Wl,--rpath /home/m2mazmud/plain-openssl/lib   -L${Openssl_Path}/lib -lssl -lcrypto  -Wl,-Bsymbolic -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  -Wl,--verbose -lphpcpp -lprotobuf  -o $@
 #ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o 

+ 132 - 49
PostLA/PostLAMessaging.cpp

@@ -1,7 +1,6 @@
 //
 // Created by miti on 2019-12-24.
 //
-
 #include "PostLAMessaging.h"
 #include "sgx_trts.h" // for sgx_read_rand
 #include "crypto.h" // for aes_gcm_128
@@ -46,95 +45,179 @@ void PostLAMessaging::set_la_symmetric_key(uint8_t* given_key) {
     }
 }
 
-void PostLAMessaging::set_fd(int given_fd)
+void PostLAMessaging::set_headers_fd(int given_fd)
 {
-    protobufReaderWriter.set_fd(given_fd);
+    headersChannel.set_fd(given_fd);
 }
 
-uint32_t PostLAMessaging::encrypt_decrypt_msgs(int encrypt_decrypt, std::vector<std::string>& input_msgs,
-                         std::vector<std::string>& output_msgs)
+void PostLAMessaging::set_data_fd(int given_fd)
 {
-    unsigned char *input; unsigned char *output;
-    uint32_t input_size, output_size, ret;
+    dataChannel.set_fd(given_fd);
+}
+
+
+uint32_t PostLAMessaging::encrypt_decrypt_msgs(int encrypt_decrypt, std::vector<std::vector<unsigned char>>& input_msgs,
+                         std::vector<std::vector<unsigned char>>& output_msgs)
+{
+    unsigned char *input, *output;
+    uint32_t input_size, output_size, ret, counter;
     output=NULL;
 
-    for (std::string msg:input_msgs)
+    printf("In encrypt_decrypt_msgs\n"); fflush(stdout);
+    for (auto msg:input_msgs)
     {
-        input_size = msg.length();
-        input = (unsigned char*) msg.c_str();
+        printf("In the loop.\n"); fflush(stdout);
+        input_size = msg.size();
+        input = (unsigned char*) &msg[0];
+        printf("Input length %d\n", input_size);
+        for(counter=0; counter<input_size; counter++)
+            printf("%02x ", input[counter]);
+        printf("\n");
         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;
+            return ret;
         }
-        output_msgs.push_back(std::string(reinterpret_cast<const char *> (output), output_size));
+        printf("Output size %d\n", output_size);
+        for(counter=0; counter<output_size; counter++)
+            printf("%02x ", output[counter]);
+        printf("\n");
+        std::vector<unsigned char> output_field(output, output + output_size);
+        output_msgs.push_back(output_field);
     }
-    free(output);
-
+    printf("Outside da loop.\n"); fflush(stdout);
+    if(output != NULL)
+        free(output);
     return 0;
 }
 
+void PostLAMessaging::create_vector_from_protobuf(decryptor_to_extension_msg &protobuf_msg,
+                                 std::vector<std::vector<unsigned char>> &output_vector)
+{
+    uint32_t counter, no_of_fields;
+    std::string msg;
 
-/*
- * virtual void create_vector_from_protobuf(google::protobuf::MessageLite& protobuf_msg,
-                                         std::vector<std::string> &native_msg_list) {}
-*/
+    no_of_fields=protobuf_msg.fields_size();
+    for(counter=0; counter<no_of_fields; counter++)
+    {
+        msg = protobuf_msg.fields(counter).field();
+        std::vector<unsigned char> output_field(msg.begin(), msg.end());
+        output_vector.push_back(output_field);
+    }
+
+}
 
-uint32_t PostLAMessaging::receive_secure_msgs(std::vector<std::string> &plaintext_msg_list) {
-    std::vector<std::string> ciphertext_msg_list;
+void PostLAMessaging::create_protobuf_from_vector(std::vector<std::vector<unsigned char>> &input_vector,
+                                 extension_to_decryptor_msg &protobuf_msg)
+{
+    unsigned char* input_ptr;
+    std::vector<unsigned char> input_field;
+    size_t input_field_length;
 
-    /*google::protobuf::MessageLite protobuf_msg;
+    input_field = input_vector.at(0);
+    input_ptr = &input_field[0];
+    input_field_length = input_field.size();
+    protobuf_msg.set_ciphertext_client_public_key(input_ptr, input_field_length);
+    input_vector.erase(input_vector.begin());
 
-    // read encrypted data
-    if(!protobufReaderWriter.read_msg(protobuf_msg))
+    for(auto input_field : input_vector) // counter=0; counter<no_of_fields; counter++
     {
-        printf("Not all of the decryptor's message was read\n"); fflush(stdout);
-        return 0xf3;
+        input_field_length = input_field.size();
+        input_ptr = &input_field[0];
+        protobuf_msg.add_fields()->set_field(input_ptr, input_field_length);
     }
 
-    create_vector_from_protobuf(protobuf_msg, ciphertext_msg_list);
-    */
-
-    return encrypt_decrypt_msgs(0, ciphertext_msg_list, plaintext_msg_list);
 }
 
-uint32_t PostLAMessaging::receive_secure_msg(std::string &plaintext_msg) {
-    std::vector<std::string> ip_msg_list;
-    uint32_t ret_status;
+uint32_t PostLAMessaging::receive_data_from_decryptor(std::vector<std::vector<unsigned char>> &plaintext_msg_list) {
+    std::vector<std::vector<unsigned char>> ciphertext_msg_list;
 
-    ret_status = receive_secure_msgs(ip_msg_list);
-    if(ret_status != 0)
-        return ret_status;
+    decryptor_to_extension_msg msg;
 
-    plaintext_msg = ip_msg_list.front();
-    return 0;
+    // read encrypted data
+    if(dataChannel.read_msg(msg) != 0)
+    {
+        printf("Not all of the decryptor's message was read\n"); fflush(stdout);
+        return 0xf3;
+    }
+    printf("Read the msg from the decryptor.\n"); fflush(stdout);
+    create_vector_from_protobuf(msg, ciphertext_msg_list);
+    printf("created a vector\n"); fflush(stdout);
+    return encrypt_decrypt_msgs(0, ciphertext_msg_list, plaintext_msg_list);
 }
 
-
-uint32_t PostLAMessaging::send_secure_msgs(std::vector<std::string> &plaintext_msg_list)
+uint32_t PostLAMessaging::send_data_to_decryptor(std::vector<std::vector<unsigned char>> &plaintext_msg_list)
 {
     uint32_t ret;
-    std::vector<std::string> ciphertext_msg_list;
+    extension_to_decryptor_msg msg;
+    std::vector<std::vector<unsigned char>> ciphertext_msg_list;
 
     ret=encrypt_decrypt_msgs(1, plaintext_msg_list, ciphertext_msg_list);
     if(ret!=0)
         return ret;
-
-    // TODO: Fix with correct protobuf references. (write)
-    /*
-    // write message to decryptor
-    create_protobuf_from_vector(ciphertext_msg_list, protobuf_msg);
-
-    google::protobuf::MessageLite protobuf_msg;
-    if(!protobufReaderWriter.write_msg(protobuf_msg))
+    printf("About to create a protobuf vector\n"); fflush(stdout);
+    create_protobuf_from_vector(ciphertext_msg_list, msg);
+    printf("About to write the message to the data channel.\n"); fflush(stdout);
+    if(dataChannel.write_msg(msg) != 0)
     {
         printf("Not all of the client's pub key and ciphertext data was written\n"); fflush(stdout);
         return 0xfe;
     }
-    */
+
+    return 0;
+}
+
+uint32_t PostLAMessaging::receive_header_from_decryptor(std::string &plaintext_header) {
+    std::vector<std::vector<unsigned char>> ip_list, binary_list;
+    unsigned char* binary_ptr;
+    std::vector<unsigned char> binary_header;
+    size_t binary_header_length;
+    uint8_t* base64_ciphertext_header;
+    int base64_ciphertext_header_length;
+    uint32_t ret_status;
+
+    printf("About to send-receive header.\n"); fflush(stdout);
+
+    mitigator_header headerMsg;
+    headerMsg.set_name("Name:", 5);
+    headerMsg.set_value("!!Value", 7);
+    if(headersChannel.write_msg(headerMsg) != 0)
+    {
+        printf("Error in writing msg for headers.\n"); fflush(stdout); return 0x1;
+    }
+    printf("Wrote a placeholder message to the header.\n"); fflush(stdout);
+
+    if(headersChannel.read_msg(headerMsg) != 0)
+    {
+        printf("Error in reading msg for headers.\n"); fflush(stdout); return 0x2;
+    }
+    printf("Read the following header name and value from the decryptor:\nName:-%s-\n", headerMsg.name().c_str()); fflush(stdout);
+    plaintext_header = headerMsg.name();
+
+    std::vector<unsigned char> input_field(headerMsg.value().begin(), headerMsg.value().end());
+    ip_list.push_back(input_field);
+
+    ret_status = encrypt_decrypt_msgs(0, ip_list, binary_list);
+    if(ret_status != 0)
+        return ret_status;
+
+    binary_header = binary_list.at(0);
+    binary_ptr = &binary_header[0];
+    binary_header_length = binary_header.size();
+
+    base64_ciphertext_header = (uint8_t* ) malloc(2*binary_header_length);
+    base64_ciphertext_header_length = base64_encoding_wrapper((unsigned char*) binary_ptr, binary_header_length , base64_ciphertext_header);
+    if(base64_ciphertext_header_length <= 0)
+    {
+        printf("Error encoding the ciphertext header into base64 format.\n"); fflush(stdout);  return 0x3;
+    }
+    printf("Got this header value:-%s-\n", base64_ciphertext_header);
+    plaintext_header.append((const char* )base64_ciphertext_header, (size_t) base64_ciphertext_header_length);
+    printf("Got this header:%s\n", plaintext_header.c_str()); fflush(stdout);
+
     return 0;
 }
 

+ 4 - 4
include/MainLogic.h

@@ -12,13 +12,13 @@
 
 class MainLogic : public Php::Base {
     LA laInitiator;
-    PostLAMessaging postLaMessagingData;
-    PostLAMessaging postLaMessagingHeaders;
+    PostLAMessaging postLaMessaging;
     uint32_t header_refresh_counter;
     std::string last_header_value;
     int set_up_socket_connect(int port);
-    int conduct_la_get_initial_header(int fd1, int fd2);
-    int decode_base64_fields_list(std::vector <std::string> &base64_fields_list, std::vector <std::string> &binary_fields_list);
+    int conduct_la();
+    int get_initial_headers();
+    int decode_base64_fields_list(std::vector <std::string> &base64_fields_list, std::vector <std::vector<unsigned char>> &binary_fields_list);
 public:
     void deployment_stage();
     Php::Value get_mitigator_header();

+ 27 - 10
include/PostLAMessaging.h

@@ -4,21 +4,38 @@
 
 #ifndef APACHE_PHP_EXTENSION_POSTLAMESSAGING_H
 #define APACHE_PHP_EXTENSION_POSTLAMESSAGING_H
+#include "PostLAMessages.pb.h"
 #include "ProtobufMessageRW.h"
 #include <string>
 #include <vector>
 class PostLAMessaging {
     uint8_t key[16];
-    ProtobufMessageRW protobufReaderWriter;
-    uint32_t aes_gcm_wrapper(int enc, uint8_t* plaintext, uint32_t plaintext_length, uint8_t* ciphertext, uint32_t* ciphertext_length);
-    uint32_t encrypt_decrypt_msgs(int encrypt_decrypt, std::vector<std::string> &input_msgs,
-                                              std::vector<std::string> &output_msgs);
+    ProtobufMessageRW headersChannel;
+    ProtobufMessageRW dataChannel;
+
+    uint32_t aes_gcm_wrapper(int enc, uint8_t *plaintext, uint32_t plaintext_length, uint8_t *ciphertext,
+                             uint32_t *ciphertext_length);
+
+    uint32_t encrypt_decrypt_msgs(int encrypt_decrypt, std::vector <std::vector<unsigned char>> &input_msgs,
+                                  std::vector <std::vector<unsigned char>> &output_msgs);
+
+    void create_vector_from_protobuf(decryptor_to_extension_msg &protobuf_msg,
+                                     std::vector <std::vector<unsigned char>> &output_vector);
+
+    void create_protobuf_from_vector(std::vector <std::vector<unsigned char>> &input_vector,
+                                     extension_to_decryptor_msg &protobuf_msg);
+
 public:
-    void set_la_symmetric_key(uint8_t* given_key);
-    void set_fd(int given_fd);
-    uint32_t receive_secure_msg(std::string& output_msg);
-    uint32_t receive_secure_msgs(std::vector<std::string>& output_msgs);
-    uint32_t send_secure_msgs(std::vector<std::string>& input_msgs);
-};
+    void set_la_symmetric_key(uint8_t *given_key);
 
+    void set_headers_fd(int given_fd);
+
+    void set_data_fd(int given_fd);
+
+    uint32_t receive_header_from_decryptor(std::string &output_msg);
+
+    uint32_t receive_data_from_decryptor(std::vector <std::vector<unsigned char>> &output_msgs);
+
+    uint32_t send_data_to_decryptor(std::vector <std::vector<unsigned char>> &plaintext_msg_list);
+};
 #endif //APACHE_PHP_EXTENSION_POSTLAMESSAGING_H

+ 23 - 10
systemMain.cpp

@@ -15,22 +15,35 @@ int __ImageBase=0;
 
 // Mitigator-Public-Key:
 
+MainLogic *mainLogic = NULL;
+
+Php::Value totally_normal_get_mitigator_header()
+{
+    return mainLogic->get_mitigator_header();
+}
+
+void totally_normal_deployment_stage()
+{   mainLogic = new MainLogic;
+    return mainLogic->deployment_stage();
+}
+
+Php::Value totally_normal_php_decrypt_wrapper(Php::Parameters & params)
+{
+    return mainLogic->php_decrypt_wrapper(params);
+}
+
+
 extern "C" {
     // export the "get_module" function that will be called by the Zend engine
     PHPCPP_EXPORT void *get_module()
     {
         // create extension
         static Php::Extension extension("decryptor_la_setup_and_decryption","1.0");
-        MainLogic nativeMainLogic;
-
-        Php::Class<MainLogic> myMainLogic("MainLogic");
-        myMainLogic.method<&MainLogic::get_mitigator_header>("get_mitigator_header");
-        myMainLogic.method<&MainLogic::deployment_stage>("deployment_stage");
-        myMainLogic.method<&MainLogic::php_decrypt_wrapper>("php_decrypt_wrapper", { Php::ByVal("string", Php::Type::String), Php::ByVal("string", Php::Type::String) }   );
-        std::function<void()> startup_callback_fn = std::bind(&MainLogic::deployment_stage, nativeMainLogic); //nativeMainLogic.deployment_stage;
-        extension.onStartup(startup_callback_fn);
-        // return the extension module
-    	extension.add(myMainLogic);
+        extension.onStartup(totally_normal_deployment_stage);
+        extension.add<totally_normal_get_mitigator_header>("get_mitigator_header");
+        extension.add<totally_normal_php_decrypt_wrapper>("php_decrypt_wrapper",
+                                                          {Php::ByVal("array", Php::Type::Array)}
+                                                         );
         return extension.module();
     }
 }