hactoolnet: Copy hactool's option to suppress outputting decrypted keys

This commit is contained in:
Alex Barney 2023-11-15 19:11:17 -07:00
parent 3f5cd08b68
commit f28e7a7dbb
4 changed files with 23 additions and 9 deletions

View file

@ -57,6 +57,7 @@ NCA options:
--basenca Set Base NCA to use with update partitions.
--basetitlekey Specify single (encrypted) titlekey for the base NCA.
--titlekey Specify single (encrypted) titlekey.
--suppresskeys Suppress output of decrypted keys.
KIP1 options:
--uncompressed <f> Specify file path for saving uncompressed KIP1.
RomFS options:

View file

@ -20,6 +20,7 @@ internal static class CliParser
new CliOption("enablehash", 'h', 0, (o, _) => o.EnableHash = true),
new CliOption("disablekeywarns", 0, (o, _) => o.DisableKeyWarns = true),
new CliOption("enableallkeywarns", 0, (o, _) => o.EnableAllKeyWarns = true),
new CliOption("suppresskeys", 0, (o, _) => o.SuppressKeydataOutput = true),
new CliOption("keyset", 'k', 1, (o, a) => o.Keyfile = a[0]),
new CliOption("titlekeys", 1, (o, a) => o.TitleKeyFile = a[0]),
new CliOption("consolekeys", 1, (o, a) => o.ConsoleKeyFile = a[0]),
@ -294,6 +295,7 @@ internal static class CliParser
sb.AppendLine(" --basenca Set Base NCA to use with update partitions.");
sb.AppendLine(" --basetitlekey Specify single (encrypted) titlekey for the base NCA.");
sb.AppendLine(" --titlekey Specify single (encrypted) titlekey for the NCA.");
sb.AppendLine(" --suppresskeys Suppress output of decrypted keys.");
sb.AppendLine("KIP1 options:");
sb.AppendLine(" --uncompressed <f> Specify file path for saving uncompressed KIP1.");
sb.AppendLine("RomFS options:");

View file

@ -18,6 +18,7 @@ internal class Options
public bool EnableHash;
public bool DisableKeyWarns;
public bool EnableAllKeyWarns;
public bool SuppressKeydataOutput;
public string Keyfile;
public string TitleKeyFile;
public string ConsoleKeyFile;

View file

@ -239,7 +239,7 @@ internal static class ProcessNca
nca.OpenEncryptedNca().WriteAllBytes(ctx.Options.CiphertextOut, ctx.Logger);
}
if (!ctx.Options.ReadBench) ctx.Logger.LogMessage(ncaHolder.Print());
if (!ctx.Options.ReadBench) ctx.Logger.LogMessage(ncaHolder.Print(ctx.Options));
IStorage OpenStorage(int index)
{
@ -309,7 +309,7 @@ internal static class ProcessNca
return keyGeneration - 1;
}
private static string Print(this NcaHolder ncaHolder)
private static string Print(this NcaHolder ncaHolder, Options options)
{
Nca nca = ncaHolder.Nca;
int masterKey = GetMasterKeyRevisionFromKeyGeneration(nca.Header.KeyGeneration);
@ -347,7 +347,11 @@ internal static class ProcessNca
{
PrintItem(sb, colLen, "Rights ID:", nca.Header.RightsId.ToArray());
PrintItem(sb, colLen, "Titlekey (Encrypted):", nca.GetEncryptedTitleKey());
PrintItem(sb, colLen, "Titlekey (Decrypted):", nca.GetDecryptedTitleKey());
if (!options.SuppressKeydataOutput)
{
PrintItem(sb, colLen, "Titlekey (Decrypted):", nca.GetDecryptedTitleKey());
}
}
else
{
@ -367,10 +371,13 @@ internal static class ProcessNca
sb.AppendLine("Key Area (Encrypted):");
PrintItem(sb, colLen, "Key (RSA-OAEP Encrypted):", nca.Header.GetKeyArea().ToArray());
sb.AppendLine("Key Area (Decrypted):");
for (int i = 0; i < 2; i++)
if (!options.SuppressKeydataOutput)
{
PrintItem(sb, colLen, $" Key {i} (Decrypted):", nca.GetDecryptedKey(i));
sb.AppendLine("Key Area (Decrypted):");
for (int i = 0; i < 2; i++)
{
PrintItem(sb, colLen, $" Key {i} (Decrypted):", nca.GetDecryptedKey(i));
}
}
}
else if (version == NcaVersion.Nca0FixedKey)
@ -392,10 +399,13 @@ internal static class ProcessNca
PrintItem(sb, colLen, $" Key {i} (Encrypted):", nca.Header.GetEncryptedKey(i).ToArray());
}
sb.AppendLine("Key Area (Decrypted):");
for (int i = 0; i < keyCount; i++)
if (!options.SuppressKeydataOutput)
{
PrintItem(sb, colLen, $" Key {i} (Decrypted):", nca.GetDecryptedKey(i));
sb.AppendLine("Key Area (Decrypted):");
for (int i = 0; i < keyCount; i++)
{
PrintItem(sb, colLen, $" Key {i} (Decrypted):", nca.GetDecryptedKey(i));
}
}
}
}