diff options
| author | Wither OrNot | 2025-04-07 23:23:19 +0000 |
|---|---|---|
| committer | Wither OrNot | 2025-04-07 23:23:19 +0000 |
| commit | b7868ff296016917c38657474117d5ca820b2312 (patch) | |
| tree | 5c3dd53fe258c322c14dc2d69b8864a98de91a4a /LibTSforge/Crypto/PhysStoreCrypto.cs | |
| parent | cb5c97d443982e547a8dd5a76032de8fa6859b61 (diff) | |
| parent | 3a3ac06ca3715127475c7a2c7b3f0782e1690dfb (diff) | |
| download | TSforge-b7868ff296016917c38657474117d5ca820b2312.zip | |
Merge branch 'longhorn' of https://github.com/massgravel/TSforge into longhorn1.1.0-longhorn+1
Diffstat (limited to 'LibTSforge/Crypto/PhysStoreCrypto.cs')
| -rw-r--r-- | LibTSforge/Crypto/PhysStoreCrypto.cs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/LibTSforge/Crypto/PhysStoreCrypto.cs b/LibTSforge/Crypto/PhysStoreCrypto.cs index b0acc2e..08978e2 100644 --- a/LibTSforge/Crypto/PhysStoreCrypto.cs +++ b/LibTSforge/Crypto/PhysStoreCrypto.cs @@ -16,33 +16,33 @@ namespace LibTSforge.Crypto byte[] aesKeySig = br.ReadBytes(0x80); byte[] encAesKey = br.ReadBytes(0x80); - if (CryptoUtils.RSAVerifySignature(rsaKey, encAesKey, aesKeySig)) + if (!CryptoUtils.RSAVerifySignature(rsaKey, encAesKey, aesKeySig)) { - byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey); - byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey); - byte[] hmacKey = decData.Take(0x10).ToArray(); // SHA-1 salt on Vista - byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray(); // SHA-1 hash on Vista - byte[] psData = decData.Skip(0x28).ToArray(); + throw new Exception("Failed to decrypt physical store."); + } + + byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey); + byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey); + byte[] hmacKey = decData.Take(0x10).ToArray(); // SHA-1 salt on Vista + byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray(); // SHA-1 hash on Vista + byte[] psData = decData.Skip(0x28).ToArray(); - if (version != PSVersion.Vista) + if (version != PSVersion.Vista) + { + if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig)) { - if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig)) - { - throw new InvalidDataException("Failed to verify HMAC. Physical store is corrupt."); - } + throw new InvalidDataException("Failed to verify HMAC. Physical store is corrupt."); } - else + } + else + { + if (!CryptoUtils.SaltSHAVerify(hmacKey, psData, hmacSig)) { - if (!CryptoUtils.SaltSHAVerify(hmacKey, psData, hmacSig)) - { - throw new InvalidDataException("Failed to verify checksum. Physical store is corrupt."); - } + throw new InvalidDataException("Failed to verify checksum. Physical store is corrupt."); } - - return psData; } - throw new Exception("Failed to decrypt physical store."); + return psData; } public static byte[] EncryptPhysicalStore(byte[] data, bool production, PSVersion version) @@ -65,7 +65,7 @@ namespace LibTSforge.Crypto byte[] aesKeySig = CryptoUtils.RSASign(rsaKey, encAesKey); byte[] hmacSig = version != PSVersion.Vista ? CryptoUtils.HMACSign(hmacKey, data) : CryptoUtils.SaltSHASum(hmacKey, data); - byte[] decData = new byte[] { }; + byte[] decData = { }; decData = decData.Concat(hmacKey).Concat(hmacSig).Concat(BitConverter.GetBytes(0)).Concat(data).ToArray(); byte[] encData = CryptoUtils.AESEncrypt(decData, aesKey); |
