|
45 | 45 |
|
46 | 46 | BOOT_LOG_MODULE_DECLARE(mcuboot);
|
47 | 47 |
|
48 |
| -#if defined(MCUBOOT_DECOMPRESS_IMAGES) |
49 |
| -#include <nrf_compress/implementation.h> |
50 |
| -#include <compression/decompression.h> |
51 |
| -#endif |
52 |
| - |
53 | 48 | #ifdef MCUBOOT_ENC_IMAGES
|
54 | 49 | #include "bootutil/enc_key.h"
|
55 | 50 | #endif
|
@@ -512,7 +507,7 @@ bootutil_img_validate(struct boot_loader_state *state,
|
512 | 507 | #endif
|
513 | 508 | )
|
514 | 509 | {
|
515 |
| -#if (defined(EXPECTED_KEY_TLV) && defined(MCUBOOT_HW_KEY)) || defined(MCUBOOT_HW_ROLLBACK_PROT) || defined(MCUBOOT_DECOMPRESS_IMAGES) |
| 510 | +#if (defined(EXPECTED_KEY_TLV) && defined(MCUBOOT_HW_KEY)) || defined(MCUBOOT_HW_ROLLBACK_PROT) |
516 | 511 | int image_index = (state == NULL ? 0 : BOOT_CURR_IMG(state));
|
517 | 512 | #endif
|
518 | 513 | uint32_t off;
|
@@ -560,67 +555,6 @@ bootutil_img_validate(struct boot_loader_state *state,
|
560 | 555 | #endif
|
561 | 556 |
|
562 | 557 | BOOT_LOG_DBG("bootutil_img_validate: flash area %p", fap);
|
563 |
| -#ifdef MCUBOOT_DECOMPRESS_IMAGES |
564 |
| - /* If the image is compressed, the integrity of the image must also be validated */ |
565 |
| - if (MUST_DECOMPRESS(fap, image_index, hdr)) { |
566 |
| - bool found_decompressed_size = false; |
567 |
| - bool found_decompressed_sha = false; |
568 |
| - bool found_decompressed_signature = false; |
569 |
| - |
570 |
| - rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_ANY, true); |
571 |
| - if (rc) { |
572 |
| - goto out; |
573 |
| - } |
574 |
| - |
575 |
| - if (it.tlv_end > bootutil_max_image_size(state, fap)) { |
576 |
| - rc = -1; |
577 |
| - goto out; |
578 |
| - } |
579 |
| - |
580 |
| - while (true) { |
581 |
| - uint16_t expected_size = 0; |
582 |
| - bool *found_flag = NULL; |
583 |
| - |
584 |
| - rc = bootutil_tlv_iter_next(&it, &off, &len, &type); |
585 |
| - if (rc < 0) { |
586 |
| - goto out; |
587 |
| - } else if (rc > 0) { |
588 |
| - break; |
589 |
| - } |
590 |
| - |
591 |
| - switch (type) { |
592 |
| - case IMAGE_TLV_DECOMP_SIZE: |
593 |
| - expected_size = sizeof(size_t); |
594 |
| - found_flag = &found_decompressed_size; |
595 |
| - break; |
596 |
| - case IMAGE_TLV_DECOMP_SHA: |
597 |
| - expected_size = IMAGE_HASH_SIZE; |
598 |
| - found_flag = &found_decompressed_sha; |
599 |
| - break; |
600 |
| - case IMAGE_TLV_DECOMP_SIGNATURE: |
601 |
| - found_flag = &found_decompressed_signature; |
602 |
| - break; |
603 |
| - default: |
604 |
| - continue; |
605 |
| - }; |
606 |
| - |
607 |
| - if (type == IMAGE_TLV_DECOMP_SIGNATURE && !EXPECTED_SIG_LEN(len)) { |
608 |
| - rc = -1; |
609 |
| - goto out; |
610 |
| - } else if (type != IMAGE_TLV_DECOMP_SIGNATURE && len != expected_size) { |
611 |
| - rc = -1; |
612 |
| - goto out; |
613 |
| - } |
614 |
| - |
615 |
| - *found_flag = true; |
616 |
| - } |
617 |
| - |
618 |
| - rc = (!found_decompressed_size || !found_decompressed_sha || !found_decompressed_signature); |
619 |
| - if (rc) { |
620 |
| - goto out; |
621 |
| - } |
622 |
| - } |
623 |
| -#endif |
624 | 558 |
|
625 | 559 | #if defined(EXPECTED_HASH_TLV) && !defined(MCUBOOT_SIGN_PURE)
|
626 | 560 | #if defined(MCUBOOT_SWAP_USING_OFFSET) && defined(MCUBOOT_SERIAL_RECOVERY)
|
@@ -887,161 +821,6 @@ bootutil_img_validate(struct boot_loader_state *state,
|
887 | 821 | skip_security_counter_check:
|
888 | 822 | #endif
|
889 | 823 |
|
890 |
| -#ifdef MCUBOOT_DECOMPRESS_IMAGES |
891 |
| - /* Only after all previous verifications have passed, perform a dry-run of the decompression |
892 |
| - * and ensure the image is valid |
893 |
| - */ |
894 |
| - if (!rc && MUST_DECOMPRESS(fap, image_index, hdr)) { |
895 |
| - image_hash_valid = 0; |
896 |
| - FIH_SET(valid_signature, FIH_FAILURE); |
897 |
| - |
898 |
| - rc = bootutil_img_hash_decompress(state, hdr, fap, tmp_buf, tmp_buf_sz, |
899 |
| - hash, seed, seed_len); |
900 |
| - if (rc) { |
901 |
| - goto out; |
902 |
| - } |
903 |
| - |
904 |
| - rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_DECOMP_SHA, true); |
905 |
| - if (rc) { |
906 |
| - goto out; |
907 |
| - } |
908 |
| - |
909 |
| - if (it.tlv_end > bootutil_max_image_size(state, fap)) { |
910 |
| - rc = -1; |
911 |
| - goto out; |
912 |
| - } |
913 |
| - |
914 |
| - while (true) { |
915 |
| - rc = bootutil_tlv_iter_next(&it, &off, &len, &type); |
916 |
| - if (rc < 0) { |
917 |
| - goto out; |
918 |
| - } else if (rc > 0) { |
919 |
| - break; |
920 |
| - } |
921 |
| - |
922 |
| - if (type == IMAGE_TLV_DECOMP_SHA) { |
923 |
| - /* Verify the image hash. This must always be present. */ |
924 |
| - if (len != sizeof(hash)) { |
925 |
| - rc = -1; |
926 |
| - goto out; |
927 |
| - } |
928 |
| - rc = LOAD_IMAGE_DATA(hdr, fap, off, buf, sizeof(hash)); |
929 |
| - if (rc) { |
930 |
| - goto out; |
931 |
| - } |
932 |
| - |
933 |
| - FIH_CALL(boot_fih_memequal, fih_rc, hash, buf, sizeof(hash)); |
934 |
| - if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) { |
935 |
| - FIH_SET(fih_rc, FIH_FAILURE); |
936 |
| - goto out; |
937 |
| - } |
938 |
| - |
939 |
| - image_hash_valid = 1; |
940 |
| - } |
941 |
| - } |
942 |
| - |
943 |
| - rc = !image_hash_valid; |
944 |
| - if (rc) { |
945 |
| - goto out; |
946 |
| - } |
947 |
| - |
948 |
| -#ifdef EXPECTED_SIG_TLV |
949 |
| -#ifdef EXPECTED_KEY_TLV |
950 |
| - rc = bootutil_tlv_iter_begin(&it, hdr, fap, EXPECTED_KEY_TLV, false); |
951 |
| - if (rc) { |
952 |
| - goto out; |
953 |
| - } |
954 |
| - |
955 |
| - if (it.tlv_end > bootutil_max_image_size(state, fap)) { |
956 |
| - rc = -1; |
957 |
| - goto out; |
958 |
| - } |
959 |
| - |
960 |
| - while (true) { |
961 |
| - rc = bootutil_tlv_iter_next(&it, &off, &len, &type); |
962 |
| - if (rc < 0) { |
963 |
| - goto out; |
964 |
| - } else if (rc > 0) { |
965 |
| - break; |
966 |
| - } |
967 |
| - |
968 |
| - if (type == EXPECTED_KEY_TLV) { |
969 |
| - /* |
970 |
| - * Determine which key we should be checking. |
971 |
| - */ |
972 |
| - if (len > KEY_BUF_SIZE) { |
973 |
| - rc = -1; |
974 |
| - goto out; |
975 |
| - } |
976 |
| -#ifndef MCUBOOT_HW_KEY |
977 |
| - rc = LOAD_IMAGE_DATA(hdr, fap, off, buf, len); |
978 |
| - if (rc) { |
979 |
| - goto out; |
980 |
| - } |
981 |
| - key_id = bootutil_find_key(buf, len); |
982 |
| -#else |
983 |
| - rc = LOAD_IMAGE_DATA(hdr, fap, off, key_buf, len); |
984 |
| - if (rc) { |
985 |
| - goto out; |
986 |
| - } |
987 |
| - key_id = bootutil_find_key(image_index, key_buf, len); |
988 |
| -#endif /* !MCUBOOT_HW_KEY */ |
989 |
| - /* |
990 |
| - * The key may not be found, which is acceptable. There |
991 |
| - * can be multiple signatures, each preceded by a key. |
992 |
| - */ |
993 |
| - } |
994 |
| - } |
995 |
| -#endif /* EXPECTED_KEY_TLV */ |
996 |
| - |
997 |
| - rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_DECOMP_SIGNATURE, true); |
998 |
| - if (rc) { |
999 |
| - goto out; |
1000 |
| - } |
1001 |
| - |
1002 |
| - if (it.tlv_end > bootutil_max_image_size(state, fap)) { |
1003 |
| - rc = -1; |
1004 |
| - goto out; |
1005 |
| - } |
1006 |
| - |
1007 |
| - while (true) { |
1008 |
| - rc = bootutil_tlv_iter_next(&it, &off, &len, &type); |
1009 |
| - if (rc < 0) { |
1010 |
| - goto out; |
1011 |
| - } else if (rc > 0) { |
1012 |
| - rc = 0; |
1013 |
| - break; |
1014 |
| - } |
1015 |
| - |
1016 |
| - if (type == IMAGE_TLV_DECOMP_SIGNATURE) { |
1017 |
| - /* Ignore this signature if it is out of bounds. */ |
1018 |
| - if (key_id < 0 || key_id >= bootutil_key_cnt) { |
1019 |
| - key_id = -1; |
1020 |
| - continue; |
1021 |
| - } |
1022 |
| - |
1023 |
| - if (!EXPECTED_SIG_LEN(len) || len > sizeof(buf)) { |
1024 |
| - rc = -1; |
1025 |
| - goto out; |
1026 |
| - } |
1027 |
| - rc = LOAD_IMAGE_DATA(hdr, fap, off, buf, len); |
1028 |
| - if (rc) { |
1029 |
| - goto out; |
1030 |
| - } |
1031 |
| - |
1032 |
| - FIH_CALL(bootutil_verify_sig, valid_signature, hash, sizeof(hash), |
1033 |
| - buf, len, key_id); |
1034 |
| - key_id = -1; |
1035 |
| - } |
1036 |
| - } |
1037 |
| -#endif /* EXPECTED_SIG_TLV */ |
1038 |
| - } |
1039 |
| -#endif |
1040 |
| - |
1041 |
| -#ifdef EXPECTED_SIG_TLV |
1042 |
| - FIH_SET(fih_rc, valid_signature); |
1043 |
| -#endif |
1044 |
| - |
1045 | 824 | out:
|
1046 | 825 | if (rc) {
|
1047 | 826 | FIH_SET(fih_rc, FIH_FAILURE);
|
|
0 commit comments