|
@@ -1,33 +1,3 @@
|
|
|
-
|
|
|
- * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
|
|
|
- *
|
|
|
- * Redistribution and use in source and binary forms, with or without
|
|
|
- * modification, are permitted provided that the following conditions
|
|
|
- * are met:
|
|
|
- *
|
|
|
- * * Redistributions of source code must retain the above copyright
|
|
|
- * notice, this list of conditions and the following disclaimer.
|
|
|
- * * Redistributions in binary form must reproduce the above copyright
|
|
|
- * notice, this list of conditions and the following disclaimer in
|
|
|
- * the documentation and/or other materials provided with the
|
|
|
- * distribution.
|
|
|
- * * Neither the name of Intel Corporation nor the names of its
|
|
|
- * contributors may be used to endorse or promote products derived
|
|
|
- * from this software without specific prior written permission.
|
|
|
- *
|
|
|
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.challa
|
|
|
- *
|
|
|
- */
|
|
|
|
|
|
#include <stdio.h>
|
|
|
#include <map>
|
|
@@ -36,18 +6,10 @@
|
|
|
#include "sgx_urts.h"
|
|
|
#define __STDC_FORMAT_MACROS
|
|
|
#include <inttypes.h>
|
|
|
-#include<unistd.h>
|
|
|
-
|
|
|
-#include "sgx_tseal.h"
|
|
|
#include "LocalAttestationUntrusted.h"
|
|
|
+#include "Sealing.h"
|
|
|
|
|
|
|
|
|
-
|
|
|
-#include <fcntl.h>
|
|
|
-#include <sys/types.h>
|
|
|
-#include <sys/stat.h>
|
|
|
-#include <errno.h>
|
|
|
-
|
|
|
|
|
|
#define TCHAR char
|
|
|
#define _TCHAR char
|
|
@@ -58,7 +20,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
-sgx_enclave_id_t e2_enclave_id = 0;
|
|
|
+sgx_enclave_id_t enclave_id = 0;
|
|
|
#define Decryptor_PATH "libDecryptor.so"
|
|
|
|
|
|
|
|
@@ -108,7 +70,7 @@ uint32_t unseal_signing_key_pair_from_disk(int fd, size_t sealed_msg_length_in_f
|
|
|
printf("%x ", *(sealed_data+counter));
|
|
|
printf("\n"); fflush(stdout);
|
|
|
|
|
|
- Decryptor_unseal_and_restore_long_term_signing_key_pair_wrapper(e2_enclave_id, &ret_status, sealed_data, &length);
|
|
|
+ Decryptor_unseal_and_restore_long_term_signing_key_pair_wrapper(enclave_id, &ret_status, sealed_data, &length);
|
|
|
free(sealed_data);
|
|
|
return ret_status;
|
|
|
}
|
|
@@ -118,13 +80,13 @@ uint32_t create_and_seal_signing_key_pair_to_disk(int fd)
|
|
|
uint32_t ret_status=0, length=0, counter=0;
|
|
|
uint8_t* sealed_data;
|
|
|
|
|
|
- Decryptor_calculate_sealed_keypair_size_wrapper(e2_enclave_id, &length);
|
|
|
+ Decryptor_calculate_sealed_keypair_size_wrapper(enclave_id, &length);
|
|
|
if(length == 0xFFFFFFFF)
|
|
|
return 0xFFFFFFFF;
|
|
|
sealed_data=(uint8_t*) malloc(length);
|
|
|
printf("length: %d\n", length); fflush(stdout);
|
|
|
|
|
|
- Decryptor_create_and_seal_long_term_signing_key_pair_wrapper(e2_enclave_id, &ret_status, &length, sealed_data);
|
|
|
+ Decryptor_create_and_seal_long_term_signing_key_pair_wrapper(enclave_id, &ret_status, &length, sealed_data);
|
|
|
if(ret_status != SGX_SUCCESS)
|
|
|
{
|
|
|
printf("create_and_seal called returned an error: %x", ret_status);
|
|
@@ -142,76 +104,51 @@ uint32_t create_and_seal_signing_key_pair_to_disk(int fd)
|
|
|
|
|
|
int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
|
|
|
{
|
|
|
- uint32_t ret_status;
|
|
|
+ uint32_t ret_status, counter;
|
|
|
sgx_status_t status;
|
|
|
|
|
|
int launch_token_updated;
|
|
|
sgx_launch_token_t launch_token;
|
|
|
- sgx_ec256_public_t pub_key; uint32_t counter;
|
|
|
+
|
|
|
+ int server_fd, accept_fd;
|
|
|
|
|
|
- size_t sealed_msg_length_in_file;
|
|
|
- status = sgx_create_enclave(Decryptor_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e2_enclave_id, NULL);
|
|
|
+ status = sgx_create_enclave(Decryptor_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &enclave_id, NULL);
|
|
|
if(status != SGX_SUCCESS)
|
|
|
{
|
|
|
printf("\nLoad Enclave Failure");
|
|
|
return -1;
|
|
|
}
|
|
|
- printf("\nDecryptor - EnclaveID %" PRIx64, e2_enclave_id);
|
|
|
+ printf("\nDecryptor - EnclaveID %" PRIx64, enclave_id);
|
|
|
fflush(stdout);
|
|
|
|
|
|
- int sealed_signing_key_fd = open("sealed_signing_key.txt", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
|
|
- if(sealed_signing_key_fd == -1)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Sealing sealer;
|
|
|
+ const char* sealed_keypair_file = "sealed_signing_key.txt";
|
|
|
+ ret_status = sealer.initialize_long_term_keypair(enclave_id, sealed_keypair_file);
|
|
|
+ if(ret_status != 0)
|
|
|
{
|
|
|
- perror("\nError in opening the file sealed_signing_key.txt - ");
|
|
|
- fflush(stderr);
|
|
|
- return 0xFFFFFFFF;
|
|
|
+ sgx_destroy_enclave(enclave_id);
|
|
|
+ return ret_status;
|
|
|
}
|
|
|
- printf("\nSuccessfully opened a file to seal the signing key pair for the client.\n");
|
|
|
- fflush(stdout);
|
|
|
- struct stat st; ret_status = fstat(sealed_signing_key_fd, &st);
|
|
|
- if(ret_status != 0)
|
|
|
- {
|
|
|
- perror("error in finding the file size. - ");
|
|
|
- fflush(stderr);
|
|
|
- return 0xffffffff;
|
|
|
-
|
|
|
- }
|
|
|
- sealed_msg_length_in_file = st.st_size;
|
|
|
- if(sealed_msg_length_in_file == 0)
|
|
|
-
|
|
|
-
|
|
|
- { printf("Creating new keypair.\n"); fflush(stdout); ret_status = create_and_seal_signing_key_pair_to_disk(sealed_signing_key_fd); }
|
|
|
- else
|
|
|
- { printf("Unsealing keypair.\n"); fflush(stdout); ret_status = unseal_signing_key_pair_from_disk(sealed_signing_key_fd, sealed_msg_length_in_file); }
|
|
|
-
|
|
|
- if(ret_status != 0)
|
|
|
- {
|
|
|
- printf("Some error \n");
|
|
|
-
|
|
|
- fflush(stdout);
|
|
|
- sgx_destroy_enclave(e2_enclave_id);
|
|
|
|
|
|
- return 0xFFFFFFFF;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- close(sealed_signing_key_fd);
|
|
|
- uint8_t verification_key[64];
|
|
|
- Decryptor_get_long_term_verification_key_wrapper(e2_enclave_id, verification_key);
|
|
|
+
|
|
|
+ uint8_t verification_key[64];
|
|
|
+ Decryptor_get_long_term_verification_key_wrapper(enclave_id, verification_key);
|
|
|
printf("Verification key\n"); fflush(stdout);
|
|
|
for(counter=0;counter<32;counter++)
|
|
|
printf("%02x", verification_key[counter]);
|
|
|
- printf("\n"); fflush(stdout);
|
|
|
- for(counter=0;counter<32;counter++)
|
|
|
- printf("%02x", verification_key[counter + 32]);
|
|
|
- printf("\n"); fflush(stdout);
|
|
|
-
|
|
|
+ printf("\n"); fflush(stdout);
|
|
|
+ for(counter=0;counter<32;counter++)
|
|
|
+ printf("%02x", verification_key[counter + 32]);
|
|
|
+ printf("\n"); fflush(stdout);
|
|
|
|
|
|
- int server_fd, accept_fd;
|
|
|
- ret_status = LocalAttestationUntrusted::prepare_local_attestation_as_responder_msg1(e2_enclave_id);
|
|
|
+ ret_status = LocalAttestationUntrusted::prepare_local_attestation_as_responder_msg1(enclave_id);
|
|
|
if(ret_status !=0)
|
|
|
{
|
|
|
- printf("Could not prepare_local_attestation_as_responder_msg1"); fflush(stdout); sgx_destroy_enclave(e2_enclave_id);
|
|
|
+ printf("Could not prepare_local_attestation_as_responder_msg1"); fflush(stdout); sgx_destroy_enclave(enclave_id);
|
|
|
return ret_status;
|
|
|
}
|
|
|
|
|
@@ -219,26 +156,26 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
|
|
|
if(server_fd <=0)
|
|
|
{
|
|
|
printf("Error in setting up server socket."); fflush(stdout);
|
|
|
- sgx_destroy_enclave(e2_enclave_id);
|
|
|
+ sgx_destroy_enclave(enclave_id);
|
|
|
return server_fd;
|
|
|
}
|
|
|
printf("Successfully set up a socket to communicate with the verifier enclave.\n");
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
|
- ret_status = LocalAttestationUntrusted::local_attestation_as_responder_msg2_msg3(e2_enclave_id, server_fd, &accept_fd);
|
|
|
+ ret_status = LocalAttestationUntrusted::local_attestation_as_responder_msg2_msg3(enclave_id, server_fd, &accept_fd);
|
|
|
if(ret_status!=0)
|
|
|
{
|
|
|
printf("local attestation - with the verifier - did not successfully return: %x\n", ret_status); fflush(stdout);
|
|
|
- sgx_destroy_enclave(e2_enclave_id);
|
|
|
+ sgx_destroy_enclave(enclave_id);
|
|
|
return 0xFFFFFFFF;
|
|
|
}
|
|
|
|
|
|
- ret_status = LocalAttestationUntrusted::post_local_attestation_with_verifier(e2_enclave_id, accept_fd);
|
|
|
+ ret_status = LocalAttestationUntrusted::post_local_attestation_with_verifier(enclave_id, accept_fd);
|
|
|
if(ret_status!=0)
|
|
|
{
|
|
|
printf("post local attestation - with the verifier - did not successfully return: %x\n", ret_status); fflush(stdout);
|
|
|
- sgx_destroy_enclave(e2_enclave_id);
|
|
|
+ sgx_destroy_enclave(enclave_id);
|
|
|
return 0xFFFFFF01;
|
|
|
}
|
|
|
|
|
@@ -247,29 +184,29 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
|
|
|
if(server_fd <=0)
|
|
|
{
|
|
|
printf("Error in setting up server socket."); fflush(stdout);
|
|
|
- sgx_destroy_enclave(e2_enclave_id);
|
|
|
+ sgx_destroy_enclave(enclave_id);
|
|
|
return server_fd;
|
|
|
}
|
|
|
printf("Successfully set up a socket to communicate with the Apache enclave.\n");
|
|
|
fflush(stdout);
|
|
|
|
|
|
- ret_status = LocalAttestationUntrusted::local_attestation_as_responder_msg2_msg3(e2_enclave_id,server_fd,&accept_fd);
|
|
|
+ ret_status = LocalAttestationUntrusted::local_attestation_as_responder_msg2_msg3(enclave_id,server_fd,&accept_fd);
|
|
|
if(ret_status<0)
|
|
|
{
|
|
|
printf("local attestation - with the apache - did not successfully return: %x\n", ret_status); fflush(stdout);
|
|
|
- sgx_destroy_enclave(e2_enclave_id);
|
|
|
+ sgx_destroy_enclave(enclave_id);
|
|
|
return 0xFFFFFFFF;
|
|
|
}
|
|
|
|
|
|
- ret_status = LocalAttestationUntrusted::post_local_attestation_with_apache(e2_enclave_id,accept_fd);
|
|
|
+ ret_status = LocalAttestationUntrusted::post_local_attestation_with_apache(enclave_id,accept_fd);
|
|
|
if(ret_status!=0)
|
|
|
{
|
|
|
printf("post local attestation - with the apache - did not successfully return: %x\n", ret_status); fflush(stdout);
|
|
|
- sgx_destroy_enclave(e2_enclave_id);
|
|
|
+ sgx_destroy_enclave(enclave_id);
|
|
|
return 0xFFFFFF01;
|
|
|
}
|
|
|
|
|
|
- sgx_destroy_enclave(e2_enclave_id);
|
|
|
+ sgx_destroy_enclave(enclave_id);
|
|
|
|
|
|
return 0;
|
|
|
}
|