Extkeys: Allow skipping key warning output.

This commit is contained in:
Michael Scire 2018-12-12 06:12:43 -08:00
parent 3058366f12
commit 4d8d84dae2
5 changed files with 15 additions and 5 deletions

View File

@ -22,6 +22,7 @@ Options:
-t, --intype=type Specify input file type [nca, xci, pfs0, romfs, hfs0, npdm, pk11, pk21, ini1, kip1, nax0, keygen]
--titlekey=key Set title key for Rights ID crypto titles.
--contentkey=key Set raw key for NCA body decryption.
--disablekeywarns Disables warning output when loading external keys.
NCA options:
--plaintext=file Specify file path for saving a decrypted copy of the NCA.
--header=file Specify Header file path.

View File

@ -198,7 +198,9 @@ void extkeys_parse_titlekeys(hactool_settings_t *settings, FILE *f) {
}
}
if (should_ignore_key) {
fprintf(stderr, "[WARN]: Invalid title.keys content: \"%s\", (value \"%s\")\n", key, value);
if (!settings->skip_key_warnings) {
fprintf(stderr, "[WARN]: Invalid title.keys content: \"%s\", (value \"%s\")\n", key, value);
}
} else {
parse_hex_key(rights_id, key, sizeof(rights_id));
parse_hex_key(titlekey, value, sizeof(titlekey));
@ -208,9 +210,10 @@ void extkeys_parse_titlekeys(hactool_settings_t *settings, FILE *f) {
}
}
void extkeys_initialize_keyset(nca_keyset_t *keyset, FILE *f) {
void extkeys_initialize_settings(hactool_settings_t *settings, FILE *f) {
char *key, *value;
int ret;
nca_keyset_t *keyset = &settings->keyset;
while ((ret = get_kv(f, &key, &value)) != 1 && ret != -2) {
if (ret == 0) {
@ -387,7 +390,7 @@ void extkeys_initialize_keyset(nca_keyset_t *keyset, FILE *f) {
}
}
}
if (!matched_key) {
if (!matched_key && !settings->skip_key_warnings) {
fprintf(stderr, "[WARN]: Failed to match key \"%s\", (value \"%s\")\n", key, value);
}
}

View File

@ -7,7 +7,7 @@
#include "settings.h"
void parse_hex_key(unsigned char *key, const char *hex, unsigned int len);
void extkeys_initialize_keyset(nca_keyset_t *keyset, FILE *f);
void extkeys_initialize_settings(hactool_settings_t *settings, FILE *f);
void extkeys_parse_titlekeys(hactool_settings_t *settings, FILE *f);

7
main.c
View File

@ -35,6 +35,7 @@ static void usage(void) {
" -t, --intype=type Specify input file type [nca, xci, pfs0, romfs, hfs0, npdm, pk11, pk21, ini1, kip1, nax0, keygen]\n"
" --titlekey=key Set title key for Rights ID crypto titles.\n"
" --contentkey=key Set raw key for NCA body decryption.\n"
" --disablekeywarns Disables warning output when loading external keys.\n"
"NCA options:\n"
" --plaintext=file Specify file path for saving a decrypted copy of the NCA.\n"
" --header=file Specify Header file path.\n"
@ -178,6 +179,7 @@ int main(int argc, char **argv) {
{"json", 1, NULL, 37},
{"saveini1json", 0, NULL, 38},
{"uncompressed", 1, NULL, 39},
{"disablekeywarns", 0, NULL, 40},
{NULL, 0, NULL, 0},
};
@ -385,6 +387,9 @@ int main(int argc, char **argv) {
case 39:
filepath_set(&nca_ctx.tool_ctx->settings.uncompressed_path, optarg);
break;
case 40:
nca_ctx.tool_ctx->settings.skip_key_warnings = 1;
break;
default:
usage();
return EXIT_FAILURE;
@ -406,7 +411,7 @@ int main(int argc, char **argv) {
}
if (keyfile != NULL) {
extkeys_initialize_keyset(&tool_ctx.settings.keyset, keyfile);
extkeys_initialize_settings(&tool_ctx.settings, keyfile);
if (tool_ctx.settings.has_sdseed) {
for (unsigned int key = 0; key < 2; key++) {
for (unsigned int i = 0; i < 0x20; i++) {

View File

@ -71,6 +71,7 @@ typedef struct {
typedef struct {
nca_keyset_t keyset;
int skip_key_warnings;
int has_cli_titlekey;
unsigned char cli_titlekey[0x10];
unsigned char dec_cli_titlekey[0x10];