Browse Source

Made new header files for custom classes and added some changes to cpp files

dettanym 5 years ago
parent
commit
4a985beaaa

+ 29 - 0
Decryptor/ECDSASignatureBox.cpp

@@ -0,0 +1,29 @@
+#include "Openssl_crypto.h"
+
+class ECDSASignatureBox : public ECDHKeypair {
+public:
+  void get_keypair(uint8_t* output_keypair);
+  uint32_t sign(uint8_t* signature_data, uint32_t signature_data_length, uint8_t* signature)
+  {
+    return compute_ecdsa_signature(signature_data, signature_data_length, private_key, signature);
+  }
+
+  void get_keypair(uint8_t* output_keypair)
+  {
+    // TODO: What happens if the ECDH keypair's generate keypair hasnt been set.
+    uint32_t counter;
+    for(counter=0; counter<ECDH_PRIVATE_KEY_SIZE; counter++)
+      *(output_keypair + counter) = *(private_key + counter);
+    for(counter=0; counter<ECDH_PUBLIC_KEY_SIZE; counter++)
+      *(output_keypair + counter) = *(public_key + counter);
+  }
+
+  void set_keypair(uint8_t* input_keypair)
+  {
+    uint32_t counter;
+    for(counter=0; counter<ECDH_PRIVATE_KEY_SIZE; counter++)
+      *(private_key + counter) = *(input_keypair + counter);
+    for(counter=0; counter<ECDH_PUBLIC_KEY_SIZE; counter++)
+      *(public_key + counter) = *(input_keypair + counter);
+  }
+}

+ 10 - 0
Include/ECDHKeypair.h

@@ -0,0 +1,10 @@
+#include"Openssl_crypto.h"
+class ECDHKeypair {
+  uint8_t private_key[ECDH_PUBLIC_KEY_SIZE];
+  uint8_t public_key[ECDH_PRIVATE_KEY_SIZE];
+  static const int ECDH_PUBLIC_KEY_SIZE=2*SGX_ECP256_KEY_SIZE;
+  static const int ECDH_PRIVATE_KEY_SIZE=SGX_ECP256_KEY_SIZE;
+public:
+  ECDHKeypair();
+  uint32_t generate_keypair();
+};

+ 6 - 0
Include/ECDSASignatureBox.h

@@ -0,0 +1,6 @@
+#include "ECDHKeypair.h"
+class ECDSASignatureBox : public ECDHKeypair {
+public:
+  void get_keypair(uint8_t* output_keypair);
+  uint32_t sign(uint8_t* signature_data, uint32_t signature_data_length, uint8_t* signature);
+  }

+ 9 - 0
Include/HybridEncryption.h

@@ -0,0 +1,9 @@
+#include "Openssl_crypto.h"
+#include "SymmetricEncryptionBox.h"
+#include "HybridEncryptionBox.h"
+class HybridEncryptionBox : public ECDHKeypair, public SymmetricEncryptionBox {
+  public:
+    HybridEncryptionBox(): ECDHKeypair(), SymmetricEncryptionBox();
+    uint32_t get_public_key(uint8_t* blank_key);
+    unsigned long initialize_symmetric_key(uint8_t* given_public_key);
+};

+ 11 - 0
Include/SymmetricEncryptionBox.h

@@ -0,0 +1,11 @@
+#include "Openssl_crypto.h"
+class SymmetricEncryptionBox {
+  uint8_t iv[12];
+  uint8_t symmetric_key[32]; // SHA256 used with ECDHE -> or AES whatever symmetric_key.
+  // increments last 4 bytes (in big-endian order)
+  uint32_t aes_gcm_increment_iv_internal_call(uint8_t* iv);
+  public:
+    SymmetricEncryptionBox();
+    uint32_t set_symmetric_key(uint8_t* given_key);
+    uint32_t encrypt_decrypt(int enc, uint8_t* plaintext, uint32_t plaintext_length, uint8_t* ciphertext, uint32_t* ciphertext_length, uint8_t* tag);
+};

+ 36 - 7
LocalAttestationCode/EnclaveMessageExchange.h → LocalAttestationCode/LocalAttestationTrusted.h

@@ -29,12 +29,24 @@
  *
  */
 
-
-#include "datatypes.h"
-#include "sgx_eid.h"
 #include "sgx_trts.h"
-#include <map>
+#include "sgx_utils.h"
+// #include "EnclaveMessageExchange.h"
+#include "sgx_eid.h"
+#include "error_codes.h"
+#include "sgx_ecp_types.h"
+#include "sgx_thread.h"
 #include "dh_session_protocol.h"
+#include "sgx_dh.h"
+#include "sgx_tcrypto.h"
+#include "LocalAttestationCode_t.h"
+#include "sgx_tseal.h"
+
+//#include "datatypes.h"
+//#include "sgx_eid.h"
+//#include "sgx_trts.h"
+//#include <map>
+//#include "dh_session_protocol.h"
 
 #ifndef LOCALATTESTATION_H_
 #define LOCALATTESTATION_H_
@@ -43,9 +55,26 @@
 extern "C" {
 #endif
 
-//uint32_t SGXAPI create_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, dh_session_t *p_session_info);
-//uint32_t SGXAPI send_request_receive_response(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, dh_session_t *p_session_info, char *inp_buff, size_t inp_buff_len, size_t max_out_buff_size, char **out_buff, size_t* out_buff_len);
-//uint32_t SGXAPI close_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id);
+static class LocalAttestationTrusted{
+  dh_session_t global_session_info;
+  uint32_t global_session_id=0;
+  uint32_t one_successful_la_done;
+  sgx_ecc_state_handle_t ecc_state;
+  uint8_t verifier_mr_enclave[32];
+  SymmetricEncryptionBox symmetricEncryptionBoxApache;
+  SymmetricEncryptionBox symmetricEncryptionBoxVerifier;
+
+public:
+    extern "C" uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity);
+    ATTESTATION_STATUS session_request(sgx_dh_msg1_t *dh_msg1, uint32_t *session_id);
+    ATTESTATION_STATUS exchange_report(sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *dh_msg3, uint32_t* session_id); 
+    LocalAttestationTrusted(): symmetricEncryptionBoxApache(), symmetricEncryptionBoxVerifier();
+
+}; 
+
+
+
+
 
 #ifdef __cplusplus
 }

+ 5 - 4
LocalAttestationCode/LocalAttestationTrustedWrapper.cpp

@@ -1,9 +1,10 @@
-uint32_t session_request_wrapper([out] sgx_dh_msg1_t *dh_msg1, [out] uint32_t *session_id)
+#include "LocalAttestationTrusted.h"
+uint32_t session_request_wrapper(sgx_dh_msg1_t *dh_msg1, uint32_t *session_id)
 {
-  return LocalAttestationTrusted::session_request_wrapper(dh_msg1, session_id);
+  return LocalAttestationTrusted::session_request(dh_msg1, session_id);
 }
 
-uint32_t exchange_report_wrapper(dh_msg2, dh_msg3, session_id)
+uint32_t exchange_report_wrapper(sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *dh_msg3, uint32_t *session_id)
 {
-  return LocalAttestationTrusted::exchange_report_wrapper(dh_msg2, dh_msg3, session_id);
+  return LocalAttestationTrusted::exchange_report(dh_msg2, dh_msg3, session_id);
 }

+ 1 - 1
Makefile

@@ -1,4 +1,4 @@
-LocalAttestationUntrusted#
+#
 # Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without