Skip to content

Commit b6f7642

Browse files
committed
Fix TPMS_ECC_POINT parsing for TPM attestation
1 parent 0afa4a9 commit b6f7642

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,4 @@ ASALocalRun/
332332
/Test/coverage.netcoreapp3.1.cobertura.xml
333333

334334
.DS_Store
335+
/testEnvironments.json

Src/Fido2/AttestationFormat/Tpm.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ public PubArea(byte[] pubArea)
611611
Exponent = Convert.ToUInt32(Math.Pow(2, 16) + 1);
612612
}
613613
}
614+
// TPM2B_PUBLIC_KEY_RSA
615+
Unique = AuthDataHelper.GetSizedByteArray(pubArea, ref offset);
614616
}
615617

616618
// TPMI_ECC_CURVE
@@ -625,10 +627,15 @@ public PubArea(byte[] pubArea)
625627
{
626628
CurveID = AuthDataHelper.GetSizedByteArray(pubArea, ref offset, 2);
627629
KDF = AuthDataHelper.GetSizedByteArray(pubArea, ref offset, 2);
628-
}
629630

630-
// TPMU_PUBLIC_ID
631-
Unique = AuthDataHelper.GetSizedByteArray(pubArea, ref offset);
631+
// TPMS_ECC_POINT
632+
ECPoint = new()
633+
{
634+
X = AuthDataHelper.GetSizedByteArray(pubArea, ref offset),
635+
Y = AuthDataHelper.GetSizedByteArray(pubArea, ref offset),
636+
};
637+
Unique = DataHelper.Concat(ECPoint.X, ECPoint.Y);
638+
}
632639

633640
if (pubArea.Length != offset)
634641
throw new Fido2VerificationException("Leftover bytes decoding pubArea");
@@ -645,21 +652,8 @@ public PubArea(byte[] pubArea)
645652
public uint Exponent { get; private set; }
646653
public byte[]? CurveID { get; private set; }
647654
public byte[]? KDF { get; private set; }
648-
public byte[] Unique { get; private set; }
655+
public byte[]? Unique { get; private set; }
649656
public TpmEccCurve EccCurve => (TpmEccCurve)Enum.ToObject(typeof(TpmEccCurve), BinaryPrimitives.ReadUInt16BigEndian(CurveID));
650-
651-
public ECPoint ECPoint
652-
{
653-
get
654-
{
655-
var point = new ECPoint();
656-
var uniqueOffset = 0;
657-
var size = AuthDataHelper.GetSizedByteArray(Unique, ref uniqueOffset, 2);
658-
point.X = AuthDataHelper.GetSizedByteArray(Unique, ref uniqueOffset, BinaryPrimitives.ReadUInt16BigEndian(size));
659-
size = AuthDataHelper.GetSizedByteArray(Unique, ref uniqueOffset, 2);
660-
point.Y = AuthDataHelper.GetSizedByteArray(Unique, ref uniqueOffset, BinaryPrimitives.ReadUInt16BigEndian(size));
661-
return point;
662-
}
663-
}
657+
public ECPoint ECPoint { get; private set; }
664658
}
665659
}

Test/Attestation/Tpm.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5920,7 +5920,6 @@ internal static byte[] CreatePubArea(
59205920
raw.Write(scheme);
59215921
raw.Write(curveID);
59225922
raw.Write(kdf);
5923-
raw.Write(GetUInt16BigEndianBytes(unique.Length));
59245923
raw.Write(unique);
59255924
}
59265925
else

0 commit comments

Comments
 (0)