[Assignment-7] embedded_device
All checks were successful
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (push) Successful in 1m2s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (push) Successful in 1m0s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (push) Successful in 59s
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (pull_request) Successful in 31s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (pull_request) Successful in 8s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (pull_request) Successful in 8s

This commit is contained in:
Sascha Tommasone 2024-07-06 17:37:44 +02:00
parent fded121689
commit 192c1b5a52
Signed by: saschato
GPG key ID: 751068A86FCAA217

View file

@ -1,6 +1,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "util.h"
#include <openssl/sha.h> #include <openssl/sha.h>
#include <openssl/ec.h> #include <openssl/ec.h>
@ -19,11 +21,6 @@ typedef struct {
uint8_t *public_key_path; uint8_t *public_key_path;
} embedded_device_args; } embedded_device_args;
static void syntax_exit() {
fprintf(stderr, "syntax error!\n");
exit(EXIT_FAILURE);
}
static EVP_PKEY *read_public_key(uint8_t *public_key_file, EVP_PKEY **key) { static EVP_PKEY *read_public_key(uint8_t *public_key_file, EVP_PKEY **key) {
if(public_key_file == NULL) { if(public_key_file == NULL) {
fprintf(stderr, "public_key_file is a null pointer!\n"); fprintf(stderr, "public_key_file is a null pointer!\n");
@ -63,16 +60,6 @@ static void hash_firmware(uint8_t *firmware_path, EVP_MD_CTX **ctx) {
exit: fclose(fd); exit: fclose(fd);
} }
static void read_signature(uint8_t *signature, size_t *signature_size) {
FILE *fd = stdin;
if(fd == NULL) {
fprintf(stderr, "failed to stdin!\n");
}
// TODO: ersmal ne pause :)
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
embedded_device_args args = { embedded_device_args args = {
.firmware_path = NULL, .firmware_path = NULL,
@ -110,11 +97,15 @@ int main(int argc, char **argv) {
goto clean; goto clean;
} }
read_signature(NULL, NULL); uint8_t signature[BUFSIZE] = {0};
goto clean; size_t signature_size = read(0, signature, BUFSIZE);
if(signature_size < 70) {
printf("failed to read firmware signature\n");
goto clean;
}
hash_firmware(args.firmware_path, &ctx); hash_firmware(args.firmware_path, &ctx);
if (EVP_DigestVerifyFinal(ctx, NULL, 0) != 1) { if (EVP_DigestVerifyFinal(ctx, signature, signature_size) != 1) {
printf("failed to verify firmware signature\n"); printf("failed to verify firmware signature\n");
goto clean; goto clean;
} }