public void LegacyPduMacCalcWith0x0IntStaticTest() { byte[] bytes = File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_LegacyAggregationResponsePdu_0x0_Int)); ImprintTag mac; using (TlvReader tlvReader = new TlvReader(new MemoryStream(bytes))) { mac = new LegacyAggregationPdu(tlvReader.ReadTag()).Mac; } Assert.IsTrue(LegacyPdu.ValidateMac(bytes, mac, Util.EncodeNullTerminatedUtf8String(TestConstants.ServicePass)), "MAC should be valid"); }
public void LegacyPduMacCalcInvalidTest() { byte[] bytes = File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_LegacyAggregationResponsePdu)); ImprintTag mac = new ImprintTag(0x1, false, false, new DataHash(HashAlgorithm.Sha2256, new byte[] { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32 })); Assert.IsFalse(LegacyPdu.ValidateMac(bytes, mac, Util.EncodeNullTerminatedUtf8String(TestConstants.ServicePass)), "MAC should be invalid"); }
public void LegacyPduMacCalcWith0x0IntStaticInvalidTest() { byte[] bytes = File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_LegacyAggregationResponsePdu_0x0_Int)); LegacyAggregationPdu pdu; using (TlvReader tlvReader = new TlvReader(new MemoryStream(bytes))) { pdu = new LegacyAggregationPdu(tlvReader.ReadTag()); } // 0x0 value representing an integer is converted to an empty TLV, thus MAC check will fail. byte[] pduBytes = pdu.Encode(); Assert.IsFalse(LegacyPdu.ValidateMac(pduBytes, pdu.Mac, Util.EncodeNullTerminatedUtf8String(TestConstants.ServicePass)), "MAC should be invalid"); }