Skip to content

Commit 18c7f7c

Browse files
committed
[accless] E: Remove Redundant Headers In Attestation Lib
1 parent 277ea85 commit 18c7f7c

File tree

4 files changed

+8
-85
lines changed

4 files changed

+8
-85
lines changed

accless/libs/attestation/attestation.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,11 @@
1111

1212
namespace accless::attestation {
1313

14-
// We copy this structures from:
15-
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/sev-guest.h#L80
16-
constexpr size_t SNP_REPORT_USER_DATA_SIZE = 64;
17-
constexpr size_t SNP_REPORT_RESP_SIZE = 4000;
18-
19-
// FIXME: check if all of these are used
20-
constexpr size_t SGX_REPORT_DATA_SIZE = 64;
21-
constexpr size_t SNP_REPORT_DATA_SIZE = 64;
22-
constexpr size_t MOCK_QUOTE_HEADER_SIZE = 16;
23-
constexpr uint32_t MOCK_QUOTE_VERSION = 1;
14+
// FIXME(#44): eventually move this to an accless AES-GCM library.
2415
constexpr size_t AES_128_KEY_SIZE = 16;
2516
constexpr size_t AES_GCM_IV_SIZE = 12;
2617
constexpr size_t AES_GCM_TAG_SIZE = 16;
2718

28-
struct snp_report_req {
29-
uint8_t user_data[SNP_REPORT_USER_DATA_SIZE];
30-
uint32_t vmpl;
31-
uint8_t rsvd[28];
32-
};
33-
34-
struct snp_report_resp {
35-
uint8_t data[SNP_REPORT_RESP_SIZE];
36-
};
37-
3819
namespace utils {
3920
// Helper methods
4021
std::string extractJsonStringField(const std::string &json,

accless/libs/attestation/mock.cpp

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <stdexcept>
1212

1313
namespace accless::attestation::mock {
14+
constexpr size_t MOCK_QUOTE_HEADER_SIZE = 16;
15+
constexpr uint32_t MOCK_QUOTE_VERSION = 1;
16+
1417
std::vector<uint8_t> buildMockQuote(const std::vector<uint8_t> &reportData,
1518
const std::array<uint8_t, 8> &magic) {
1619
std::vector<uint8_t> quote;
@@ -34,67 +37,4 @@ std::vector<uint8_t> buildMockQuote(const std::vector<uint8_t> &reportData,
3437

3538
return quote;
3639
}
37-
38-
/*
39-
size_t mockCurlWriteCallback(char *ptr, size_t size, size_t nmemb,
40-
void *userdata) {
41-
size_t total = size * nmemb;
42-
auto *response = static_cast<std::string *>(userdata);
43-
response->append(ptr, total);
44-
return total;
45-
}
46-
47-
std::string postMockQuote(const std::string &url, const std::string &certPath,
48-
const std::string &body,
49-
const std::string &endpoint) {
50-
CURL *curl = curl_easy_init();
51-
if (curl == nullptr) {
52-
throw std::runtime_error("accless(att): failed to init curl");
53-
}
54-
55-
char errbuf[CURL_ERROR_SIZE];
56-
errbuf[0] = 0;
57-
58-
std::string response;
59-
std::string fullUrl = url + endpoint;
60-
curl_easy_setopt(curl, CURLOPT_URL, fullUrl.c_str());
61-
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
62-
curl_easy_setopt(curl, CURLOPT_CAINFO, certPath.c_str());
63-
curl_easy_setopt(curl, CURLOPT_POST, 1L);
64-
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
65-
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
66-
static_cast<long>(body.size()));
67-
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, mockCurlWriteCallback);
68-
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
69-
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
70-
71-
struct curl_slist *headers = nullptr;
72-
headers = curl_slist_append(headers, "Content-Type: application/json");
73-
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
74-
75-
CURLcode res = curl_easy_perform(curl);
76-
long status = 0;
77-
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
78-
curl_easy_cleanup(curl);
79-
curl_slist_free_all(headers);
80-
81-
if (res != CURLE_OK) {
82-
size_t len = strlen(errbuf);
83-
fprintf(stderr, "accless(att): curl error: ");
84-
if (len) {
85-
fprintf(stderr, "%s%s", errbuf,
86-
((errbuf[len - 1] != '\n') ? "\n" : ""));
87-
} else {
88-
fprintf(stderr, "%s\n", curl_easy_strerror(res));
89-
}
90-
throw std::runtime_error("accless(att): curl error posting mock quote");
91-
}
92-
if (status != 200) {
93-
throw std::runtime_error(
94-
"accless(att): attestation service rejected mock quote");
95-
}
96-
97-
return response;
98-
}
99-
*/
10040
} // namespace accless::attestation::mock

accless/libs/attestation/mock_sgx.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace accless::attestation::mock {
88

9+
constexpr size_t SGX_REPORT_DATA_SIZE = 64;
910
const std::array<uint8_t, 8> MOCK_QUOTE_MAGIC_SGX = {'A', 'C', 'C', 'L',
1011
'S', 'G', 'X', '!'};
1112

@@ -14,7 +15,8 @@ std::string getMockSgxAttestationJwt() {
1415
accless::attestation::ec::EcKeyPair keyPair;
1516

1617
// Embed EC keypair in empty (mocked) SGX quote.
17-
auto reportData = keyPair.getReportData();
18+
std::array<uint8_t, SGX_REPORT_DATA_SIZE> reportData =
19+
keyPair.getReportData();
1820
std::vector<uint8_t> reportVec(reportData.begin(), reportData.end());
1921

2022
// Populate the mocked quote.

accless/libs/attestation/snp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ std::string getAttestationJwt(const std::string &gid,
197197
accless::attestation::ec::EcKeyPair keyPair;
198198

199199
// Get auxiliary report data: serialized public halve of the EC keypair.
200-
std::array<uint8_t, SGX_REPORT_DATA_SIZE> reportData =
200+
std::array<uint8_t, SNP_REPORT_USER_DATA_SIZE> reportData =
201201
keyPair.getReportData();
202202
std::vector<uint8_t> reportDataVec(reportData.begin(), reportData.end());
203203

0 commit comments

Comments
 (0)