Truncate p and c before transforming strings to hex
This commit is contained in:
parent
dce8c3d066
commit
d4bb214536
@ -68,9 +68,9 @@ public class AESKey
|
||||
}
|
||||
public bool CheckSunMac([NotNullWhen(true)] string? mac, PICCData piccData, byte[]? payload = null)
|
||||
{
|
||||
if (mac is null || !Regex.IsMatch(mac, "[a-f0-9A-F]{16}"))
|
||||
if (!PICCData.ValidateC(mac))
|
||||
return false;
|
||||
return CheckSunMac(mac.HexToBytes(), piccData, payload);
|
||||
return CheckSunMac(mac[0..16].HexToBytes(), piccData, payload);
|
||||
}
|
||||
|
||||
public byte[] GetSunMac(PICCData piccData, byte[]? payload = null)
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>1.0.22</Version>
|
||||
<Version>1.0.23</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@ -58,7 +58,7 @@ public record BoltcardPICCData : PICCData
|
||||
{
|
||||
if (!ValidateP(p))
|
||||
return null;
|
||||
var bytes = encryptionKey.Decrypt(p.HexToBytes());
|
||||
var bytes = encryptionKey.Decrypt(p[0..32].HexToBytes());
|
||||
if (!ValidateBoltcardPICCData(bytes))
|
||||
return null;
|
||||
return new BoltcardPICCData(PICCData.Create(bytes));
|
||||
@ -120,8 +120,8 @@ public record PICCData(byte[]? Uid, int? Counter)
|
||||
return null;
|
||||
return TryBoltcardDecryptCheck(encryptionKey, authenticationKey, p, c, payload);
|
||||
}
|
||||
internal static bool ValidateP(string p) => p != null && Regex.IsMatch(p, "[a-f0-9A-F]{32}");
|
||||
internal static bool ValidateC(string c) => c != null && Regex.IsMatch(c, "[a-f0-9A-F]{16}");
|
||||
internal static bool ValidateP([NotNullWhen(true)] string? p) => p is not null && Regex.IsMatch(p, "^[a-f0-9A-F]{32}");
|
||||
internal static bool ValidateC([NotNullWhen(true)] string? c) => c is not null && Regex.IsMatch(c, "^[a-f0-9A-F]{16}");
|
||||
|
||||
/// <summary>
|
||||
/// Decrypt the PICCData from the Boltcard and check the checksum.
|
||||
@ -137,7 +137,7 @@ public record PICCData(byte[]? Uid, int? Counter)
|
||||
if (!ValidateP(p) || !ValidateC(c))
|
||||
return null;
|
||||
|
||||
var bytes = encryptionKey.Decrypt(p.HexToBytes());
|
||||
var bytes = encryptionKey.Decrypt(p[0..32].HexToBytes());
|
||||
PICCData piccData;
|
||||
try
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user