summaryrefslogtreecommitdiff
path: root/utils/sbtools/sbtoelf.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/sbtools/sbtoelf.c')
-rw-r--r--utils/sbtools/sbtoelf.c53
1 files changed, 16 insertions, 37 deletions
diff --git a/utils/sbtools/sbtoelf.c b/utils/sbtools/sbtoelf.c
index 3824ee094e..87017ab12d 100644
--- a/utils/sbtools/sbtoelf.c
+++ b/utils/sbtools/sbtoelf.c
@@ -703,8 +703,7 @@ void usage(void)
703 printf(" -k <file>\tAdd key file\n"); 703 printf(" -k <file>\tAdd key file\n");
704 printf(" -z\t\tAdd zero key\n"); 704 printf(" -z\t\tAdd zero key\n");
705 printf(" -r\t\tUse raw command mode\n"); 705 printf(" -r\t\tUse raw command mode\n");
706 printf(" --single-key <key>\tAdd single key\n"); 706 printf(" --add-key <key>\tAdd single key (hex or usbotp)\n");
707 printf(" --usb-otp <vid>:<pid>\tAdd USB OTP device\n");
708 exit(1); 707 exit(1);
709} 708}
710 709
@@ -722,12 +721,11 @@ int main(int argc, char **argv)
722 { 721 {
723 {"help", no_argument, 0, '?'}, 722 {"help", no_argument, 0, '?'},
724 {"debug", no_argument, 0, 'd'}, 723 {"debug", no_argument, 0, 'd'},
725 {"single-key", required_argument, 0, 's'}, 724 {"add-key", required_argument, 0, 'a'},
726 {"usb-otp", required_argument, 0, 'u'},
727 {0, 0, 0, 0} 725 {0, 0, 0, 0}
728 }; 726 };
729 727
730 int c = getopt_long(argc, argv, "?do:k:zr", long_options, NULL); 728 int c = getopt_long(argc, argv, "?do:k:zra:", long_options, NULL);
731 if(c == -1) 729 if(c == -1)
732 break; 730 break;
733 switch(c) 731 switch(c)
@@ -753,39 +751,14 @@ int main(int argc, char **argv)
753 add_keys(&g_zero_key, 1); 751 add_keys(&g_zero_key, 1);
754 break; 752 break;
755 } 753 }
756 case 's': 754 case 'a':
757 { 755 {
758 struct crypto_key_t key; 756 struct crypto_key_t key;
759 key.method = CRYPTO_KEY; 757 char *s = optarg;
760 if(strlen(optarg) != 32) 758 if(!parse_key(&s, &key))
761 bug("The key given in argument is invalid"); 759 bug("Invalid key specified as argument");
762 for(int i = 0; i < 16; i++) 760 if(*s != 0)
763 { 761 bug("Trailing characters after key specified as argument");
764 byte a, b;
765 if(convxdigit(optarg[2 * i], &a) || convxdigit(optarg[2 * i + 1], &b))
766 bugp("The key given in argument is invalid\n");
767 key.u.key[i] = (a << 4) | b;
768 }
769 add_keys(&key, 1);
770 break;
771 }
772 case 'u':
773 {
774 int vid, pid;
775 char *p = strchr(optarg, ':');
776 if(p == NULL)
777 bug("Invalid VID/PID\n");
778
779 char *end;
780 vid = strtol(optarg, &end, 16);
781 if(end != p)
782 bug("Invalid VID/PID\n");
783 pid = strtol(p + 1, &end, 16);
784 if(end != (optarg + strlen(optarg)))
785 bug("Invalid VID/PID\n");
786 struct crypto_key_t key;
787 key.method = CRYPTO_USBOTP;
788 key.u.vid_pid = vid << 16 | pid;
789 add_keys(&key, 1); 762 add_keys(&key, 1);
790 break; 763 break;
791 } 764 }
@@ -794,8 +767,14 @@ int main(int argc, char **argv)
794 } 767 }
795 } 768 }
796 769
770 if(g_out_prefix == NULL)
771 g_out_prefix = "";
772
797 if(argc - optind != 1) 773 if(argc - optind != 1)
798 bug("Missing sb file or too many files after options\n"); 774 {
775 usage();
776 return 1;
777 }
799 778
800 const char *sb_file = argv[optind]; 779 const char *sb_file = argv[optind];
801 FILE *fd = fopen(sb_file, "rb"); 780 FILE *fd = fopen(sb_file, "rb");