From 5a12559f5d55a162da3108fe2e8a93fbfe64fe31 Mon Sep 17 00:00:00 2001 From: Sascha Tommasone Date: Sat, 6 Jul 2024 16:02:26 +0200 Subject: [PATCH] [Assignment-7] . --- 7-SGX_Hands-on/src/app/embedded_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/7-SGX_Hands-on/src/app/embedded_device.c b/7-SGX_Hands-on/src/app/embedded_device.c index f6fcce0..c4782cd 100644 --- a/7-SGX_Hands-on/src/app/embedded_device.c +++ b/7-SGX_Hands-on/src/app/embedded_device.c @@ -27,6 +27,7 @@ static void syntax_exit() { static EVP_PKEY *read_public_key(uint8_t *public_key_file, EVP_PKEY **key) { if(public_key_file == NULL) { fprintf(stderr, "public_key_file is a null pointer!\n"); + return NULL; } FILE *fd = fopen(public_key_file, "rb"); @@ -44,11 +45,13 @@ static EVP_PKEY *read_public_key(uint8_t *public_key_file, EVP_PKEY **key) { static void hash_firmware(uint8_t *firmware_path, EVP_MD_CTX **ctx) { if(firmware_path == NULL) { fprintf(stderr, "firmware_path is a null pointer!\n"); + return; } FILE *fd = fopen(firmware_path, "rb"); if(fd == NULL) { fprintf(stderr, "failed to open firmware!\n"); + goto exit; } size_t size; @@ -56,8 +59,8 @@ static void hash_firmware(uint8_t *firmware_path, EVP_MD_CTX **ctx) { while((size = fread(buf, 1, BUFSIZE, fd)) != 0) { EVP_DigestVerifyUpdate(*ctx, buf, size); } - - fclose(fd); + + exit: fclose(fd); } static void read_signature(uint8_t *signature, size_t *signature_size) {