123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- /*
- * 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.
- *
- */
- // App.cpp : Defines the entry point for the console application.
- #include <stdio.h>
- #include <map>
- #include "../Enclave1/Enclave1_u.h"
- #include "../Enclave2/Enclave2_u.h"
- #include "../Enclave3/Enclave3_u.h"
- #include "sgx_eid.h"
- #include "sgx_urts.h"
- #define __STDC_FORMAT_MACROS
- #include <inttypes.h>
- #define UNUSED(val) (void)(val)
- #define TCHAR char
- #define _TCHAR char
- #define _T(str) str
- #define scanf_s scanf
- #define _tmain main
- extern std::map<sgx_enclave_id_t, uint32_t>g_enclave_id_map;
- sgx_enclave_id_t e1_enclave_id = 0;
- sgx_enclave_id_t e2_enclave_id = 0;
- sgx_enclave_id_t e3_enclave_id = 0;
- #define ENCLAVE1_PATH "libenclave1.so"
- #define ENCLAVE2_PATH "libenclave2.so"
- #define ENCLAVE3_PATH "libenclave3.so"
- void waitForKeyPress()
- {
- char ch;
- int temp;
- printf("\n\nHit a key....\n");
- temp = scanf_s("%c", &ch);
- }
- uint32_t load_enclaves()
- {
- uint32_t enclave_temp_no;
- int ret, launch_token_updated;
- sgx_launch_token_t launch_token;
- enclave_temp_no = 0;
- ret = sgx_create_enclave(ENCLAVE1_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e1_enclave_id, NULL);
- if (ret != SGX_SUCCESS) {
- return ret;
- }
- enclave_temp_no++;
- g_enclave_id_map.insert(std::pair<sgx_enclave_id_t, uint32_t>(e1_enclave_id, enclave_temp_no));
- ret = sgx_create_enclave(ENCLAVE2_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e2_enclave_id, NULL);
- if (ret != SGX_SUCCESS) {
- return ret;
- }
- enclave_temp_no++;
- g_enclave_id_map.insert(std::pair<sgx_enclave_id_t, uint32_t>(e2_enclave_id, enclave_temp_no));
- ret = sgx_create_enclave(ENCLAVE3_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e3_enclave_id, NULL);
- if (ret != SGX_SUCCESS) {
- return ret;
- }
- enclave_temp_no++;
- g_enclave_id_map.insert(std::pair<sgx_enclave_id_t, uint32_t>(e3_enclave_id, enclave_temp_no));
- return SGX_SUCCESS;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- uint32_t ret_status;
- sgx_status_t status;
- UNUSED(argc);
- UNUSED(argv);
- if(load_enclaves() != SGX_SUCCESS)
- {
- printf("\nLoad Enclave Failure");
- }
- printf("\nAvaliable Enclaves");
- printf("\nEnclave1 - EnclaveID %" PRIx64, e1_enclave_id);
- printf("\nEnclave2 - EnclaveID %" PRIx64, e2_enclave_id);
- printf("\nEnclave3 - EnclaveID %" PRIx64, e3_enclave_id);
-
- do
- {
- //Test Create session between Enclave1(Source) and Enclave2(Destination)
- status = Enclave1_test_create_session(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave1_test_create_session Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nSecure Channel Establishment between Source (E1) and Destination (E2) Enclaves successful !!!");
- }
- else
- {
- printf("\nSession establishment and key exchange failure between Source (E1) and Destination (E2): Error code is %x", ret_status);
- break;
- }
- }
- //Test Enclave to Enclave call between Enclave1(Source) and Enclave2(Destination)
- status = Enclave1_test_enclave_to_enclave_call(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave1_test_enclave_to_enclave_call Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nEnclave to Enclave Call between Source (E1) and Destination (E2) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nEnclave to Enclave Call failure between Source (E1) and Destination (E2): Error code is %x", ret_status);
- break;
- }
- }
- //Test message exchange between Enclave1(Source) and Enclave2(Destination)
- status = Enclave1_test_message_exchange(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave1_test_message_exchange Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nMessage Exchange between Source (E1) and Destination (E2) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nMessage Exchange failure between Source (E1) and Destination (E2): Error code is %x", ret_status);
- break;
- }
- }
- //Test Create session between Enclave1(Source) and Enclave3(Destination)
- status = Enclave1_test_create_session(e1_enclave_id, &ret_status, e1_enclave_id, e3_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave1_test_create_session Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nSecure Channel Establishment between Source (E1) and Destination (E3) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nSession establishment and key exchange failure between Source (E1) and Destination (E3): Error code is %x", ret_status);
- break;
- }
- }
- //Test Enclave to Enclave call between Enclave1(Source) and Enclave3(Destination)
- status = Enclave1_test_enclave_to_enclave_call(e1_enclave_id, &ret_status, e1_enclave_id, e3_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave1_test_enclave_to_enclave_call Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nEnclave to Enclave Call between Source (E1) and Destination (E3) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nEnclave to Enclave Call failure between Source (E1) and Destination (E3): Error code is %x", ret_status);
- break;
- }
- }
- //Test message exchange between Enclave1(Source) and Enclave3(Destination)
- status = Enclave1_test_message_exchange(e1_enclave_id, &ret_status, e1_enclave_id, e3_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave1_test_message_exchange Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nMessage Exchange between Source (E1) and Destination (E3) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nMessage Exchange failure between Source (E1) and Destination (E3): Error code is %x", ret_status);
- break;
- }
- }
- //Test Create session between Enclave2(Source) and Enclave3(Destination)
- status = Enclave2_test_create_session(e2_enclave_id, &ret_status, e2_enclave_id, e3_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave2_test_create_session Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nSecure Channel Establishment between Source (E2) and Destination (E3) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nSession establishment and key exchange failure between Source (E2) and Destination (E3): Error code is %x", ret_status);
- break;
- }
- }
- //Test Enclave to Enclave call between Enclave2(Source) and Enclave3(Destination)
- status = Enclave2_test_enclave_to_enclave_call(e2_enclave_id, &ret_status, e2_enclave_id, e3_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave2_test_enclave_to_enclave_call Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nEnclave to Enclave Call between Source (E2) and Destination (E3) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nEnclave to Enclave Call failure between Source (E2) and Destination (E3): Error code is %x", ret_status);
- break;
- }
- }
- //Test message exchange between Enclave2(Source) and Enclave3(Destination)
- status = Enclave2_test_message_exchange(e2_enclave_id, &ret_status, e2_enclave_id, e3_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave2_test_message_exchange Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nMessage Exchange between Source (E2) and Destination (E3) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nMessage Exchange failure between Source (E2) and Destination (E3): Error code is %x", ret_status);
- break;
- }
- }
-
- //Test Create session between Enclave3(Source) and Enclave1(Destination)
- status = Enclave3_test_create_session(e3_enclave_id, &ret_status, e3_enclave_id, e1_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave3_test_create_session Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nSecure Channel Establishment between Source (E3) and Destination (E1) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nSession establishment and key exchange failure between Source (E3) and Destination (E1): Error code is %x", ret_status);
- break;
- }
- }
- //Test Enclave to Enclave call between Enclave3(Source) and Enclave1(Destination)
- status = Enclave3_test_enclave_to_enclave_call(e3_enclave_id, &ret_status, e3_enclave_id, e1_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave3_test_enclave_to_enclave_call Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nEnclave to Enclave Call between Source (E3) and Destination (E1) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nEnclave to Enclave Call failure between Source (E3) and Destination (E1): Error code is %x", ret_status);
- break;
- }
- }
- //Test message exchange between Enclave3(Source) and Enclave1(Destination)
- status = Enclave3_test_message_exchange(e3_enclave_id, &ret_status, e3_enclave_id, e1_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave3_test_message_exchange Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nMessage Exchange between Source (E3) and Destination (E1) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nMessage Exchange failure between Source (E3) and Destination (E1): Error code is %x", ret_status);
- break;
- }
- }
- //Test Closing Session between Enclave1(Source) and Enclave2(Destination)
- status = Enclave1_test_close_session(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave1_test_close_session Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nClose Session between Source (E1) and Destination (E2) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nClose session failure between Source (E1) and Destination (E2): Error code is %x", ret_status);
- break;
- }
- }
- //Test Closing Session between Enclave1(Source) and Enclave3(Destination)
- status = Enclave1_test_close_session(e1_enclave_id, &ret_status, e1_enclave_id, e3_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave1_test_close_session Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nClose Session between Source (E1) and Destination (E3) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nClose session failure between Source (E1) and Destination (E3): Error code is %x", ret_status);
- break;
- }
- }
- //Test Closing Session between Enclave2(Source) and Enclave3(Destination)
- status = Enclave2_test_close_session(e2_enclave_id, &ret_status, e2_enclave_id, e3_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave2_test_close_session Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nClose Session between Source (E2) and Destination (E3) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nClose session failure between Source (E2) and Destination (E3): Error code is %x", ret_status);
- break;
- }
- }
- //Test Closing Session between Enclave3(Source) and Enclave1(Destination)
- status = Enclave3_test_close_session(e3_enclave_id, &ret_status, e3_enclave_id, e1_enclave_id);
- if (status!=SGX_SUCCESS)
- {
- printf("Enclave3_test_close_session Ecall failed: Error code is %x", status);
- break;
- }
- else
- {
- if(ret_status==0)
- {
- printf("\n\nClose Session between Source (E3) and Destination (E1) Enclaves successful !!!");
- }
- else
- {
- printf("\n\nClose session failure between Source (E3) and Destination (E1): Error code is %x", ret_status);
- break;
- }
- }
- #pragma warning (push)
- #pragma warning (disable : 4127)
- }while(0);
- #pragma warning (pop)
- sgx_destroy_enclave(e1_enclave_id);
- sgx_destroy_enclave(e2_enclave_id);
- sgx_destroy_enclave(e3_enclave_id);
- waitForKeyPress();
- return 0;
- }
|