diff --git a/sbattach.c b/sbattach.c index b2c217c..408a6b7 100644 --- a/sbattach.c +++ b/sbattach.c @@ -31,6 +31,9 @@ #include +#include +#include + #include #include @@ -83,6 +86,8 @@ static int attach_sig(struct image *image, const char *image_filename, uint8_t *sigbuf; size_t size; int fd, rc; + PKCS7 *p7; + const uint8_t *tmp_buf; sigbuf = NULL; @@ -117,6 +122,23 @@ static int attach_sig(struct image *image, const char *image_filename, image->sigbuf = sigbuf; image->sigsize = size; + tmp_buf = sigbuf; + p7 = d2i_PKCS7(NULL, &tmp_buf, image->sigsize); + if (!p7) { + fprintf(stderr, "Unable to parse signature data in file: %s\n", + sig_filename); + ERR_print_errors_fp(stderr); + goto out; + } + rc = PKCS7_verify(p7, NULL, NULL, NULL, NULL, + PKCS7_BINARY | PKCS7_NOVERIFY | PKCS7_NOSIGS); + if (!rc) { + fprintf(stderr, "PKCS7 verification failed for file %s\n", + sig_filename); + ERR_print_errors_fp(stderr); + goto out; + } + rc = image_write(image, image_filename); if (rc) fprintf(stderr, "Error writing %s: %s\n", image_filename, @@ -208,6 +230,9 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + ERR_load_crypto_strings(); + OpenSSL_add_all_digests(); + image = image_load(image_filename); if (!image) { fprintf(stderr, "Can't load image file %s\n", image_filename);