Skip to content

Commit 1efe23c

Browse files
lingyujllly
authored andcommitted
Add support for AESM command line option --supported_attestation_types
Signed-off-by: lingyuji <[email protected]>
1 parent 33a1ec1 commit 1efe23c

File tree

8 files changed

+136
-37
lines changed

8 files changed

+136
-37
lines changed

psw/ae/aesm_service/source/bundles/ecdsa_quote_service_bundle/ecdsa_quote_service_bundle.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ class EcdsaQuoteServiceImp : public IQuoteProviderService
427427
*att_key_id_num = 1;
428428
return AESM_SUCCESS;
429429
}
430+
431+
uint16_t get_attestation_type()
432+
{
433+
return ATTESTATION_TYPE_ECDSA;
434+
435+
}
430436
};
431437

432438
class Activator : public BundleActivator

psw/ae/aesm_service/source/bundles/epid_quote_service_bundle/epid_quote_service_bundle.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,12 @@ class EpidQuoteServiceImp : public IEpidQuoteService, public IQuoteProviderServi
577577
update_info, update_info_size,
578578
config, status);
579579
}
580+
581+
uint16_t get_attestation_type()
582+
{
583+
return ATTESTATION_TYPE_EPID;
584+
585+
}
580586
};
581587

582588
class Activator : public BundleActivator

psw/ae/aesm_service/source/bundles/quote_ex_service_bundle/quote_ex_service_bundle.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,16 @@ class QuoteExServiceImp : public IQuoteProxyService
6767
std::vector<quote_provider_t> available_providers;
6868
ListenerToken listenerToken;
6969
AESMLogicMutex quote_ex_mutex;
70+
uint16_t supported_attestation_types;
7071

7172
public:
72-
QuoteExServiceImp():initialized(false), default_quoting_type(AESM_QUOTING_DEFAULT_VALUE) {}
73+
QuoteExServiceImp():initialized(false), default_quoting_type(AESM_QUOTING_DEFAULT_VALUE),
74+
supported_attestation_types(0) {}
75+
76+
void set_supported_attestation_types(uint16_t att_types)
77+
{
78+
supported_attestation_types = att_types;
79+
}
7380

7481
ae_error_t start()
7582
{
@@ -95,27 +102,38 @@ class QuoteExServiceImp : public IQuoteProxyService
95102
if (IQuoteProviderService::VERSION != bundle.GetVersion().GetMajor())
96103
continue;
97104

98-
auto service = context.GetService(sr);
99-
if (service
100-
&& (AE_SUCCESS == service->start()))
101-
{
102-
uint32_t num = 0;
103-
sgx_att_key_id_ext_t att_key_id_ext_list[BUNLE_ATT_KEY_NUM_MAX] ={0};
104105

105-
available_providers.push_back(service);
106-
if (AESM_SUCCESS != service->get_att_key_id_num(&num))
107-
continue;
108-
if (num > BUNLE_ATT_KEY_NUM_MAX)
109-
continue;
110-
if (AESM_SUCCESS != service->get_att_key_id((uint8_t *)att_key_id_ext_list, sizeof(att_key_id_ext_list)))
111-
continue;
112-
for (int i = 0; i <num; i++)
113-
{
114-
available_key_id_t temp = {0};
115-
memcpy_s(&temp.key_id, sizeof(temp.key_id), &att_key_id_ext_list[i], sizeof(att_key_id_ext_list[i]));
116-
temp.service = service;
117-
available_key_ids.push_back(temp);
118-
AESM_DBG_INFO("quote type %d available", temp.key_id.base.algorithm_id);
106+
auto service = context.GetService(sr);
107+
if (service) {
108+
ae_error_t service_started = service->start();
109+
if (AE_SUCCESS == service_started) {
110+
uint32_t num = 0;
111+
sgx_att_key_id_ext_t att_key_id_ext_list[BUNLE_ATT_KEY_NUM_MAX] ={0};
112+
113+
available_providers.push_back(service);
114+
if (AESM_SUCCESS != service->get_att_key_id_num(&num))
115+
continue;
116+
if (num > BUNLE_ATT_KEY_NUM_MAX)
117+
continue;
118+
if (AESM_SUCCESS != service->get_att_key_id((uint8_t *)att_key_id_ext_list, sizeof(att_key_id_ext_list)))
119+
continue;
120+
for (int i = 0; i <num; i++)
121+
{
122+
available_key_id_t temp = {0};
123+
memcpy_s(&temp.key_id, sizeof(temp.key_id), &att_key_id_ext_list[i], sizeof(att_key_id_ext_list[i]));
124+
temp.service = service;
125+
available_key_ids.push_back(temp);
126+
AESM_DBG_INFO("quote type %d available", temp.key_id.base.algorithm_id);
127+
}
128+
}
129+
else {
130+
// If the attestation type was required but the service failed to start, return error.
131+
// Otherwise ignore the failure
132+
uint16_t att_type_of_service = service->get_attestation_type();
133+
if (supported_attestation_types & att_type_of_service) {
134+
AESM_DBG_INFO("Failed to start attestation service : %d ", att_type_of_service);
135+
return service_started;
136+
}
119137
}
120138
}
121139
}

psw/ae/aesm_service/source/core/AESMLogicWrapper.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
static cppmicroservices::BundleContext g_fw_ctx;
6262
using namespace cppmicroservices;
6363
static Framework g_fw = FrameworkFactory().NewFramework();
64-
64+
extern uint16_t supported_attestation_types;
6565

6666
#ifdef US_PLATFORM_POSIX
6767
#define PATH_SEPARATOR "/"
@@ -688,6 +688,23 @@ ae_error_t AESMLogicWrapper::service_start()
688688
// Start the framework itself.
689689
g_fw.Start();
690690
auto bundles = g_fw_ctx.GetBundles();
691+
// check required attestation bundles
692+
bool found_epid = false, found_ecdsa = false;
693+
for (Bundle &bundle : bundles) {
694+
if (bundle.GetSymbolicName() == "epid_quote_service_bundle_name")
695+
found_epid = true;
696+
else if (bundle.GetSymbolicName() == "ecdsa_quote_service_bundle_name")
697+
found_ecdsa = true;
698+
}
699+
if (!found_epid && (supported_attestation_types & ATTESTATION_TYPE_EPID)) {
700+
AESM_LOG_ERROR("EPID attestation is required but the bundle is not installed.");
701+
return AE_FAILURE;
702+
}
703+
if (!found_ecdsa && (supported_attestation_types & ATTESTATION_TYPE_ECDSA)) {
704+
AESM_LOG_ERROR("ECDSA attestation is required but the bundle is not installed.");
705+
return AE_FAILURE;
706+
}
707+
691708
for (auto &bundle : bundles)
692709
{
693710
bundle.Start();
@@ -722,8 +739,14 @@ ae_error_t AESMLogicWrapper::service_start()
722739
}
723740
{
724741
std::shared_ptr<IQuoteProxyService> service;
725-
if (get_service_wrapper(service, g_fw_ctx))
726-
service->start();
742+
if (get_service_wrapper(service, g_fw_ctx))
743+
{
744+
service->set_supported_attestation_types(supported_attestation_types);
745+
ae_error_t ret = service->start();
746+
747+
if (ret != AE_SUCCESS)
748+
return ret;
749+
}
727750
}
728751
AESM_DBG_INFO("aesm service started");
729752

psw/ae/aesm_service/source/core/main.cpp

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,22 @@
3434
#include <CAESMServer.h>
3535
#include <CSelector.h>
3636
#include <AESMLogicWrapper.h>
37+
#include "quote_ex_service.h"
3738
#include <curl/curl.h>
3839
#include <oal/error_report.h>
3940

4041
#include <SocketConfig.h>
4142

4243
#include <iostream>
44+
#include <getopt.h>
4345

4446
static CAESMServer* server = NULL;
4547
volatile bool reload = false;
48+
// Each bit indicates a certain type of attestation is supported.
49+
// If a attestation type is marked as supported but AESM fails to load the corresponding module,
50+
// AESM will exit.
51+
// Currently only two attestation types can be supported: Bit 0: EPID Bit 1: ECDSA
52+
uint16_t supported_attestation_types = 0;
4653

4754
void signal_handler(int sig)
4855
{
@@ -67,26 +74,61 @@ void signal_handler(int sig)
6774
}
6875
}
6976

77+
void print_usage() {
78+
printf("Usage: aesm_service [--no-daemon] [--no-syslog] [--supported_attestation_types=[EPID][,ECDSA]]\n");
79+
}
80+
7081
int main(int argc, char *argv[]) {
7182
bool noDaemon = false, noSyslog = false;
83+
int opt= 0;
7284

73-
if (argc > 3) {
74-
AESM_LOG_INIT();
75-
AESM_LOG_FATAL("Invalid command line.");
76-
AESM_LOG_FINI();
77-
exit(1);
78-
}
85+
//Specifying the expected options
86+
static struct option long_options[] = {
87+
{"no-daemon", no_argument, 0, 0 },
88+
{"no-syslog", no_argument, 0, 1 },
89+
{"supported_attestation_types", required_argument, 0, 2 },
90+
{0, 0, 0, 0}
91+
};
7992

80-
for (int i = 1; i < argc; ++i) {
81-
std::string arg = argv[i];
82-
if (arg == "--no-daemon") {
83-
noDaemon = true;
84-
}
85-
else if (arg == "--no-syslog"){
86-
noSyslog = true;
93+
int long_index =0;
94+
while ((opt = getopt_long(argc, argv, "012:", long_options, &long_index )) != -1) {
95+
switch (opt) {
96+
case 0:
97+
noDaemon = true;
98+
break;
99+
case 1:
100+
noSyslog = true;
101+
break;
102+
case 2:
103+
if (optarg) {
104+
char * token = strtok(optarg, ",");
105+
while( token != NULL ) {
106+
if (strcasecmp(token, "epid") == 0) {
107+
supported_attestation_types |= ATTESTATION_TYPE_EPID;
108+
}
109+
else if (strcasecmp(token, "ecdsa") == 0) {
110+
supported_attestation_types |= ATTESTATION_TYPE_ECDSA;
111+
}
112+
else {
113+
print_usage();
114+
exit(EXIT_FAILURE);
115+
}
116+
token = strtok(NULL, ",");
117+
}
118+
}
119+
break;
120+
default:
121+
print_usage();
122+
exit(EXIT_FAILURE);
87123
}
88124
}
89125

126+
if (optind < argc) {
127+
fprintf(stderr, "%s: invalid option -- '%s'\n", argv[0], argv[optind]);
128+
print_usage();
129+
exit(EXIT_FAILURE);
130+
}
131+
90132
AESM_LOG_INIT_EX(noSyslog);
91133

92134
if(!noDaemon) {

psw/ae/aesm_service/source/interfaces/quote_ex_service.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <stddef.h>
3737
#include "aesm_error.h"
3838

39+
#define ATTESTATION_TYPE_EPID 0x0001
40+
#define ATTESTATION_TYPE_ECDSA 0x0002
3941

4042
struct IQuoteExService : virtual public IService
4143
{

psw/ae/aesm_service/source/interfaces/quote_provider_service.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct IQuoteProviderService : public IQuoteExService, public IGetAttKeyID
3939
// The value should be the same as the major version in manifest.json
4040
enum {VERSION = 2};
4141
virtual ~IQuoteProviderService() = default;
42+
virtual uint16_t get_attestation_type() = 0;
4243
};
4344

4445
#endif /* QUOTE_PROVIDER_SERVICE_EXPORT_H */

psw/ae/aesm_service/source/interfaces/quote_proxy_service.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct IQuoteProxyService : public IQuoteExService, public ISelectAttKeyID, publ
4040
// The value should be the same as the major version in manifest.json
4141
enum {VERSION = 2};
4242
virtual ~IQuoteProxyService() = default;
43+
virtual void set_supported_attestation_types(uint16_t att_types) = 0;
4344
};
4445

4546
#endif /* QUOTE_PROXY_SERVICE_EXPORT_H */

0 commit comments

Comments
 (0)