When you have a C/C++ project created without Intel SGX, you cannot use Intel SGX support. In this case, you need to add SGX nature to this project to use Intel SGX support:
After you add the SGX nature to your project, you should see:
+
+
+
A subdirectory sgx in the project which contains a Makefile file.
+
+
+
+
Makefile for Intel(R) SGX
+
+
+
The Intel SGX tools as shown in the following graphic:
+
+
+
+
Intel(R) SGX Tools
+
+
+
New configurations specific to SGX technology. You may see the configurations for the project by clicking to the down arrow of button usually found at the top of the Eclipse window:
+
+
+
+
Configurations Specific to Intel(R) SGX Technology
After you add the SGX nature to a project, you can start creating a minimal but complete skeleton for a new enclave:
+
+
Right-click on the project root in Project Explorer.
+
+
Open the dialog Add New SGX Enclave by selecting Software Guard Extensions Tools → Add SGX Enclave from the contextual menu.
+
+
+
+
Add New Intel® SGX Enclave Dialog
+
+
+
Choose a name for the enclave in Enclave name field. This name is used in the process of generation of the skeleton to give unicity to the source files and the name of the resulting executable, so you can add more than one enclave to the same project.
+
+
+
If you do not select the Generate sample untrusted application checkbox, the plugin generates only a trusted file and a Makefile fragment to build and compile the trusted part. See the following graphic. All the code for the enclave, including build Makefile, is put in a directory <root>/sgx/enclave_<name> . C/C++ code for the enclave proper are in <root>/sgx/enclave_<name>/trusted.
+
+
+
+
Generated Skeleton for an Enclave. The option to Generate Sample was not Used
+
+
+
If you select Generate sample untrusted application checkbox, a simple ready to work sample application is generated, including untrusted stubs and implementation for a sample OCALL and ECALL.
+
+
+
+
Generated Sample Untrusted Application
+
+
+
+
+
+
NOTE:
+
If you select the Generate sample untrusted application checkbox, ecalls from the untrusted part are not be resolved by Eclipse C/C++ indexer. These functions are marked with a red line. The declaration of these ecalls resides in the unstrusted stub header which is generated during the build proces and is not indexed by Eclipse. To resolve this problem, right-click on project root and select Index → Freshen All Files.
Trusted Static Libraries helps enclave author have libraries of shared code to be reused by enclaves, in exactly the same manner as usual static libxxx.a libraries are used to share code between regular non-SGX applications. The plugin adds a command to generate the skeleton of a trusted shared library.
+
To add a new SGX Trusted Library:
+
+
+
Open Add New SGX Static Trusted Library dialog by right-click on the root of the project and select the appropriate command from Software Guard Extensions Tools menu:
+
+
+
+
Add New SGX Static Trusted Library Dialog
+
+
+
Choose a name for the library and click OK. A skeleton for a trusted library is generated in directory <root>/sgx/trustedlib_<name>:
Add an untrusted module to generate the untrusted stubs so you use an enclave, provided you have access to its .edl file. The enclave might have been built in the current project or in a different project.
+
To use trusted functionality of an enclave for which its *.edl is known, use the command Add SGX Untrusted Module:
+
+
+
Open dialog Add Sgx Untrusted Module by right-click-ing the project root in Package Explorer and chose the command from Software Guard Extension Tools.
+
+
+
+
Add SGX Untrusted Module
+
+
+
Use the Browse button to navigate the file system using a file dialog, and click OK. The untrusted module is copied to <root>/sgx/untrusted_<edl file name>. The selected *.edl is copied to the project.
This topic provides the command reference for the following scenarios of using Intel(R) Software Guard Extensions Eclipse* Plug-in:
+
+
Adding SGX nature to a project
+
Adding an SGX enclave
+
Adding an SGX trusted library
+
Adding an SGX untrusted module
+
Updating SGX enclave signing key
+
Updating enclave configuration files
+
Two steps sign enclave
+
+
All commands brought by Intel(R) Software Guard Extensions Eclipse Plug-in are available by right-clicking on the Project root in Project explorer view in menu Software Guard Extension Tools:
If you do not install Intel(R) SGX SDK for Linux* OS in the default location, you need to specify the path for Intel SGX SDK using the following steps:
+
+
+
Go to Window menu ->Preferences. Enter SGX in the filter text field to quickly locate the SGX Preferences page.
+
+
+
+
SGX Preference Page
+
+
Enter the path for Intel SGX SDK for Linux OS in the SGX SDK Directory field.
+
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Creating_a_New_C_C_Project_with_SGX_Nature.htm b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Creating_a_New_C_C_Project_with_SGX_Nature.htm
new file mode 100644
index 0000000000..f3db754ab1
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Creating_a_New_C_C_Project_with_SGX_Nature.htm
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Creating a New C/C++ Project with SGX Nature
+
+
+
+
Creating a New C/C++ Project with SGX Nature
+
You can create a new project with SGX nature. To create such a project, follow these steps:
+
+
+
Open a standard Eclipse new project: File menu → Project... . If you have installed Intel® Software Guard Extensions Eclipse Plug-in, you can see the category C/C++ with SGX Enabled in the New Project dialog.
+
+
+
+
New Project
+
This category has 2 sub-categories, SGX C project and SGX C++ project. These sub-categories are similar to the sub-categories C Project and C++ Project of standard C/C++ category.
+
+
Select one of the 2 sub-categories, SGX C project or SGX C++ project, and click Next.
+
Complete creating the project using the regular process of creating a standard C or C++ project.
+
+
+
NOTE:
+
Projects created following the subcategories under C/C++ with SGX Enabled are identical with their standard counterparts, except that they have SGX Nature added. There is no difference between creating a C or C++ project with SGX enabled, or creating a standard C/C++ project and launch Add SGX nature from it, as described in precedent paragraph.
Generating hash is the first step in the 2-Steps signing process.To generate hash, use the following steps:
+
+
+
Right-click on project root, go to Software Guard Extensions Tools menu → Two StepSigne Enclave → Generate Hash
+
+
+
+
Two StepSigne Enclave - Generate Hash
+
+
In the Generate Hash dialog, enter the required inputs to the corresponding fields:
Enter the path to the compiled enclave to be signed in the Enclave Path field. Click Select Enclave to open a file dialog to select the enclave.
In the Hash File Location field , enter the path of the output file that will contain signing materials. By default this file has the same file name as the unsigned enclave, with .hex extension added. To change the path, click Select File Path to open a file dialog to select the file path.
In the Configuration File path field, enter the path of the configuration filefor the generated hash. Click Select Config to open a dialog to select from all enclave configuration files in the project (similar with the one of the command Update Config).
+
+
Click OK after you fill in all the fields. The Intel(R) SGX SDK is launched under the hood with the provided parameters and the hash file is generated. A dialog box appears to confirm the completion:
+
+
+
+
Generating Hash Completion Dialog
+
+
+
You complete the first step, generating hash, in the two step signing enclave. The *.hex file may be signed with the external facility, which generates a signature for it and a public verification key.
+
If you click OK, the Generate Signed Enclave dialog appears. The required fileds in this dialog have been pre-configured with the paths of the unsigned enclave, the configuration file and of the *.hex file. To generated the final signed enclave ready for production immediately, click OK.
+
+
+
+
Generate Signed Enclave Dialog with Pre-configurations
+
If you click Cancel in the Generate Signed Enclave dialog, you can continue the signing process later using the Generate Signed Enclave command.
Getting Started with Intel(R) Software Guard Extensions Eclipse* Plugin
+
This section contains steps to set up your Intel(R) Software Guard Extensions Eclipse* Plugin on a Linux* system, including necessary softwares, steps to install the product, and steps to configure your preferred product directory.
Install Intel(R) Software Guard Extensions Eclipse* Plug-in as a regular Eclipse Plugin:
+
+
Download the zip archive of Intel(R) Software Guard Extensions Eclipse Plug-in from Intel Site
+
+
Go to Help menu -> Install New Software. Click the Add button for the Work with field to open the Add Repository dialog as shown in the following graphic:
+
+
+
+
Add Repository Dialog
+
+
+
Enter SGX Archive in the Name field . Click the Archive... button and select the location of the downloaded archive as shown in the following graphic:
+
+
+
+
The Location of the Plugin zip Archive
+
+
Press OK to add the archive as a repository.
+
In the Install dialog, select the Software Guard Extensions Plugin check-box and proceed with the usual steps.
Intel(R) Software Guard Extensions is a new Intel technology, whose objective is to enable a high level of protection of secrets. It operates by allocating hardware-protected memory where code and data reside. The protected memory area within an application process is called an enclave. Data within the enclave memory can only be accessed by code that resides within that enclave. Enclave code can be invoked by special instructions.
+
An enclave can be built and loaded as a shared object.
+
Throughout this document, Intel(R) SGX refers to Intel(R) Software Guard Extensions.
+
An Intel(R) SGX application design is different from the design of non- Intel(R) SGX application as it specifies dividing the application into two logical parts:
+
+
Trusted part. The code that accesses the secret resides here and it is called an enclave. More than one enclave can exist in an application.
+
Untrusted part. This includes the rest of the modules in the application, that is outside in an enclave.
+
+
The trusted components and untrusted components are developed as separate modules.
+
The trusted part or the enclave is implemented in C or C++. It is supplied as a collection of functions and data packaged in the form of a dynamically loaded library, a DLL in Windows* OS and a shared object in Linux* OS. It may be supplied either as a pre-built signed library or as a signed shared library built during compilation of the untrusted component.
+
Enclave functions within an enclave library are wrapped by auto-generated proxy and bridge functions that simplify the mechanism of using the Intel(R) SGX technology by developers.
+
The role of these functions is to handle the following tasks:
+
+
Call an enclave function from untrusted code, also called an ECALL (enclave call).
+
Call an untrusted function from within an enclave, also called an OCALL (outside call).
+
Handle interrupts.
+
Handle exceptions.
+
+
The proxy and bridge functions are generated by the sgx_edger8r tool provided by Intel(R) SGX SDK. It reads an edl file (Enclave Descriptor Language) which describes the functions that form the trusted and untrusted component boundaries within the application.
+
After the enclave is built, a signed version of it is created using the tool sgx_sign also provided by Intel(R) SGX SDK. It is this signed version may be loaded and executed in the encrypted memory.
+
Enclaves may have some specific properties which are added as meta-information during the signing process. The meta-information is stored in one configuration xml file per enclave, whose details may be seen in Intel(R) Software Guard Extensions Evaluation SDK for Linux* OS.
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Introducing_Intel_Software_Guard_Extensions.htm b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Introducing_Intel_Software_Guard_Extensions.htm
new file mode 100644
index 0000000000..e65c2fbaa1
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Introducing_Intel_Software_Guard_Extensions.htm
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ What can be done with Linux SGX Eclipse Plugin?
+
+
+
+
The Intel(R) Software Guard Extensions Eclipse* Plug-in helps the enclave developer to maintain enclaves and untrusted related code inside Eclipse* C/C++ projects. To use this support, add SGX nature to the C/C++ project. See Adding SGX Nature to a Project for details.
+
Once the SGX nature is added to a project, you will have access to the SGX commands. SGX nature adds also a folder called sgx to the root of the project, and a Makefile inside it. All resources of the project managed by Intel(R) Software Guard Extensions Eclipse Plug-inare located inside this directory. You can build and run enclaves related code using GNU* Make tool through the Makefile.
+
The plugin is generating minimal but ready-to-work code skeletons, complete with their own Makefile having all the required make targets as to call sgx_edger8r tool to generate the proxies and bridges, compile these source, generate a shared object and finally, to sign the enclave with the sgx_sign tool. This provide a starting point you may build upon.
This Developer Guide is intended for use by Independent Service Vendors who wish to harden their Linux* applications using Intel(R) SGX Technology, code named Intel(R) Software Guard Extensions. The guide describes the procedure for installation of Intel(R) SGX Plugin for Eclipse* IDE and development of Intel(R) SGX components using the plugin. The Intel(R) SGX Plugin for Eclipse leverages on the Intel(R) Software Guard Extensions Evaluation SDK, which is a collection of APIs, libraries and tools that enable you to develop, build and debug Intel(R) SGX applications in C/C++.
+
To learn more about the Intel(R) Software Guard Extensions Evaluation SDK, see the Intel(R) Software Guard Extensions Evaluation SDK for Linux* OS.
No license (express or implied, by estoppel or otherwise) to any intellectual
+ property rights is granted by this document.
+
Intel disclaims all express and implied warranties, including without
+ limitation, the implied warranties of merchantability, fitness for a particular
+ purpose, and non-infringement, as well as any warranty arising from course
+ of performance, course of dealing, or usage in trade.
+
This document contains information on products, services and/or processes
+ in development. All information provided here is subject to change
+ without notice. Contact your Intel representative to obtain the latest
+ forecast, schedule, specifications and roadmaps.
+
The products and services described may contain defects or errors known
+ as errata which may cause deviations from published specifications. Current
+ characterized errata are available on request.
+
Intel technologies features and benefits depend on system configuration
+ and may require enabled hardware, software or service activation. Learn
+ more at Intel.com, or from the OEM or retailer.
+
Copies of documents which have an order number and are referenced in
+ this document may be obtained by calling 1-800-548-4725 or by visiting
+ www.intel.com/design/literature.htm.
+
Intel, the Intel logo, Xeon, and Xeon Phi are trademarks of Intel Corporation
+ in the U.S. and/or other countries.
+
+
+
+
+
Optimization Notice
+
+
+
+
+
Intel's compilers may or may not optimize to the same degree
+ for non-Intel microprocessors for optimizations that are not unique
+ to Intel microprocessors. These optimizations include SSE2, SSE3,
+ and SSSE3 instruction sets and other optimizations. Intel does
+ not guarantee the availability, functionality, or effectiveness
+ of any optimization on microprocessors not manufactured by Intel.
+ Microprocessor-dependent optimizations in this product are intended
+ for use with Intel microprocessors. Certain optimizations not
+ specific to Intel microarchitecture are reserved for Intel microprocessors.
+ Please refer to the applicable product User and Reference Guides
+ for more information regarding the specific instruction sets covered
+ by this notice.
+
Notice revision #20110804
+
+
+
+
* Other names and brands may be claimed as the property of others.
To use Intel(R) Software Guard Extensions Eclipse Plug-in, install the following softwares:
+
+
Eclipse* Mars 1 with CDT IDE for C/C++ Developpers (version 4.5.1). To use this version, install Java* Development Kit (JDK) or Java* Runtime Environment (JRE) version 1.8 or above.
Intel(R) Software Guard Extensions Eclipse* Plugin provides an option to generate a sample application together with the enclave code when the enclave is created. After the project is build, the sample application is built also and ready to run. You can see the sample application named sample in the enclave directory in Project Explorer. You can run this sample as a local C/C++ application as shown in the following figure:
+
+
+
+
Sample Application
+
See the result of the execution in Eclipse console window as shown below:
+
+
+
+
The Result of Running Samples Generated for Enclaves
There are usually two types of builds that a regular non-SGX project defines:
+
+
Debug
+
Release
+
+
SGX-enabled projects add to this picture support to build and test SGX-enabled application on non-SGX platforms (or emulator) using simulation libraries. This approach doubles the set of build types, creating four possible combinations. For these combinations, you need to use different sets of compilation and linking flags and link different libraries.
+
The non-debug hardware build is meant to give production code, so it requires the maximum attention when signed. The Two Steps Sign schema is required for production enclaves, which involves an external signing facility, not part of Intel SGX SDK. The other configurations are not meant for production but they have to be signed too. The simplest and more convenient Single Step schema is used for them.
+
Again for testing purpose, you might want to experiment with a non-production enclave built with release compilation and linking flags, on a real hardware SGX-enabled platform. That would be an enclave built exactly as a production enclave, except for the sign process which would be Single Step. To support the construction of such enclave, there is a hardware non-debug build configuration dubbed Prerelease.
+
So there are five SGX related configurations when SGX Nature is added to a project:
+
+
+
+
Intel(R) SGX Configurations
+
The following table resumes the existing SGX configurations and relate them with compilation/linking flags (debug/non-debug) and signing scheme (single vs. two steps):
+
Intel(R) SGX Configurations
+
+
+
+
+
+
+
+
Configuration Name
+
Simulation?
+
Debug?
+
Signing Schema
+
+
+
SGX Hardware Debug
+
Hardware
+
Debug
+
Single Step
+
+
+
SGX Hardware Pre-release
+
Hardware
+
Non-debug
+
Single Step
+
+
+
SGX Hardware Release
+
Hardware
+
Non-debug
+
Two Step
+
+
+
SGX Simulation
+
Simulation
+
Non-debug
+
Single Step
+
+
+
SGX Simulation
+
Debug Simulation
+
Debug
+
Single step
+
+
+
+
Intel® Software Guard Extensions Eclipse Plug-in uses standard GNU* make tool to build the trusted and the untrusted code, using the generated file sgx/Makefile.
+
This fact does not impose any restriction on the build tool chosen for the hosting project. Intel® Software Guard Extensions Eclipse* Plug-in uses its own build configurations which do not interfere with the configurations that you might have in your project.
+
When SGX configurations are selected, by default only code under <root>/sgx directory get built.
+
You can customize SGX configurations as any other Eclipse build configurations from the project properties dialog. For example:
+
+
Right-click in Project Explorer Properties → C/C++ Build
+
Uncheck the Use default build command checkbox.
+
+
Then you can customize and integrate SGX build process. You can use Makefile instead of sgx/Makefile in the example shown in the following figure:
+
+
+
+
Customization of SGX Build Command
+
The build process is done using standard Eclipse interface for build, by example from the main Project menu:
Intel(R) Software Guard Extensions (Intel(R) SGX) is an Intel technology for a
+pplication developers seeking to protect select code and data from disclosure or
+modification. Intel(R) SGX makes such protections possible through the use of
+enclaves. Enclaves are protected areas of execution. Application code can be put
+into an enclave through special instructions and software made available to
+developers by the Intel(R) SGX SDK.
To help you develop enclaves, Intel(R) Software Guard Extensions Eclipse Plug-in generates all required structure including:
+
+
c/c++ files and header files
+
.edl file
+
*.config.xml file
+
a sample Makefile
+
a sample signing key
+
+
While these structure might be appropriate for development and debugging, you need a 2-step process to integrate your own signing schema for generating production enclaves.
+
+
Generate hash: the signer tool generates signing material from the unsigned compiled enclave and from the configuration file for the enclave. The signed material comes as an opaque sequence of bytes which are put in a file with extension .hex. This file is used with the external signing facility. You come back with a signature for the .hex file plus the public key of your signing facility, and proceed to Step 2.
+
Generate signed enclaves : the signer tool generates the final signed enclave.
+
+
To complete this task, provide the following input parameters:
+
+
The unsigned enclave
+
The configuration file
+
The output file produced when you generate hash (the .hex file)
+
The files produced by the external signing facility: the signature of the .hex file and public key for it
+
The plugin checks if the input parameters are consistent:
+
The .hex file matches the unsigned enclave and the configuration file,
+
The signed material is verified with the public key
+
+
If the parameters are consistenet, the production signed enclave is produced.
+
+
NOTE:
+
If you generate signed enclave right after generating hash, you can only enter the parameters specific for generating signed enclave.
+
+
To use the two-step signing function, activate the configuration SGX Hardware Release mode. When this configuration is active, the compilation does not produce a signed enclave, as in the other SGX configurations; the process only produces unsigned enclaves.
+
+
+
+
Configure SGX Hardware Release Mode
+
When you configure the plugin in the SGX Hardware Release Mode, you can see the Generate Hash and Generate Signed Enclave options through Software Guard Extension Tools->Two Step Sign Enclave.
A configuration file is an important part in the definition of an enclave. Intel(R) SGX SDK signer tool requires such *.xml configuration file as necessary input.
+
To update this configuration file, use the Update Config command:
+
+
+
Right-click on the root project, Software Extension Guards Tools->Select Config File.
+
+
+
+
Select Configuration File
+
+
+
Click OK or double-click the selected configuration file to open the Enclave Configuration Settings dialog.
+
+
+
+
Enclave Configuration Settings
+
For details on the meaning of the fields, see Intel(R) Software Guard Extensions Developer Guide.
All skeletons enclave samples produced by the plugin contain a sample signing key. You might want to import another sign key that you already have, or generate a new one. Use the command Update SGX Enclave Signing Key to complete this task.
+
+
Choose Update SGX Enclave Signing Key by right-click on the project in Project Explorer -> Software Guard Extension Tools menu. The Import or (Re)Generate Enclave Signing Key dialog appears.
+
In the Import or (Re)Generate Enclave Signing Key dialog, click Select to open a file dialog to select the output key.
+
+
Click Improt Key to update a selected signing key by copying another existing key or click Generate Key to update the selected signing key by generating a new key. In both cases, the new signature key is put into the file in text field Enclave Signing Key.
+
+
+
+
Import or (Re)Generate Enclave Signing Key
+
+
Click OK to update the enclave signing key.
+
+
Under the hood, a new key is generated using openssl*, which needs to be installed on the machine:
Intel(R) Software Guard Extensions Plug-in for Eclipse*
+
Developer Guide
+
Intel(R) Software Guard Extensions (Intel(R) SGX) is an Intel technology for a
+pplication developers seeking to protect select code and data from disclosure or
+modification. Intel(R) SGX makes such protections possible through the use of
+enclaves. Enclaves are protected areas of execution. Application code can be put
+into an enclave through special instructions and software made available to
+developers by the Intel(R) SGX SDK.
No license (express or implied, by estoppel or otherwise) to any intellectual
+ property rights is granted by this document.
+
Intel disclaims all express and implied warranties, including without
+ limitation, the implied warranties of merchantability, fitness for a particular
+ purpose, and non-infringement, as well as any warranty arising from course
+ of performance, course of dealing, or usage in trade.
+
This document contains information on products, services and/or processes
+ in development. All information provided here is subject to change
+ without notice. Contact your Intel representative to obtain the latest
+ forecast, schedule, specifications and roadmaps.
+
The products and services described may contain defects or errors known
+ as errata which may cause deviations from published specifications. Current
+ characterized errata are available on request.
+
Intel technologies features and benefits depend on system configuration
+ and may require enabled hardware, software or service activation. Learn
+ more at Intel.com, or from the OEM or retailer.
+
Copies of documents which have an order number and are referenced in
+ this document may be obtained by calling 1-800-548-4725 or by visiting
+ www.intel.com/design/literature.htm.
+
Intel, the Intel logo, Xeon, and Xeon Phi are trademarks of Intel Corporation
+ in the U.S. and/or other countries.
+
+
+
+
+
Optimization Notice
+
+
+
+
+
Intel's compilers may or may not optimize to the same degree
+ for non-Intel microprocessors for optimizations that are not unique
+ to Intel microprocessors. These optimizations include SSE2, SSE3,
+ and SSSE3 instruction sets and other optimizations. Intel does
+ not guarantee the availability, functionality, or effectiveness
+ of any optimization on microprocessors not manufactured by Intel.
+ Microprocessor-dependent optimizations in this product are intended
+ for use with Intel microprocessors. Certain optimizations not
+ specific to Intel microarchitecture are reserved for Intel microprocessors.
+ Please refer to the applicable product User and Reference Guides
+ for more information regarding the specific instruction sets covered
+ by this notice.
+
Notice revision #20110804
+
+
+
+
* Other names and brands may be claimed as the property of others.
This Developer Guide is intended for use by Independent Service Vendors who wish to harden their Linux* applications using Intel(R) SGX Technology, code named Intel(R) Software Guard Extensions. The guide describes the procedure for installation of Intel(R) SGX Plugin for Eclipse* IDE and development of Intel(R) SGX components using the plugin. The Intel(R) SGX Plugin for Eclipse leverages on the Intel(R) Software Guard Extensions Evaluation SDK, which is a collection of APIs, libraries and tools that enable you to develop, build and debug Intel(R) SGX applications in C/C++.
+
To learn more about the Intel(R) Software Guard Extensions Evaluation SDK, see the Intel(R) Software Guard Extensions Evaluation SDK for Linux* OS.
+
+
Introducing Intel(R) Software Guard Extensions
+
Intel(R) Software Guard Extensions is a new Intel technology, whose objective is to enable a high level of protection of secrets. It operates by allocating hardware-protected memory where code and data reside. The protected memory area within an application process is called an enclave. Data within the enclave memory can only be accessed by code that resides within that enclave. Enclave code can be invoked by special instructions.
+
An enclave can be built and loaded as a shared object.
+
Throughout this document, Intel(R) SGX refers to Intel(R) Software Guard Extensions.
+
An Intel(R) SGX application design is different from the design of non- Intel(R) SGX application as it specifies dividing the application into two logical parts:
+
+
Trusted part. The code that accesses the secret resides here and it is called an enclave. More than one enclave can exist in an application.
+
Untrusted part. This includes the rest of the modules in the application, that is outside in an enclave.
+
+
The trusted components and untrusted components are developed as separate modules.
+
The trusted part or the enclave is implemented in C or C++. It is supplied as a collection of functions and data packaged in the form of a dynamically loaded library, a DLL in Windows* OS and a shared object in Linux* OS. It may be supplied either as a pre-built signed library or as a signed shared library built during compilation of the untrusted component.
+
Enclave functions within an enclave library are wrapped by auto-generated proxy and bridge functions that simplify the mechanism of using the Intel(R) SGX technology by developers.
+
The role of these functions is to handle the following tasks:
+
+
Call an enclave function from untrusted code, also called an ECALL (enclave call).
+
Call an untrusted function from within an enclave, also called an OCALL (outside call).
+
Handle interrupts.
+
Handle exceptions.
+
+
The proxy and bridge functions are generated by the sgx_edger8r tool provided by Intel(R) SGX SDK. It reads an edl file (Enclave Descriptor Language) which describes the functions that form the trusted and untrusted component boundaries within the application.
+
After the enclave is built, a signed version of it is created using the tool sgx_sign also provided by Intel(R) SGX SDK. It is this signed version may be loaded and executed in the encrypted memory.
+
Enclaves may have some specific properties which are added as meta-information during the signing process. The meta-information is stored in one configuration xml file per enclave, whose details may be seen in Intel(R) Software Guard Extensions Evaluation SDK for Linux* OS.
The Intel(R) Software Guard Extensions Eclipse* Plug-in helps the enclave developer to maintain enclaves and untrusted related code inside Eclipse* C/C++ projects. To use this support, add SGX nature to the C/C++ project. See Adding SGX Nature to a Project for details.
+
Once the SGX nature is added to a project, you will have access to the SGX commands. SGX nature adds also a folder called sgx to the root of the project, and a Makefile inside it. All resources of the project managed by Intel(R) Software Guard Extensions Eclipse Plug-inare located inside this directory. You can build and run enclaves related code using GNU* Make tool through the Makefile.
+
The plugin is generating minimal but ready-to-work code skeletons, complete with their own Makefile having all the required make targets as to call sgx_edger8r tool to generate the proxies and bridges, compile these source, generate a shared object and finally, to sign the enclave with the sgx_sign tool. This provide a starting point you may build upon.
+
+
+
Getting Started with Intel(R) Software Guard Extensions Eclipse* Plug-in
+
This section contains steps to set up your Intel(R) Software Guard Extensions Eclipse* Plug-in on a Linux* system, including necessary softwares, steps to install the product, and steps to configure your preferred product directory.
To use Intel(R) Software Guard Extensions Eclipse Plug-in, install the following softwares:
+
+
Eclipse* Mars 1 with CDT IDE for C/C++ Developpers (version 4.5.1). To use this version, install Java* Development Kit (JDK) or Java* Runtime Environment (JRE) version 1.8 or above.
Install Intel(R) Software Guard Extensions Eclipse* Plug-in as a regular Eclipse Plugin:
+
+
Download the zip archive of Intel(R) Software Guard Extensions Eclipse Plug-in from Intel Site
+
+
Go to Help menu -> Install New Software. Click the Add button for the Work with field to open the Add Repository dialog as shown in the following graphic:
+
+
+
+
Add Repository Dialog
+
+
+
Enter SGX Archive in the Name field . Click the Archive... button and select the location of the downloaded archive as shown in the following graphic:
+
+
+
+
The Location of the Plugin zip Archive
+
+
Press OK to add the archive as a repository.
+
In the Install dialog, select the Software Guard Extensions Plugin check-box and proceed with the usual steps.
If you do not install Intel(R) SGX SDK for Linux* OS in the default location, you need to specify the path for Intel SGX SDK using the following steps:
+
+
+
Go to Window menu ->Preferences. Enter SGX in the filter text field to quickly locate the SGX Preferences page.
+
+
+
+
SGX Preference Page
+
+
Enter the path for Intel SGX SDK for Linux OS in the SGX SDK Directory field.
+
+
+
+
Command Reference
+
This topic provides the command reference for the following scenarios of using Intel(R) Software Guard Extensions Eclipse* Plug-in:
+
+
Adding SGX nature to a project
+
Adding an SGX enclave
+
Adding an SGX trusted library
+
Adding an SGX untrusted module
+
Updating SGX enclave signing key
+
Updating enclave configuration files
+
Two steps sign enclave
+
+
All commands brought by Intel(R) Software Guard Extensions Eclipse Plug-in are available by right-clicking on the Project root in Project explorer view in menu Software Guard Extension Tools:
Project Explorer
+
+
Adding SGX Nature to a Project
+
The nature of an Eclipse project is a concept defined by an Eclipse Platform which allows a plug-in to tag a project as a specific kind of project. Intel(R) Software Guard Extensions uses an SGX nature to add SGX-specific behavior to projects. Project natures are defined by plug-ins, and are typically added or removed per-project when the user performs some action defined by the plug-in.
+
To use Intel(R) Software Guard Extensions Eclipse Plug-in in your project, you need to add SGX nature to it. You may either add SGX nature to a pre-existing C/C++ project or create a project with SGX nature from start. See Adding SGX Nature to a non-SGX project and Creating a New C/C++ Project with SGX Nature for how to complete these tasks.
+
+
+
Adding SGX Nature to a non-SGX project
+
When you have a C/C++ project created without Intel SGX, you cannot use Intel SGX support. In this case, you need to add SGX nature to this project to use Intel SGX support:
After you add the SGX nature to your project, you should see:
+
+
+
A subdirectory sgx in the project which contains a Makefile file.
+
+
+
+
Makefile for Intel(R) SGX
+
+
+
The Intel SGX tools as shown in the following graphic:
+
+
+
+
Intel(R) SGX Tools
+
+
+
New configurations specific to SGX technology. You may see the configurations for the project by clicking to the down arrow of button usually found at the top of the Eclipse window:
+
+
+
+
Configurations Specific to Intel(R) SGX Technology
+
+
+
+
+
Creating a New C/C++ Project with SGX Nature
+
You can create a new project with SGX nature. To create such a project, follow these steps:
+
+
+
Open a standard Eclipse new project: File menu → Project... . If you have installed Intel® Software Guard Extensions Eclipse Plug-in, you can see the category C/C++ with SGX Enabled in the New Project dialog.
+
+
+
+
New Project
+
This category has 2 sub-categories, SGX C project and SGX C++ project. These sub-categories are similar to the sub-categories C Project and C++ Project of standard C/C++ category.
+
+
Select one of the 2 sub-categories, SGX C project or SGX C++ project, and click Next.
+
Complete creating the project using the regular process of creating a standard C or C++ project.
+
+
+
NOTE:
+
Projects created following the subcategories under C/C++ with SGX Enabled are identical with their standard counterparts, except that they have SGX Nature added. There is no difference between creating a C or C++ project with SGX enabled, or creating a standard C/C++ project and launch Add SGX nature from it, as described in precedent paragraph.
+
+
+
+
Adding an SGX Enclave
+
After you add the SGX nature to a project, you can start creating a minimal but complete skeleton for a new enclave:
+
+
Right-click on the project root in Project Explorer.
+
+
Open the dialog Add New SGX Enclave by selecting Software Guard Extensions Tools → Add SGX Enclave from the contextual menu.
+
+
+
+
Add New Intel® SGX Enclave Dialog
+
+
+
Choose a name for the enclave in Enclave name field. This name is used in the process of generation of the skeleton to give unicity to the source files and the name of the resulting executable, so you can add more than one enclave to the same project.
+
+
+
If you do not select the Generate sample untrusted application checkbox, the plugin generates only a trusted file and a Makefile fragment to build and compile the trusted part. See the following graphic. All the code for the enclave, including build Makefile, is put in a directory <root>/sgx/enclave_<name> . C/C++ code for the enclave proper are in <root>/sgx/enclave_<name>/trusted.
+
+
+
+
Generated Skeleton for an Enclave. The option to Generate Sample was not Used
+
+
+
If you select Generate sample untrusted application checkbox, a simple ready to work sample application is generated, including untrusted stubs and implementation for a sample OCALL and ECALL.
+
+
+
+
Generated Sample Untrusted Application
+
+
+
+
+
+
NOTE:
+
If you select the Generate sample untrusted application checkbox, ecalls from the untrusted part are not be resolved by Eclipse C/C++ indexer. These functions are marked with a red line. The declaration of these ecalls resides in the unstrusted stub header which is generated during the build proces and is not indexed by Eclipse. To resolve this problem, right-click on project root and select Index → Freshen All Files.
+
+
+
+
Adding an SGX Trusted Library
+
Trusted Static Libraries helps enclave author have libraries of shared code to be reused by enclaves, in exactly the same manner as usual static libxxx.a libraries are used to share code between regular non-SGX applications. The plugin adds a command to generate the skeleton of a trusted shared library.
+
To add a new SGX Trusted Library:
+
+
+
Open Add New SGX Static Trusted Library dialog by right-click on the root of the project and select the appropriate command from Software Guard Extensions Tools menu:
+
+
+
+
Add New SGX Static Trusted Library Dialog
+
+
+
Choose a name for the library and click OK. A skeleton for a trusted library is generated in directory <root>/sgx/trustedlib_<name>:
+
+
+
+
A Generated Trusted Library
+
+
+
+
+
Adding an SGX Untrusted Module
+
Add an untrusted module to generate the untrusted stubs so you use an enclave, provided you have access to its .edl file. The enclave might have been built in the current project or in a different project.
+
To use trusted functionality of an enclave for which its *.edl is known, use the command Add SGX Untrusted Module:
+
+
+
Open dialog Add Sgx Untrusted Module by right-click-ing the project root in Package Explorer and chose the command from Software Guard Extension Tools.
+
+
+
+
Add SGX Untrusted Module
+
+
+
Use the Browse button to navigate the file system using a file dialog, and click OK. The untrusted module is copied to <root>/sgx/untrusted_<edl file name>. The selected *.edl is copied to the project.
+
+
+
+
Copying the Untrusted Module to a Project
+
+
+
+
+
Updating SGX Enclave Signing Key
+
All skeletons enclave samples produced by the plugin contain a sample signing key. You might want to import another sign key that you already have, or generate a new one. Use the command Update SGX Enclave Signing Key to complete this task.
+
+
Choose Update SGX Enclave Signing Key by right-click on the project in Project Explorer -> Software Guard Extension Tools menu. The Import or (Re)Generate Enclave Signing Key dialog appears.
+
In the Import or (Re)Generate Enclave Signing Key dialog, click Select to open a file dialog to select the output key.
+
+
Click Improt Key to update a selected signing key by copying another existing key or click Generate Key to update the selected signing key by generating a new key. In both cases, the new signature key is put into the file in text field Enclave Signing Key.
+
+
+
+
Import or (Re)Generate Enclave Signing Key
+
+
Click OK to update the enclave signing key.
+
+
Under the hood, a new key is generated using openssl*, which needs to be installed on the machine:
A configuration file is an important part in the definition of an enclave. Intel(R) SGX SDK signer tool requires such *.xml configuration file as necessary input.
+
To update this configuration file, use the Update Config command:
+
+
+
Right-click on the root project, Software Extension Guards Tools->Select Config File.
+
+
+
+
Select Configuration File
+
+
+
Click OK or double-click the selected configuration file to open the Enclave Configuration Settings dialog.
+
+
+
+
Enclave Configuration Settings
+
For details on the meaning of the fields, see Intel(R) Software Guard Extensions Developer Guide.
+
+
+
+
+
Two Steps Sign Enclave
+
To help you develop enclaves, Intel(R) Software Guard Extensions Eclipse Plug-in generates all required structure including:
+
+
c/c++ files and header files
+
.edl file
+
*.config.xml file
+
a sample Makefile
+
a sample signing key
+
+
While these structure might be appropriate for development and debugging, you need a 2-step process to integrate your own signing schema for generating production enclaves.
+
+
Generate hash: the signer tool generates signing material from the unsigned compiled enclave and from the configuration file for the enclave. The signed material comes as an opaque sequence of bytes which are put in a file with extension .hex. This file is used with the external signing facility. You come back with a signature for the .hex file plus the public key of your signing facility, and proceed to Step 2.
+
Generate signed enclaves : the signer tool generates the final signed enclave.
+
+
To complete this task, provide the following input parameters:
+
+
The unsigned enclave
+
The configuration file
+
The output file produced when you generate hash (the .hex file)
+
The files produced by the external signing facility: the signature of the .hex file and public key for it
+
The plugin checks if the input parameters are consistent:
+
The .hex file matches the unsigned enclave and the configuration file,
+
The signed material is verified with the public key
+
+
If the parameters are consistenet, the production signed enclave is produced.
+
+
NOTE:
+
If you generate signed enclave right after generating hash, you can only enter the parameters specific for generating signed enclave.
+
+
To use the two-step signing function, activate the configuration SGX Hardware Release mode. When this configuration is active, the compilation does not produce a signed enclave, as in the other SGX configurations; the process only produces unsigned enclaves.
+
+
+
+
Configure SGX Hardware Release Mode
+
When you configure the plugin in the SGX Hardware Release Mode, you can see the Generate Hash and Generate Signed Enclave options through Software Guard Extension Tools->Two Step Sign Enclave.
+
+
+
+
Two Step Sign Enclave Menu
+
+
+
Generate Hash
+
Generating hash is the first step in the 2-Steps signing process.To generate hash, use the following steps:
+
+
+
Right-click on project root, go to Software Guard Extensions Tools menu → Two StepSigne Enclave → Generate Hash
+
+
+
+
Two StepSigne Enclave - Generate Hash
+
+
In the Generate Hash dialog, enter the required inputs to the corresponding fields:
Enter the path to the compiled enclave to be signed in the Enclave Path field. Click Select Enclave to open a file dialog to select the enclave.
In the Hash File Location field , enter the path of the output file that will contain signing materials. By default this file has the same file name as the unsigned enclave, with .hex extension added. To change the path, click Select File Path to open a file dialog to select the file path.
In the Configuration File path field, enter the path of the configuration filefor the generated hash. Click Select Config to open a dialog to select from all enclave configuration files in the project (similar with the one of the command Update Config).
+
+
Click OK after you fill in all the fields. The Intel(R) SGX SDK is launched under the hood with the provided parameters and the hash file is generated. A dialog box appears to confirm the completion:
+
+
+
+
Generating Hash Completion Dialog
+
+
+
You complete the first step, generating hash, in the two step signing enclave. The *.hex file may be signed with the external facility, which generates a signature for it and a public verification key.
+
If you click OK, the Generate Signed Enclave dialog appears. The required fileds in this dialog have been pre-configured with the paths of the unsigned enclave, the configuration file and of the *.hex file. To generated the final signed enclave ready for production immediately, click OK.
+
+
+
+
Generate Signed Enclave Dialog with Pre-configurations
+
If you click Cancel in the Generate Signed Enclave dialog, you can continue the signing process later using the Generate Signed Enclave command.
+
+
+
Generate Signed Enclaves
+
Generating signed enclave is the second step in the 2-Steps signing process. You should have the following files to complete this step:
+
+
The .hex file generated with Generate Hash command
+
The files produced from the external signing facility
+
The signature of the .hex file
+
The public verification key
+
+
To generate signed encalves, use the following steps:
+
+
+
Right-click on the project root, and go to Software Guard Extensions Tools menu → Two Step Sign Enclave → Generate Signed Enclave.
+
+
+
+
Generate Signed Enclave Dialog
+
+
Enter the inputs to all the fields and click OK.
+
+
+
+
Building and Running SGX Code
+
This section describes the following topics about building and running SGX code:
+
+
SGX build configurations
+
Running samples generated for enclaves
+
+
+
SGX Build Configurations
+
There are usually two types of builds that a regular non-SGX project defines:
+
+
Debug
+
Release
+
+
SGX-enabled projects add to this picture support to build and test SGX-enabled application on non-SGX platforms (or emulator) using simulation libraries. This approach doubles the set of build types, creating four possible combinations. For these combinations, you need to use different sets of compilation and linking flags and link different libraries.
+
The non-debug hardware build is meant to give production code, so it requires the maximum attention when signed. The Two Steps Sign schema is required for production enclaves, which involves an external signing facility, not part of Intel SGX SDK. The other configurations are not meant for production but they have to be signed too. The simplest and more convenient Single Step schema is used for them.
+
Again for testing purpose, you might want to experiment with a non-production enclave built with release compilation and linking flags, on a real hardware SGX-enabled platform. That would be an enclave built exactly as a production enclave, except for the sign process which would be Single Step. To support the construction of such enclave, there is a hardware non-debug build configuration dubbed Prerelease.
+
So there are five SGX related configurations when SGX Nature is added to a project:
+
+
+
+
Intel(R) SGX Configurations
+
The following table resumes the existing SGX configurations and relate them with compilation/linking flags (debug/non-debug) and signing scheme (single vs. two steps):
+
Intel(R) SGX Configurations
+
+
+
+
+
+
+
+
Configuration Name
+
Simulation?
+
Debug?
+
Signing Schema
+
+
+
SGX Hardware Debug
+
Hardware
+
Debug
+
Single Step
+
+
+
SGX Hardware Pre-release
+
Hardware
+
Non-debug
+
Single Step
+
+
+
SGX Hardware Release
+
Hardware
+
Non-debug
+
Two Step
+
+
+
SGX Simulation
+
Simulation
+
Non-debug
+
Single Step
+
+
+
SGX Simulation
+
Debug Simulation
+
Debug
+
Single step
+
+
+
+
Intel® Software Guard Extensions Eclipse Plug-in uses standard GNU* make tool to build the trusted and the untrusted code, using the generated file sgx/Makefile.
+
This fact does not impose any restriction on the build tool chosen for the hosting project. Intel® Software Guard Extensions Eclipse* Plug-in uses its own build configurations which do not interfere with the configurations that you might have in your project.
+
When SGX configurations are selected, by default only code under <root>/sgx directory get built.
+
You can customize SGX configurations as any other Eclipse build configurations from the project properties dialog. For example:
+
+
Right-click in Project Explorer Properties → C/C++ Build
+
Uncheck the Use default build command checkbox.
+
+
Then you can customize and integrate SGX build process. You can use Makefile instead of sgx/Makefile in the example shown in the following figure:
+
+
+
+
Customization of SGX Build Command
+
The build process is done using standard Eclipse interface for build, by example from the main Project menu:
+
+
+
+
Project Menu
+
+
+
Running Samples Generated for Enclaves
+
Intel(R) Software Guard Extensions Eclipse* Plugin provides an option to generate a sample application together with the enclave code when the enclave is created. After the project is build, the sample application is built also and ready to run. You can see the sample application named sample in the enclave directory in Project Explorer. You can run this sample as a local C/C++ application as shown in the following figure:
+
+
+
+
Sample Application
+
See the result of the execution in Eclipse console window as shown below:
+
+
+
+
The Result of Running Samples Generated for Enclaves
+
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/plugin.xml b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/plugin.xml
new file mode 100644
index 0000000000..533d28bf13
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/plugin.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/src/com/intel/sgx/userguide/Activator.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/src/com/intel/sgx/userguide/Activator.java
new file mode 100644
index 0000000000..f10dec9896
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/src/com/intel/sgx/userguide/Activator.java
@@ -0,0 +1,73 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+package com.intel.sgx.userguide;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "com.intel.sgx.userguide"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/toc.xml b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/toc.xml
new file mode 100644
index 0000000000..85c36da39e
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/toc.xml
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.classpath b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.classpath
new file mode 100644
index 0000000000..6c009435ce
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.classpath
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.project b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.project
new file mode 100644
index 0000000000..aec7e39589
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.project
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ com.intel.sgx
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.settings/org.eclipse.jdt.core.prefs b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..a698e59674
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/META-INF/MANIFEST.MF b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..f06f84d713
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/META-INF/MANIFEST.MF
@@ -0,0 +1,26 @@
+License: Eclipse Public License Version 1.0 ("EPL")
+bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name
+Bundle-SymbolicName: com.intel.sgx;singleton:=true
+Bundle-Version: 1.0.1.qualifier
+Bundle-Activator: com.intel.sgx.Activator
+Bundle-Vendor: %Bundle-Vendor
+Require-Bundle: org.eclipse.cdt.core;bundle-version="5.11.0",
+ org.eclipse.core.runtime;bundle-version="3.11.1",
+ org.eclipse.ui;bundle-version="3.107.0",
+ org.eclipse.cdt.managedbuilder.ui;bundle-version="8.2.2",
+ org.eclipse.cdt.managedbuilder.core;bundle-version="8.3.0",
+ org.eclipse.core.resources;bundle-version="3.10.1",
+ org.eclipse.cdt.ui;bundle-version="5.11.0",
+ org.eclipse.core.expressions;bundle-version="3.5.0",
+ org.eclipse.ui.ide;bundle-version="3.11.0"
+Bundle-ActivationPolicy: lazy
+Export-Package: com.intel.sgx,
+ com.intel.sgx.build,
+ com.intel.sgx.dialogs,
+ com.intel.sgx.discovery,
+ com.intel.sgx.handlers,
+ com.intel.sgx.natures,
+ com.intel.sgx.preferences,
+ com.intel.sgx.templates
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/OSGI-INF/l10n/bundle.properties b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 0000000000..171c78c844
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/OSGI-INF/l10n/bundle.properties
@@ -0,0 +1,15 @@
+#########################################################################
+# Copyright (c) 2016 Intel Corporation. #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Eclipse Public License v1.0 #
+# which accompanies this distribution, and is available at #
+# http://www.eclipse.org/legal/epl-v10.html #
+# #
+# Contributors: #
+# Intel Corporation - initial implementation and documentation #
+#########################################################################
+
+
+Bundle-Vendor = Intel Corporation
+Bundle-Name = SGX(R) Linux Eclipse Plugin
\ No newline at end of file
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/build.properties b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/build.properties
new file mode 100644
index 0000000000..d055ac2fdc
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/build.properties
@@ -0,0 +1,24 @@
+#########################################################################
+# Copyright (c) 2016 Intel Corporation. #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Eclipse Public License v1.0 #
+# which accompanies this distribution, and is available at #
+# http://www.eclipse.org/legal/epl-v10.html #
+# #
+# Contributors: #
+# Intel Corporation - initial implementation and documentation #
+#########################################################################
+
+
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ templates/,\
+ discovery/,\
+ build.properties,\
+ OSGI-INF/,\
+ OSGI-INF/l10n/bundle.properties
+jre.compilation.profile = JavaSE-1.8
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.c b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.c
new file mode 100644
index 0000000000..139597f9cb
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.c
@@ -0,0 +1,2 @@
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.cpp b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.cpp
new file mode 100644
index 0000000000..139597f9cb
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.cpp
@@ -0,0 +1,2 @@
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/plugin.xml b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/plugin.xml
new file mode 100644
index 0000000000..86a2ba5d05
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/plugin.xml
@@ -0,0 +1,786 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ An C project, with SGX Commands and Configurations
+
+
+
+
+
+ An C++ project, with SGX Commands and Configurations
+
+
+
+
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Activator.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Activator.java
new file mode 100644
index 0000000000..580330b423
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Activator.java
@@ -0,0 +1,75 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+package com.intel.sgx;
+
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ public static final String PLUGIN_ID = "com.intel.sgx";//$NON-NLS-1$
+
+ private static Activator plugin;
+
+ public Activator() {
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+
+ public static void log(Exception e) {
+ plugin.getLog().log(newStatus(e));
+ }
+
+ public static IStatus newStatus(Exception e) {
+ return new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e);
+ }
+
+ public static URL findFile(Path path) {
+ return FileLocator.find(plugin.getBundle(), path, null);
+ }
+
+ public static Bundle getBundle(String id){
+ for(Bundle bundle : plugin.getBundle().getBundleContext().getBundles()){
+ if(bundle.getSymbolicName().equals(id))
+ return bundle;
+ }
+ return null;
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/CConfigurationDataProvider2.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/CConfigurationDataProvider2.java
new file mode 100644
index 0000000000..59cdc66e33
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/CConfigurationDataProvider2.java
@@ -0,0 +1,46 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx;
+
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
+import org.eclipse.cdt.core.settings.model.extension.CConfigurationDataProvider;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class CConfigurationDataProvider2 extends CConfigurationDataProvider {
+
+ public CConfigurationDataProvider2() {
+ }
+
+ @Override
+ public CConfigurationData loadConfiguration(ICConfigurationDescription des,
+ IProgressMonitor monitor) throws CoreException {
+ return null;
+ }
+
+ @Override
+ public CConfigurationData createConfiguration(
+ ICConfigurationDescription des,
+ ICConfigurationDescription baseDescription,
+ CConfigurationData baseData, boolean clone, IProgressMonitor monitor)
+ throws CoreException {
+ return null;
+ }
+
+ @Override
+ public void removeConfiguration(ICConfigurationDescription des,
+ CConfigurationData data, IProgressMonitor monitor) {
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Messages.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Messages.java
new file mode 100644
index 0000000000..d4133b2962
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Messages.java
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "com.intel.sgx.messages";//$NON-NLS-1$
+
+ /*
+ * TODO - These Strings can be used all through the package to control what messages are displayed.
+ * Todo here is to identify any message that needs to be made configurable.
+ */
+ public static String CreateNativeFolders_No_folders;
+ public static String CreateNativeFolders_Missing_project_name;
+ public static String CreateNativeFolders_Project_does_not_exist;
+
+ static{
+ //Bundle initialization.
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages(){
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/SdkPathVariableProvider.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/SdkPathVariableProvider.java
new file mode 100644
index 0000000000..43f13da5f9
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/SdkPathVariableProvider.java
@@ -0,0 +1,70 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx;
+import java.io.File;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.variableresolvers.PathVariableResolver;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import com.intel.sgx.preferences.PreferenceConstants;
+import com.intel.sgx.preferences.SGXPreferencePage;
+
+public class SdkPathVariableProvider extends PathVariableResolver {
+
+ public SdkPathVariableProvider() {
+ super();
+ }
+
+ @Override
+ public String[] getVariableNames(String variable, IResource resource) {
+ String variableNames[] = {"SGX_SDK_DIR_PATH"};
+ return (variableNames);
+ }
+
+ @Override
+ public String getValue(String variable, IResource resource) {
+ if(variable.equals("SGX_SDK_DIR_PATH")) {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ String SDKPath = store.getString(PreferenceConstants.SDK_PATH);
+ IPath SDKCanonicalPath= new Path(SDKPath);
+ return(SDKCanonicalPath.append("Include").toOSString());
+ }
+ return null;
+ }
+
+ public static String getSGXSdkLocation() {
+ return Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH);
+ }
+
+ public static boolean isSGXSdkLocationValid() {
+ String location = getSGXSdkLocation();
+ if (location.length() == 0)
+ return false;
+
+ return isValidSGXSdkLocation(location);
+ }
+
+ public static boolean isValidSGXSdkLocation(String location) {
+ File dir = new File(location);
+ if (!dir.isDirectory())
+ return false;
+
+ return new PreferenceConstants.SGXSDK64Descriptor(dir).getSignerPath().canExecute()
+ || new PreferenceConstants.SGXSDK32Descriptor(dir).getSignerPath().canExecute();
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/build/SGXSDKCommandLauncher.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/build/SGXSDKCommandLauncher.java
new file mode 100644
index 0000000000..c0eb394532
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/build/SGXSDKCommandLauncher.java
@@ -0,0 +1,38 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * This class follows the same solution provided in the NDK_PLUGIN for NDKCommandLauncher.
+ */
+package com.intel.sgx.build;
+
+import org.eclipse.cdt.core.CommandLauncher;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+import com.intel.sgx.SdkPathVariableProvider;
+/**
+ * This launches the sgx-ndk-build.
+ */
+public class SGXSDKCommandLauncher extends CommandLauncher {
+
+ @Override
+ public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory,
+ IProgressMonitor monitor)
+ throws CoreException {
+
+ return super.execute(commandPath, args, env, changeToDirectory, monitor);
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddEnclaveFileDialog.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddEnclaveFileDialog.java
new file mode 100644
index 0000000000..e663a1c390
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddEnclaveFileDialog.java
@@ -0,0 +1,126 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import javax.swing.JOptionPane;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import com.intel.sgx.handlers.AddEnclave;
+
+public class AddEnclaveFileDialog extends SGXDialogBase {
+
+ private Text fileNameField;
+ private AddEnclave addHandler;
+ private boolean generateApp = true;
+
+ public AddEnclaveFileDialog(Shell shell, AddEnclave addHandler) {
+ super(shell);
+ this.addHandler = addHandler;
+ this.shell = shell;
+ // setShellStyle(SWT.RESIZE | SWT.TITLE);
+ }
+
+ public boolean generateApp()
+ {
+ return generateApp;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(1,false);
+ composite.setLayout(gridLayout);
+
+ final Group container = new Group(composite, SWT.NONE);
+ container.setLayout(new GridLayout(3,false));
+ GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid1.horizontalSpan = 3;
+ container.setLayoutData(innergrid1);
+
+ addLabel(container, "Enter the name of the Enclave. Make sure the name is unique within the hosting application.");
+
+ final Label fileNameLabel = new Label(container, SWT.NONE);
+ fileNameLabel.setText("Enclave name:");
+ fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false));
+
+ fileNameField = new Text(container,SWT.SINGLE | SWT.BORDER);
+ GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL);
+ textGridData1.minimumWidth = 400;
+ textGridData1.grabExcessHorizontalSpace = true;
+ fileNameField.setLayoutData(textGridData1);
+
+ Button generateUntrustedApp = new Button(container, SWT.CHECK);
+ generateUntrustedApp.setText("Generate sample untrusted application?");
+ generateUntrustedApp.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false, 3, 1));
+ generateUntrustedApp.setSelection(true);
+
+ generateUntrustedApp.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ Button btn = (Button) event.getSource();
+ generateApp = btn.getSelection();
+ }
+ });
+
+ container.layout();
+ composite.layout();
+ return composite;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Add New SGX Enclave Dialog");
+ newShell.layout();
+ }
+
+ @Override
+ protected
+ void okPressed() {
+ addHandler.edlFilename = fileNameField.getText();
+ if(!fileNameField.getText().isEmpty()
+ ){
+ if(Character.isDigit(fileNameField.getText().charAt(0)))
+ {
+ JOptionPane.showMessageDialog(null, "Enclave names starting with digits are not allowed.", "Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ else
+ super.okPressed();
+ }
+ }
+
+ @Override
+ protected Point getInitialSize(){
+ return new Point(675,200);
+ }
+
+ public String getFileName() {
+ return fileNameField.getText();
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddTrustedStaticLibFileDialog.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddTrustedStaticLibFileDialog.java
new file mode 100644
index 0000000000..b353c716c8
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddTrustedStaticLibFileDialog.java
@@ -0,0 +1,109 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import javax.swing.JOptionPane;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import com.intel.sgx.handlers.AddTrustedStaticLib;
+
+public class AddTrustedStaticLibFileDialog extends SGXDialogBase {
+
+ private Text fileNameField;
+ private AddTrustedStaticLib addHandler;
+ private boolean generateApp = false;
+
+ public AddTrustedStaticLibFileDialog(Shell shell, AddTrustedStaticLib addHandler) {
+ super(shell);
+ this.addHandler = addHandler;
+ this.shell = shell;
+ // setShellStyle(SWT.RESIZE | SWT.TITLE);
+ }
+
+ public boolean generateApp()
+ {
+ return generateApp;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(1,false);
+ composite.setLayout(gridLayout);
+
+ final Group container = new Group(composite, SWT.NONE);
+ container.setLayout(new GridLayout(3,false));
+ GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid1.horizontalSpan = 3;
+ container.setLayoutData(innergrid1);
+
+ addLabel(container, "Enter the name of the Static Trusted Library.");
+ addLabel(container, "Make sure the name is unique within the hosting application.");
+
+ final Label fileNameLabel = new Label(container, SWT.NONE);
+ fileNameLabel.setText("Static Trusted Library Name:");
+ fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false));
+
+ fileNameField = new Text(container,SWT.SINGLE | SWT.BORDER);
+ GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL);
+ textGridData1.minimumWidth = 400;
+ textGridData1.grabExcessHorizontalSpace = true;
+ fileNameField.setLayoutData(textGridData1);
+
+ composite.layout();
+
+ return composite;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Add New SGX Static Trusted Library Dialog");
+ }
+
+ @Override
+ protected
+ void okPressed(){
+ addHandler.edlFilename = fileNameField.getText();
+ if(!fileNameField.getText().isEmpty()
+ ){
+ if(Character.isDigit(fileNameField.getText().charAt(0)))
+ {
+ JOptionPane.showMessageDialog(null, "Enclave names starting with digits are not allowed.", "Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ else
+ super.okPressed();
+ }
+ }
+
+ @Override
+ protected Point getInitialSize(){
+ return new Point(675,200);
+ }
+
+ public String getFileName() {
+ return fileNameField.getText();
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddUntrustedModuleDialog.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddUntrustedModuleDialog.java
new file mode 100644
index 0000000000..15779d4651
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddUntrustedModuleDialog.java
@@ -0,0 +1,138 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import java.io.File;
+
+import javax.swing.JOptionPane;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import com.intel.sgx.handlers.AddUntrustedModule;
+
+public class AddUntrustedModuleDialog extends Dialog {
+
+ private Text fileNameField,makeFilePathField;
+ private Shell shell;
+ private AddUntrustedModule addHandler;
+ private boolean generateApp = false;
+
+ public AddUntrustedModuleDialog(Shell shell, AddUntrustedModule addHandler) {
+ super(shell);
+ this.addHandler = addHandler;
+ this.shell = shell;
+ //setShellStyle(SWT.RESIZE | SWT.TITLE);
+ }
+
+ public boolean generateApp()
+ {
+ return generateApp;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(1,false);
+ composite.setLayout(gridLayout);
+
+ final Group container = new Group(composite, SWT.NONE);
+ container.setLayout(new GridLayout(3,false));
+ GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid1.horizontalSpan = 3;
+ container.setLayoutData(innergrid1);
+
+ final Label messageLabel = new Label(container, SWT.NONE);
+ messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
+ messageLabel.setText("Enter the path to the Enclave Descriptor file (*.edl) of the enclave to host.");
+
+
+ final Label fileNameLabel = new Label(container, SWT.NONE);
+ fileNameLabel.setText("Filename:");
+ fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false));
+
+
+ fileNameField = new Text(container,SWT.SINGLE | SWT.BORDER);
+ GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL);
+ textGridData1.minimumWidth = 400;
+ textGridData1.grabExcessHorizontalSpace = true;
+ fileNameField.setLayoutData(textGridData1);
+
+ final Button browseButton = new Button(container, SWT.PUSH);
+ browseButton.setText("Browse");
+ GridData buttonGridData1 = new GridData(GridData.END);
+ buttonGridData1.horizontalAlignment = SWT.RIGHT;
+ buttonGridData1.horizontalSpan = 1;
+ buttonGridData1.minimumWidth = 120;
+ browseButton.setLayoutData(buttonGridData1);
+ browseButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String result = null;
+ shell = new Shell();
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setFilterExtensions(new String [] {"*.edl"});
+ dialog.setFilterPath("");
+ result = dialog.open();
+ fileNameField.setText(result);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ return composite;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Add SGX Untrusted Module.");
+ }
+
+ @Override
+ protected
+ void okPressed(){
+ addHandler.edlFilename = fileNameField.getText();
+ if(!fileNameField.getText().isEmpty())
+ if((new File(fileNameField.getText())).isFile())
+ super.okPressed();
+ else
+ JOptionPane.showMessageDialog(null, "EDL file does not exist.", "Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+
+ @Override
+ protected Point getInitialSize(){
+ return new Point(675,200);
+ }
+
+ public String getFileName() {
+ return fileNameField.getText();
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/EnclaveConfigDialog.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/EnclaveConfigDialog.java
new file mode 100644
index 0000000000..20595f8095
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/EnclaveConfigDialog.java
@@ -0,0 +1,257 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import org.eclipse.jface.preference.JFacePreferences;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import com.intel.sgx.handlers.EnclaveConfigHandler;
+
+public class EnclaveConfigDialog extends SGXDialogBase {
+
+ @SuppressWarnings("unused")
+ private Shell shell;
+ private EnclaveConfigHandler enclaveConfig;
+ private Label statusLabel;
+ private Text prodID;
+ private Text isvSvn;
+ private Text threadStackSize;
+ private Text globalHeapSize;
+ private Text tcsNum;
+ private Combo tcsPolicy;
+ private Button disableDebug;
+
+ public EnclaveConfigDialog(Shell parentshell,EnclaveConfigHandler enclaveConfigHandler) {
+ super(parentshell);
+ this.shell = parentshell;
+ this.enclaveConfig = enclaveConfigHandler;
+ setShellStyle(SWT.RESIZE | SWT.TITLE);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+
+ Composite container = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(3,false);
+ container.setLayout(gridLayout);
+
+ final Group groupLabel1 = new Group(container, SWT.None);
+ groupLabel1.setLayout(new GridLayout(3,false));
+ GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid1.horizontalSpan = 3;
+ groupLabel1.setLayoutData(innergrid1);
+
+ Label warningLabel = new Label(groupLabel1,SWT.BEGINNING | SWT.WRAP);
+ warningLabel.setText("Note: Use this Menu to change the Enclave settings.");
+
+ statusLabel = new Label(container,SWT.BEGINNING | SWT.WRAP);
+ GridData statusGrid = new GridData(GridData.FILL_HORIZONTAL);
+ statusGrid.horizontalSpan = 3;
+ statusLabel.setLayoutData(statusGrid);
+ statusLabel.setText("");
+ statusLabel.setForeground(JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR));
+
+ final Group groupLabel2 = new Group(container, SWT.None);
+ groupLabel2.setLayout(new GridLayout(3,false));
+ groupLabel2.setText("Modify the Enclave Settings here...");
+ GridData innergrid = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid.horizontalSpan = 3;
+ groupLabel2.setLayoutData(innergrid);
+
+ final Label messageLabel0 = new Label(groupLabel2, SWT.NONE);
+ messageLabel0.setText("Product ID:");
+ messageLabel0.setLayoutData(new GridData(GridData.BEGINNING));
+
+ prodID = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalSpan = 2;
+ gridData.widthHint = 400;
+ prodID.setLayoutData(gridData);
+ prodID.setText(enclaveConfig.prodId);
+ prodID.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent modifyEvent) {
+ statusLabel.setText("");
+ enclaveConfig.prodId = prodID.getText();
+ }
+ });
+
+ final Label messageLabel1 = new Label(groupLabel2, SWT.NONE);
+ messageLabel1.setText("ISV SVN:");
+ messageLabel1.setLayoutData(new GridData(GridData.BEGINNING));
+
+ isvSvn = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
+ isvSvn.setLayoutData(gridData);
+ isvSvn.setText(enclaveConfig.isvSvn);
+ isvSvn.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent modifyEvent) {
+ statusLabel.setText("");
+ enclaveConfig.isvSvn = isvSvn.getText();
+ }
+ });
+
+ final Label messageLabel2 = new Label(groupLabel2, SWT.NONE);
+ messageLabel2.setText("Thread Stack Size:");
+ messageLabel2.setLayoutData(new GridData(GridData.BEGINNING));
+
+ threadStackSize = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
+ threadStackSize.setLayoutData(gridData);
+ threadStackSize.setText(enclaveConfig.threadStackSize);
+ threadStackSize.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent modifyEvent) {
+ enclaveConfig.threadStackSize = threadStackSize.getText();
+ if(!(threadStackSize.getText().matches("0x[0-9a-fA-F]{1,}000")))
+ {
+ statusLabel.setText("Error: The Thread Stack Size value must be Page Aligned.");
+ }
+ else
+ {
+ if(!(enclaveConfig.globalHeapSize.matches("0x[0-9a-fA-F]{1,}000")))
+ statusLabel.setText("Error: The Global Heap Size value must be Page Aligned.");
+ else
+ statusLabel.setText("");
+ }
+ }
+ });
+
+ final Label messageLabel3 = new Label(groupLabel2, SWT.NONE);
+ messageLabel3.setText("Global Heap Size:");
+ messageLabel3.setLayoutData(new GridData(GridData.BEGINNING));
+
+ globalHeapSize = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
+ globalHeapSize.setLayoutData(gridData);
+ globalHeapSize.setText(enclaveConfig.globalHeapSize);
+ globalHeapSize.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent modifyEvent) {
+ enclaveConfig.globalHeapSize = globalHeapSize.getText();
+ if(!(globalHeapSize.getText().matches("0x[0-9a-fA-F]{1,}000")))
+ {
+ statusLabel.setText("Error: The Global Heap Size value must be Page Aligned.");
+ }
+ else
+ {
+ if(!(enclaveConfig.threadStackSize.matches("0x[0-9a-fA-F]{1,}000")))
+ statusLabel.setText("Error: The Thread Stack Size value must be Page Aligned.");
+ else
+ statusLabel.setText("");
+
+ }
+ }
+ });
+
+ final Label messageLabel4 = new Label(groupLabel2, SWT.NONE);
+ messageLabel4.setText("TCS Number:");
+ messageLabel4.setLayoutData(new GridData(GridData.BEGINNING));
+
+ tcsNum = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
+ tcsNum.setLayoutData(gridData);
+ tcsNum.setText(enclaveConfig.tcsNum);
+ tcsNum.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent modifyEvent) {
+ statusLabel.setText("");
+ enclaveConfig.tcsNum = tcsNum.getText();
+ }
+ });
+
+ final Label messageLabel5 = new Label(groupLabel2, SWT.NONE);
+ messageLabel5.setText("TCS Policy:");
+ messageLabel5.setLayoutData(new GridData(GridData.BEGINNING));
+
+ final String[] items = {"Unbound","Bound"};
+ tcsPolicy = new Combo(groupLabel2, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
+ tcsPolicy.setItems(items);
+ String item = items[Integer.parseInt(enclaveConfig.tcsPolicy)];
+ int index = tcsPolicy.indexOf(item);
+ tcsPolicy.select(index < 0 ? 0 : index);
+ tcsPolicy.setLayoutData(gridData);
+ tcsPolicy.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e){
+ statusLabel.setText("");
+ enclaveConfig.tcsPolicy = (tcsPolicy.getSelectionIndex() == 0 ? "0" : "1");
+ }
+ });
+
+
+ final Label messageLabel6 = new Label(groupLabel2, SWT.NONE);
+ messageLabel6.setText("Disable Debug:");
+ messageLabel6.setLayoutData(new GridData(GridData.BEGINNING));
+
+ disableDebug = new Button(groupLabel2,SWT.CHECK);
+ GridData gridData1 = new GridData(GridData.FILL_HORIZONTAL);
+ disableDebug.setLayoutData(gridData1);
+ disableDebug.setSelection(enclaveConfig.disableDebug.equals("1")?true:false);
+ disableDebug.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent e){
+ statusLabel.setText("");
+ enclaveConfig.disableDebug = disableDebug.getSelection()?"1":"0";
+ }
+ });
+
+ if(statusLabel.getText() != null){
+ statusLabel.setVisible(true);
+ }
+ else{
+ statusLabel.setVisible(false);
+ }
+
+ return container;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Enclave Configuration Settings:");
+ }
+
+ @Override
+ protected Point getInitialSize(){
+ return new Point(450,400);
+ }
+
+ @Override
+ protected
+ void okPressed(){
+ enclaveConfig.prodId = this.prodID.getText();
+ enclaveConfig.isvSvn = this.isvSvn.getText();
+ enclaveConfig.threadStackSize = this.threadStackSize.getText();
+ enclaveConfig.globalHeapSize = this.globalHeapSize.getText();
+ enclaveConfig.tcsNum = this.tcsNum.getText();
+ enclaveConfig.tcsPolicy = this.tcsPolicy.getSelectionIndex() == 0 ? "0" : "1";
+ enclaveConfig.disableDebug = disableDebug.getSelection()?"1":"0";
+
+
+ if((statusLabel.getText() == "") && (enclaveConfig.globalHeapSize.matches("0x[0-9a-fA-F]{1,}000")) && (enclaveConfig.threadStackSize.matches("0x[0-9a-fA-F]{1,}000")))
+ super.okPressed();
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/RemoveEnclaveFileDialog.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/RemoveEnclaveFileDialog.java
new file mode 100644
index 0000000000..6db3d2e1c4
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/RemoveEnclaveFileDialog.java
@@ -0,0 +1,122 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+//import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import com.intel.sgx.handlers.RemoveEnclave;
+
+public class RemoveEnclaveFileDialog extends Dialog{
+
+ private Text fileNameField;
+ private Shell shell;
+ private RemoveEnclave removeHandler;
+
+ public RemoveEnclaveFileDialog(Shell shell, RemoveEnclave removeHandler) {
+ super(shell);
+ this.removeHandler = removeHandler;
+ this.shell = shell;
+ setShellStyle(SWT.RESIZE | SWT.TITLE);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(1,false);
+ composite.setLayout(gridLayout);
+
+ final Group container = new Group(composite, SWT.None);
+ container.setLayout(new GridLayout(3,false));
+ GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid1.horizontalSpan = 3;
+ container.setLayoutData(innergrid1);
+ container.setText("Path to Enclave directory:");
+
+ final Label messageLabel = new Label(container, SWT.NONE);
+ messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
+ messageLabel.setText("Enter the name of the Enclave Or Navigate to the Enclave folder to be removed from the host.");
+
+ final Label fileNameLabel = new Label(container, SWT.NONE);
+ fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false));
+ fileNameLabel.setText("Enclave Name:");
+
+ fileNameField = new Text(container, SWT.SINGLE | SWT.BORDER);
+ GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL);
+ textGridData1.minimumWidth = 400;
+ textGridData1.grabExcessHorizontalSpace = true;
+ fileNameField.setLayoutData(textGridData1);
+
+ final Button browseButton = new Button(container, SWT.PUSH);
+ browseButton.setText("Browse");
+ GridData buttonGridData1 = new GridData(GridData.END);
+ buttonGridData1.horizontalAlignment = SWT.RIGHT;
+ buttonGridData1.horizontalSpan = 1;
+ buttonGridData1.minimumWidth = 120;
+ browseButton.setLayoutData(buttonGridData1);
+ browseButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String result = fileNameField.getText();
+
+ DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
+ dialog.setMessage("Select the Enclave Directory to remove.");
+ dialog.setFilterPath("");
+ result = dialog.open();
+ fileNameField.setText(result);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ return container;
+ }
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Remove an Imported Enclave");
+ }
+
+ @Override
+ protected void okPressed(){
+ removeHandler.edlFilename = fileNameField.getText();
+ if(!fileNameField.getText().isEmpty())
+ super.okPressed();
+ }
+
+ @Override
+ protected Point getInitialSize(){
+ return new Point(675,205);
+ }
+
+ public String getFileName() {
+ return fileNameField.getText();
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/SGXDialogBase.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/SGXDialogBase.java
new file mode 100644
index 0000000000..4b49a8bb31
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/SGXDialogBase.java
@@ -0,0 +1,222 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import java.io.InputStream;
+import java.util.Scanner;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.IShellProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
+
+import com.intel.sgx.Activator;
+
+public abstract class SGXDialogBase extends Dialog {
+
+ protected Shell shell;
+ public Text configFileField;
+ public static FilteredResourcesSelectionDialog dialogForConfig(Shell shell) {
+ // final IContainer container = ResourcesPlugin.getWorkspace().getRoot();
+
+ final IContainer container = SGXDialogBase.getCurrentProject();
+
+ FilteredResourcesSelectionDialog d = new FilteredResourcesSelectionDialog(
+ shell, false, container, IResource.FILE) {
+ {
+ setInitialPattern("**");
+ }
+
+ @Override
+ protected IStatus validateItem(Object item) {
+ // return Status.OK_STATUS;
+ IFile f = (IFile) item;
+ if (f.getParent() instanceof IProject) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "The selected resource has to be part of the source folder");
+ }
+
+
+ return super.validateItem(item);
+ }
+
+ protected ItemsFilter createFilter() {
+ return new ResourceFilter(container, true, IResource.FILE) {
+
+ @Override
+ public boolean matchItem(Object item) {
+ return isConfigFile(item);
+ }
+
+ private boolean isConfigFile(Object item) {
+ if (!(item.toString().endsWith(".xml") && super
+ .matchItem(item))) {
+ return false;
+ }
+ try {
+ IFile iFile = (IFile) item;
+ return streamContainsString(iFile.getContents(),
+ "");
+ } catch (Throwable e) {
+ return false;
+ }
+ }
+
+ };
+
+ }
+
+ public boolean streamContainsString(InputStream is,
+ String searchString) {
+ Scanner streamScanner = new Scanner(is);
+ if (streamScanner.findWithinHorizon(searchString, 0) != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ };
+ return d;
+ }
+
+
+
+ protected SelectionListener configFileSelectionListener = new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+
+ FilteredResourcesSelectionDialog d = dialogForConfig(shell);
+ d.setTitle("Select Config File");
+ if (d.open() == Dialog.OK) {
+ IFile target = (IFile) d.getResult()[0];
+ configFileField.setText(target.getLocation().toOSString());
+ }
+ ;
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ };
+
+ public SGXDialogBase(Shell parentShell) {
+ super(parentShell);
+ }
+
+ public SGXDialogBase(IShellProvider parentShell) {
+ super(parentShell);
+ }
+
+ protected Text addGroup(Composite composite, String title, String subtitle,
+ String label, String selectButtonLabel, SelectionListener selectionListener) {
+ final Group container = new Group(composite, SWT.None);
+ container.setLayout(new GridLayout(3, false));
+ GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid1.horizontalSpan = 3;
+ container.setLayoutData(innergrid1);
+ container.setText(title);
+
+ final Label messageLabel = new Label(container, SWT.NONE);
+ messageLabel.setLayoutData(new GridData(GridData.BEGINNING,
+ GridData.CENTER, false, false, 3, 1));
+ messageLabel.setText(subtitle);
+
+ final Label messageLabel1 = new Label(container, SWT.NONE);
+ messageLabel1.setText(label);
+ messageLabel1.setLayoutData(new GridData(GridData.BEGINNING));
+
+ Text directoryNameField = new Text(container, SWT.SINGLE | SWT.BORDER);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalSpan = 1;
+ gridData.widthHint = 400;
+ directoryNameField.setLayoutData(gridData);
+
+ final Button selectButton = new Button(container, SWT.PUSH);
+ selectButton.setText(selectButtonLabel);
+ GridData buttonGridData = new GridData(GridData.END);
+ buttonGridData.horizontalAlignment = SWT.RIGHT;
+ buttonGridData.horizontalSpan = 1;
+ buttonGridData.minimumWidth = 120;
+ selectButton.setLayoutData(buttonGridData);
+ selectButton.addSelectionListener(selectionListener);
+ return directoryNameField;
+ }
+
+
+ public IPath getCurrentProjectPath() {
+ IProject project = getCurrentProject();
+
+ IPath path = null;
+ if (project != null) {
+ path = project.getLocation();
+ }
+ return path;
+ }
+
+ static public IProject getCurrentProject() {
+ IProject project = null;
+
+
+ IWorkbenchWindow window = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ if (window != null) {
+ IStructuredSelection selection = (IStructuredSelection) window
+ .getSelectionService().getSelection();
+ Object firstElement = selection.getFirstElement();
+ if (firstElement instanceof IAdaptable) {
+ project = (IProject) ((IAdaptable) firstElement)
+ .getAdapter(IProject.class);
+ }
+ }
+ return project;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell){
+ super.configureShell(newShell);
+ }
+
+ protected void addLabel(final Group container, String labelText) {
+ final Label messageLabel = new Label(container, SWT.NONE);
+ messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
+ messageLabel.setText(labelText);
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignDialogBase.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignDialogBase.java
new file mode 100644
index 0000000000..07d25c7321
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignDialogBase.java
@@ -0,0 +1,174 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import java.io.File;
+import java.util.Scanner;
+
+import javax.swing.JOptionPane;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public abstract class TwoStepSignDialogBase extends SGXDialogBase {
+
+ public Text enclaveFileField;
+ public Text hashFileField;
+ public Text externalSignPublicKeyFileField;
+ public Text externalSignedHashFileField;
+ public Text outputSignedEnclaveFileField;
+
+ public TwoStepSignDialogBase(Shell parentShell) {
+ super(parentShell);
+ setShellStyle(SWT.RESIZE | SWT.TITLE);
+ this.shell = TwoStepSignDialogBase.this.getParentShell();
+
+ }
+
+ // for each field, a corresponding listener
+ protected SelectionListener enclaveFileSelectionListener = new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String result = enclaveFileField.getText();
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+
+
+
+ dialog.setFilterExtensions(new String[]{"*.so"} );
+ dialog.setFilterPath(getCurrentProjectPath().toOSString());
+
+ if (result != null && !result.isEmpty()) {
+ dialog.setFilterPath(new File(result).getParent());
+ } else {
+ dialog.setFilterPath(getCurrentProjectPath().toOSString());
+ }
+
+ result = dialog.open();
+
+ enclaveFileField.setText(result);
+
+ hashFileField.setText(result + ".hex");
+
+ if (outputSignedEnclaveFileField != null){
+ String outputSignedEnclavePath = result;
+ if(outputSignedEnclavePath.endsWith(".so"))
+ {
+ outputSignedEnclavePath =
+ outputSignedEnclavePath.substring(0,outputSignedEnclavePath.length() - ".so".length());
+ outputSignedEnclaveFileField.setText(outputSignedEnclavePath+".signed.so");
+ }
+
+ }
+
+
+
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+ };
+
+ protected SelectionListener hashFileSelectionListener = new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String result = hashFileField.getText();
+
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+
+ if (result != null && !result.isEmpty()) {
+ dialog.setFilterPath(new File(result).getParent());
+ } else {
+ dialog.setFilterPath(getCurrentProjectPath().toOSString());
+ }
+
+ result = dialog.open();
+
+ hashFileField.setText(result);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+
+ };
+
+ protected SelectionListener publicKeyLocationSelectionListener = new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String result = externalSignPublicKeyFileField.getText();
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setFilterExtensions(new String [] {"*.pem", "*"});
+ dialog.setFilterPath(getCurrentProjectPath().toOSString());
+ result = dialog.open();
+ externalSignPublicKeyFileField.setText(result);
+ }
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ };
+
+ protected SelectionListener externalSignedHashFileSelectionListener = new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String result = externalSignedHashFileField.getText();
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setFilterPath(getCurrentProjectPath().toOSString());
+ result = dialog.open();
+ externalSignedHashFileField.setText(result);
+ }
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ };
+
+ protected SelectionListener outputSignedEnclaveListener = new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String result = outputSignedEnclaveFileField.getText();
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+
+
+ dialog.setFilterExtensions(new String[]{"*.so", } );
+ dialog.setFilterPath(getCurrentProjectPath().toOSString());
+
+ if (result != null && !result.isEmpty()) {
+ dialog.setFilterPath(new File(result).getParent());
+ } else {
+ dialog.setFilterPath(getCurrentProjectPath().toOSString());
+ }
+
+ result = dialog.open();
+
+ outputSignedEnclaveFileField.setText(result);
+
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+ };
+
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ }
+
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog1.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog1.java
new file mode 100644
index 0000000000..fdba448164
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog1.java
@@ -0,0 +1,72 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+import com.intel.sgx.handlers.TwoStepSignHandlerBase;
+
+public class TwoStepSignStep1Dialog1 extends TwoStepSignDialogBase {
+
+ final private TwoStepSignHandlerBase handler;
+
+ public TwoStepSignStep1Dialog1(Shell parentShell, TwoStepSignHandlerBase handler) {
+ super(parentShell);
+ this.handler = handler;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(1, false);
+ composite.setLayout(gridLayout);
+
+ enclaveFileField = addGroup(composite, "Unsigned Enclave Path:",
+ "Select Enclave for which to generate the Hash.",
+ "Enclave Path:", "Select Enclave", enclaveFileSelectionListener);
+
+ hashFileField = addGroup(composite, "Generate Hash:",
+ "Select Location to Output Hash File.", "Hash File Location:",
+ "Select File Path", hashFileSelectionListener);
+
+ configFileField = addGroup(composite, "Configuration File:",
+ "Select Input Configuration XML File. ",
+ "Configuration File:", "Select Config",
+ configFileSelectionListener);
+
+ composite.pack(true);
+ return composite;
+ }
+
+ @Override
+ protected void okPressed() {
+ handler.enclaveFile = enclaveFileField.getText();
+ handler.hashFile = hashFileField.getText();
+ handler.configFile = configFileField.getText();
+
+ super.okPressed();
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Two Step Enclave Sign - Generate Hash");
+ }
+
+
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog2.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog2.java
new file mode 100644
index 0000000000..4c2852f9f4
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog2.java
@@ -0,0 +1,89 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+public class TwoStepSignStep1Dialog2 extends TwoStepSignDialogBase {
+
+ final private String hashFile;
+
+ public TwoStepSignStep1Dialog2(Shell parentShell, String hashFile) {
+ super(parentShell);
+ this.hashFile = hashFile;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(1,false);
+ composite.setLayout(gridLayout);
+
+ addGroup1(composite);
+ addGroup3(composite);
+
+
+ return composite;
+ }
+
+ private void addGroup1(Composite composite) {
+ final Group container = new Group(composite, SWT.None);
+ container.setLayout(new GridLayout(3,false));
+ GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid1.horizontalSpan = 3;
+ container.setLayoutData(innergrid1);
+ container.setText("Hash File:");
+
+ final Label messageLabel = new Label(container, SWT.NONE);
+ messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
+ messageLabel.setText("Hash File Generated at Location:");
+
+ final Label messageLabel1 = new Label(container, SWT.NONE);
+ messageLabel1.setText(hashFile);
+
+ messageLabel1.setLayoutData(new GridData(GridData.BEGINNING));
+ }
+
+ private void addGroup3(Composite composite) {
+ final Group container3 = new Group(composite, SWT.None);
+ container3.setLayout(new GridLayout(3,false));
+ GridData innergrid3 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid3.horizontalSpan = 3;
+ container3.setLayoutData(innergrid3);
+ container3.setText("Generate Signed Enclave (Step-2):");
+
+ final Label messageLabel4 = new Label(container3, SWT.NONE);
+ messageLabel4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
+ messageLabel4.setText("To Generate Signed Enclave Now: Click OK");
+
+ final Label messageLabel5 = new Label(container3, SWT.NONE);
+ messageLabel5.setLayoutData(new GridData(GridData.CENTER, GridData.END, false, false, 3, 1));
+ messageLabel5.setText("To Generate Signed Enclave Later: Click Cancel");
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Two Step Enclave Sign - Generate Hash");
+ }
+
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog3.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog3.java
new file mode 100644
index 0000000000..976f1c21b3
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog3.java
@@ -0,0 +1,105 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+import com.intel.sgx.handlers.TwoStepSignHandlerBase;
+
+public class TwoStepSignStep1Dialog3 extends TwoStepSignDialogBase {
+
+ final private TwoStepSignHandlerBase handler;
+
+ public TwoStepSignStep1Dialog3(Shell parentShell, TwoStepSignHandlerBase handler) {
+ super(parentShell);
+ this.handler = handler;
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(1, false);
+ composite.setLayout(gridLayout);
+
+ addInfoGroup(composite);
+
+ externalSignPublicKeyFileField = addGroup(composite, "Public Key:",
+ "Select the Public Key file obtained from signing facility",
+ "Public Key:", "Select", publicKeyLocationSelectionListener);
+
+ externalSignedHashFileField = addGroup(composite, "Signature:",
+ "Select the Signature file obtained from signing facility.",
+ "Signature:",
+ "Select", externalSignedHashFileSelectionListener);
+
+
+ outputSignedEnclaveFileField = addGroup(composite, "Signed Enclave:",
+ "Select where to save the output Signed Enclave.",
+ "Signed Enclave:",
+ "Select", outputSignedEnclaveListener);
+
+ return composite;
+ }
+
+ protected void addInfoGroup(Composite composite) {
+ final Group container = new Group(composite, SWT.None);
+ container.setLayout(new GridLayout(3,false));
+ GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid1.horizontalSpan = 3;
+ container.setLayoutData(innergrid1);
+ container.setText("Hash and Enclave:");
+
+
+ addInfoKeyValue(container, "Enclave File:", handler.enclaveFile);
+ addInfoKeyValue(container, "Config File:", handler.configFile);
+ addInfoKeyValue(container, "Hash File:", handler.hashFile);
+ }
+
+ private void addInfoKeyValue(final Group container, String key,
+ String value) {
+ final Label messageLabel2 = new Label(container, SWT.NONE);
+ messageLabel2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
+ messageLabel2.setText(key);
+
+ final Label messageLabel3 = new Label(container, SWT.NONE);
+ messageLabel3.setText(value);
+ messageLabel3.setLayoutData(new GridData(GridData.BEGINNING));
+ }
+
+ @Override
+ protected void okPressed() {
+ handler.externalSignPublicKeyFile = externalSignPublicKeyFileField.getText();
+ handler.externallySignedHashFile = externalSignedHashFileField.getText();
+ handler.outputSignedEnclaveFile = outputSignedEnclaveFileField.getText();
+ super.okPressed();
+ }
+
+
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Two Step Enclave Sign - Generate Signed Enclave");
+ }
+
+
+
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep2Dialog.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep2Dialog.java
new file mode 100644
index 0000000000..acd9e99627
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep2Dialog.java
@@ -0,0 +1,92 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+import com.intel.sgx.handlers.TwoStepSignHandlerBase;
+import com.intel.sgx.handlers.TwoStepSignStep2;
+
+public class TwoStepSignStep2Dialog extends TwoStepSignDialogBase{
+
+ final private TwoStepSignHandlerBase handler;
+
+
+ public TwoStepSignStep2Dialog(Shell parentShell, TwoStepSignHandlerBase handler) {
+ super(parentShell);
+ this.handler = handler;
+ }
+
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(1,false);
+ composite.setLayout(gridLayout);
+
+
+
+ enclaveFileField= addGroup(composite, "Enclave:",
+ "Select the unsigned enclave file",
+ "Unsigned Enclave File:", "Select", enclaveFileSelectionListener);
+
+ configFileField = addGroup(composite, "Configuration File:",
+ "Select Input Configuration XML File. ",
+ "Configuration File:", "Select Config",
+ configFileSelectionListener);
+
+ hashFileField= addGroup(composite, "Hash:",
+ "Select the Hash file obtained from previous step",
+ "Hash File:", "Select", hashFileSelectionListener);
+
+ externalSignPublicKeyFileField= addGroup(composite, "Public Key:",
+ "Select the Public Key file obtained from external signing facility",
+ "Public Key:", "Select", publicKeyLocationSelectionListener);
+
+ externalSignedHashFileField = addGroup(composite, "Signature:",
+ "Select the Signature file obtained from signing facility.",
+ "Signature:",
+ "Select", externalSignedHashFileSelectionListener);
+
+ outputSignedEnclaveFileField = addGroup(composite, "Signed Enclave:",
+ "Select where to save the output Signed Enclave.",
+ "Signed Enclave:",
+ "Select", outputSignedEnclaveListener);
+
+ return composite;
+ }
+
+
+ @Override
+ protected void okPressed() {
+ handler.enclaveFile = enclaveFileField.getText();
+ handler.hashFile = hashFileField.getText();
+ handler.configFile = configFileField.getText();
+ handler.externalSignPublicKeyFile = externalSignPublicKeyFileField.getText();
+ handler.externallySignedHashFile = externalSignedHashFileField.getText();
+ handler.outputSignedEnclaveFile = outputSignedEnclaveFileField.getText();
+
+ super.okPressed();
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Two Step Enclave Sign - Generate Signed Enclave");
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/UpdateSignKeyDialog.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/UpdateSignKeyDialog.java
new file mode 100644
index 0000000000..502fb2dcfa
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/UpdateSignKeyDialog.java
@@ -0,0 +1,191 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.dialogs;
+
+import java.io.File;
+
+import javax.swing.JOptionPane;
+
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import com.intel.sgx.handlers.UpdateSigningKey;
+
+public class UpdateSignKeyDialog extends SGXDialogBase {
+
+ private Shell shell;
+ public Text sourceKeyFileField;
+ public Text destinationKeyFileField;
+ public static boolean regenerate = false;
+
+ private final SelectionListener destinationKeyFileSelectionListener = new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String result = destinationKeyFileField.getText();
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setFilterPath(getCurrentProjectPath().toOSString());
+ dialog.setFilterExtensions(new String [] {"*.pem", "*"});
+ result = dialog.open();
+ destinationKeyFileField.setText(result);
+ }
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ };
+
+ private final SelectionListener sourceKeyFileSelectionListener = new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String result = sourceKeyFileField.getText();
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setFilterExtensions(new String [] {"*.pem", "*"});
+ dialog.setFilterPath(getCurrentProjectPath().toOSString());
+ result = dialog.open();
+ sourceKeyFileField.setText(result);
+ }
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ };
+ final private UpdateSigningKey handler;
+
+ public UpdateSignKeyDialog(Shell parentShell, UpdateSigningKey handler) {
+ super(parentShell);
+ this.shell = parentShell;
+ this.handler = handler;
+ setShellStyle(SWT.RESIZE | SWT.TITLE);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ final GridLayout gridLayout = new GridLayout(1,false);
+ composite.setLayout(gridLayout);
+
+ destinationKeyFileField = addGroup(composite, "Enclave Signing Key:",
+ "Select the Signing Key to be Updated or Generated.",
+ "Enclave Signing Key:", "Select", destinationKeyFileSelectionListener);
+
+ sourceKeyFileField = addGroup(composite, "Import:",
+ "To import your own Signing Key use the Import Signing Key option.",
+ "Import Signing Key:", "Import Key", sourceKeyFileSelectionListener);
+
+ addGroup2(composite);
+
+ return composite;
+ }
+
+ protected void addGroup2(Composite composite) {
+ final Group container2 = new Group(composite, SWT.None);
+ container2.setLayout(new GridLayout(3,false));
+ GridData innergrid2 = new GridData(GridData.FILL_HORIZONTAL);
+ innergrid2.horizontalSpan = 3;
+ container2.setLayoutData(innergrid2);
+ container2.setText("Generate:");
+
+ final Label messageLabel3 = new Label(container2, SWT.NONE);
+ messageLabel3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
+ messageLabel3.setText("To Generate a new Signing Key use the Generate Signing Key option.");
+
+ Label warningLabel2 = new Label(container2,SWT.FILL | SWT.WRAP);
+ warningLabel2.setText("Generate a new Signing Key:");
+ warningLabel2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Label dummy2 = new Label(container2,0);
+ dummy2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ final Button updateSigningKey = new Button(container2, SWT.PUSH);
+ updateSigningKey.setText("Generate Key");
+ GridData buttonGridData2 = new GridData(GridData.END);
+ buttonGridData2.horizontalAlignment = SWT.RIGHT;
+ buttonGridData2.horizontalSpan = 1;
+ buttonGridData2.minimumWidth = 120;
+ updateSigningKey.setLayoutData(buttonGridData2);
+ updateSigningKey.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ if( !destinationKeyFileField.getText().isEmpty())
+ {
+ regenerate = true;
+ UpdateSignKeyDialog.this.setReturnCode(InputDialog.OK);
+ okPressed();
+ UpdateSignKeyDialog.this.close();
+ }
+ else
+ JOptionPane.showMessageDialog(null, "Enclave Signing Key field is not provided.", "Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ }
+
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Import or (Re)Generate Enclave Signing Key");
+ }
+
+ @Override
+ protected void okPressed() {
+
+ handler.sourceKeyFile = sourceKeyFileField.getText();
+ handler.destinationKeyFile = destinationKeyFileField.getText();
+ if((!sourceKeyFileField.getText().isEmpty() && !destinationKeyFileField.getText().isEmpty() &&
+ (new File(sourceKeyFileField.getText())).isFile())
+ || regenerate == true )
+ {
+ System.out.println("regenerate = " + regenerate);
+ super.okPressed();
+ }
+ else
+ {
+ if(sourceKeyFileField.getText().isEmpty() && destinationKeyFileField.getText().isEmpty())
+ JOptionPane.showMessageDialog(null, "Enclave Signing Key and Import Singing Key are not provided.", "Error",
+ JOptionPane.ERROR_MESSAGE);
+ else
+ {
+ if(sourceKeyFileField.getText().isEmpty())
+ JOptionPane.showMessageDialog(null, "Import Singing Key is not provided.", "Error",
+ JOptionPane.ERROR_MESSAGE);
+ else
+ if(!(new File(sourceKeyFileField.getText())).isFile())
+ JOptionPane.showMessageDialog(null, "Invalid Import Singing Key.", "Error",
+ JOptionPane.ERROR_MESSAGE);
+
+ if(destinationKeyFileField.getText().isEmpty())
+ JOptionPane.showMessageDialog(null, "Enclave Signing Key is not provided.", "Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ }
+
+
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveredPathInfo.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveredPathInfo.java
new file mode 100644
index 0000000000..2c48b2fb39
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveredPathInfo.java
@@ -0,0 +1,202 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.discovery;
+
+import java.util.List;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo;
+import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredScannerInfoSerializable;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+import com.intel.sgx.Activator;
+/*
+ * This code has been taken from the NDK plugin for Linux. If there is an update to this code there, then refactor this code.
+ */
+public class SGXSDKDiscoveredPathInfo implements IDiscoveredPathInfo {
+
+ private final IProject mProject;
+ private long mLastUpdate = IFile.NULL_STAMP;
+ private IPath[] mIncludePaths;
+ private Map mSymbols;
+ private boolean mNeedReindexing = false;
+ private static final IPath LINUX_MK = new Path("sgx/Makefile");
+
+ //Keys for preferences
+ // public static final String LAST_UPDATE = "lastUpdate"; //$NON-NLS-1$
+
+
+ public SGXSDKDiscoveredPathInfo(IProject project) {
+ this.mProject = project;
+ load();
+ }
+
+ @Override
+ public IProject getProject() {
+ return mProject;
+ }
+
+ @Override
+ public IPath[] getIncludePaths() {
+ if (mNeedReindexing) {
+ CCorePlugin.getIndexManager().reindex(CoreModel.getDefault().create(mProject));
+ mNeedReindexing = false;
+ }
+ return mIncludePaths;
+ }
+
+ void setIncludePaths(List pathStrings) {
+ mIncludePaths = new IPath[pathStrings.size()];
+ int i = 0;
+ for (String path : pathStrings)
+ mIncludePaths[i++] = new Path(path);
+ mNeedReindexing = true;
+ }
+
+ @Override
+ public Map getSymbols() {
+ if (mSymbols == null)
+ mSymbols = new HashMap();
+ return mSymbols;
+ }
+
+ void setSymbols(Map symbols) {
+ this.mSymbols = symbols;
+ }
+
+ @Override
+ public IDiscoveredScannerInfoSerializable getSerializable() {
+ return null;
+ }
+
+ public void update(IProgressMonitor monitor) throws CoreException {
+ if (!needUpdating())
+ return;
+
+ new SGXSDKDiscoveryUpdater(this).runUpdate(monitor);
+
+ if (mIncludePaths != null && mSymbols != null) {
+ recordUpdate();
+ save();
+ }
+ }
+
+ private boolean needUpdating() {
+
+
+ if (mLastUpdate == IFile.NULL_STAMP) {
+ return true;
+ }
+
+ return mProject.getFile(LINUX_MK).getLocalTimeStamp() > mLastUpdate;
+ }
+
+ private void recordUpdate() {
+ mLastUpdate = mProject.getFile(LINUX_MK).getLocalTimeStamp();
+ }
+
+ public void delete() {
+ mLastUpdate = IFile.NULL_STAMP;
+ }
+
+ private File getInfoFile() {
+ File stateLoc = Activator.getDefault().getStateLocation().toFile();
+ return new File(stateLoc, mProject.getName() + ".pathInfo"); //$NON-NLS-1$
+ }
+
+ private void save() {
+ try {
+ File infoFile = getInfoFile();
+ infoFile.getParentFile().mkdirs();
+ PrintStream out = new PrintStream(infoFile);
+
+ out.print("t,"); //$NON-NLS-1$
+ out.print(mLastUpdate);
+ out.println();
+
+ for (IPath include : mIncludePaths) {
+ out.print("i,"); //$NON-NLS-1$
+ out.print(include.toPortableString());
+ out.println();
+ }
+
+ for (Entry symbol : mSymbols.entrySet()) {
+ out.print("d,"); //$NON-NLS-1$
+ out.print(symbol.getKey());
+ out.print(","); //$NON-NLS-1$
+ out.print(symbol.getValue());
+ out.println();
+ }
+
+ out.close();
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+
+ }
+
+ private void load() {
+ try {
+ File infoFile = getInfoFile();
+ if (!infoFile.exists())
+ return;
+
+ long timestamp = IFile.NULL_STAMP;
+ List includes = new ArrayList();
+ Map defines = new HashMap();
+
+ BufferedReader reader = new BufferedReader(new FileReader(infoFile));
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ switch (line.charAt(0)) {
+ case 't':
+ timestamp = Long.valueOf(line.substring(2));
+ break;
+ case 'i':
+ includes.add(Path.fromPortableString(line.substring(2)));
+ break;
+ case 'd':
+ int n = line.indexOf(',', 2);
+ if (n == -1)
+ defines.put(line.substring(2), ""); //$NON-NLS-1$
+ else
+ defines.put(line.substring(2, n), line.substring(n + 1));
+ break;
+ }
+ }
+ reader.close();
+
+ mLastUpdate = timestamp;
+ mIncludePaths = includes.toArray(new IPath[includes.size()]);
+ mSymbols = defines;
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveryUpdater.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveryUpdater.java
new file mode 100644
index 0000000000..4c10fccdcc
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveryUpdater.java
@@ -0,0 +1,310 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.discovery;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.managedbuilder.core.IBuilder;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+import com.intel.sgx.Activator;
+import com.intel.sgx.build.SGXSDKCommandLauncher;
+
+/*
+ * This code has been taken from the NDK plugin for Linux. If there is an update to this code there, then refactor this code.
+ */
+public class SGXSDKDiscoveryUpdater {
+ private final SGXSDKDiscoveredPathInfo mPathInfo;
+ private final IProject mProject;
+
+ private boolean mCPlusPlus = false;
+ private String mCommand;
+ private List mArguments = new ArrayList();
+
+ public SGXSDKDiscoveryUpdater(SGXSDKDiscoveredPathInfo pathInfo) {
+ mPathInfo = pathInfo;
+ mProject = pathInfo.getProject();
+ }
+
+ public void runUpdate(IProgressMonitor monitor) throws CoreException {
+ try {
+ // Run make -nB to get the list of commands
+ IPath commandPath = new Path("make"); //$NON-NLS-1$
+ String[] args = {"-f", "sgx/Makefile", "-n", "-B" }; //$NON-NLS-1$
+ String[] env = calcEnvironment();
+ File projectDir = new File(mProject.getLocationURI());
+ IPath changeToDirectory = new Path(projectDir.getAbsolutePath());
+ Process proc = new SGXSDKCommandLauncher().execute(commandPath, args, env,changeToDirectory, monitor);
+ if (proc == null) {
+ return;
+ }
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ String line = reader.readLine();
+ while (line != null) {
+ checkBuildLine(line);
+ line = reader.readLine();
+ }
+
+ if (mCommand == null) {
+ return;
+ }
+
+ // Run the unique commands with special gcc options to extract the
+ // symbols and paths
+ // -E -P -v -dD
+ mArguments.add("-E"); //$NON-NLS-1$
+ mArguments.add("-P"); //$NON-NLS-1$
+ mArguments.add("-v"); //$NON-NLS-1$
+ mArguments.add("-dD"); //$NON-NLS-1$
+
+ URL url = Activator.findFile(new Path("discovery/" + (mCPlusPlus ? "test.cpp" : "test.c"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ File testFile = new File(FileLocator.toFileURL(url).toURI());
+ String testFileName = testFile.getAbsolutePath().replace('\\', '/');
+ mArguments.add(testFileName);
+
+ args = mArguments.toArray(new String[mArguments.size()]);
+ proc = new SGXSDKCommandLauncher().execute(new Path(mCommand), args, env,changeToDirectory, monitor);
+
+ final InputStream errStream = proc.getErrorStream();
+ new Thread() {
+ @Override
+ public void run() {
+ checkIncludes(errStream);
+ };
+ }.start();
+
+ checkDefines(proc.getInputStream());
+ } catch (IOException e) {
+ throw new CoreException(Activator.newStatus(e));
+ } catch (URISyntaxException e) {
+ throw new CoreException(Activator.newStatus(e));
+ }
+ }
+
+ private String[] calcEnvironment() throws CoreException {
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(mProject);
+ IBuilder builder = info.getDefaultConfiguration().getBuilder();
+ HashMap envMap = new HashMap();
+ if (builder.appendEnvironment()) {
+ ICConfigurationDescription cfgDes = ManagedBuildManager.getDescriptionForConfiguration(builder.getParent().getParent());
+ IEnvironmentVariableManager mngr = CCorePlugin.getDefault().getBuildEnvironmentManager();
+ IEnvironmentVariable[] vars = mngr.getVariables(cfgDes, true);
+ for (IEnvironmentVariable var : vars) {
+ envMap.put(var.getName(), var.getValue());
+ }
+ }
+ // Add variables from build info
+ Map builderEnv = builder.getExpandedEnvironment();
+ if (builderEnv != null)
+ envMap.putAll(builderEnv);
+ List strings = new ArrayList(envMap.size());
+ for (Entry entry : envMap.entrySet()) {
+ StringBuffer buffer = new StringBuffer(entry.getKey());
+ buffer.append('=').append(entry.getValue());
+ strings.add(buffer.toString());
+ }
+ return strings.toArray(new String[strings.size()]);
+ }
+
+ private static class Line {
+ private final String line;
+ private int pos;
+
+ public Line(String line) {
+ this.line = line;
+ }
+
+ public Line(String line, int pos) {
+ this(line);
+ this.pos = pos;
+ }
+
+ public String getToken() {
+ skipWhiteSpace();
+ if (pos == line.length())
+ return null;
+
+ int start = pos;
+ boolean inQuote = false;
+
+ while (true) {
+ char c = line.charAt(pos);
+ if (c == ' ') {
+ if (!inQuote)
+ return line.substring(start, pos);
+ } else if (c == '"') {
+ inQuote = !inQuote;
+ }
+
+ if (++pos == line.length())
+ return null;
+ }
+
+ }
+
+ private String getRemaining() {
+ if (pos == line.length())
+ return null;
+
+ skipWhiteSpace();
+ String rc = line.substring(pos);
+ pos = line.length();
+ return rc;
+ }
+
+ private void skipWhiteSpace() {
+ while (true) {
+ if (pos == line.length())
+ return;
+ char c = line.charAt(pos);
+ if (c == ' ')
+ pos++;
+ else
+ return;
+ }
+ }
+ }
+
+ private void checkBuildLine(String text) {
+ Line line = new Line(text);
+ String cmd = line.getToken();
+ if (cmd == null) {
+ return;
+ } else if (cmd.endsWith("g++")) { //$NON-NLS-1$
+ if (mCommand == null || !mCPlusPlus) {
+ mCommand = cmd;
+ mCPlusPlus = true;
+ }
+ gatherOptions(line);
+ } else if (cmd.endsWith("gcc")) { //$NON-NLS-1$
+ if (mCommand == null){
+ mCommand = cmd;
+ }
+ gatherOptions(line);
+ }
+
+ }
+
+ private void gatherOptions(Line line) {
+ for (String option = line.getToken(); option != null; option = line.getToken()) {
+ if (option.startsWith("-")) { //$NON-NLS-1$
+ // only look at options
+ if (option.equals("-I")) { //$NON-NLS-1$
+ String dir = line.getToken();
+ if (dir != null)
+ addArg(option + dir);
+ } else if (option.startsWith("-I")) { //$NON-NLS-1$
+ addArg(option);
+ } else if (option.equals("-D")) { //$NON-NLS-1$
+ String def = line.getToken();
+ if (def != null)
+ addArg(option + def);
+ } else if (option.startsWith("-D")) { //$NON-NLS-1$
+ addArg(option);
+ } else if (option.startsWith("-f")) { //$NON-NLS-1$
+ addArg(option);
+ } else if (option.startsWith("-m")) { //$NON-NLS-1$
+ addArg(option);
+ } else if (option.startsWith("--sysroot")) { //$NON-NLS-1$
+ addArg(option);
+ }
+ }
+ }
+ }
+
+ private void addArg(String arg) {
+ if (!mArguments.contains(arg))
+ mArguments.add(arg);
+ }
+
+ private void checkIncludes(InputStream in) {
+ try {
+ List includes = new ArrayList();
+ boolean inIncludes1 = false;
+ boolean inIncludes2 = false;
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ String line = reader.readLine();
+ while (line != null) {
+ if (!inIncludes1) {
+ if (line.equals("#include \"...\" search starts here:")) //$NON-NLS-1$
+ inIncludes1 = true;
+ } else {
+ if (!inIncludes2) {
+ if (line.equals("#include <...> search starts here:")) //$NON-NLS-1$
+ inIncludes2 = true;
+ else
+ includes.add(line.trim());
+ } else {
+ if (line.equals("End of search list.")) { //$NON-NLS-1$
+ mPathInfo.setIncludePaths(includes);
+ } else {
+ includes.add(line.trim());
+ }
+ }
+ }
+ line = reader.readLine();
+ }
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+ }
+
+ private void checkDefines(InputStream in) {
+ try {
+ Map defines = new HashMap();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ String line = reader.readLine();
+ while (line != null) {
+ if (line.startsWith("#define")) { //$NON-NLS-1$
+ Line l = new Line(line, 7);
+ String var = l.getToken();
+ if (var == null)
+ continue;
+ String value = l.getRemaining();
+ if (value == null)
+ value = ""; //$NON-NLS-1$
+ defines.put(var, value);
+ }
+ line = reader.readLine();
+ }
+ mPathInfo.setSymbols(defines);
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKScannerInfoCollector.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKScannerInfoCollector.java
new file mode 100644
index 0000000000..fb21bff5cf
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKScannerInfoCollector.java
@@ -0,0 +1,103 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.discovery;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo;
+import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector3;
+import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollectorCleaner;
+import org.eclipse.cdt.make.core.scannerconfig.InfoContext;
+import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
+import org.eclipse.cdt.managedbuilder.scannerconfig.IManagedScannerInfoCollector;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/*
+ * This code has been taken from the NDK plugin for Linux. If there is an update to this code there, then refactor this code.
+ */
+public class SGXSDKScannerInfoCollector implements IScannerInfoCollector3,IScannerInfoCollectorCleaner,IManagedScannerInfoCollector{
+
+ private SGXSDKDiscoveredPathInfo sgxPathInfo;
+
+ @Override
+ public void setProject(IProject project) {
+ throw new Error("Not implemented");
+ }
+
+ @Override
+ public void updateScannerConfiguration(IProgressMonitor monitor)
+ throws CoreException {
+ sgxPathInfo.update(monitor);
+ }
+
+ @Override
+ public IDiscoveredPathInfo createPathInfoObject() {
+ return sgxPathInfo;
+ }
+
+ @Override
+ public void contributeToScannerConfig(Object resource, @SuppressWarnings("rawtypes") Map scannerInfo) {
+ throw new Error("Not implemented");
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public List getCollectedScannerInfo(Object resource, ScannerInfoTypes type) {
+ throw new Error("Not implemented");
+ }
+
+ @Override
+ public Map getDefinedSymbols() {
+ throw new Error("Not implemented");
+ }
+
+ @Override
+ public List getIncludePaths() {
+ throw new Error("Not implemented");
+ }
+
+ @Override
+ public void deleteAllPaths(IResource resource) {
+ throw new Error("Not implemented");
+ }
+
+ @Override
+ public void deleteAllSymbols(IResource resource) {
+ throw new Error("Not implemented");
+ }
+
+ @Override
+ public void deletePath(IResource resource, String path) {
+ throw new Error("Not implemented");
+ }
+
+ @Override
+ public void deleteSymbol(IResource resource, String symbol) {
+ throw new Error("Not implemented");
+ }
+
+ @Override
+ public void deleteAll(IResource resource) {
+ sgxPathInfo.delete();
+ }
+
+ @Override
+ public void setInfoContext(InfoContext context) {
+ sgxPathInfo = new SGXSDKDiscoveredPathInfo(context.getProject());
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddEnclave.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddEnclave.java
new file mode 100644
index 0000000000..e998de690b
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddEnclave.java
@@ -0,0 +1,213 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import com.intel.sgx.Activator;
+import com.intel.sgx.dialogs.AddEnclaveFileDialog;
+import com.intel.sgx.preferences.PreferenceConstants;
+
+public class AddEnclave extends ModuleCreationBaseHandler implements IHandler {
+
+ public String edlFilename = "";
+ public String linuxMakePath = "";
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ String edlBasename,linuxPath,enclaveBasename;
+ IProject project = null;
+
+ // Display display = Display.getCurrent();
+ // Shell shell = new Shell(display);
+ Shell shell = null;
+ AddEnclaveFileDialog dialog = new AddEnclaveFileDialog(shell, this);
+ if (dialog.open() != InputDialog.OK) {
+ return null;
+ }
+
+ if((edlFilename.isEmpty())){
+ System.err.println("No Enclave selected to Import.");
+ return null;
+ }
+
+ edlBasename = edlFilename;
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ Object element = null;
+ if (selection instanceof IStructuredSelection) {
+ element = ((IStructuredSelection) selection).getFirstElement();
+ if (element instanceof IResource) {
+ project = ((IResource) element).getProject();
+ }
+ }
+ if (!project.exists()) {
+ System.err.println("Error: Project not found");
+ return null;
+ }
+
+ for (IConfigurationElement i : Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.core.resources.projectNature")){
+ }
+
+
+
+
+ IPath linuxMkRelPath = (Path.fromOSString(linuxMakePath)).makeRelativeTo(project.getLocation().append("sgx").append("enclave_"+edlBasename));
+
+
+ if(linuxMkRelPath.removeLastSegments(1).lastSegment().toString().equalsIgnoreCase("sgx")){
+ linuxPath = linuxMkRelPath.removeLastSegments(3).toOSString();
+ enclaveBasename = linuxMkRelPath.removeLastSegments(2).lastSegment().toString();
+ }
+
+ else{
+ linuxPath = linuxMkRelPath.removeLastSegments(2).toOSString();
+ enclaveBasename = linuxMkRelPath.removeLastSegments(1).lastSegment().toString();
+ }
+
+ IProgressMonitor monitor = new NullProgressMonitor();
+ TemplateCore template = null;
+ if(isCPProject(project))
+ if(dialog.generateApp())
+ {
+ template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveC++WithSample");
+ }
+ else
+ {
+ template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveC++Minimal");
+ }
+ else
+ if(dialog.generateApp())
+ {
+ template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveCWithSample");
+ }
+ else
+ {
+ template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveCMinimal");
+ }
+
+ Map valueStore = template.getValueStore();
+ valueStore.put("projectName", project.getName());
+ valueStore.put("workspacePath", linuxPath);
+ valueStore.put("baseName", enclaveBasename);
+ valueStore.put("enclaveName",edlFilename);
+ valueStore.put("EnclaveName",capitalize(edlFilename));
+ valueStore.put("ENCLAVENAME",edlFilename.toUpperCase());
+ valueStore.put("SdkPathFromPlugin", Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH));
+
+ IStatus[] statuses = template.executeTemplateProcesses(monitor, false);
+ for(IStatus e: statuses)
+ {
+ }
+
+ ManagedBuildManager.saveBuildInfo(project, true);
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ Activator.log(e);
+ e.printStackTrace();
+ }
+
+
+ return null;
+ }
+
+ private String capitalize(final String line) {
+ return Character.toUpperCase(line.charAt(0)) + line.substring(1);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ public void setFilename(String filename) {
+ edlFilename = filename;
+ }
+
+
+
+
+ public static void copyFile(File source, File dest) throws IOException {
+ byte[] bytes = new byte[4092];
+ if (source != null && dest != null) {
+ if (source.isFile()) {
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ try {
+ in = new FileInputStream(source);
+ out = new FileOutputStream(dest);
+ int len;
+ while ((len = in.read(bytes)) != -1) {
+ out.write(bytes, 0, len);
+ }
+ } catch (Exception e) {
+ Activator.log(e);
+ System.err.println("Error: " + e.toString());
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } finally {
+ if (out != null)
+ out.close();
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddSGXNature.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddSGXNature.java
new file mode 100644
index 0000000000..569b608adb
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddSGXNature.java
@@ -0,0 +1,163 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+//import org.eclipse.core.resources.IWorkspaceRunnable;
+//import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+//import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import com.intel.sgx.Activator;
+import com.intel.sgx.natures.SGXNature;
+
+public class AddSGXNature implements IHandler {
+
+ private IProject project;
+
+ public AddSGXNature() {
+ project = null;
+ }
+
+ @Override
+ public void addHandlerListener(IHandlerListener arg0) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ Object element = null;
+ if (selection instanceof IStructuredSelection) {
+ element = ((IStructuredSelection) selection).getFirstElement();
+ if (element instanceof IResource) {
+ project = ((IResource) element).getProject();
+ }
+ }
+ if (!project.exists()) {
+ System.err.println("Error: Project not found");
+ return null;
+ } else {
+ try {
+ TemplateCore template = TemplateEngine.getDefault().getTemplateById("AddSGXNature");
+
+ Map valueStore = template.getValueStore();
+ valueStore.put("projectName",project.getName());
+ valueStore.put("baseName",project.getName());
+
+ IProgressMonitor monitor = new NullProgressMonitor();
+ template.executeTemplateProcesses(monitor, false);
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ try{
+ IProjectDescription description = project.getDescription();
+ String[] natures = description.getNatureIds();
+
+ String[] newNatures = new String[natures.length + 1];
+ System.arraycopy(natures, 0, newNatures, 0, natures.length);
+ newNatures[natures.length] = SGXNature.NATURE_ID;
+ IStatus status = workspace.validateNatureSet(newNatures);
+
+ if (status.getCode() == IStatus.OK) {
+ description.setNatureIds(newNatures);
+ project.setDescription(description, null);
+ }
+
+ project.refreshLocal(IResource.DEPTH_ONE,null);
+ } catch(CoreException e){
+ Activator.log(e);
+ throw new InvocationTargetException(e);
+ }
+ } catch(InvocationTargetException e){
+ Activator.log(e);
+ e.printStackTrace();
+ }
+
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE,null);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener arg0) {
+ }
+
+ public static void copyFile(File source, File dest) throws IOException {
+ byte[] bytes = new byte[4092];
+ if (source != null && dest != null) {
+ if (source.isFile()) {
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ try {
+ in = new FileInputStream(source);
+ out = new FileOutputStream(dest);
+ int len;
+ while ((len = in.read(bytes)) != -1) {
+ out.write(bytes, 0, len);
+ }
+ } catch (Exception e) {
+ System.err.println("Error: " + e.toString());
+
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } finally {
+ if (out != null)
+ out.close();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddTrustedStaticLib.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddTrustedStaticLib.java
new file mode 100644
index 0000000000..efeeeedd3a
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddTrustedStaticLib.java
@@ -0,0 +1,193 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import com.intel.sgx.Activator;
+import com.intel.sgx.dialogs.AddTrustedStaticLibFileDialog;
+import com.intel.sgx.preferences.PreferenceConstants;
+
+public class AddTrustedStaticLib extends ModuleCreationBaseHandler implements IHandler {
+
+ public String edlFilename = "";
+ public String linuxMakePath = "";
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ String edlBasename,linuxPath,enclaveBasename;
+ IProject project = null;
+
+ // Display display = Display.getCurrent();
+ // Shell shell = new Shell(display);
+ Shell shell = null;
+ AddTrustedStaticLibFileDialog dialog = new AddTrustedStaticLibFileDialog(shell, this);
+ if (dialog.open() != InputDialog.OK) {
+ return null;
+ }
+
+ if((edlFilename.isEmpty() )){
+ System.err.println("No Enclave selected to Import.");
+ return null;
+ }
+
+ edlBasename = edlFilename;
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ Object element = null;
+ if (selection instanceof IStructuredSelection) {
+ element = ((IStructuredSelection) selection).getFirstElement();
+ if (element instanceof IResource) {
+ project = ((IResource) element).getProject();
+ }
+ }
+ if (!project.exists()) {
+ System.err.println("Error: Project not found");
+ return null;
+ }
+
+ for (IConfigurationElement i : Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.core.resources.projectNature")){
+ }
+
+
+
+
+ IPath linuxMkRelPath = (Path.fromOSString(linuxMakePath)).makeRelativeTo(project.getLocation().append("sgx").append("enclave_"+edlBasename));
+
+
+ if(linuxMkRelPath.removeLastSegments(1).lastSegment().toString().equalsIgnoreCase("sgx")){
+ linuxPath = linuxMkRelPath.removeLastSegments(3).toOSString();
+ enclaveBasename = linuxMkRelPath.removeLastSegments(2).lastSegment().toString();
+ }
+
+ else{
+ linuxPath = linuxMkRelPath.removeLastSegments(2).toOSString();
+ enclaveBasename = linuxMkRelPath.removeLastSegments(1).lastSegment().toString();
+ }
+
+ IProgressMonitor monitor = new NullProgressMonitor();
+ TemplateCore template = null;
+ if(isCPProject(project))
+ template = TemplateEngine.getDefault().getTemplateById("SGXTrustedStaticLibraryC++Minimal");
+ else
+ template = TemplateEngine.getDefault().getTemplateById("SGXTrustedStaticLibraryCMinimal");
+
+ Map valueStore = template.getValueStore();
+ valueStore.put("projectName", project.getName());
+ valueStore.put("workspacePath", linuxPath);
+ valueStore.put("baseName", enclaveBasename);
+ valueStore.put("enclaveName",edlFilename);
+ valueStore.put("EnclaveName",capitalize(edlFilename));
+ valueStore.put("ENCLAVENAME",edlFilename.toUpperCase());
+ valueStore.put("SdkPathFromPlugin", Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH));
+
+ IStatus[] statuses = template.executeTemplateProcesses(monitor, false);
+
+
+ ManagedBuildManager.saveBuildInfo(project, true);
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ Activator.log(e);
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private String capitalize(final String line) {
+ return Character.toUpperCase(line.charAt(0)) + line.substring(1);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ public void setFilename(String filename) {
+ edlFilename = filename;
+ }
+
+ public static void copyFile(File source, File dest) throws IOException {
+ byte[] bytes = new byte[4092];
+ if (source != null && dest != null) {
+ if (source.isFile()) {
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ try {
+ in = new FileInputStream(source);
+ out = new FileOutputStream(dest);
+ int len;
+ while ((len = in.read(bytes)) != -1) {
+ out.write(bytes, 0, len);
+ }
+ } catch (Exception e) {
+ Activator.log(e);
+ System.err.println("Error: " + e.toString());
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } finally {
+ if (out != null)
+ out.close();
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddUntrustedModule.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddUntrustedModule.java
new file mode 100644
index 0000000000..4ebf8da34c
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddUntrustedModule.java
@@ -0,0 +1,231 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Map;
+
+
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import com.intel.sgx.Activator;
+import com.intel.sgx.dialogs.AddUntrustedModuleDialog;
+import com.intel.sgx.preferences.PreferenceConstants;
+
+public class AddUntrustedModule extends ModuleCreationBaseHandler implements IHandler {
+
+ public String edlFilename = "";
+ public String libPath = "";
+ private IPath edlCanonicalFilename;
+ private IPath libCanonicalPathname;
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ String edlBasename,edlPath,linuxLibPath,modulePath,enclaveBasename;
+ IProject project = null;
+
+ //Display display = Display.getCurrent();
+ Shell shell = null;
+
+ AddUntrustedModuleDialog dialog = new AddUntrustedModuleDialog(shell, this);
+ if (dialog.open() != InputDialog.OK) {
+ return null;
+ }
+
+ if((edlFilename.isEmpty() && libPath.isEmpty())){
+ System.err.println("No Enclave selected to Import.");
+ return null;
+ }
+ if( edlFilename.isEmpty() ){
+ System.err.println("Edl File not selected.");
+ return null;
+ }
+ edlCanonicalFilename = Path.fromOSString(edlFilename);
+ if (!edlCanonicalFilename.getFileExtension().toLowerCase().equals("edl")) {
+ System.err.println("Error: EDL file extension = "+ edlCanonicalFilename.getFileExtension());
+ return null;
+ }
+ edlBasename = edlCanonicalFilename.removeFileExtension().lastSegment();
+
+
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ Object element = null;
+ if (selection instanceof IStructuredSelection) {
+ element = ((IStructuredSelection) selection).getFirstElement();
+ if (element instanceof IResource) {
+ project = ((IResource) element).getProject();
+ }
+ }
+ if (!project.exists()) {
+ System.err.println("Error: Project not found");
+ return null;
+ }
+
+ IPath targetRelPath = project.getProjectRelativePath().append("sgx").append("untrusted_" + edlBasename);
+
+ try {
+ for (int i = 1; i <= targetRelPath.segmentCount(); i++) {
+ IFolder subfolder = project.getFolder(targetRelPath.uptoSegment(i));
+
+ if (!subfolder.exists()) {
+ subfolder.create(true, true, null);
+ }
+ }
+ } catch (CoreException e) {
+ System.err.println("Error: Error creating enclave directory.");
+ Activator.log(e);
+ e.printStackTrace();
+ }
+
+ IPath edlRelPath = (Path.fromOSString(edlFilename)).makeRelativeTo(project.getLocation().append("sgx"));
+ edlPath = edlRelPath.toOSString();
+ IPath linuxLibRelPath = (Path.fromOSString(libPath)).makeRelativeTo(project.getLocation().append("sgx"));
+
+ if(linuxLibRelPath.removeLastSegments(1).lastSegment().toString().equalsIgnoreCase("sgx")){
+ linuxLibPath = linuxLibRelPath.removeLastSegments(3).toOSString();
+ modulePath = linuxLibRelPath.removeFirstSegments(linuxLibRelPath.segmentCount()-3).removeLastSegments(1).toOSString();
+ }
+ else if(linuxLibRelPath.removeLastSegments(1).lastSegment().toString().equalsIgnoreCase("src")){
+ linuxLibPath = linuxLibRelPath.removeLastSegments(3).toOSString();
+ modulePath = linuxLibRelPath.removeFirstSegments(linuxLibRelPath.segmentCount()-3).removeLastSegments(1).toOSString();
+ }
+ else{
+ linuxLibPath = linuxLibRelPath.removeLastSegments(2).toOSString();
+ modulePath = linuxLibRelPath.removeFirstSegments(linuxLibRelPath.segmentCount()-2).removeLastSegments(1).toOSString();
+ }
+
+ IProgressMonitor monitor = new NullProgressMonitor();
+ TemplateCore template = null;
+ if(isCPProject(project))
+ template = TemplateEngine.getDefault().getTemplateById("SGXUntrustedModuleC++Minimal");
+ else
+ template = TemplateEngine.getDefault().getTemplateById("SGXUntrustedModuleCMinimal");
+
+
+
+ Map valueStore = template.getValueStore();
+
+
+ valueStore.put("projectName", project.getName());
+ valueStore.put("sourcepath",linuxLibPath);
+ valueStore.put("edlPath", edlPath);
+ valueStore.put("baseName", edlBasename);
+ valueStore.put("workspacePath", linuxLibPath);//deprecate
+ valueStore.put("modPath", modulePath);
+ valueStore.put("ENCLAVENAME",edlBasename.toUpperCase());
+ valueStore.put("libPath",libPath);
+ valueStore.put("SdkPathFromPlugin", Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH));
+
+ IStatus[] statuses = template.executeTemplateProcesses(monitor, false);
+
+ try {
+ copyFile(new File(edlFilename), project.getLocation().append("sgx").append("untrusted_"+edlBasename).append(edlBasename+".edl").toFile());
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+
+
+ ManagedBuildManager.saveBuildInfo(project, true);
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ Activator.log(e);
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ public void setFilename(String filename) {
+ edlFilename = filename;
+ }
+
+ public static void copyFile(File source, File dest) throws IOException {
+ byte[] bytes = new byte[4092];
+ if (source != null && dest != null) {
+ if (source.isFile()) {
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ try {
+ in = new FileInputStream(source);
+ out = new FileOutputStream(dest);
+ int len;
+ while ((len = in.read(bytes)) != -1) {
+ out.write(bytes, 0, len);
+ }
+ } catch (Exception e) {
+ Activator.log(e);
+ System.err.println("Error: " + e.toString());
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } finally {
+ if (out != null)
+ out.close();
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/EnclaveConfigHandler.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/EnclaveConfigHandler.java
new file mode 100644
index 0000000000..fffa912c4f
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/EnclaveConfigHandler.java
@@ -0,0 +1,156 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngine;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import com.intel.sgx.Activator;
+import com.intel.sgx.dialogs.EnclaveConfigDialog;
+import com.intel.sgx.dialogs.SGXDialogBase;
+
+public class EnclaveConfigHandler extends SGXHandler {
+
+ public String prodId;
+ public String isvSvn;
+ public String threadStackSize;
+ public String globalHeapSize;
+ public String tcsNum;
+ public String tcsPolicy;
+ public String disableDebug;
+ private IFile configPath;
+
+ @Override
+ public void addHandlerListener(IHandlerListener arg0) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object executeSGXStuff() throws CancelException, ErrorException {
+
+ FilteredResourcesSelectionDialog d = SGXDialogBase
+ .dialogForConfig(shell);
+ d.setTitle("Select Config File");
+ if (d.open() != Dialog.OK) {
+ cancel();
+ }
+
+ configPath = ((IFile) d.getResult()[0]);
+
+ readConfig(configPath.getLocation());
+ EnclaveConfigDialog dialog = new EnclaveConfigDialog(shell, this);
+ if (dialog.open() != InputDialog.OK) {
+ return null;
+ }
+ writeConfig();
+ refreshProject();
+
+ return null;
+ }
+
+ protected void writeConfig() {
+ IProgressMonitor monitor = new NullProgressMonitor();
+ TemplateCore template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveConfig");
+
+ Map valueStore = template.getValueStore();
+ valueStore.put("projectName", project.getName());
+ valueStore.put("configFile", configPath.getProjectRelativePath().toOSString());
+ valueStore.put("ProdID", this.prodId);
+ valueStore.put("IsvSvn", this.isvSvn);
+ valueStore.put("ThreadStackSize", this.threadStackSize);
+ valueStore.put("GlobalHeapSize", this.globalHeapSize);
+ valueStore.put("TcsNumber", this.tcsNum);
+ valueStore.put("TcsPolicy", this.tcsPolicy);
+ valueStore.put("DisableDebug", this.disableDebug);
+ IStatus[] result = template.executeTemplateProcesses(monitor, true);
+
+ for (IStatus status: result) {
+ }
+ }
+
+
+
+ protected void readConfig(IPath configPath) throws ErrorException {
+
+ try {
+ String xmlFile = configPath.toString();
+ File configFile = new File(xmlFile);
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dBuilder;
+ dBuilder = dbFactory.newDocumentBuilder();
+ Document doc = dBuilder.parse(configFile);
+ doc.getDocumentElement().normalize();
+
+ NodeList nList = doc.getElementsByTagName("EnclaveConfiguration");
+ Node nNode = nList.item(0);
+
+ if (nNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element e = (Element) nNode;
+ this.prodId = e.getElementsByTagName("ProdID").item(0)
+ .getTextContent();
+ this.isvSvn = e.getElementsByTagName("ISVSVN").item(0)
+ .getTextContent();
+ this.threadStackSize = e.getElementsByTagName("StackMaxSize")
+ .item(0).getTextContent();
+ this.globalHeapSize = e.getElementsByTagName("HeapMaxSize")
+ .item(0).getTextContent();
+ this.tcsNum = e.getElementsByTagName("TCSNum").item(0)
+ .getTextContent();
+ this.tcsPolicy = e.getElementsByTagName("TCSPolicy").item(0)
+ .getTextContent();
+ this.disableDebug = e.getElementsByTagName("DisableDebug")
+ .item(0).getTextContent();
+ }
+
+ } catch (ParserConfigurationException e) {
+ Activator.log(e);
+ e.printStackTrace();
+ quitWithError("Could not parse '"+configPath.toOSString()+"'");
+ } catch (SAXException e) {
+ Activator.log(e);
+ e.printStackTrace();
+ quitWithError("Could not parse '"+configPath.toOSString()+"'");
+ } catch (IOException e) {
+ Activator.log(e);
+ e.printStackTrace();
+ quitWithError("Could not read'"+configPath.toOSString()+"'");
+ }
+
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/ModuleCreationBaseHandler.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/ModuleCreationBaseHandler.java
new file mode 100644
index 0000000000..708208c6cb
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/ModuleCreationBaseHandler.java
@@ -0,0 +1,39 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+
+public class ModuleCreationBaseHandler {
+ public boolean isCPProject(IProject project)
+ {
+ boolean isCPProject = false;
+ IProjectDescription description;
+ try {
+ description = project.getDescription();
+ String[] natures = description.getNatureIds();
+ for(String nature: natures){
+ if(nature.equals("org.eclipse.cdt.core.ccnature"))
+ isCPProject = true;
+ }
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return isCPProject;
+
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/RemoveEnclave.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/RemoveEnclave.java
new file mode 100644
index 0000000000..058e622996
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/RemoveEnclave.java
@@ -0,0 +1,169 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import com.intel.sgx.Activator;
+import com.intel.sgx.dialogs.RemoveEnclaveFileDialog;
+
+public class RemoveEnclave implements IHandler {
+
+ public String edlFilename = "";
+ private IPath edlCanonicalFilename;
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ String edlBasename;
+ IProject project = null;
+
+ // Display display = Display.getCurrent();
+ // Shell shell = new Shell(display);
+
+ RemoveEnclaveFileDialog dialog = new RemoveEnclaveFileDialog(null, this);
+
+ if (dialog.open() != InputDialog.OK) {
+ return null;
+ }
+
+ edlCanonicalFilename = Path.fromOSString(edlFilename);
+ edlBasename = edlCanonicalFilename.lastSegment();
+
+ if(edlBasename.isEmpty()){
+ return null;
+ }
+
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ Object element = null;
+ if(selection instanceof IStructuredSelection) {
+ element = ((IStructuredSelection)selection).getFirstElement();
+ if (element instanceof IResource) {
+ project= ((IResource)element).getProject();
+ }
+ }
+ if (!project.exists()) {
+ System.err.println("Error: Project not found");
+ return null;
+ }
+
+ IPath targetRelPath = project.getProjectRelativePath().append("sgx").append("enclave_" + edlBasename);
+
+ try {
+ for (int i=1;i<=targetRelPath.segmentCount();i++) {
+ IFolder subfolder = project.getFolder(targetRelPath.uptoSegment(i));
+
+ if (subfolder.exists()){
+ if(subfolder.getProjectRelativePath().toOSString().contains("enclave_"+edlBasename)){
+ subfolder.delete(true, true, null);
+ break;
+ }
+ }
+ }
+ targetRelPath = project.getProjectRelativePath().append("sgx").append(edlBasename);
+ for (int i=1;i<=targetRelPath.segmentCount();i++) {
+ IFolder subfolder = project.getFolder(targetRelPath.uptoSegment(i));
+
+ if (subfolder.exists()){
+ if(subfolder.getProjectRelativePath().toOSString().contains(edlBasename)){
+ subfolder.delete(true, true, null);
+ break;
+ }
+ }
+ }
+ } catch (Exception e) {
+ Activator.log(e);
+ }
+
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ Activator.log(e);
+ } catch (IllegalArgumentException e){
+ Activator.log(e);
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ public static void copyFile(File source, File dest) throws IOException {
+ byte[] bytes = new byte[4092];
+ if (source != null && dest != null) {
+ if (source.isFile()) {
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ try {
+ in = new FileInputStream(source);
+ out = new FileOutputStream(dest);
+ int len;
+ while ((len = in.read(bytes)) != -1) {
+ out.write(bytes, 0, len);
+ }
+ } catch (Exception e) {
+ System.err.println("Error: " + e.toString());
+ Activator.log(e);
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } finally {
+ if (out != null)
+ out.close();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXHandler.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXHandler.java
new file mode 100644
index 0000000000..bfd5bcb551
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXHandler.java
@@ -0,0 +1,206 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.swing.JOptionPane;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Utility base class for all Handlers The derived classes must implement
+ * executeSgxStuff() instead of execute(). The user may call methods cancel(),
+ * quitWithError() & info()
+ *
+ * @author mlutescu
+ *
+ */
+public abstract class SGXHandler implements IHandler {
+
+ public String projectPath = null;
+ protected IProject project;
+ protected Shell shell;
+
+ /**
+ * Throwing this IS an error. Means that the process can't continue
+ *
+ * @author mlutescu
+ *
+ */
+ static protected class ErrorException extends Exception {
+
+ public ErrorException(String message) {
+ super(message);
+ }
+
+ }
+
+ /**
+ * Throwing this is not an error; just signals stop of execution because the
+ * user cancels
+ *
+ * @author mlutescu
+ *
+ */
+ static protected class CancelException extends Exception {
+
+ public CancelException() {
+ super();
+ }
+
+ }
+
+ @Override
+ public final Object execute(ExecutionEvent event) throws ExecutionException {
+ try {
+ initializeShell();
+ initializeProject(event);
+ return executeSGXStuff();
+ } catch (ErrorException e) {
+ e.printStackTrace();
+ } catch (CancelException e) {
+ // do nothing by design ; it's Ok to not handle this exception.
+ }
+ return null;
+ }
+
+ protected abstract Object executeSGXStuff() throws ErrorException,
+ CancelException;
+
+ public SGXHandler() {
+ super();
+ }
+
+ public static void copyFile(File source, File dest) throws ErrorException {
+ byte[] bytes = new byte[4092];
+ if (source != null && dest != null) {
+ if (source.isFile()) {
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ try {
+ in = new FileInputStream(source);
+ out = new FileOutputStream(dest);
+ int len;
+ while ((len = in.read(bytes)) != -1) {
+ out.write(bytes, 0, len);
+ }
+ } catch (IOException e) {
+ System.err.println("Error: " + e.toString());
+ quitWithError("Could not copy from\n" + "'"
+ + source.getAbsolutePath() + "'\n" + "to\n" + "'"
+ + dest.getAbsolutePath());
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected static void quitWithError(String message) throws ErrorException {
+ JOptionPane.showMessageDialog(null, message, "Two Step Enclave Sign",
+ JOptionPane.ERROR_MESSAGE);
+ throw new ErrorException(message);
+ }
+
+ static protected void cancel() throws CancelException {
+ throw new CancelException();
+ }
+
+ protected void initializeProject(ExecutionEvent event)
+ throws ErrorException {
+ project = null;
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ Object element = null;
+ if (selection instanceof IStructuredSelection) {
+ element = ((IStructuredSelection) selection).getFirstElement();
+ if (element instanceof IResource) {
+ project = ((IResource) element).getProject();
+ }
+ }
+
+ if (!project.exists()) {
+ quitWithError("Project not found");
+ }
+
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener arg0) {
+ }
+
+ @Override
+ public void addHandlerListener(IHandlerListener arg0) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ protected void initializeShell() {
+ shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ }
+
+ protected void refreshProject() throws ErrorException {
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e1) {
+ quitWithError(e1.getLocalizedMessage());
+ }
+ }
+
+ protected void info(String windowName, String message) {
+ JOptionPane.showMessageDialog(null, message,windowName,
+ JOptionPane.INFORMATION_MESSAGE);
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXSDKWizardHandler.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXSDKWizardHandler.java
new file mode 100644
index 0000000000..b445c5ea8a
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXSDKWizardHandler.java
@@ -0,0 +1,38 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import org.eclipse.cdt.managedbuilder.core.IToolChain;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.ui.wizards.STDWizardHandler;
+
+public class SGXSDKWizardHandler extends STDWizardHandler {
+
+ public SGXSDKWizardHandler() {
+ super(null, null);
+ }
+
+
+ @Override
+ public IToolChain[] getSelectedToolChains() {
+ IToolChain[] tcs = ManagedBuildManager.getRealToolChains();
+ for (IToolChain tc : tcs) {
+ if (tc.getId().equals("com.intel.sgx.SGXtoolChain"))
+ return new IToolChain[] {
+ tc
+ };
+ }
+ return super.getSelectedToolChains();
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignHandlerBase.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignHandlerBase.java
new file mode 100644
index 0000000000..59ae2eb7a4
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignHandlerBase.java
@@ -0,0 +1,196 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import com.intel.sgx.preferences.PreferenceConstants;
+
+public abstract class TwoStepSignHandlerBase extends SGXHandler {
+
+ public String hashFile = null;
+ public String configFile = null;
+ public String enclaveFile = null;
+ public String externalSignPublicKeyFile = null;
+ public String externallySignedHashFile = null;
+ public String outputSignedEnclaveFile = null;
+
+ protected File signtool;
+
+ public TwoStepSignHandlerBase() {
+ super();
+ }
+
+ protected void executeGenData() throws ErrorException {
+ validateConfigFile();
+ validateEnclaveFile();
+
+ refreshProject();
+ executeSignTool(new String[] { "gendata",
+ "-enclave", enclaveFile,
+ "-config", configFile,
+ "-out", hashFile });
+ refreshProject();
+
+ validateHashFile();
+
+ }
+
+ protected void executeCatSig() throws ErrorException {
+ validateEnclaveFile();
+ validateConfigFile();
+ validateHashFile();
+
+ validateExternalSignPublicKeyFile();
+ validateExternallySignedHashFile();
+
+ executeSignTool("catsig",
+ // enclave data:
+ "-enclave", enclaveFile,
+ "-config", configFile,
+ // previously generated:
+ "-unsigned", hashFile,
+ // externally generated
+ "-key", externalSignPublicKeyFile,
+ "-sig", externallySignedHashFile,
+ // output
+ "-out", outputSignedEnclaveFile
+
+ );
+
+ refreshProject();
+
+ validateOutputSignedEnclaveFile();
+
+ info("Two Step Enclave Sign","Enclave signed successfully !");
+ }
+
+ void initializeSigntool() throws ErrorException {
+ signtool = PreferenceConstants.getSDKDescriptor().getSignerPath();
+ if (!signtool.exists() || signtool.isDirectory()) {
+ quitWithError("Error generating hash! Sign Tool Not Found !\n Please make sure to have written in the box the value for SGX SDK Directory in Window->Preferences->SGX Preferences. \n Usually the path is in /opt/intel/sgxsdk/" );
+ }
+
+ }
+
+ protected void validateEnclaveFile() throws ErrorException {
+ File enclave = new File(enclaveFile);
+ if (!enclave.exists() || enclave.isDirectory()) {
+ quitWithError("Error generating hash! Unsigned Enclave File Not Found! Try building the enclave first");
+ }
+ }
+
+ protected void validateConfigFile() throws ErrorException {
+ if (configFile == null || configFile.isEmpty()) {
+ quitWithError("Error Enclave Configuration File Not Found !");
+ }
+ File config = new File(configFile);
+ if (!config.exists() || config.isDirectory()) {
+ quitWithError("Enclave Config File Not Found !");
+ }
+ }
+
+ protected void validateExternallySignedHashFile() throws ErrorException {
+ if (externallySignedHashFile == null || externallySignedHashFile.isEmpty()) {
+ quitWithError("Error signing enclave! Signature File Not Found !");
+ }
+
+ File signature = new File(externallySignedHashFile);
+ if (!signature.exists() || signature.isDirectory()) {
+ quitWithError("Error signing enclave! Signature File Not Found !");
+ }
+ }
+
+ protected void validateExternalSignPublicKeyFile() throws ErrorException {
+ if (externalSignPublicKeyFile == null || externalSignPublicKeyFile.isEmpty()) {
+ quitWithError("Public Key File Not Found !");
+ }
+
+ File publickkey = new File(externalSignPublicKeyFile);
+ if (!publickkey.exists() || publickkey.isDirectory()) {
+ quitWithError("Error signing enclave! Public Key File Not Found !");
+ }
+ }
+
+ private void validateOutputSignedEnclaveFile() throws ErrorException {
+ if(outputSignedEnclaveFile == null || outputSignedEnclaveFile.isEmpty())
+ {
+ quitWithError("Output Signed File Not Found !");
+ }
+ File outputSignedEnclave = new File(outputSignedEnclaveFile);
+ if(!outputSignedEnclave.exists() || outputSignedEnclave.isDirectory())
+ {
+ quitWithError("Output Signed File Not Found !");
+ }
+
+ // TODO Auto-generated method stub
+
+ }
+
+ protected void validateHashFile() throws ErrorException {
+ if(hashFile == null || hashFile.isEmpty())
+ {
+ quitWithError("Hash File Not Found !");
+ }
+ File hash = new File(hashFile);
+ if(!hash.exists() || hash.isDirectory())
+ {
+ quitWithError("Hash File Not Found !");
+ }
+ }
+
+
+ protected void executeSignTool(String... args) throws ErrorException {
+
+ Process q;
+ try {
+
+ String[] allArgs = new String[args.length+1];
+ allArgs[0] = signtool.getAbsolutePath();
+ System.arraycopy(args, 0, allArgs, 1, args.length);
+
+ for (String arg : args){
+ }
+ String fullOutput = "";
+ q = Runtime.getRuntime().exec(allArgs);
+
+ BufferedReader stdInput = new BufferedReader(new InputStreamReader(
+ q.getInputStream()));
+ BufferedReader stdErr = new BufferedReader(new InputStreamReader(
+ q.getErrorStream()));
+ String s = null;
+ while ((s = stdInput.readLine()) != null) {
+ }
+ String[] out = new String[20];
+ int i = 0;
+ while ((out[i] = stdErr.readLine()) != null) {
+ fullOutput += out[i]+"\n";
+ i++;
+ }
+ String result = out[i - 1];
+
+ if (!result.equals("Succeed.")) {
+ // quitWithError("Error generating hash! " + out[i - 2]);
+ quitWithError("Error generating hash! " + fullOutput);
+ }
+ } catch (IOException e) {
+ quitWithError(e.getLocalizedMessage());
+ }
+
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep1.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep1.java
new file mode 100644
index 0000000000..cb2f3649bd
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep1.java
@@ -0,0 +1,74 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import org.eclipse.jface.dialogs.InputDialog;
+
+import com.intel.sgx.dialogs.SGXDialogBase;
+import com.intel.sgx.dialogs.TwoStepSignStep1Dialog1;
+import com.intel.sgx.dialogs.TwoStepSignStep1Dialog2;
+import com.intel.sgx.dialogs.TwoStepSignStep1Dialog3;
+
+// Generate Hash
+public class TwoStepSignStep1 extends TwoStepSignHandlerBase {
+
+ public TwoStepSignStep1() {
+ }
+
+ @Override
+ protected Object executeSGXStuff() throws ErrorException, CancelException {
+
+ initializeSigntool();
+
+ showDialog1();
+ showDialog2();
+ showDialog3();
+ return null;
+ }
+
+ private void showDialog1() throws CancelException, ErrorException {
+
+ TwoStepSignStep1Dialog1 dialog1 = new TwoStepSignStep1Dialog1(shell, this);
+ if (dialog1.open() != InputDialog.OK) {
+ cancel();
+ }
+
+ executeGenData();
+
+ }
+
+ private void showDialog2() throws CancelException {
+ TwoStepSignStep1Dialog2 dialog2 = new TwoStepSignStep1Dialog2(shell,
+ hashFile);
+
+ if (dialog2.open() != InputDialog.OK) {
+ cancel();
+ }
+ }
+
+ protected void showDialog3() throws CancelException, ErrorException {
+ SGXDialogBase dialog3 = new TwoStepSignStep1Dialog3(shell, this);
+ if (dialog3.open() != InputDialog.OK) {
+ cancel();
+ }
+
+ validateExternalSignPublicKeyFile();
+
+ validateExternallySignedHashFile();
+
+ executeCatSig();
+
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep2.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep2.java
new file mode 100644
index 0000000000..f19738036c
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep2.java
@@ -0,0 +1,39 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import org.eclipse.jface.dialogs.InputDialog;
+
+import com.intel.sgx.dialogs.TwoStepSignStep2Dialog;
+
+// Sign
+public class TwoStepSignStep2 extends TwoStepSignHandlerBase {
+
+ public TwoStepSignStep2() {
+ }
+
+ @Override
+ protected Object executeSGXStuff() throws ErrorException, CancelException {
+ initializeSigntool();
+
+ TwoStepSignStep2Dialog dialog = new TwoStepSignStep2Dialog(shell, this);
+ if(dialog.open() != InputDialog.OK) {
+ cancel();
+ }
+
+ executeCatSig();
+ return null;
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/UpdateSigningKey.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/UpdateSigningKey.java
new file mode 100644
index 0000000000..68870ea3cf
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/UpdateSigningKey.java
@@ -0,0 +1,101 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.handlers;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+//import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+//import java.security.KeyPair;
+//import java.security.KeyPairGenerator;
+//import java.security.NoSuchAlgorithmException;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+//import org.bouncycastle.openssl.PEMWriter;
+import com.intel.sgx.Activator;
+import com.intel.sgx.dialogs.UpdateSignKeyDialog;
+
+public class UpdateSigningKey extends SGXHandler {
+
+ public String sourceKeyFile = null;
+ public String destinationKeyFile = null;
+ public String projectPath = null;
+
+ @Override
+ protected Object executeSGXStuff() throws ErrorException, CancelException {
+
+ UpdateSignKeyDialog dialog = new UpdateSignKeyDialog(shell, this);
+ int result = dialog.open();
+ if (result != InputDialog.OK) {
+ cancel();
+ }
+
+ if(UpdateSignKeyDialog.regenerate == false)
+ {
+ IPath sourceFile = Path.fromOSString(sourceKeyFile);
+ IPath destFile = Path.fromOSString(destinationKeyFile);
+ copyFile(sourceFile.toFile(), destFile.toFile());
+ refreshProject();
+ info("Update SGX Enclave Signing Key","copied \n'" + sourceKeyFile + "' into \n'" + destFile + "'");
+ } else {
+ UpdateSignKeyDialog.regenerate = false;
+ try {
+ Process q;
+ String opensslCmd = "openssl genrsa -out " + destinationKeyFile
+ + " -3 3072";
+ q = Runtime.getRuntime().exec(opensslCmd);
+ BufferedReader stdInput = new BufferedReader(
+ new InputStreamReader(q.getInputStream()));
+ BufferedReader stdErr = new BufferedReader(
+ new InputStreamReader(q.getErrorStream()));
+ String s = null;
+ while ((s = stdInput.readLine()) != null) {
+ }
+ while ((s = stdErr.readLine()) != null) {
+ }
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ if (q.exitValue() == 0){
+ info("Update SGX Enclave Signing Key","'"+destinationKeyFile+"'"+" was generated!");
+ } else {
+ quitWithError("Could not generate '"+destinationKeyFile+"'!!!");
+ }
+ } catch (IOException e) {
+ Activator.log(e);
+ e.printStackTrace();
+ } catch (CoreException e) {
+ Activator.log(e);
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/about.html b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/about.html
new file mode 100644
index 0000000000..a3b9ace448
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/about.html
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+About
+
+
+
About This Content
+
+
June 22, 2007
+
License
+
+
The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at http://www.eclipse.org/legal/epl-v10.html.
+For purposes of the EPL, "Program" will mean the Content.
+
+
If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at http://www.eclipse.org.
+
+
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/messages.properties b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/messages.properties
new file mode 100644
index 0000000000..c0011fadda
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/messages.properties
@@ -0,0 +1,16 @@
+#########################################################################
+# Copyright (c) 2016 Intel Corporation. #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Eclipse Public License v1.0 #
+# which accompanies this distribution, and is available at #
+# http://www.eclipse.org/legal/epl-v10.html #
+# #
+# Contributors: #
+# Intel Corporation - initial implementation and documentation #
+#########################################################################
+
+
+CreateNativeFolders_No_folders=No folders.
+CreateNativeFolders_Missing_project_name=Missing project Name.
+CreateNativeFolders_Project_does_not_exist=Project does not exist.
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXCCNature.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXCCNature.java
new file mode 100644
index 0000000000..fde7f7d29c
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXCCNature.java
@@ -0,0 +1,45 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.natures;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+
+public class SGXCCNature implements IProjectNature {
+
+ private IProject project;
+ public static final String NATURE_ID = "com.intel.sgx.sgxccnature";
+
+ public SGXCCNature() {
+ }
+
+ @Override
+ public void configure() throws CoreException {
+ }
+
+ @Override
+ public void deconfigure() throws CoreException {
+ }
+
+ @Override
+ public IProject getProject() {
+ return project;
+ }
+
+ @Override
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXNature.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXNature.java
new file mode 100644
index 0000000000..8db687e029
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXNature.java
@@ -0,0 +1,45 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.natures;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+
+public class SGXNature implements IProjectNature {
+
+ private IProject project;
+ public static final String NATURE_ID = "com.intel.sgx.sgxnature";
+
+ public SGXNature() {
+ }
+
+ @Override
+ public void configure() throws CoreException {
+ }
+
+ @Override
+ public void deconfigure() throws CoreException {
+ }
+
+ @Override
+ public IProject getProject() {
+ return project;
+ }
+
+ @Override
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXStaticCCNature.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXStaticCCNature.java
new file mode 100644
index 0000000000..0d642ee5c8
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXStaticCCNature.java
@@ -0,0 +1,45 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.natures;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+
+public class SGXStaticCCNature implements IProjectNature {
+
+ private IProject project;
+ public static final String NATURE_ID = "com.intel.sgx.sgxstaticccnature";
+
+ public SGXStaticCCNature() {
+ }
+
+ @Override
+ public void configure() throws CoreException {
+ }
+
+ @Override
+ public void deconfigure() throws CoreException {
+ }
+
+ @Override
+ public IProject getProject() {
+ return project;
+ }
+
+ @Override
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/ISDKDescriptor.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/ISDKDescriptor.java
new file mode 100644
index 0000000000..ec8b274912
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/ISDKDescriptor.java
@@ -0,0 +1,29 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.preferences;
+
+import java.io.File;
+
+
+public interface ISDKDescriptor {
+
+ public abstract File getSdkDir();
+
+ public abstract File getToolsDir();
+
+ public abstract File getSignerPath();
+
+ public abstract File getEdger8rPath();
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceConstants.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceConstants.java
new file mode 100644
index 0000000000..5ce1abc9cc
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceConstants.java
@@ -0,0 +1,112 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.preferences;
+
+import java.io.File;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import com.intel.sgx.Activator;
+
+/**
+ * Constant definitions for plug-in preferences
+ */
+public class PreferenceConstants {
+
+ public static final String SDK_PATH = "SDKPathPreference";
+
+ public static ISDKDescriptor getSDKDescriptor() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ File sdkDir = new File(store.getString(PreferenceConstants.SDK_PATH));
+
+ if (System.getProperty("os.arch").contains("64")) {
+ return new SGXSDK64Descriptor(sdkDir);
+ } else {
+ return new SGXSDK32Descriptor(sdkDir);
+ }
+ }
+
+
+ static public class SGXSDK32Descriptor implements ISDKDescriptor {
+ private final File sdkDir;
+ private final File toolDir;
+ private final File signerPath;
+ private final File edger8rPath;
+
+ public SGXSDK32Descriptor(File location){
+ this.sdkDir = location;
+ this.toolDir = new File(location, "bin/x86");
+ this.signerPath = new File(toolDir, "sgx_sign");
+ this.edger8rPath = new File(toolDir, "sgx_edger8r");
+ }
+
+ @Override
+ public File getSdkDir() {
+ return sdkDir;
+ }
+
+ @Override
+ public File getToolsDir() {
+ return toolDir;
+ }
+
+ @Override
+ public File getSignerPath() {
+ return signerPath;
+ }
+
+ @Override
+ public File getEdger8rPath() {
+ return edger8rPath;
+ }
+
+ }
+
+
+ static public class SGXSDK64Descriptor implements ISDKDescriptor {
+ private final File sdkDir;
+ private final File toolDir;
+ private final File signerPath;
+ private final File edger8rPath;
+
+ public SGXSDK64Descriptor(File sdkDir){
+ this.sdkDir = sdkDir;
+ this.toolDir = new File(sdkDir, "bin/x64");
+ this.signerPath = new File(toolDir, "sgx_sign");
+ this.edger8rPath = new File(toolDir, "sgx_edger8r");
+ }
+
+ @Override
+ public File getSdkDir() {
+ return sdkDir;
+ }
+
+ @Override
+ public File getToolsDir() {
+ return toolDir;
+ }
+
+ @Override
+ public File getSignerPath() {
+ return signerPath;
+ }
+
+ @Override
+ public File getEdger8rPath() {
+ return edger8rPath;
+ }
+
+ }
+
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceInitializer.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceInitializer.java
new file mode 100644
index 0000000000..b85d5e5299
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceInitializer.java
@@ -0,0 +1,32 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.preferences;
+
+import com.intel.sgx.Activator;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * Class used to initialize default preference values.
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer {
+
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ store.setDefault(PreferenceConstants.SDK_PATH, "");
+ Activator.getDefault().getPreferenceStore().setValue(PreferenceConstants.SDK_PATH, "/opt/intel/sgxsdk");
+ Activator.getDefault().getPreferenceStore().setDefault(PreferenceConstants.SDK_PATH, "/opt/intel/sgxsdk");
+ }
+}
diff --git a/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/SGXPreferencePage.java b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/SGXPreferencePage.java
new file mode 100644
index 0000000000..bbf6608a71
--- /dev/null
+++ b/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/SGXPreferencePage.java
@@ -0,0 +1,110 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2016 Intel Corporation. //
+// //
+// All rights reserved. This program and the accompanying materials //
+// are made available under the terms of the Eclipse Public License v1.0 //
+// which accompanies this distribution, and is available at //
+// http://www.eclipse.org/legal/epl-v10.html //
+// //
+// Contributors: //
+// Intel Corporation - initial implementation and documentation //
+///////////////////////////////////////////////////////////////////////////
+
+
+package com.intel.sgx.preferences;
+
+import org.eclipse.jface.preference.DirectoryFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+import com.intel.sgx.Activator;
+import com.intel.sgx.SdkPathVariableProvider;
+
+/**
+ * This class represents a preference page that
+ * is contributed to the Preferences dialog. By
+ * subclassing FieldEditorPreferencePage, we
+ * can use the field support built into JFace that allows
+ * us to create a page that is small and knows how to
+ * save, restore and apply itself.
+ *