|
@@ -9,7 +9,7 @@
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
-
|
|
|
+#include "crypto.h"
|
|
|
#include "ProtobufLAInitiator.h"
|
|
|
using namespace std;
|
|
|
|
|
@@ -42,6 +42,7 @@ class Mitigator : public Php::Base
|
|
|
uint32_t return_sgx, count, base64_encoded_token_H_length;
|
|
|
unsigned char* base64_encoded_mitigator_header_and_value;
|
|
|
|
|
|
+ base64_encoded_mitigator_header_and_value = (unsigned char*) malloc( 400 );
|
|
|
|
|
|
memcpy(base64_encoded_mitigator_header_and_value, mitigator_pubkey_header.c_str(), mitigator_pubkey_header.length());
|
|
|
return_sgx = local_attestation_initiator(DECRYPTOR_PORT);
|
|
@@ -60,7 +61,6 @@ class Mitigator : public Php::Base
|
|
|
else {
|
|
|
printf("\nSuccessful LA with port %d.\n", DECRYPTOR_PORT);
|
|
|
fflush(stdout);
|
|
|
- base64_encoded_mitigator_header_and_value = (unsigned char*) malloc(400);
|
|
|
return_sgx= post_local_attestation_get_mitigator_header(base64_encoded_mitigator_header_and_value + mitigator_pubkey_header.length(),
|
|
|
&base64_encoded_token_H_length);
|
|
|
if(return_sgx != 0)
|
|
@@ -70,6 +70,7 @@ class Mitigator : public Php::Base
|
|
|
}
|
|
|
mitigator_pubkey_header_value=std::string((char*)base64_encoded_mitigator_header_and_value,mitigator_pubkey_header.length()+base64_encoded_token_H_length);
|
|
|
}
|
|
|
+ free(base64_encoded_mitigator_header_and_value);
|
|
|
}
|
|
|
|
|
|
static Php::Value get_mitigator_header()
|
|
@@ -79,45 +80,63 @@ class Mitigator : public Php::Base
|
|
|
|
|
|
static Php::Value php_decrypt_wrapper(Php::Parameters ¶ms )
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
unsigned char* plaintext_user_data, * base64_client_ciphertext, *base64_client_public_key, *base64_client_data, *client_data;
|
|
|
uint32_t plaintext_length, base64_client_ciphertext_length, base64_client_public_key_length, base64_client_data_length, client_data_length, ret_status, counter;
|
|
|
std::string plaintext_user_data_str;
|
|
|
-
|
|
|
+ uint32_t old_client_data_length;
|
|
|
base64_client_ciphertext = (unsigned char*) static_cast<const char*>(params[1]);
|
|
|
base64_client_public_key = (unsigned char*) static_cast<const char*>(params[0]);
|
|
|
base64_client_ciphertext_length = params[1].size();
|
|
|
base64_client_public_key_length = params[0].size();
|
|
|
- base64_client_data = (unsigned char*) malloc(params[1].size() + params[0].size());
|
|
|
- memcpy(base64_client_data, base64_client_public_key, base64_client_public_key_length);
|
|
|
- memcpy(base64_client_data + base64_client_public_key_length, base64_client_ciphertext, base64_client_ciphertext_length);
|
|
|
- base64_client_data_length = base64_client_public_key_length + base64_client_ciphertext_length;
|
|
|
+
|
|
|
|
|
|
plaintext_user_data = (unsigned char*) malloc( base64_client_ciphertext_length );
|
|
|
+ plaintext_length = base64_client_ciphertext_length;
|
|
|
memcpy(plaintext_user_data, base64_client_ciphertext, base64_client_ciphertext_length);
|
|
|
plaintext_user_data_str = std::string((char*) plaintext_user_data, base64_client_ciphertext_length);
|
|
|
|
|
|
printf("Base64 encoded key:\n");
|
|
|
for(counter=0; counter < base64_client_public_key_length; counter++)
|
|
|
- printf("%c", base64_client_data[counter]);
|
|
|
+ printf("%c", base64_client_public_key[counter]);
|
|
|
printf("\n"); fflush(stdout);
|
|
|
|
|
|
printf("Ciphertext received:\n");
|
|
|
- for(counter=base64_client_public_key_length; counter < base64_client_public_key_length + base64_client_ciphertext_length; counter++ )
|
|
|
- printf("%02x", base64_client_data[counter]);
|
|
|
+ for(counter=0; counter < base64_client_ciphertext_length; counter++ )
|
|
|
+ printf("%c", base64_client_ciphertext[counter]);
|
|
|
printf("\n"); fflush(stdout);
|
|
|
-
|
|
|
- client_data = (unsigned char*) malloc(base64_client_data_length);
|
|
|
- ret_status = base64_decoding_on_all_client_data(base64_client_data, base64_client_data_length, client_data, &client_data_length);
|
|
|
- free(base64_client_data);
|
|
|
+
|
|
|
+ client_data = (unsigned char*) malloc(base64_client_ciphertext_length + base64_client_public_key_length);
|
|
|
+ ret_status = base64_decoding_wrapper(client_data, base64_client_public_key, base64_client_public_key_length);
|
|
|
if(ret_status<=0)
|
|
|
{
|
|
|
- printf("Could not do base64 decoding correctly.\n"); fflush(stdout);
|
|
|
- free(plaintext_user_data);
|
|
|
- free(client_data);
|
|
|
- return plaintext_user_data_str;
|
|
|
+ printf("Could not do base64 decoding correctly.\n"); fflush(stdout);
|
|
|
+ free(plaintext_user_data);
|
|
|
+ free(client_data);
|
|
|
+ return plaintext_user_data_str;
|
|
|
}
|
|
|
-
|
|
|
+ client_data_length = ret_status;
|
|
|
+ old_client_data_length=client_data_length;
|
|
|
+ printf("Client public key:\n");
|
|
|
+ for(counter=0; counter<client_data_length; counter++)
|
|
|
+ printf("%d ", client_data[counter]);
|
|
|
+
|
|
|
+
|
|
|
+ ret_status = base64_decoding_wrapper(client_data + client_data_length, base64_client_ciphertext, base64_client_ciphertext_length);
|
|
|
+ if(ret_status<=0)
|
|
|
+ {
|
|
|
+ printf("Could not do base64 decoding correctly.\n"); fflush(stdout);
|
|
|
+ free(plaintext_user_data);
|
|
|
+ free(client_data);
|
|
|
+ return plaintext_user_data_str;
|
|
|
+ }
|
|
|
+ client_data_length += ret_status;
|
|
|
+
|
|
|
+ printf("\n Ciphertext from client:\n");
|
|
|
+ for(counter=old_client_data_length; counter<client_data_length; counter++)
|
|
|
+ printf("%d ", client_data[counter]);
|
|
|
+ printf("\n"); fflush(stdout);
|
|
|
+
|
|
|
ret_status=decrypt_client_data_through_decryptor(client_data, client_data_length, (unsigned char*) plaintext_user_data, &plaintext_length);
|
|
|
if(ret_status != 0)
|
|
|
{
|
|
@@ -129,16 +148,13 @@ class Mitigator : public Php::Base
|
|
|
|
|
|
printf("Going to return this plaintext:\n");
|
|
|
for(counter=0;counter<plaintext_length;counter++)
|
|
|
- printf("0x%02x ", plaintext_user_data[counter]);
|
|
|
+ printf("%c", plaintext_user_data[counter]);
|
|
|
fflush(stdout);
|
|
|
|
|
|
-
|
|
|
+ plaintext_user_data_str = std::string((char*) plaintext_user_data, plaintext_length);
|
|
|
free(plaintext_user_data);
|
|
|
-
|
|
|
-
|
|
|
+ free(client_data);
|
|
|
return plaintext_user_data_str;
|
|
|
-*/
|
|
|
- return params[1];
|
|
|
}
|
|
|
};
|
|
|
|