Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/Signing.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following options are supported:
- `--der` save generated private key in DER format.
- `--exportpubkey` to export the public key (corresponding to the private key generated with `-g`) to a DER file. This option only has an effect if used in conjunction with the `-g` option.
- `--nolocalkeys` to generate a keystore entry with zeroized key material. This option is only useful on platforms that support using an external key by reference, such as wolfHSM. Only has an effect if used in conjunction with the `-g` option.
- `--no-overwrite` to avoid prompt warning that keyfiles files already exist. This option ensures existing files are not overwritten.

Arguments are not exclusive, and can be repeated more than once to populate a keystore with multiple keys.

Expand Down Expand Up @@ -185,7 +186,7 @@ Options:
By default, the sign tool appends the sha of the base image to the manifest header,
so wolfBoot will refuse to start a delta update if the sha does not match the
one of the existing image. However, this takes up 32 to 48 bytes extra in the
manifest header, so this option is available to provide compatibility on
manifest header, so this option is available to provide compatibility on
existing installations without this feature, where the header size does not
allow to accommodate the field

Expand Down
44 changes: 30 additions & 14 deletions tools/keytools/keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
/* Globals */
static FILE *fpub, *fpub_image;
static int force = 0;
static int no_overwrite = 0; /* when set, avoids prompt if !force and files exist */
#if defined(WOLFBOOT_RENESAS_RSIP) || \
defined(WOLFBOOT_RENESAS_TSIP) || \
defined(WOLFBOOT_RENESAS_SCEPROTECT)
Expand Down Expand Up @@ -1155,18 +1156,24 @@ static void key_gen_check(const char *kfilename)
FILE *f;
f = fopen(kfilename, "rb");
if (!force && (f != NULL)) {
char reply[40];
int replySz;
printf("** Warning: key file already exists! Are you sure you want to generate a new key and overwrite the existing key? [Type 'Yes']: ");
fflush(stdout);
replySz = scanf("%s", reply);
printf("Reply is [%s]\n", reply);
fclose(f);
if (replySz < 0 || strcmp(reply, "Yes") != 0) {
printf("Operation aborted by user.");
exit(5);
} else {
unlink(kfilename);
if (no_overwrite) {
printf("** Warning: key file already exists and will not be overwritten!");
}
else {
char reply[40];
int replySz;
printf("** Warning: key file already exists! Are you sure you want to generate a new key and overwrite the existing key? [Type 'Yes']: ");
fflush(stdout);
replySz = scanf("%s", reply);
printf("Reply is [%s]\n", reply);
fclose(f);
if (replySz < 0 || strcmp(reply, "Yes") != 0) {
printf("Operation aborted by user.");
exit(5);
}
else {
unlink(kfilename);
}
}
}
}
Expand Down Expand Up @@ -1402,6 +1409,9 @@ int main(int argc, char** argv)
else if (strcmp(argv[i], "--force") == 0) {
force = 1;
}
else if (strcmp(argv[i], "--no-overwrite") == 0) {
no_overwrite = 1;
}
else if (strcmp(argv[i], "--der") == 0) {
saveAsDer = 1;
}
Expand Down Expand Up @@ -1436,6 +1446,7 @@ int main(int argc, char** argv)
i++;
sprintf(pubkeyfile,"%s%s", argv[i], "/keystore.c");
sprintf(pubkeyimg, "%s%s", argv[i], "/keystore.der");
printf("keystore file: %s\n", pubkeyfile);
i++;
continue;
}
Expand All @@ -1458,15 +1469,20 @@ int main(int argc, char** argv)
exit(0);
fpub = fopen(pubkeyfile, "rb");
if (!force && (fpub != NULL)) {
if (no_overwrite) {
printf("** Not overwriting existing keystore file: %s\n", pubkeyfile);
exit(0);
}
char reply[40];
int replySz;
printf("** Warning: keystore already exists! Are you sure you want to generate a new key and overwrite the existing key? [Type 'Yes']: ");
printf("** Warning: keystore file already exists! %s\n", pubkeyfile);
printf("Are you sure you want to generate a new key and overwrite the existing key ? [Type 'Yes'] : ");
fflush(stdout);
replySz = scanf("%s", reply);
printf("Reply is [%s]\n", reply);
fclose(fpub);
if (replySz < 0 || strcmp(reply, "Yes") != 0) {
printf("Operation aborted by user.");
printf("Operation aborted by user.\n");
exit(5);
} else {
unlink(pubkeyfile);
Expand Down