[Assignment-7] embedded_device
This commit is contained in:
parent
36ce364e2d
commit
a4303acdf6
1 changed files with 9 additions and 18 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue