| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License.. |
| |
| #ifndef MESSAGEHANDLER_H |
| #define MESSAGEHANDLER_H |
| |
| #include <string> |
| #include <stdio.h> |
| #include <limits.h> |
| #include <unistd.h> |
| #include <iostream> |
| #include <iomanip> |
| |
| #include "Enclave.h" |
| #include "NetworkManagerServer.h" |
| #include "Messages.pb.h" |
| #include "UtilityFunctions.h" |
| #include "remote_attestation_result.h" |
| //#include "LogBase.h" |
| #include "../GeneralSettings.h" |
| |
| using namespace std; |
| using namespace util; |
| |
| class MessageHandler { |
| |
| public: |
| MessageHandler(int port = Settings::rh_port); |
| virtual ~MessageHandler(); |
| |
| sgx_ra_msg3_t* getMSG3(); |
| int init(); |
| void start(); |
| vector<string> incomingHandler(string v, int type); |
| |
| private: |
| sgx_status_t initEnclave(); |
| uint32_t getExtendedEPID_GID(); |
| |
| void assembleAttestationMSG(Messages::AttestationMessage msg, ra_samp_response_header_t **pp_att_msg); |
| string handleAttestationResult(Messages::AttestationMessage msg); |
| void assembleMSG2(Messages::MessageMSG2 msg, sgx_ra_msg2_t **pp_msg2); |
| string handleMSG2(Messages::MessageMSG2 msg); |
| string handleMSG0(Messages::MessageMsg0 msg); |
| string generateMSG1(); |
| string handleVerification(); |
| string generateMSG0(); |
| string createInitMsg(int type, string msg); |
| |
| string generateAttestationFailed(uint32_t id, sgx_ra_context_t context); |
| string handlePsiHashData(Messages::MessagePsiHashData msg); |
| string handlePsiHashDataFinished(Messages::MessagePsiHashDataFinished msg, bool* again); |
| |
| protected: |
| Enclave *enclave = NULL; |
| |
| private: |
| int busy_retry_time = 4; |
| NetworkManagerServer *nm = NULL; |
| |
| }; |
| |
| #endif |
| |