Skip to content

Instantly share code, notes, and snippets.

@algon-320
Last active January 15, 2022 11:22
Show Gist options
  • Save algon-320/9256454fb8d9ba8ad44bc3877d644175 to your computer and use it in GitHub Desktop.
Save algon-320/9256454fb8d9ba8ad44bc3877d644175 to your computer and use it in GitHub Desktop.
a test program for `sgx_report_attestation_status`
#include <stdio.h>
#include <stdlib.h>
#include <sgx_uae_epid.h>
int main(int argc, char *argv[]) {
// Read hex string from stdin
char buf[202+1];
if (!fgets(buf, 203, stdin)) abort();
// Conver hex string to byte sequence
unsigned char platform_info[101];
for (int i = 0; i < 202; i += 2) {
const char hex[2] = {buf[i], buf[i+1]};
unsigned char b = (unsigned char)strtol(hex, NULL, 16);
platform_info[i/2] = b;
}
sgx_status_t status;
sgx_update_info_bit_t update_info;
status = sgx_report_attestation_status(
(sgx_platform_info_t*)platform_info,
1,
&update_info);
switch (status) {
case SGX_SUCCESS:
printf("SGX_SUCCESS\n");
break;
case SGX_ERROR_INVALID_PARAMETER:
printf("SGX_ERROR_INVALID_PARAMETER\n");
break;
case SGX_ERROR_AE_INVALID_EPIDBLOB:
printf("SGX_ERROR_AE_INVALID_EPIDBLOB\n");
break;
case SGX_ERROR_UPDATE_NEEDED:
printf("SGX_ERROR_UPDATE_NEEDED\n");
printf("ucodeUpdate = %d\n", update_info.ucodeUpdate);
printf("csmeFwUpdate = %d\n", update_info.csmeFwUpdate);
printf("pswUpdate = %d\n", update_info.pswUpdate);
break;
case SGX_ERROR_OUT_OF_MEMORY:
printf("SGX_ERROR_OUT_OF_MEMORY\n");
break;
case SGX_ERROR_SERVICE_UNAVAILABLE:
printf("SGX_ERROR_SERVICE_UNAVAILABLE\n");
break;
case SGX_ERROR_SERVICE_TIMEOUT:
printf("SGX_ERROR_SERVICE_TIMEOUT\n");
break;
case SGX_ERROR_BUSY:
printf("SGX_ERROR_BUSY\n");
break;
case SGX_ERROR_NETWORK_FAILURE:
printf("SGX_ERROR_NETWORK_FAILURE\n");
break;
case SGX_ERROR_OUT_OF_EPC:
printf("SGX_ERROR_OUT_OF_EPC\n");
break;
case SGX_ERROR_UNRECOGNIZED_PLATFORM:
printf("SGX_ERROR_UNRECOGNIZED_PLATFORM\n");
break;
case SGX_ERROR_UNEXPECTED:
printf("SGX_ERROR_UNEXPECTED\n");
break;
}
return 0;
}
main: main.c
gcc main.c $(shell pkg-config --cflags --libs libsgx_epid) -o main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment