[Assignment-7] add SGX sample code from VM
All checks were successful
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (push) Successful in 1m2s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (push) Successful in 1m3s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (push) Successful in 1m0s
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (pull_request) Successful in 30s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (pull_request) Successful in 10s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (pull_request) Successful in 8s
All checks were successful
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (push) Successful in 1m2s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (push) Successful in 1m3s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (push) Successful in 1m0s
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (pull_request) Successful in 30s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (pull_request) Successful in 10s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (pull_request) Successful in 8s
This commit is contained in:
parent
5616ddc4e5
commit
ba8e969470
163 changed files with 24030 additions and 0 deletions
|
|
@ -0,0 +1,209 @@
|
|||
#include "VerificationManager.h"
|
||||
#include "../GeneralSettings.h"
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
using namespace util;
|
||||
using namespace std;
|
||||
|
||||
VerificationManager* VerificationManager::instance = NULL;
|
||||
|
||||
VerificationManager::VerificationManager() {
|
||||
this->nm = NetworkManagerClient::getInstance(Settings::rh_port, Settings::rh_host);
|
||||
this->ws = WebService::getInstance();
|
||||
this->ws->init();
|
||||
this->sp = new ServiceProvider(this->ws);
|
||||
}
|
||||
|
||||
|
||||
VerificationManager::~VerificationManager() {}
|
||||
|
||||
|
||||
VerificationManager* VerificationManager::getInstance() {
|
||||
if (instance == NULL) {
|
||||
instance = new VerificationManager();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
int VerificationManager::init() {
|
||||
if (this->sp) {
|
||||
delete this->sp;
|
||||
this->sp = new ServiceProvider(this->ws);
|
||||
}
|
||||
|
||||
this->nm->Init();
|
||||
this->nm->connectCallbackHandler([this](string v, int type) {
|
||||
return this->incomingHandler(v, type);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void VerificationManager::start() {
|
||||
this->nm->startService();
|
||||
Log("Remote attestation done");
|
||||
}
|
||||
|
||||
|
||||
string VerificationManager::handleMSG0(Messages::MessageMsg0 msg) {
|
||||
Log("MSG0 received");
|
||||
|
||||
if (msg.status() != TYPE_TERMINATE) {
|
||||
uint32_t extended_epid_group_id = msg.epid();
|
||||
int ret = this->sp->sp_ra_proc_msg0_req(extended_epid_group_id);
|
||||
|
||||
if (ret == 0) {
|
||||
msg.set_status(TYPE_OK);
|
||||
return nm->serialize(msg);
|
||||
}
|
||||
} else {
|
||||
Log("Termination received!");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
string VerificationManager::handleMSG1(Messages::MessageMSG1 msg1) {
|
||||
Log("MSG1 received");
|
||||
|
||||
Messages::MessageMSG2 msg2;
|
||||
msg2.set_type(RA_MSG2);
|
||||
|
||||
int ret = this->sp->sp_ra_proc_msg1_req(msg1, &msg2);
|
||||
|
||||
if (ret != 0) {
|
||||
Log("Error, processing MSG1 failed");
|
||||
} else {
|
||||
Log("MSG1 processed correctly and MSG2 created");
|
||||
return nm->serialize(msg2);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
string VerificationManager::handleMSG3(Messages::MessageMSG3 msg) {
|
||||
Log("MSG3 received");
|
||||
|
||||
Messages::AttestationMessage att_msg;
|
||||
att_msg.set_type(RA_ATT_RESULT);
|
||||
|
||||
int ret = this->sp->sp_ra_proc_msg3_req(msg, &att_msg);
|
||||
|
||||
if (ret == -1) {
|
||||
Log("Error, processing MSG3 failed");
|
||||
} else {
|
||||
Log("MSG3 processed correctly and attestation result created");
|
||||
return nm->serialize(att_msg);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
string VerificationManager::handleAppAttOk() {
|
||||
Log("APP attestation result received");
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
string VerificationManager::prepareVerificationRequest() {
|
||||
Log("Prepare Verification request");
|
||||
|
||||
Messages::InitialMessage msg;
|
||||
msg.set_type(RA_VERIFICATION);
|
||||
|
||||
return nm->serialize(msg);
|
||||
}
|
||||
|
||||
|
||||
string VerificationManager::createInitMsg(int type, string msg) {
|
||||
Messages::InitialMessage init_msg;
|
||||
init_msg.set_type(type);
|
||||
init_msg.set_size(msg.size());
|
||||
|
||||
return nm->serialize(init_msg);
|
||||
}
|
||||
|
||||
|
||||
vector<string> VerificationManager::incomingHandler(string v, int type) {
|
||||
vector<string> res;
|
||||
|
||||
if (!v.empty()) {
|
||||
string s;
|
||||
bool ret;
|
||||
|
||||
switch (type) {
|
||||
case RA_MSG0: {
|
||||
Messages::MessageMsg0 msg0;
|
||||
ret = msg0.ParseFromString(v);
|
||||
if (ret && (msg0.type() == RA_MSG0)) {
|
||||
s = this->handleMSG0(msg0);
|
||||
res.push_back(to_string(RA_MSG0));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RA_MSG1: {
|
||||
Messages::MessageMSG1 msg1;
|
||||
ret = msg1.ParseFromString(v);
|
||||
if (ret && (msg1.type() == RA_MSG1)) {
|
||||
s = this->handleMSG1(msg1);
|
||||
res.push_back(to_string(RA_MSG2));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RA_MSG3: {
|
||||
Messages::MessageMSG3 msg3;
|
||||
ret = msg3.ParseFromString(v);
|
||||
if (ret && (msg3.type() == RA_MSG3)) {
|
||||
s = this->handleMSG3(msg3);
|
||||
res.push_back(to_string(RA_ATT_RESULT));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RA_APP_ATT_OK: {
|
||||
Messages::SecretMessage sec_msg;
|
||||
ret = sec_msg.ParseFromString(v);
|
||||
if (ret) {
|
||||
if (sec_msg.type() == RA_APP_ATT_OK) {
|
||||
this->handleAppAttOk();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Log("Unknown type: %d", type, log::error);
|
||||
break;
|
||||
}
|
||||
|
||||
res.push_back(s);
|
||||
} else { //after handshake
|
||||
res.push_back(to_string(RA_VERIFICATION));
|
||||
res.push_back(this->prepareVerificationRequest());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#ifndef VERIFICATIONMANAGER_H
|
||||
#define VERIFICATIONMANAGER_H
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ServiceProvider.h"
|
||||
#include "NetworkManagerClient.h"
|
||||
#include "LogBase.h"
|
||||
#include "Messages.pb.h"
|
||||
#include "WebService.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class VerificationManager {
|
||||
|
||||
public:
|
||||
static VerificationManager* getInstance();
|
||||
virtual ~VerificationManager();
|
||||
int init();
|
||||
vector<string> incomingHandler(string v, int type);
|
||||
void start();
|
||||
|
||||
private:
|
||||
VerificationManager();
|
||||
string prepareVerificationRequest();
|
||||
string handleMSG0(Messages::MessageMsg0 m);
|
||||
string handleMSG1(Messages::MessageMSG1 msg);
|
||||
string handleMSG3(Messages::MessageMSG3 msg);
|
||||
string createInitMsg(int type, string msg);
|
||||
string handleAppAttOk();
|
||||
|
||||
private:
|
||||
static VerificationManager* instance;
|
||||
NetworkManagerClient *nm = NULL;
|
||||
ServiceProvider *sp = NULL;
|
||||
WebService *ws = NULL;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "LogBase.h"
|
||||
#include "NetworkManager.h"
|
||||
#include "VerificationManager.h"
|
||||
#include "UtilityFunctions.h"
|
||||
|
||||
using namespace util;
|
||||
|
||||
int Main(int argc, char *argv[]) {
|
||||
LogBase::Inst();
|
||||
|
||||
int ret = 0;
|
||||
|
||||
VerificationManager *vm = VerificationManager::getInstance();
|
||||
vm->init();
|
||||
vm->start();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv ) {
|
||||
try {
|
||||
int ret = Main(argc, argv);
|
||||
return ret;
|
||||
} catch (std::exception & e) {
|
||||
Log("exception: %s", e.what());
|
||||
} catch (...) {
|
||||
Log("unexpected exception");
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue