├── CEE.tar.gz
├── CEE
├── .cproject
├── .project
├── Makefile
├── README.txt
├── isv_app
│ ├── isv_app.cpp
│ ├── operations.cpp
│ ├── operations.h
│ ├── refTxGen.js
│ ├── refTxGen_realmoney.js
│ ├── sample_messages.h
│ ├── svm-train.c
│ ├── svm.h
│ ├── txEncode.js
│ ├── txRLP_hash.txt
│ ├── txRawHex.txt
│ ├── txSend.js
│ ├── txSignature_r.txt
│ ├── txSignature_s.txt
│ └── txSignature_v.txt
├── isv_enclave
│ ├── Edger8rSyntax
│ │ ├── Arrays.cpp
│ │ ├── Arrays.edl
│ │ ├── Functions.cpp
│ │ ├── Functions.edl
│ │ ├── Pointers.cpp
│ │ ├── Pointers.edl
│ │ ├── Types.cpp
│ │ └── Types.edl
│ ├── TrustedLibrary
│ │ ├── Libc.cpp
│ │ ├── Libc.edl
│ │ ├── Libcxx.cpp
│ │ ├── Libcxx.edl
│ │ ├── Thread.cpp
│ │ └── Thread.edl
│ ├── asm_avr.inc
│ ├── asm_avr_mult_square.inc
│ ├── curve-specific.inc
│ ├── enclave_fann.cpp
│ ├── enclave_keccak.cpp
│ ├── enclave_svm.cpp
│ ├── enclave_utilities.cpp
│ ├── ethers.h
│ ├── include
│ │ ├── enclave_utilities.h
│ │ ├── fann
│ │ │ ├── CMakeFiles
│ │ │ │ ├── CMakeDirectoryInformation.cmake
│ │ │ │ └── progress.marks
│ │ │ ├── CMakeLists.txt
│ │ │ ├── Makefile
│ │ │ ├── cmake_install.cmake
│ │ │ ├── config.h
│ │ │ ├── doublefann.h
│ │ │ ├── fann.h
│ │ │ ├── fann_activation.h
│ │ │ ├── fann_cascade.h
│ │ │ ├── fann_cpp.h
│ │ │ ├── fann_data.h
│ │ │ ├── fann_data_cpp.h
│ │ │ ├── fann_error.h
│ │ │ ├── fann_internal.h
│ │ │ ├── fann_io.h
│ │ │ ├── fann_train.h
│ │ │ ├── fann_training_data_cpp.h
│ │ │ ├── fixedfann.h
│ │ │ ├── floatfann.h
│ │ │ ├── parallel_fann.h
│ │ │ └── parallel_fann.hpp
│ │ ├── keccak.h
│ │ ├── secp256k1.h
│ │ ├── secp256k1_ecdh.h
│ │ ├── secp256k1_recovery.h
│ │ └── svm.h
│ ├── isv_enclave.config.xml
│ ├── isv_enclave.cpp
│ ├── isv_enclave.edl
│ ├── isv_enclave.lds
│ ├── isv_enclave_private.pem
│ ├── keccak256.h
│ ├── platform-specific.inc
│ ├── types.h
│ ├── uECC.h
│ └── uECC_vli.h
├── sample_libcrypto
│ ├── libsample_libcrypto.so
│ └── sample_libcrypto.h
└── service_provider
│ ├── ecp.cpp
│ ├── ecp.h
│ ├── ias_ra.cpp
│ ├── ias_ra.h
│ ├── network_ra.cpp
│ ├── network_ra.h
│ ├── remote_attestation_result.h
│ ├── service_provider.cpp
│ └── service_provider.h
├── CEE_old
├── .cproject
├── .project
├── Makefile
├── README.md
├── README.txt
├── isv_app
│ ├── isv_app.cpp
│ ├── operations.cpp
│ ├── operations.h
│ ├── refTxGen.js
│ ├── refTxGen_realmoney.js
│ ├── sample_messages.h
│ ├── svm-train.c
│ ├── svm.h
│ ├── txEncode.js
│ ├── txRLP_hash.txt
│ ├── txRawHex.txt
│ ├── txSend.js
│ ├── txSignature_r.txt
│ ├── txSignature_s.txt
│ └── txSignature_v.txt
├── isv_enclave
│ ├── Edger8rSyntax
│ │ ├── Arrays.cpp
│ │ ├── Arrays.edl
│ │ ├── Functions.cpp
│ │ ├── Functions.edl
│ │ ├── Pointers.cpp
│ │ ├── Pointers.edl
│ │ ├── Types.cpp
│ │ └── Types.edl
│ ├── TrustedLibrary
│ │ ├── Libc.cpp
│ │ ├── Libc.edl
│ │ ├── Libcxx.cpp
│ │ ├── Libcxx.edl
│ │ ├── Thread.cpp
│ │ └── Thread.edl
│ ├── asm_avr.inc
│ ├── asm_avr_mult_square.inc
│ ├── curve-specific.inc
│ ├── ethers.h
│ ├── include
│ │ ├── secp256k1.h
│ │ ├── secp256k1_ecdh.h
│ │ ├── secp256k1_recovery.h
│ │ └── svm.h
│ ├── isv_enclave.config.xml
│ ├── isv_enclave.cpp
│ ├── isv_enclave.edl
│ ├── isv_enclave.lds
│ ├── isv_enclave_private.pem
│ ├── keccak256.h
│ ├── platform-specific.inc
│ ├── types.h
│ ├── uECC.h
│ └── uECC_vli.h
├── sample_libcrypto
│ └── sample_libcrypto.h
└── service_provider
│ ├── ecp.cpp
│ ├── ecp.h
│ ├── ias_ra.cpp
│ ├── ias_ra.h
│ ├── network_ra.cpp
│ ├── network_ra.h
│ ├── remote_attestation_result.h
│ ├── service_provider.cpp
│ └── service_provider.h
├── CloudStorage
└── Reserved_ML_Data
│ ├── 101.txt
│ ├── 102.txt
│ ├── DO1_1.txt
│ ├── DO1_10.txt
│ ├── DO1_11.txt
│ ├── DO1_12.txt
│ ├── DO1_13.txt
│ ├── DO1_14.txt
│ ├── DO1_15.txt
│ ├── DO1_16.txt
│ ├── DO1_17.txt
│ ├── DO1_18.txt
│ ├── DO1_19.txt
│ ├── DO1_2.txt
│ ├── DO1_20.txt
│ ├── DO1_21.txt
│ ├── DO1_22.txt
│ ├── DO1_23.txt
│ ├── DO1_24.txt
│ ├── DO1_25.txt
│ ├── DO1_26.txt
│ ├── DO1_27.txt
│ ├── DO1_28.txt
│ ├── DO1_29.txt
│ ├── DO1_3.txt
│ ├── DO1_30.txt
│ ├── DO1_31.txt
│ ├── DO1_32.txt
│ ├── DO1_33.txt
│ ├── DO1_34.txt
│ ├── DO1_35.txt
│ ├── DO1_36.txt
│ ├── DO1_37.txt
│ ├── DO1_38.txt
│ ├── DO1_39.txt
│ ├── DO1_4.txt
│ ├── DO1_40.txt
│ ├── DO1_5.txt
│ ├── DO1_6.txt
│ ├── DO1_7.txt
│ ├── DO1_8.txt
│ ├── DO1_9.txt
│ ├── adult.txt
│ ├── digits.png
│ └── heart_scale
├── Contracts
├── DataBroker_v1.js
├── DataBroker_v1.sol
├── DataBroker_v2.js
├── DataBroker_v2.sol
├── DataBroker_v3.js
├── DataBroker_v3.sol
├── DataOwner_v1.js
├── DataOwner_v1.sol
├── DataOwner_v2.js
├── DataOwner_v2.sol
├── DataOwner_v3.js
├── DataOwner_v3.sol
├── DistributeFund.js
├── DistributeFund.sol
├── DistributeFund_2.js
├── DistributeFund_2.sol
└── HowToDeploy&AccessContract.md
├── DataBroker
├── App
│ ├── app.cpp
│ ├── attestation_service.cpp
│ ├── attestation_service.h
│ ├── clientdata_operation.cpp
│ ├── clientdata_operation.h
│ ├── ecp.cpp
│ ├── ecp.h
│ ├── ias_ra.cpp
│ ├── ias_ra.h
│ ├── network_ra.cpp
│ ├── network_ra.h
│ ├── operations.cpp
│ ├── operations.h
│ ├── remote_attestation_result.h
│ ├── txCheckContract.js
│ └── txSendDirectly.js
├── Enclave
│ ├── Edger8rSyntax
│ │ ├── Arrays.cpp
│ │ ├── Arrays.edl
│ │ ├── Functions.cpp
│ │ ├── Functions.edl
│ │ ├── Pointers.cpp
│ │ ├── Pointers.edl
│ │ ├── Types.cpp
│ │ └── Types.edl
│ ├── TrustedLibrary
│ │ ├── Libc.cpp
│ │ ├── Libc.edl
│ │ ├── Libcxx.cpp
│ │ ├── Libcxx.edl
│ │ ├── Thread.cpp
│ │ └── Thread.edl
│ ├── asm_avr.inc
│ ├── asm_avr_mult_square.inc
│ ├── curve-specific.inc
│ ├── enclave.config.xml
│ ├── enclave.cpp
│ ├── enclave.edl
│ ├── enclave.lds
│ ├── enclave_private.pem
│ ├── ethers.h
│ ├── include
│ │ ├── secp256k1.h
│ │ ├── secp256k1_ecdh.h
│ │ ├── secp256k1_recovery.h
│ │ └── svm.h
│ ├── keccak256.h
│ ├── platform-specific.inc
│ ├── types.h
│ ├── uECC.h
│ └── uECC_vli.h
├── Makefile
└── sample_libcrypto
│ ├── libsample_libcrypto.so
│ └── sample_libcrypto.h
├── DataConsumer
├── App
│ ├── Datause.sol
│ ├── app.cpp
│ ├── attestation_service.cpp
│ ├── attestation_service.h
│ ├── ecp.cpp
│ ├── ecp.h
│ ├── ias_ra.cpp
│ ├── ias_ra.h
│ ├── keccak.cpp
│ ├── keccak.h
│ ├── network_ra.cpp
│ ├── network_ra.h
│ ├── operations.cpp
│ ├── operations.h
│ ├── remote_attestation_result.h
│ └── txSendDirectly.js
├── Makefile
└── sample_libcrypto
│ ├── libsample_libcrypto.so
│ ├── sample_libcrypto.h
│ └── txGenSend.js
├── DataOwner
├── App
│ ├── DO_sim.h
│ ├── app.cpp
│ ├── attestation_service.cpp
│ ├── attestation_service.h
│ ├── ecp.cpp
│ ├── ecp.h
│ ├── ias_ra.cpp
│ ├── ias_ra.h
│ ├── network_ra.cpp
│ ├── network_ra.h
│ ├── operations.cpp
│ ├── operations.h
│ ├── remote_attestation_result.h
│ └── txSendDirectly.js
├── DataFiles
│ └── Reserved_ML_Data
│ │ ├── adult.txt
│ │ ├── digits.png
│ │ └── heart_scale
├── Makefile
├── process_adult_data.py
└── sample_libcrypto
│ ├── libsample_libcrypto.so
│ ├── sample_libcrypto.h
│ └── txGenSend.js
├── DataOwner_group
├── App
│ ├── DO_sim.h
│ ├── app.cpp
│ ├── attestation_service.cpp
│ ├── attestation_service.h
│ ├── ecp.cpp
│ ├── ecp.h
│ ├── ias_ra.cpp
│ ├── ias_ra.h
│ ├── network_ra.cpp
│ ├── network_ra.h
│ ├── operations.cpp
│ ├── operations.h
│ ├── remote_attestation_result.h
│ └── txSendDirectly.js
├── DataFiles
│ └── Reserved_ML_Data
│ │ ├── adult.txt
│ │ ├── digits.png
│ │ └── heart_scale
├── Makefile
├── process_adult_data.py
└── sample_libcrypto
│ ├── libsample_libcrypto.so
│ ├── sample_libcrypto.h
│ └── txGenSend.js
├── Enclave_testML
├── .cproject
├── .project
├── Makefile
├── README.txt
├── isv_app
│ ├── enclave_keccak.cpp
│ ├── isv_app.cpp
│ ├── keccak.h
│ ├── operations.cpp
│ ├── operations.h
│ ├── refTxGen.js
│ ├── refTxGen_realmoney.js
│ ├── sample_messages.h
│ ├── txEncode.js
│ ├── txRLP_hash.txt
│ ├── txRawHex.txt
│ ├── txSend.js
│ ├── txSignature_r.txt
│ ├── txSignature_s.txt
│ └── txSignature_v.txt
├── isv_enclave
│ ├── Edger8rSyntax
│ │ ├── Arrays.cpp
│ │ ├── Arrays.edl
│ │ ├── Functions.cpp
│ │ ├── Functions.edl
│ │ ├── Pointers.cpp
│ │ ├── Pointers.edl
│ │ ├── Types.cpp
│ │ └── Types.edl
│ ├── TrustedLibrary
│ │ ├── Libc.cpp
│ │ ├── Libc.edl
│ │ ├── Libcxx.cpp
│ │ ├── Libcxx.edl
│ │ ├── Thread.cpp
│ │ └── Thread.edl
│ ├── asm_avr.inc
│ ├── asm_avr_mult_square.inc
│ ├── curve-specific.inc
│ ├── enclave_fann.cpp
│ ├── enclave_keccak.cpp
│ ├── enclave_svm.cpp
│ ├── enclave_utilities.cpp
│ ├── ethers.h
│ ├── include
│ │ ├── enclave_utilities.h
│ │ ├── fann
│ │ │ ├── CMakeFiles
│ │ │ │ ├── CMakeDirectoryInformation.cmake
│ │ │ │ └── progress.marks
│ │ │ ├── CMakeLists.txt
│ │ │ ├── Makefile
│ │ │ ├── cmake_install.cmake
│ │ │ ├── config.h
│ │ │ ├── doublefann.h
│ │ │ ├── fann.h
│ │ │ ├── fann_activation.h
│ │ │ ├── fann_cascade.h
│ │ │ ├── fann_cpp.h
│ │ │ ├── fann_data.h
│ │ │ ├── fann_data_cpp.h
│ │ │ ├── fann_error.h
│ │ │ ├── fann_internal.h
│ │ │ ├── fann_io.h
│ │ │ ├── fann_train.h
│ │ │ ├── fann_training_data_cpp.h
│ │ │ ├── fixedfann.h
│ │ │ ├── floatfann.h
│ │ │ ├── parallel_fann.h
│ │ │ └── parallel_fann.hpp
│ │ ├── keccak.h
│ │ ├── secp256k1.h
│ │ ├── secp256k1_ecdh.h
│ │ ├── secp256k1_recovery.h
│ │ └── svm.h
│ ├── isv_enclave.config.xml
│ ├── isv_enclave.cpp
│ ├── isv_enclave.edl
│ ├── isv_enclave.lds
│ ├── isv_enclave_private.pem
│ ├── platform-specific.inc
│ ├── types.h
│ ├── uECC.h
│ └── uECC_vli.h
├── process_adult_data.py
├── sample_libcrypto
│ ├── libsample_libcrypto.so
│ └── sample_libcrypto.h
└── service_provider
│ ├── ecp.cpp
│ ├── ecp.h
│ ├── ias_ra.cpp
│ ├── ias_ra.h
│ ├── network_ra.cpp
│ ├── network_ra.h
│ ├── remote_attestation_result.h
│ ├── service_provider.cpp
│ └── service_provider.h
├── Eval&Tools
├── Config.md
├── ExpData.ods
├── attestationTimes-a.png
├── attestationTimes-b.png
├── attestationTimes-new.png
├── computationRuntimes.png
├── contractCallTimes.png
├── costCallingDBContract.png
├── createDataOwnerContracts_batch.js
├── getPrivateKeyLocally.js
├── getPrivateKeyLocally_batch.js
├── plot_attest_time.py
├── plot_comp_time.py
├── plot_contract_call_time.py
├── plot_cost.py
├── plot_total_cost.py
└── totalCostCallingContract.png
├── Intel
├── client.cnf
├── client.crt
├── client.key
├── client.pfx
├── client.req
├── server.crt
└── server.key
├── LICENSE
├── README.md
├── allmake.sh
├── cleanmake.sh
└── iDataAgent
├── App
├── app.cpp
├── attestation_service.cpp
├── attestation_service.h
├── clientdata_operation.cpp
├── clientdata_operation.h
├── ecp.cpp
├── ecp.h
├── ias_ra.cpp
├── ias_ra.h
├── network_ra.cpp
├── network_ra.h
├── operations.cpp
├── operations.h
├── remote_attestation_result.h
├── txCheckContract.js
└── txSendDirectly.js
├── Enclave
├── Edger8rSyntax
│ ├── Arrays.cpp
│ ├── Arrays.edl
│ ├── Functions.cpp
│ ├── Functions.edl
│ ├── Pointers.cpp
│ ├── Pointers.edl
│ ├── Types.cpp
│ └── Types.edl
├── TrustedLibrary
│ ├── Libc.cpp
│ ├── Libc.edl
│ ├── Libcxx.cpp
│ ├── Libcxx.edl
│ ├── Thread.cpp
│ └── Thread.edl
├── asm_avr.inc
├── asm_avr_mult_square.inc
├── curve-specific.inc
├── enclave.config.xml
├── enclave.cpp
├── enclave.edl
├── enclave.lds
├── enclave_private.pem
├── ethers.h
├── include
│ ├── secp256k1.h
│ ├── secp256k1_ecdh.h
│ ├── secp256k1_recovery.h
│ └── svm.h
├── keccak256.h
├── platform-specific.inc
├── types.h
├── uECC.h
└── uECC_vli.h
├── Makefile
└── sample_libcrypto
├── libsample_libcrypto.so
└── sample_libcrypto.h
/CEE.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE.tar.gz
--------------------------------------------------------------------------------
/CEE/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | RemoteAttestation
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
25 | org.eclipse.cdt.core.ccnature
26 | com.intel.sgx.sgxnature
27 |
28 |
29 |
--------------------------------------------------------------------------------
/CEE/README.txt:
--------------------------------------------------------------------------------
1 | ----------------------------
2 | Purpose of RemoteAttestation
3 | ----------------------------
4 | The project demonstrates:
5 | - How an application enclave can attest to a remote party
6 | - How an application enclave and the remote party can establish a secure session
7 |
8 | ------------------------------------
9 | How to Build/Execute the Sample Code
10 | ------------------------------------
11 | 1. Install Intel(R) SGX SDK for Linux* OS
12 | 2. Build the project with the prepared Makefile:
13 | a. Hardware Mode, Debug build:
14 | $ make
15 | b. Hardware Mode, Pre-release build:
16 | $ make SGX_PRERELEASE=1 SGX_DEBUG=0
17 | c. Hardware Mode, Release build:
18 | $ make SGX_DEBUG=0
19 | d. Simulation Mode, Debug build:
20 | $ make SGX_MODE=SIM
21 | e. Simulation Mode, Pre-release build:
22 | $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0
23 | f. Simulation Mode, Release build:
24 | $ make SGX_MODE=SIM SGX_DEBUG=0
25 | 3. Execute the binary directly:
26 | $ ./app
27 | 4. Remember to "make clean" before switching build mode
28 |
--------------------------------------------------------------------------------
/CEE/isv_app/operations.h:
--------------------------------------------------------------------------------
1 | #ifndef _ENCLAVE_OPERATION_H_
2 | #define _ENCLAVE_OPERATION_H_
3 |
4 |
5 | #include "isv_enclave_u.h"
6 | #include "sgx_urts.h"
7 | #include "sgx_uae_service.h"
8 | #include "remote_attestation_result.h"
9 |
10 | #if defined(__cplusplus)
11 | extern "C" {
12 | #endif
13 |
14 | #define AESGCM_KEY_SIZE 16
15 | #define AESGCM_MAC_SIZE 16
16 | #define KECCAK_HASH_SIZE 32
17 |
18 | #define TASK1_RESULT_SIZE 4 // Bytes. Summation of single digits
19 | #define TASK2_RESULT_SIZE 1000 // Bytes. SVM model
20 | #define TASK3_RESULT_SIZE 10000 // Bytes. ANN model
21 |
22 |
23 |
24 | /* Enum for all possible operation message types (except for attestation related) between CEE and DC, iDA*/
25 | typedef enum _op_msg_type_t
26 | {
27 | TYPE_OP_AUTH, // Authentication message
28 | TYPE_OP_COMP_RES, // computation result message
29 | }op_msg_type_t;
30 |
31 | typedef struct _enclave_info_t{
32 | sgx_enclave_id_t enclave_id;
33 | sgx_ra_context_t context;
34 | uint32_t extended_epid_group_id;
35 | }enclave_info_t;
36 |
37 | typedef struct _auth_msg_header_t{
38 | uint8_t type;
39 | uint8_t challenger_type;
40 | }auth_msg_header_t;
41 |
42 | typedef struct _K_result_msg_t{ // to iDA/DB
43 | int DO_ID;
44 | int file_num;
45 | uint8_t K_result_en[AESGCM_KEY_SIZE];
46 | uint8_t K_result_mac[AESGCM_MAC_SIZE];
47 | }K_result_msg_t;
48 |
49 | typedef struct _K_result_hash_msg_t{ // to DC
50 | int DO_ID;
51 | int file_num;
52 | uint8_t K_result_hash_en[KECCAK_HASH_SIZE];
53 | uint8_t K_result_hash_mac[AESGCM_MAC_SIZE];
54 | uint8_t C_result_hash_en[KECCAK_HASH_SIZE]; // Hash of the encrypted result
55 | uint8_t C_result_hash_mac[AESGCM_MAC_SIZE];
56 | }K_result_hash_msg_t;
57 |
58 | typedef struct _operation_config_msg_t{
59 | int DC_ID;
60 | int type;
61 | int start;
62 | int end;
63 | int operation;
64 | }operation_config_msg_t;
65 |
66 | bool enclave_init(enclave_info_t* enclave_info);
67 |
68 | int remote_attest_enclave(int sock_num, int* p_challenger_type, enclave_info_t* enclave_info);
69 | int remote_attest_enclave_parallel(int sock_num, int* p_challenger_type, enclave_info_t* enclave_info_original);
70 |
71 | int enclave_close(enclave_info_t* enclave_info);
72 |
73 | int enclave_compute_task(enclave_info_t* enclave_info, int Request_DC, int Request_type, int Request_start, int Request_end, int Request_operation);
74 |
75 | int send_K_result_msgs(enclave_info_t* enclave_info, int sock_iDA_DB, int sock_DC);
76 |
77 | // Produce an off-line transaction that invokes the record() function in the contract
78 | // The transaction is marshalled outside the enclave but signed inside enclave
79 | int record_datause(enclave_info_t* enclave_info, char* contract_addr);
80 |
81 |
82 | #if defined(__cplusplus)
83 | }
84 | #endif
85 | #endif
--------------------------------------------------------------------------------
/CEE/isv_app/refTxGen.js:
--------------------------------------------------------------------------------
1 | // The orginal full tx generation process of geth
2 | var Web3 = require('web3');
3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/'));
4 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/'));
5 | var util = require('ethereumjs-util');
6 | var tx = require('ethereumjs-tx');
7 |
8 | // var privateKey = '0xc0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0de';
9 | // var publicKey = util.bufferToHex(util.privateToPublic(privateKey));
10 | // console.log(publicKey);
11 | // var address = '0x' + util.bufferToHex(util.sha3(publicKey)).slice(26); //0x53ae893e4b22d707943299a8d0c844df0e3d5557
12 |
13 |
14 | var rawTx = {
15 | nonce: web3.utils.numberToHex('0'),
16 | gasPrice: web3.utils.numberToHex('20000000000'),
17 | gasLimit: web3.utils.numberToHex('100000'),
18 | to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85',
19 | value: web3.utils.numberToHex('0'),
20 | data: '0xc0de'
21 | };
22 | var p = new Buffer('c0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0de', 'hex');
23 |
24 |
25 | var transaction = new tx(rawTx);
26 |
27 | // console.log('0x' + transaction.serialize().toString('hex'));
28 |
29 | console.log('\nTransaction cefore signing:\n', transaction);
30 |
31 | transaction.sign(p); // This step needs to be done in the enclave
32 |
33 | console.log('\nTransaction after signing:\n', transaction);
34 |
35 | // console.log('from: '+ transaction.from.toString('hex'));
36 |
37 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api
38 |
39 | // // Send the raw transaction hex
40 | // web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) {
41 | // if (err) {
42 | // console.log(err);
43 | // }
44 | // else {
45 | // console.log(hash);
46 | // }
47 | // });
48 |
49 | console.log('\n- Raw Transaction Hex:\n' + RawTxHex);
50 | var txHash = util.bufferToHex(util.sha3(RawTxHex));
51 | console.log('\n- Transaction hash:\n' + txHash);
--------------------------------------------------------------------------------
/CEE/isv_app/txEncode.js:
--------------------------------------------------------------------------------
1 | var Web3 = require('web3');
2 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/'));
3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/'));
4 | var util = require('ethereumjs-util');
5 | var RLP = require('rlp');
6 | var fs = require("fs");
7 |
8 | // console.log(process.argv);
9 | var address = '0x65843be2dd4ad3bc966584e2fcbb38838d49054b';
10 |
11 | var argv = process.argv;
12 |
13 |
14 | web3.eth.getTransactionCount(address).then(function (res, err){
15 | if (err) {
16 | console.log('error: ' + err);
17 | }
18 | else {
19 | var txCount = res;
20 | var nonce = '';
21 | var value = '';
22 | if(txCount != 0){
23 | nonce = web3.utils.numberToHex(txCount);
24 | }
25 | if(argv[5] != '0'){
26 | value = web3.utils.numberToHex(argv[5]);
27 | }
28 |
29 | var txNake = [
30 | nonce,
31 | web3.utils.numberToHex(argv[2]),
32 | web3.utils.numberToHex(argv[3]),
33 | argv[4],
34 | value,
35 | argv[6]
36 | ];
37 |
38 | var txSixFieldRLP = util.bufferToHex(RLP.encode(txNake));
39 | var txRLP_hash = util.sha3(txSixFieldRLP);
40 |
41 |
42 | // console.log('\nSixFieldRLP hex:\n' + txSixFieldRLP);
43 | // console.log('\nTransaction RLP+Hash:\n' + util.bufferToHex(txRLP_hash));
44 |
45 | fs.writeFile('isv_app/txRLP_hash.txt', txRLP_hash, function(err) {
46 | if (err) {
47 | return console.error(err);
48 | }
49 | });
50 | }
51 | });
52 |
53 |
54 |
55 |
56 | // var nonce = null;
57 | // if(argv[2] != '0'){
58 | // nonce = web3.utils.numberToHex(argv[2]);
59 | // }
60 |
61 | // var txNake = [
62 | // nonce,
63 | // web3.utils.numberToHex(argv[3]),
64 | // web3.utils.numberToHex(argv[4]),
65 | // argv[5],
66 | // web3.utils.numberToHex(argv[6]),
67 | // argv[7]
68 | // ];
69 |
70 | // var txSixFieldRLP = util.bufferToHex(RLP.encode(txNake));
71 | // var txRLP_hash = util.sha3(txSixFieldRLP);
72 |
73 |
74 | // // console.log('\nSixFieldRLP hex:\n' + txSixFieldRLP);
75 | // console.log('\nTransaction RLP+Hash:\n' + util.bufferToHex(txRLP_hash));
76 |
77 | // fs.writeFile('isv_app/txRLP_hash.txt', txRLP_hash, function(err) {
78 | // if (err) {
79 | // return console.error(err);
80 | // }
81 | // });
82 |
--------------------------------------------------------------------------------
/CEE/isv_app/txRLP_hash.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE/isv_app/txRLP_hash.txt
--------------------------------------------------------------------------------
/CEE/isv_app/txRawHex.txt:
--------------------------------------------------------------------------------
1 | 0xf87840843b9aca0083030d4094992d8b41e547d40920172e5369fe0fa0d769bc5c80947bd780c747a35fd12a5454ecb45065f77df87f271ca0a8a12781ee4d8212c033c165c69f5c8650c3b7815a60eeba2093c9db4a3d6a70a0451484ba4f28e734b388779d03294a96bc18ab4e791294143564ff7263266f11
--------------------------------------------------------------------------------
/CEE/isv_app/txSend.js:
--------------------------------------------------------------------------------
1 | var Web3 = require('web3');
2 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/'));
3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/'));
4 | var util = require('ethereumjs-util');
5 | // var tx = require('ethereumjs-tx');
6 | var RLP = require('rlp');
7 | var fs = require("fs");
8 |
9 | // console.log(process.argv);
10 | var address = '0x65843be2dd4ad3bc966584e2fcbb38838d49054b';
11 | var argv = process.argv;
12 |
13 | var data;
14 |
15 | data = fs.readFileSync('isv_app/txSignature_v.txt');
16 | var txSignature_v = util.bufferToHex(data).toString();
17 |
18 | data = fs.readFileSync('isv_app/txSignature_r.txt');
19 | var txSignature_r = util.bufferToHex(data).toString();
20 |
21 | data = fs.readFileSync('isv_app/txSignature_s.txt');
22 | var txSignature_s = util.bufferToHex(data).toString();
23 |
24 |
25 | web3.eth.getTransactionCount(address).then(function (res, err){
26 | if (err) {
27 | console.log('error: ' + err);
28 | }
29 | else {
30 | var txCount = res;
31 | var nonce = '';
32 | var value = '';
33 | if(txCount != 0){
34 | nonce = web3.utils.numberToHex(txCount);
35 | }
36 | if(argv[5] != '0'){
37 | value = web3.utils.numberToHex(argv[5]);
38 | }
39 |
40 | var txFull = [
41 | nonce,
42 | web3.utils.numberToHex(argv[2]),
43 | web3.utils.numberToHex(argv[3]),
44 | argv[4],
45 | value,
46 | argv[6],
47 | txSignature_v,
48 | txSignature_r,
49 | txSignature_s
50 | ];
51 |
52 | // console.log(txFull);
53 |
54 | var txRawHex = util.bufferToHex(RLP.encode(txFull));
55 |
56 | console.log('\ntxRawHex: \n' + txRawHex);
57 |
58 | // Send the raw transaction hex
59 | console.log('\nTxHash: ');
60 |
61 | // web3.eth.sendSignedTransaction(txRawHex, function (err, hash) {
62 | // if (err) {
63 | // console.log(err);
64 | // }
65 | // else {
66 | // console.log(hash);
67 | // }
68 | // });
69 |
70 | web3.eth.sendSignedTransaction(RawTxHex).on('receipt', console.log);
71 |
72 | // Write the raw transaction hex into a file which may be used later
73 | fs.writeFile('isv_app/txRawHex.txt', txRawHex, function(err) {
74 | if (err) {
75 | return console.error(err);
76 | }
77 | });
78 | }
79 | });
--------------------------------------------------------------------------------
/CEE/isv_app/txSignature_r.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE/isv_app/txSignature_r.txt
--------------------------------------------------------------------------------
/CEE/isv_app/txSignature_s.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE/isv_app/txSignature_s.txt
--------------------------------------------------------------------------------
/CEE/isv_app/txSignature_v.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/CEE/isv_enclave/TrustedLibrary/Libc.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in
12 | * the documentation and/or other materials provided with the
13 | * distribution.
14 | * * Neither the name of Intel Corporation nor the names of its
15 | * contributors may be used to endorse or promote products derived
16 | * from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | *
30 | */
31 |
32 |
33 | #include
34 | #include "sgx_cpuid.h"
35 |
36 | #include "sgx_trts.h"
37 | #include "../Enclave.h"
38 | #include "Enclave_t.h"
39 |
40 | /* ecall_malloc_free:
41 | * Uses malloc/free to allocate/free trusted memory.
42 | */
43 | void ecall_malloc_free(void)
44 | {
45 | void *ptr = malloc(100);
46 | assert(ptr != NULL);
47 | memset(ptr, 0x0, 100);
48 | free(ptr);
49 | }
50 |
51 | /* ecall_sgx_cpuid:
52 | * Uses sgx_cpuid to get CPU features and types.
53 | */
54 | void ecall_sgx_cpuid(int cpuinfo[4], int leaf)
55 | {
56 | sgx_status_t ret = sgx_cpuid(cpuinfo, leaf);
57 | if (ret != SGX_SUCCESS)
58 | abort();
59 | }
60 |
--------------------------------------------------------------------------------
/CEE/isv_enclave/TrustedLibrary/Libc.edl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in
12 | * the documentation and/or other materials provided with the
13 | * distribution.
14 | * * Neither the name of Intel Corporation nor the names of its
15 | * contributors may be used to endorse or promote products derived
16 | * from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | *
30 | */
31 |
32 |
33 | /* Libc.edl - EDL sample for trusted C library. */
34 |
35 | enclave {
36 |
37 | from "sgx_tstdc.edl" import sgx_oc_cpuidex;
38 |
39 | /*
40 | * A subset of the C99 standard is supported as well as SGX customized functions:
41 | * sgx_cpuid, etc.
42 | */
43 |
44 | trusted {
45 | /*
46 | * Utilize malloc/free in enclave.
47 | */
48 | public void ecall_malloc_free(void);
49 |
50 | /*
51 | * Utilize SGX version __cpuid() in enclave.
52 | */
53 | public void ecall_sgx_cpuid([out] int cpuinfo[4], int leaf);
54 | };
55 | };
56 |
--------------------------------------------------------------------------------
/CEE/isv_enclave/TrustedLibrary/Libcxx.edl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in
12 | * the documentation and/or other materials provided with the
13 | * distribution.
14 | * * Neither the name of Intel Corporation nor the names of its
15 | * contributors may be used to endorse or promote products derived
16 | * from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | *
30 | */
31 |
32 |
33 | /* Libcxx.edl - EDL sample for trusted C++ library. */
34 |
35 | enclave {
36 |
37 | /*
38 | * A subset of the C++03 standard is supported.
39 | */
40 |
41 | trusted {
42 | /*
43 | * Throw/catch exception inside the enclave.
44 | */
45 | public void ecall_exception(void);
46 |
47 | /*
48 | * Utilize