summaryrefslogtreecommitdiff
path: root/utils/imxtools/sbtools/sb.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/imxtools/sbtools/sb.c')
-rw-r--r--utils/imxtools/sbtools/sb.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/utils/imxtools/sbtools/sb.c b/utils/imxtools/sbtools/sb.c
index 9b97509491..78f98b5985 100644
--- a/utils/imxtools/sbtools/sb.c
+++ b/utils/imxtools/sbtools/sb.c
@@ -503,7 +503,7 @@ static struct sb_section_t *read_section(bool data_sec, uint32_t id, byte *buf,
503 printf(OFF, "%s", indent); 503 printf(OFF, "%s", indent);
504 uint8_t checksum = instruction_checksum(hdr); 504 uint8_t checksum = instruction_checksum(hdr);
505 if(checksum != hdr->checksum) 505 if(checksum != hdr->checksum)
506 fatal(SB_CHECKSUM_ERROR, "Bad instruction checksum"); 506 fatal(SB_CHECKSUM_ERROR, "Bad instruction checksum\n");
507 if(hdr->flags != 0) 507 if(hdr->flags != 0)
508 { 508 {
509 printf(GREY, "["); 509 printf(GREY, "[");
@@ -788,7 +788,8 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
788 printf(BLUE, "Encryption keys\n"); 788 printf(BLUE, "Encryption keys\n");
789 for(int i = 0; i < g_nr_keys; i++) 789 for(int i = 0; i < g_nr_keys; i++)
790 { 790 {
791 printf(RED, " Key %d: ", i); 791 printf(RED, " Key %d\n", i),
792 printf(GREEN, " Key: ");
792 printf(YELLOW, ""); 793 printf(YELLOW, "");
793 print_key(&g_key_array[i], true); 794 print_key(&g_key_array[i], true);
794 printf(GREEN, " CBC-MAC: "); 795 printf(GREEN, " CBC-MAC: ");
@@ -859,7 +860,12 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
859 free(cbcmacs); 860 free(cbcmacs);
860 861
861 if(!valid_key) 862 if(!valid_key)
862 fatal(SB_NO_VALID_KEY, "No valid key found\n"); 863 {
864 if(g_force)
865 printf(GREY, " No valid key found\n");
866 else
867 fatal(SB_NO_VALID_KEY, "No valid key found\n");
868 }
863 869
864 if(getenv("SB_REAL_KEY") != 0) 870 if(getenv("SB_REAL_KEY") != 0)
865 { 871 {
@@ -868,6 +874,12 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
868 if(!parse_key(&env, &k) || *env) 874 if(!parse_key(&env, &k) || *env)
869 fatal(SB_ERROR, "Invalid SB_REAL_KEY\n"); 875 fatal(SB_ERROR, "Invalid SB_REAL_KEY\n");
870 memcpy(real_key, k.u.key, 16); 876 memcpy(real_key, k.u.key, 16);
877 /* assume the key is valid */
878 if(valid_key)
879 printf(GREY, " Overriding real key\n");
880 else
881 printf(GREY, " Assuming real key is ok\n");
882 valid_key = true;
871 } 883 }
872 884
873 printf(RED, " Summary:\n"); 885 printf(RED, " Summary:\n");
@@ -916,6 +928,13 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
916 if(encrypted) 928 if(encrypted)
917 printf(RED, " (Encrypted)"); 929 printf(RED, " (Encrypted)");
918 printf(OFF, "\n"); 930 printf(OFF, "\n");
931
932 /* skip it if we cannot decrypt it */
933 if(encrypted && !valid_key)
934 {
935 printf(GREY, " Skipping section content (no valid key)\n");
936 continue;
937 }
919 938
920 /* save it */ 939 /* save it */
921 byte *sec = xmalloc(size); 940 byte *sec = xmalloc(size);
@@ -939,7 +958,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
939 free(sec); 958 free(sec);
940 } 959 }
941 } 960 }
942 else 961 else if(valid_key)
943 { 962 {
944 /* advanced raw mode */ 963 /* advanced raw mode */
945 printf(BLUE, "Commands\n"); 964 printf(BLUE, "Commands\n");
@@ -1041,6 +1060,10 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
1041 } 1060 }
1042 } 1061 }
1043 } 1062 }
1063 else
1064 {
1065 printf(GREY, "Cannot read content in raw mode without a valid key\n");
1066 }
1044 1067
1045 /* final signature */ 1068 /* final signature */
1046 printf(BLUE, "Final signature:\n"); 1069 printf(BLUE, "Final signature:\n");