Skip to content

Commit 3ea8e6b

Browse files
authored
Merge pull request #300 from fqiu1/add-qgs-get-platform-info
Add new interface in QGS to get platform information
2 parents 09666b3 + 77b3476 commit 3ea8e6b

File tree

13 files changed

+720
-19
lines changed

13 files changed

+720
-19
lines changed

QuoteGeneration/quote_wrapper/qgs/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ifeq ($(CC_NO_LESS_THAN_8), 1)
4848
QGS_CXXFLAGS += -fcf-protection=none
4949
endif
5050

51-
DEPENDS = ${QGS_OBJS:.o=.d}
51+
DEPENDS = ${QGS_OBJS test_client.o:.o=.d}
5252

5353
# SGX related libraries
5454
QGS_LFLAGS = -L$(TOP_DIR)/build/linux -lsgx_tdx_logic -lsgx_pce_logic -ldl \
@@ -62,13 +62,16 @@ vpath %.c $(COMMON_DIR)/src
6262

6363
-include ${DEPENDS}
6464

65-
all: qgs
65+
all: qgs test_client
6666

6767
qgs: $(QGS_OBJS)
6868
make -C ../qgs_msg_lib/linux
6969
make -C ../tdx_quote/linux
7070
$(CXX) -o $@ $^ $(QGS_LFLAGS)
7171

72+
test_client: test_client.o
73+
$(CC) -o $@ $^ -L../qgs_msg_lib/linux -lqgs_msg
74+
7275
%.o: %.cpp
7376
$(CXX) -c $(QGS_CXXFLAGS) $<
7477

QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
173173
QGS_LOG_ERROR("qgs_msg_inflate_get_collateral_req return error\n");
174174
} else {
175175
do {
176-
extern tee_att_error_t tee_att_get_qpl_handle(const tee_att_config_t *p_context,
177-
void **pp_qpl_handle);
178-
179176
char *error1 = NULL;
180177
char *error2 = NULL;
181178
void *p_handle = NULL;
@@ -231,6 +228,40 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
231228
}
232229
break;
233230
}
231+
case GET_PLATFORM_INFO_REQ: {
232+
tee_platform_info_t platform_info;
233+
qgs_msg_error_ret = qgs_msg_inflate_get_platform_info_req(p_req, req_size);
234+
if (QGS_MSG_SUCCESS != qgs_msg_error_ret) {
235+
// TODO: need to define the error code list for R3AAL
236+
resp_error_code = QGS_MSG_ERROR_UNEXPECTED;
237+
QGS_LOG_ERROR("qgs_msg_inflate_get_platform_info_req return error\n");
238+
} else {
239+
QGS_LOG_INFO("call tee_att_init_quote\n");
240+
tee_att_ret = tee_att_get_platform_info(ptr.get(), &platform_info);
241+
if (TEE_ATT_SUCCESS != tee_att_ret) {
242+
resp_error_code = QGS_MSG_ERROR_UNEXPECTED;
243+
QGS_LOG_ERROR("tee_att_get_platform_info return 0x%x\n", tee_att_ret);
244+
} else {
245+
resp_error_code = QGS_MSG_SUCCESS;
246+
QGS_LOG_INFO("tee_att_get_platform_info return Success\n");
247+
}
248+
}
249+
if (resp_error_code == QGS_MSG_SUCCESS) {
250+
qgs_msg_error_ret = qgs_msg_gen_get_platform_info_resp(platform_info.tdqe_isv_svn,
251+
platform_info.pce_isv_svn,
252+
(uint8_t *)&(platform_info.platform_id), sizeof(platform_info.platform_id),
253+
(uint8_t *)&(platform_info.cpu_svn), sizeof(platform_info.cpu_svn),
254+
&p_resp, &resp_size);
255+
} else {
256+
qgs_msg_error_ret = qgs_msg_gen_error_resp(resp_error_code, GET_PLATFORM_INFO_RESP, &p_resp, &resp_size);
257+
}
258+
if (QGS_MSG_SUCCESS != qgs_msg_error_ret) {
259+
QGS_LOG_ERROR("call qgs_msg_gen function failed\n");
260+
qgs_msg_free(p_resp);
261+
return {};
262+
}
263+
break;
264+
}
234265
default:
235266
QGS_LOG_ERROR("Whoops, bad request!");
236267
return {};

QuoteGeneration/quote_wrapper/qgs/qgs_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class QgsConnection : public boost::enable_shared_from_this<QgsConnection> {
150150
unsigned msg_len = decode_header(m_readbuf);
151151
QGS_LOG_INFO("body should be [%d] bytes!\n", msg_len);
152152
if (!msg_len) {
153-
QGS_LOG_INFO("Failed to decode heaer, stop\n");
153+
QGS_LOG_INFO("Failed to decode header, stop\n");
154154
m_timer.cancel();
155155
stop();
156156
} else {
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/*
2+
* Copyright (C) 2011-2022 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+
#include <sys/socket.h>
33+
#include <linux/vm_sockets.h>
34+
#include "qgs_msg_lib.h"
35+
36+
#include <stdint.h>
37+
#include <string.h>
38+
#include <stdio.h>
39+
#include <unistd.h>
40+
#include <stdlib.h>
41+
42+
43+
static const unsigned HEADER_SIZE = 4;
44+
45+
#define HEX_DUMP_SIZE 16
46+
static void print_hex_dump(const char *title, const char *prefix_str,
47+
const uint8_t *buf, uint32_t len) {
48+
const uint8_t *ptr = buf;
49+
uint32_t i, rowsize = HEX_DUMP_SIZE;
50+
51+
if (!len || !buf)
52+
return;
53+
54+
fprintf(stdout, "\t\t%s", title);
55+
56+
for (i = 0; i < len; i++) {
57+
if (!(i % rowsize))
58+
fprintf(stdout, "\n%s%.8x:", prefix_str, i);
59+
if (ptr[i] <= 0x0f)
60+
fprintf(stdout, " 0%x", ptr[i]);
61+
else
62+
fprintf(stdout, " %x", ptr[i]);
63+
}
64+
65+
fprintf(stdout, "\n");
66+
}
67+
68+
int main(int argc, char *argv[])
69+
{
70+
(void)argc;
71+
(void)argv;
72+
int s = -1;
73+
int ret = 0;
74+
75+
uint8_t buf[4 * 1024] = {0};
76+
uint32_t msg_size = 0;
77+
uint32_t in_msg_size = 0;
78+
uint32_t recieved_bytes = 0;
79+
80+
uint16_t tdqe_isvsvn;
81+
uint16_t pce_isvsvn;
82+
const uint8_t *p_platform_id = NULL;
83+
uint32_t platform_id_size = 0;
84+
const uint8_t *p_cpusvn = NULL;
85+
uint32_t cpusvn_size = 0;
86+
87+
qgs_msg_error_t qgs_msg_ret = QGS_MSG_SUCCESS;
88+
qgs_msg_header_t *p_header = NULL;
89+
uint8_t *p_req = NULL;
90+
91+
qgs_msg_ret = qgs_msg_gen_get_platform_info_req(&p_req, &msg_size);
92+
if (QGS_MSG_SUCCESS != qgs_msg_ret) {
93+
fprintf(stderr, "\nqgs_msg_gen_get_platform_info_req return 0x%x\n", qgs_msg_ret);
94+
ret = 1;
95+
goto ret_point;
96+
}
97+
98+
buf[0] = (uint8_t)((msg_size >> 24) & 0xFF);
99+
buf[1] = (uint8_t)((msg_size >> 16) & 0xFF);
100+
buf[2] = (uint8_t)((msg_size >> 8) & 0xFF);
101+
buf[3] = (uint8_t)(msg_size & 0xFF);
102+
103+
memcpy(buf + HEADER_SIZE, p_req, msg_size);
104+
qgs_msg_free(p_req);
105+
106+
s = socket(AF_VSOCK, SOCK_STREAM, 0);
107+
if (-1 == s) {
108+
fprintf(stderr, "\nsocket return 0x%x\n", qgs_msg_ret);
109+
ret = 1;
110+
goto ret_point;
111+
}
112+
struct sockaddr_vm vm_addr;
113+
memset(&vm_addr, 0, sizeof(vm_addr));
114+
vm_addr.svm_family = AF_VSOCK;
115+
vm_addr.svm_reserved1 = 0;
116+
vm_addr.svm_port = 4050;
117+
vm_addr.svm_cid = VMADDR_CID_HOST;
118+
if (connect(s, (struct sockaddr *)&vm_addr, sizeof(vm_addr))) {
119+
fprintf(stderr, "\nconnect error\n");
120+
ret = 1;
121+
goto ret_point;
122+
}
123+
124+
// Write to socket
125+
if (HEADER_SIZE + msg_size != send(s, buf, HEADER_SIZE + msg_size, 0)) {
126+
fprintf(stderr, "\nsend error\n");
127+
ret = 1;
128+
goto ret_point;
129+
}
130+
131+
// Read the response size header
132+
if (HEADER_SIZE != recv(s, buf, HEADER_SIZE, 0)) {
133+
fprintf(stderr, "\nrecv error\n");
134+
ret = 1;
135+
goto ret_point;
136+
}
137+
138+
// decode the size
139+
for (unsigned i = 0; i < HEADER_SIZE; ++i) {
140+
in_msg_size = in_msg_size * 256 + ((buf[i]) & 0xFF);
141+
}
142+
143+
if (sizeof(buf) - HEADER_SIZE < in_msg_size) {
144+
fprintf(stderr, "\nReply message body is too big");
145+
ret = 1;
146+
goto ret_point;
147+
}
148+
while( recieved_bytes < in_msg_size) {
149+
int recv_ret = (int)recv(s, buf + HEADER_SIZE + recieved_bytes,
150+
in_msg_size - recieved_bytes, 0);
151+
if (recv_ret < 0) {
152+
fprintf(stderr, "\nrecv return value < 0");
153+
ret = 1;
154+
goto ret_point;
155+
}
156+
recieved_bytes += (uint32_t)recv_ret;
157+
}
158+
159+
qgs_msg_ret = qgs_msg_inflate_get_platform_info_resp(buf + HEADER_SIZE, in_msg_size,
160+
&tdqe_isvsvn, &pce_isvsvn, &p_platform_id, &platform_id_size, &p_cpusvn, &cpusvn_size);
161+
162+
if (QGS_MSG_SUCCESS != qgs_msg_ret) {
163+
fprintf(stderr, "\nqgs_msg_inflate_get_platform_info_resp return 0x%x\n", qgs_msg_ret);
164+
ret = 1;
165+
goto ret_point;
166+
}
167+
168+
// We've called qgs_msg_inflate_get_quote_resp, the message type should be GET_QUOTE_RESP
169+
p_header = (qgs_msg_header_t *)(buf + HEADER_SIZE);
170+
if (p_header->error_code != 0) {
171+
fprintf(stderr, "\nerror code in resp msg is 0x%x", p_header->error_code);
172+
ret = 1;
173+
goto ret_point;
174+
}
175+
fprintf(stdout, "\nPCE_ISVSVN: %d\tTDQE_ISVSVN: %d\n", pce_isvsvn, tdqe_isvsvn);
176+
print_hex_dump("\n\t\tQEID\n", " ", p_platform_id, platform_id_size);
177+
print_hex_dump("\n\t\tCPUSVN\n", " ", p_cpusvn, cpusvn_size);
178+
ret = 0;
179+
180+
ret_point:
181+
if (s >= 0) {
182+
close(s);
183+
}
184+
185+
return ret;
186+
}

QuoteGeneration/quote_wrapper/qgs_msg_lib/inc/qgs_msg_lib.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ typedef enum _qgs_msg_type_t {
6565
GET_QUOTE_RESP = 1,
6666
GET_COLLATERAL_REQ = 2,
6767
GET_COLLATERAL_RESP = 3,
68+
GET_PLATFORM_INFO_REQ = 4,
69+
GET_PLATFORM_INFO_RESP = 5,
6870
QGS_MSG_TYPE_MAX
6971
} qgs_msg_type_t;
7072

@@ -111,6 +113,19 @@ typedef struct _qgs_msg_get_collateral_resp_s {
111113
uint8_t collaterals[]; // payload filled in same order as upper sizes parameters
112114
} qgs_msg_get_collateral_resp_t;
113115

116+
typedef struct _qgs_msg_get_platform_info_req_t {
117+
qgs_msg_header_t header; // header.type = GET_PLATFORM_INFO_REQ
118+
} qgs_msg_get_platform_info_req_t;
119+
120+
typedef struct _qgs_msg_get_platform_info_resp_s {
121+
qgs_msg_header_t header; // header.type = GET_PLATFORM_INFO_RESP
122+
uint16_t tdqe_isvsvn;
123+
uint16_t pce_isvsvn;
124+
uint32_t platform_id_size;
125+
uint32_t cpusvn_size;
126+
uint8_t platform_id_cpusvn[];
127+
} qgs_msg_get_platform_info_resp_t;
128+
114129
#pragma pack(pop)
115130

116131
#if defined(__cplusplus)
@@ -171,6 +186,21 @@ qgs_msg_error_t qgs_msg_inflate_get_collateral_resp(
171186
const uint8_t **pp_qe_identity, uint32_t *p_qe_identity_size);
172187
uint32_t qgs_msg_get_type(const uint8_t *p_serialized_msg, uint32_t size, uint32_t *p_type);
173188

189+
qgs_msg_error_t qgs_msg_gen_get_platform_info_req(
190+
uint8_t **pp_req, uint32_t *p_req_size);
191+
qgs_msg_error_t qgs_msg_inflate_get_platform_info_req(
192+
const uint8_t *p_serialized_req, uint32_t size);
193+
qgs_msg_error_t qgs_msg_gen_get_platform_info_resp(
194+
uint16_t tdqe_isvsvn, uint16_t pce_isvsvn,
195+
const uint8_t *p_platform_id, uint32_t platform_id_size,
196+
const uint8_t *p_cpusvn, uint32_t cpusvn_size,
197+
uint8_t **pp_resp, uint32_t *p_resp_size);
198+
qgs_msg_error_t qgs_msg_inflate_get_platform_info_resp(
199+
const uint8_t *p_serialized_resp, uint32_t size,
200+
uint16_t *p_tdqe_isvsvn, uint16_t *p_pce_isvsvn,
201+
const uint8_t **pp_platform_id, uint32_t *p_platform_id_size,
202+
const uint8_t **pp_cpusvn, uint32_t *p_cpusvn_size);
203+
174204
#if defined(__cplusplus)
175205
}
176206
#endif

0 commit comments

Comments
 (0)