-
Notifications
You must be signed in to change notification settings - Fork 548
/
sgx_uae_service.cpp
731 lines (637 loc) · 22.7 KB
/
sgx_uae_service.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/*
* Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <oal/uae_oal_api.h>
#include <aesm_error.h>
#include "sgx_uae_service.h"
#include "uae_service_internal.h"
#include "config.h"
#include "stdint.h"
#include "se_sig_rl.h"
#if !defined(ntohl)
#define ntohl(u32) \
((uint32_t)(((((const unsigned char*)&(u32))[0]) << 24) \
+ ((((const unsigned char*)&(u32))[1]) << 16) \
+ ((((const unsigned char*)&(u32))[2]) << 8) \
+ (((const unsigned char*)&(u32))[3])))
#endif
#define GET_LAUNCH_TOKEN_TIMEOUT_MSEC (IPC_LATENCY)
#define SE_INIT_QUOTE_TIMEOUT_MSEC (IPC_LATENCY)
//add 3 millisecond per sig_rl entry
#define SE_GET_QUOTE_TIMEOUT_MSEC(p_sig_rl) (IPC_LATENCY + ((p_sig_rl) ? 3*ntohl(((const se_sig_rl_t*)p_sig_rl)->sig_rl.n2) : 0))
#define SE_GET_PS_CAP_TIMEOUT_MSEC (IPC_LATENCY)
#define SE_REPORT_REMOTE_ATTESTATION_FAILURE_TIMEOUT_MSEC (IPC_LATENCY)
#define GET_WHITE_LIST_SIZE_MSEC (IPC_LATENCY)
#define GET_WHITE_LIST_MSEC (IPC_LATENCY)
#define SGX_GET_EXTENDED_GROUP_ID_MSEC (IPC_LATENCY)
#define SGX_SWITCH_EXTENDED_GROUP_MSEC (IPC_LATENCY)
#define REG_WL_CERT_CHAIN_MSEC (IPC_LATENCY)
extern "C" {
sgx_status_t get_launch_token(
const enclave_css_t* signature,
const sgx_attributes_t* attribute,
sgx_launch_token_t* launch_token)
{
if (signature == NULL || attribute == NULL || launch_token == NULL)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t status = oal_get_launch_token(signature, attribute, launch_token, GET_LAUNCH_TOKEN_TIMEOUT_MSEC*1000, &result);
/*common mappings */
sgx_status_t mapped = oal_map_status(status);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
/*operation specific mapping */
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
case AESM_NO_DEVICE_ERROR:
mapped = SGX_ERROR_NO_DEVICE;
break;
case AESM_GET_LICENSETOKEN_ERROR:
mapped = SGX_ERROR_SERVICE_INVALID_PRIVILEGE;
break;
case AESM_OUT_OF_EPC:
mapped = SGX_ERROR_OUT_OF_EPC;
break;
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t sgx_init_quote(
sgx_target_info_t *p_target_info,
sgx_epid_group_id_t *p_gid)
{
if (p_target_info == NULL || p_gid == NULL)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t status = oal_init_quote(p_target_info, p_gid, SE_INIT_QUOTE_TIMEOUT_MSEC*1000, &result);
sgx_status_t mapped = oal_map_status(status);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
/*operation specific mapping */
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
case AESM_EPIDBLOB_ERROR:
mapped = SGX_ERROR_AE_INVALID_EPIDBLOB;
break;
case AESM_EPID_REVOKED_ERROR:
mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
break;
case AESM_BACKEND_SERVER_BUSY:
mapped = SGX_ERROR_BUSY;
break;
case AESM_SGX_PROVISION_FAILED:
mapped = SGX_ERROR_UNEXPECTED;
break;
case AESM_OUT_OF_EPC:
mapped = SGX_ERROR_OUT_OF_EPC;
break;
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t sgx_get_quote(
const sgx_report_t *p_report,
sgx_quote_sign_type_t quote_type,
const sgx_spid_t *p_spid,
const sgx_quote_nonce_t *p_nonce,
const uint8_t *p_sig_rl,
uint32_t sig_rl_size,
sgx_report_t *p_qe_report,
sgx_quote_t *p_quote,
uint32_t quote_size)
{
if (p_report == NULL || p_spid == NULL || p_quote == NULL || quote_size == 0 )
return SGX_ERROR_INVALID_PARAMETER;
if ((p_sig_rl == NULL && sig_rl_size != 0) ||
(p_sig_rl != NULL && sig_rl_size == 0) )
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t status = oal_get_quote(p_report, quote_type, p_spid, p_nonce, p_sig_rl, sig_rl_size, p_qe_report,
p_quote, quote_size, SE_GET_QUOTE_TIMEOUT_MSEC(p_sig_rl)*1000, &result);
sgx_status_t mapped = oal_map_status(status);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
/*operation specific mapping */
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
case AESM_EPIDBLOB_ERROR:
mapped = SGX_ERROR_AE_INVALID_EPIDBLOB;
break;
case AESM_EPID_REVOKED_ERROR:
mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
break;
case AESM_BACKEND_SERVER_BUSY:
mapped = SGX_ERROR_BUSY;
break;
case AESM_SGX_PROVISION_FAILED:
mapped = SGX_ERROR_UNEXPECTED;
break;
case AESM_OUT_OF_EPC:
mapped = SGX_ERROR_OUT_OF_EPC;
break;
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t sgx_get_ps_cap(sgx_ps_cap_t* p_sgx_ps_cap)
{
if (p_sgx_ps_cap == NULL)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uint64_t ps_cap = 0;
uae_oal_status_t status = oal_get_ps_cap(&ps_cap, SE_GET_PS_CAP_TIMEOUT_MSEC*1000, &result);
p_sgx_ps_cap->ps_cap0 = (uint32_t)ps_cap;
p_sgx_ps_cap->ps_cap1 = (uint32_t)(ps_cap >> 32);
sgx_status_t mapped = oal_map_status(status);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
/*operation specific mapping */
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
case AESM_LONG_TERM_PAIRING_FAILED:
case AESM_EPH_SESSION_FAILED:
case AESM_PSDA_UNAVAILABLE:
mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
break;
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t sgx_report_attestation_status(
const sgx_platform_info_t* p_platform_info,
int attestation_status,
sgx_update_info_bit_t* p_update_info)
{
if (p_platform_info == NULL || p_update_info == NULL)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t status = oal_report_attestation_status(p_platform_info, attestation_status, p_update_info, SE_REPORT_REMOTE_ATTESTATION_FAILURE_TIMEOUT_MSEC*1000, &result);
sgx_status_t mapped = oal_map_status(status);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
/*operation specific mapping */
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
case AESM_BACKEND_SERVER_BUSY:
mapped = SGX_ERROR_BUSY;
break;
case AESM_PLATFORM_INFO_BLOB_INVALID_SIG:
mapped = SGX_ERROR_INVALID_PARAMETER;
break;
case AESM_EPIDBLOB_ERROR:
mapped = SGX_ERROR_AE_INVALID_EPIDBLOB;
break;
case AESM_OUT_OF_EPC:
mapped = SGX_ERROR_OUT_OF_EPC;
break;
case AESM_SGX_PROVISION_FAILED:
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t create_session_ocall(
uint32_t *session_id,
uint8_t *se_dh_msg1,
uint32_t dh_msg1_size,
uint32_t timeout)
{
if(!session_id || !se_dh_msg1)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t status = oal_create_session(session_id, se_dh_msg1, dh_msg1_size, timeout*1000, &result);
sgx_status_t mapped = oal_map_status(status);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
/*operation specific mapping */
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
case AESM_MAX_NUM_SESSION_REACHED:
mapped = SGX_ERROR_BUSY;
break;
case AESM_EPH_SESSION_FAILED:
case AESM_LONG_TERM_PAIRING_FAILED:
case AESM_PSDA_UNAVAILABLE:
case AESM_SERVICE_NOT_AVAILABLE:
mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
break;
case AESM_OUT_OF_EPC:
mapped = SGX_ERROR_OUT_OF_EPC;
break;
case AESM_EPID_REVOKED_ERROR:
mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
break;
case AESM_MSG_ERROR:
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t exchange_report_ocall(
uint32_t session_id,
const uint8_t *se_dh_msg2,
uint32_t dh_msg2_size,
uint8_t *se_dh_msg3,
uint32_t dh_msg3_size,
uint32_t timeout)
{
if (!se_dh_msg2 || !se_dh_msg3)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t status = oal_exchange_report(session_id, se_dh_msg2, dh_msg2_size, se_dh_msg3, dh_msg3_size, timeout*1000, &result);
sgx_status_t mapped = oal_map_status(status);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
/*operation specific mapping */
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
case AESM_SESSION_INVALID:
mapped = SGX_ERROR_AE_SESSION_INVALID;
break;
case AESM_KDF_MISMATCH:
mapped = SGX_ERROR_KDF_MISMATCH;
break;
case AESM_EPH_SESSION_FAILED:
case AESM_LONG_TERM_PAIRING_FAILED:
case AESM_PSDA_UNAVAILABLE:
case AESM_SERVICE_NOT_AVAILABLE:
mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
break;
case AESM_OUT_OF_EPC:
mapped = SGX_ERROR_OUT_OF_EPC;
break;
case AESM_EPID_REVOKED_ERROR:
mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
break;
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t close_session_ocall(
uint32_t session_id,
uint32_t timeout)
{
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t status = oal_close_session(session_id, timeout*1000, &result);
sgx_status_t mapped = oal_map_status(status);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
/*operation specific mapping */
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
case AESM_SESSION_INVALID:
mapped = SGX_ERROR_AE_SESSION_INVALID;
break;
case AESM_EPH_SESSION_FAILED:
case AESM_LONG_TERM_PAIRING_FAILED:
case AESM_SERVICE_NOT_AVAILABLE:
mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
break;
case AESM_OUT_OF_EPC:
mapped = SGX_ERROR_OUT_OF_EPC;
break;
case AESM_EPID_REVOKED_ERROR:
mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
break;
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t invoke_service_ocall(
const uint8_t *pse_message_req,
uint32_t pse_message_req_size,
uint8_t *pse_message_resp,
uint32_t pse_message_resp_size,
uint32_t timeout)
{
if (pse_message_req == NULL || pse_message_resp == NULL)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t status = oal_invoke_service(pse_message_req, pse_message_req_size, pse_message_resp, pse_message_resp_size, timeout*1000, &result);
sgx_status_t mapped = oal_map_status(status);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
/*operation specific mapping */
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
case AESM_SESSION_INVALID:
mapped = SGX_ERROR_AE_SESSION_INVALID;
break;
case AESM_EPH_SESSION_FAILED:
case AESM_LONG_TERM_PAIRING_FAILED:
case AESM_PSDA_UNAVAILABLE:
case AESM_SERVICE_NOT_AVAILABLE:
mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
break;
case AESM_OUT_OF_EPC:
mapped = SGX_ERROR_OUT_OF_EPC;
break;
case AESM_EPID_REVOKED_ERROR:
mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
break;
case AESM_MSG_ERROR:
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t sgx_get_whitelist_size(
uint32_t* p_whitelist_size)
{
if (p_whitelist_size == NULL)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
ret = oal_get_whitelist_size(p_whitelist_size, GET_WHITE_LIST_SIZE_MSEC*1000, &result);
//common mappings
sgx_status_t mapped = oal_map_status(ret);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
//operation specific mapping
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t sgx_get_whitelist(
uint8_t* p_whitelist,
uint32_t whitelist_size)
{
if (p_whitelist == NULL || whitelist_size == 0)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
ret = oal_get_whitelist(p_whitelist, whitelist_size, GET_WHITE_LIST_MSEC*1000, &result);
//common mappings
sgx_status_t mapped = oal_map_status(ret);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
//operation specific mapping
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t sgx_get_extended_epid_group_id(
uint32_t* p_extended_epid_group_id)
{
if (p_extended_epid_group_id == NULL)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
ret = oal_get_extended_epid_group_id(p_extended_epid_group_id, SGX_GET_EXTENDED_GROUP_ID_MSEC*1000, &result);
//common mappings
sgx_status_t mapped = oal_map_status(ret);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
//operation specific mapping
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
sgx_status_t sgx_switch_extended_epid_group(uint32_t extended_epid_group_id)
{
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
ret = oal_switch_extended_epid_group(extended_epid_group_id, SGX_SWITCH_EXTENDED_GROUP_MSEC*1000, &result);
//common mappings
sgx_status_t mapped = oal_map_status(ret);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
//operation specific mapping
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
typedef enum _sgx_register_type_t {SGX_REGISTER_WHITE_LIST_CERT} sgx_register_type_t;
sgx_status_t sgx_register_wl_cert_chain(uint8_t* p_wl_cert_chain, uint32_t wl_cert_chain_size)
{
if (p_wl_cert_chain == NULL || wl_cert_chain_size == 0)
return SGX_ERROR_INVALID_PARAMETER;
aesm_error_t result = AESM_UNEXPECTED_ERROR;
uae_oal_status_t oal_ret = UAE_OAL_ERROR_UNEXPECTED;
oal_ret = oal_register_common(p_wl_cert_chain, wl_cert_chain_size, SGX_REGISTER_WHITE_LIST_CERT,
REG_WL_CERT_CHAIN_MSEC*1000, &result);
//common mappings
sgx_status_t mapped = oal_map_status(oal_ret);
if (mapped != SGX_SUCCESS)
return mapped;
mapped = oal_map_result(result);
if (mapped != SGX_SUCCESS)
{
//operation specific mapping
if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
{
switch (result)
{
default:
mapped = SGX_ERROR_UNEXPECTED;
}
}
}
return mapped;
}
// common mapper function for all OAL specific error codes
sgx_status_t oal_map_status(uae_oal_status_t status)
{
sgx_status_t retVal;
switch (status)
{
case UAE_OAL_SUCCESS:
retVal = SGX_SUCCESS;
break;
case UAE_OAL_ERROR_UNEXPECTED:
retVal = SGX_ERROR_UNEXPECTED;
break;
case UAE_OAL_ERROR_AESM_UNAVAILABLE:
retVal = SGX_ERROR_SERVICE_UNAVAILABLE;
break;
case UAE_OAL_ERROR_TIMEOUT:
retVal = SGX_ERROR_SERVICE_TIMEOUT;
break;
case UAE_OAL_ERROR_INVALID:
retVal = SGX_ERROR_INVALID_PARAMETER;
break;
default:
retVal = SGX_ERROR_UNEXPECTED;
}
return retVal;
}
sgx_status_t oal_map_result(aesm_error_t result)
{
sgx_status_t retVal = SGX_ERROR_UNEXPECTED;
switch (result)
{
case AESM_SUCCESS:
retVal = SGX_SUCCESS;
break;
case AESM_UPDATE_AVAILABLE:
retVal = SGX_ERROR_UPDATE_NEEDED;
break;
case AESM_UNEXPECTED_ERROR:
retVal = SGX_ERROR_UNEXPECTED;
break;
case AESM_PARAMETER_ERROR:
retVal = SGX_ERROR_INVALID_PARAMETER;
break;
case AESM_SERVICE_STOPPED:
case AESM_SERVICE_UNAVAILABLE:
retVal = SGX_ERROR_SERVICE_UNAVAILABLE;
break;
case AESM_OUT_OF_MEMORY_ERROR:
retVal = SGX_ERROR_OUT_OF_MEMORY;
break;
case AESM_BUSY:
retVal = SGX_ERROR_BUSY;
break;
case AESM_UNRECOGNIZED_PLATFORM:
retVal = SGX_ERROR_UNRECOGNIZED_PLATFORM;
break;
case AESM_NETWORK_ERROR:
case AESM_NETWORK_BUSY_ERROR:
case AESM_PROXY_SETTING_ASSIST:
retVal = SGX_ERROR_NETWORK_FAILURE;
break;
case AESM_NO_DEVICE_ERROR:
retVal = SGX_ERROR_NO_DEVICE;
break;
default:
retVal = SGX_ERROR_UNEXPECTED;
}
return retVal;
}
} /* extern "C" */