Minor corrections
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Dmitry Isaenko 2023-05-17 16:37:27 +03:00
parent de15275297
commit c6e56956e1
3 changed files with 12 additions and 17 deletions

View file

@ -46,14 +46,14 @@ public class KeyChainHolder {
private void collectEverything() throws Exception{ private void collectEverything() throws Exception{
rawKeySet = new HashMap<>(); rawKeySet = new HashMap<>();
BufferedReader br = new BufferedReader(new FileReader(keysFile)); try (BufferedReader br = new BufferedReader(new FileReader(keysFile))) {
String fileLine;
String fileLine; String[] keyValue;
String[] keyValue; while ((fileLine = br.readLine()) != null) {
while ((fileLine = br.readLine()) != null){ keyValue = fileLine.trim().split("\\s+?=\\s+?", 2);
keyValue = fileLine.trim().split("\\s+?=\\s+?", 2); if (keyValue.length == 2)
if (keyValue.length == 2) rawKeySet.put(keyValue[0], keyValue[1]);
rawKeySet.put(keyValue[0], keyValue[1]); }
} }
key_area_key_application = collectKeysByType("key_area_key_application"); key_area_key_application = collectKeysByType("key_area_key_application");

View file

@ -5,13 +5,9 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
import java.security.Security; import java.security.Security;
public abstract class AesCtrDecrypt { public abstract class AesCtrDecrypt {
private static boolean shouldBeInitialized = true;
protected AesCtrDecrypt(){ protected AesCtrDecrypt(){
if (shouldBeInitialized){ if (Security.getProvider("BC") == null)
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
shouldBeInitialized = false;
}
} }
/** /**

View file

@ -255,15 +255,14 @@ public class NCAProvider {
byte[] rightsIdKey = hexStrToByteArray(keys.get(byteArrToHexStringAsLE(rightsId))); // throws NullPointerException byte[] rightsIdKey = hexStrToByteArray(keys.get(byteArrToHexStringAsLE(rightsId))); // throws NullPointerException
SecretKeySpec skSpec = new SecretKeySpec( SecretKeySpec skSpec = new SecretKeySpec(
hexStrToByteArray(keys.get(String.format("titlekek_%02x", cryptoTypeReal)) hexStrToByteArray(keys.get(String.format("titlekek_%02x", cryptoTypeReal))), "AES");
), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding"); Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, skSpec); cipher.init(Cipher.DECRYPT_MODE, skSpec);
return cipher.doFinal(rightsIdKey); return cipher.doFinal(rightsIdKey);
} }
catch (Exception e){ catch (Exception e){
throw new Exception("No title.keys loaded for '"+ throw new Exception(String.format("No title.keys loaded for 'titlekek_%02x' or '%s' (%s)",
String.format("titlekek_%02x", cryptoTypeReal)+"' or '"+ byteArrToHexStringAsLE(rightsId)+"'? ("+e+")", e); cryptoTypeReal, byteArrToHexStringAsLE(rightsId), e), e);
} }
} }
private void setupNcaContentByNumber(int number, byte[] key){ private void setupNcaContentByNumber(int number, byte[] key){