public void CertificationRecordOkTest() { TlvTagBuilder builder = new TlvTagBuilder(Constants.CertificateRecord.TagType, false, false, new ITlvTag[] { new RawTag(Constants.CertificateRecord.CertificateIdTagType, false, false, new byte[] { 0x2 }), new RawTag(Constants.CertificateRecord.X509CertificateTagType, false, false, new byte[] { 0x3 }), }); CertificateRecord tag = new CertificateRecord(builder.BuildTag()); Assert.That(Util.IsArrayEqual(new byte[] { 0x2 }, tag.CertificateId.Value), "Unexpected certificate id"); Assert.That(Util.IsArrayEqual(new byte[] { 0x3 }, tag.X509Certificate.Value), "Unexpected X509 certificate."); }
public void TcpProcessorInvalidNoPayloadTest() { TcpAsyncResultCollection asyncResultCollection = new TcpAsyncResultCollection(); TcpKsiServiceAsyncResult asyncResult = new TcpKsiServiceAsyncResult(KsiServiceRequestType.AggregatorConfig, null, 123, null, null); asyncResultCollection.Add(123, asyncResult); TcpResponseProcessor processor = new TcpResponseProcessor(asyncResultCollection); byte[] data = new TlvTagBuilder(Constants.AggregationResponsePdu.TagType, false, false, new ITlvTag[] { }).BuildTag().Encode(); processor.ProcessReceivedData(data, data.Length); Assert.AreEqual(1, asyncResultCollection.Count(), "Invalid Async collection count."); Assert.AreEqual(0, asyncResult.ResultStream.Length, "Invalid async result stream content."); Assert.IsFalse(asyncResult.IsCompleted, "Async result must not be completed."); }
public void CertificationRecordWithoutCertTest() { TlvException ex = Assert.Throws <TlvException>(delegate { TlvTagBuilder builder = new TlvTagBuilder(Constants.CertificateRecord.TagType, false, false, new ITlvTag[] { new RawTag(Constants.CertificateRecord.CertificateIdTagType, false, false, new byte[] { 0x2 }), }); CertificateRecord tag = new CertificateRecord(builder.BuildTag()); }); Assert.That(ex.Message.StartsWith("Exactly one certificate must exist in certificate record"), "Unexpected exception message: " + ex.Message); }
public void HeaderMissingTest() { PublicationsFile publicationsFile = TestUtil.GetPublicationsFile(); TlvTagBuilder builder = new TlvTagBuilder(publicationsFile.Type, publicationsFile.NonCritical, publicationsFile.Forward); builder.AddChildTag(publicationsFile[1]); PublicationsFileException ex = Assert.Throws <PublicationsFileException>(delegate { PublicationsFile newPublicationsFile = new PublicationsFile(builder.BuildTag()); }); Assert.That(ex.Message.StartsWith("Exactly one publications file header must exist in publications file"), "Unexpected exception message: " + ex.Message); }
public void TestSignatureExtendedCalendarHashChainLengthDiffers() { KsiSignature signature = TestUtil.GetSignature(Resources.KsiSignature_Ok_Extended); TlvTagBuilder builder = GetBuilder(signature); builder.RemoveChildTag(signature.CalendarHashChain[signature.CalendarHashChain.Count - 1]); TestVerificationContext context = new TestVerificationContext() { Signature = signature, ExtendedCalendarHashChain = new CalendarHashChain(builder.BuildTag()) }; Verify(context, VerificationResultCode.Fail, VerificationError.Cal04); }
public void TlvTagBuilderGetTagByTypeReturnNullTest() { RawTag child1 = new RawTag(0x1, true, false, new byte[] { 0x1, 0x2 }); CompositeTestTag tag = new CompositeTestTag(0x1, false, false, new ITlvTag[] { child1, }); TlvTagBuilder builder = new TlvTagBuilder(tag); ITlvTag searchedTag = builder.GetChildByType(0x2); Assert.IsNull(searchedTag, "Invalid return tag"); }
public void InvalidHeaderIndexTest() { PublicationsFile publicationsFile = TestUtil.GetPublicationsFile(); TlvTagBuilder builder = new TlvTagBuilder(publicationsFile.Type, publicationsFile.NonCritical, publicationsFile.Forward); builder.AddChildTag(publicationsFile[1]); builder.AddChildTag(publicationsFile[0]); PublicationsFileException ex = Assert.Throws <PublicationsFileException>(delegate { PublicationsFile newPublicationsFile = new PublicationsFile(builder.BuildTag()); }); Assert.That(ex.Message.StartsWith("Publications file header should be the first element in publications file"), "Unexpected exception message: " + ex.Message); }
public void TestSignatureExtendedCalendarHashChainElementDiffers() { KsiSignature signature = TestUtil.GetSignature(Resources.KsiSignature_Ok_Extended); TlvTagBuilder builder = GetBuilder(signature); builder.ReplaceChildTag(signature.CalendarHashChain[signature.CalendarHashChain.Count - 1], new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01580192B0D06E48884432DFFC26A67C6C685BEAF0252B9DD2A0B4B05D1724C5F2"))); TestVerificationContext context = new TestVerificationContext() { Signature = signature, ExtendedCalendarHashChain = new CalendarHashChain(builder.BuildTag()) }; Verify(context, VerificationResultCode.Fail, VerificationError.Cal04); }
public void CertRecordAfterPubRecordsTest() { PublicationsFile publicationsFile = TestUtil.GetPublicationsFile(); TlvTagBuilder builder = new TlvTagBuilder(publicationsFile.Type, publicationsFile.NonCritical, publicationsFile.Forward); builder.AddChildTag(publicationsFile[0]); builder.AddChildTag(publicationsFile[30]); builder.AddChildTag(publicationsFile[1]); PublicationsFileException ex = Assert.Throws <PublicationsFileException>(delegate { PublicationsFile newPublicationsFile = new PublicationsFile(builder.BuildTag()); }); Assert.That(ex.Message.StartsWith("Certificate records should be before publication records"), "Unexpected exception message: " + ex.Message); }
private static TlvTagBuilder GetBuilder(KsiSignature signature) { TlvTagBuilder builder = new TlvTagBuilder(Constants.CalendarHashChain.TagType, false, false); foreach (ITlvTag child in signature.CalendarHashChain) { CalendarHashChain.Link link = child as CalendarHashChain.Link; if (link != null && link.Type == (uint)LinkDirection.Right) { // add a left link, this does not make the verification to fail. builder.AddChildTag(new RawTag((uint)LinkDirection.Left, false, false, Base16.Decode("01580192B0D06E48884432DFFC26A67C6C685BEAF0252B9DD2A0B4B05D1724C5F2"))); } builder.AddChildTag(child); } return(builder); }
public void TcpProcessorExtendResponseInvalidNoRequestIdTest() { TcpAsyncResultCollection asyncResultCollection = new TcpAsyncResultCollection(); TcpResponseProcessor processor = new TcpResponseProcessor(asyncResultCollection); byte[] data = new TlvTagBuilder(Constants.ExtendResponsePdu.TagType, false, false, new ITlvTag[] { new CompositeTestTag(Constants.ExtendResponsePayload.TagType, true, false, new ITlvTag[] { }), }).BuildTag().Encode(); KsiServiceProtocolException ex = Assert.Throws <KsiServiceProtocolException>(delegate { processor.ProcessReceivedData(data, data.Length); }); Assert.That(ex.Message.StartsWith("Cannot find request id tag from extender response payload"), "Unexpected exception message: " + ex.Message); }
public void CmsSignatureNotLastTestTest() { PublicationsFile publicationsFile = TestUtil.GetPublicationsFile(); TlvTagBuilder builder = new TlvTagBuilder(publicationsFile.Type, publicationsFile.NonCritical, publicationsFile.Forward); builder.AddChildTag(publicationsFile[0]); builder.AddChildTag(publicationsFile[1]); builder.AddChildTag(publicationsFile[46]); builder.AddChildTag(publicationsFile[30]); PublicationsFileException ex = Assert.Throws <PublicationsFileException>(delegate { PublicationsFile newPublicationsFile = new PublicationsFile(builder.BuildTag()); }); Assert.That(ex.Message.StartsWith("Cms signature should be last element in publications file"), "Unexpected exception message: " + ex.Message); }
public void TlvTagBuilderGetTagByTypeTest() { RawTag child1 = new RawTag(0x1, true, false, new byte[] { 0x1, 0x2 }); RawTag child2 = new RawTag(0x2, true, false, new byte[] { 0x3, 0x4 }); CompositeTestTag tag = new CompositeTestTag(0x1, false, false, new ITlvTag[] { child1, child2 }); TlvTagBuilder builder = new TlvTagBuilder(tag); ITlvTag seachedTag = builder.GetChildByType(0x2); CollectionAssert.AreEqual(seachedTag.EncodeValue(), child2.EncodeValue(), "Invalid child returned."); }
public void GetNearestPublicationRecordTest() { PublicationsFile publicationsFile = TestUtil.GetPublicationsFile(); PublicationRecordInPublicationFile latest = publicationsFile.GetLatestPublication(); PublicationRecordInPublicationFile prev = publicationsFile.GetNearestPublicationRecord(latest.PublicationData.PublicationTime - 35 * 24 * 3600); TlvTagBuilder builder = new TlvTagBuilder(publicationsFile.Type, publicationsFile.NonCritical, publicationsFile.Forward); List <ITlvTag> pubRecordList = new List <ITlvTag>(); foreach (ITlvTag tag in publicationsFile) { if (tag.Type < Constants.PublicationRecord.TagTypeInPublicationsFile) { builder.AddChildTag(tag); } if (tag.Type == Constants.PublicationRecord.TagTypeInPublicationsFile) { pubRecordList.Add(tag); } } // add publication records in reverse order for (int index = pubRecordList.Count - 1; index >= 0; index--) { ITlvTag tag = pubRecordList[index]; builder.AddChildTag(tag); } foreach (ITlvTag tag in publicationsFile) { if (tag.Type > Constants.PublicationRecord.TagTypeInPublicationsFile) { builder.AddChildTag(tag); } } PublicationsFile newPublicationsFile = new PublicationsFile(builder.BuildTag()); PublicationRecordInPublicationFile newPrev = newPublicationsFile.GetNearestPublicationRecord(latest.PublicationData.PublicationTime - 35 * 24 * 3600); Assert.AreEqual(prev.PublicationData, newPrev.PublicationData, "Unexpected nearest publicatoin record."); }
public void TlvTagBuilderRemoveNullTest() { RawTag child1 = new RawTag(0x1, true, false, new byte[] { 0x1, 0x2 }); CompositeTestTag tag = new CompositeTestTag(0x1, false, false, new ITlvTag[] { child1 }); TlvTagBuilder builder = new TlvTagBuilder(tag); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(delegate { builder.RemoveChildTag(null); }); Assert.AreEqual("childTag", ex.ParamName); }
public void TlvTagBuilderAddTest() { RawTag child1 = new RawTag(0x1, true, false, new byte[] { 0x1, 0x2 }); RawTag child2 = new RawTag(0x2, true, false, new byte[] { 0x3, 0x4 }); CompositeTestTag tag = new CompositeTestTag(0x1, false, false, new ITlvTag[] { child1 }); TlvTagBuilder builder = new TlvTagBuilder(tag); builder.AddChildTag(child2); CompositeTestTag newTag = new CompositeTestTag(builder.BuildTag()); CollectionAssert.AreEqual(newTag[1].EncodeValue(), child2.EncodeValue(), "Invalid second child."); }
public void TcpProcessorExtenderConfigOkTest() { TcpAsyncResultCollection asyncResultCollection = new TcpAsyncResultCollection(); TcpKsiServiceAsyncResult asyncResult = new TcpKsiServiceAsyncResult(KsiServiceRequestType.ExtenderConfig, null, 123, null, null); asyncResultCollection.Add(123, asyncResult); TcpResponseProcessor processor = new TcpResponseProcessor(asyncResultCollection); byte[] data = new TlvTagBuilder(Constants.ExtendResponsePdu.TagType, false, false, new ITlvTag[] { new CompositeTestTag(Constants.ExtenderConfigResponsePayload.TagType, true, false, new ITlvTag[] { }), }).BuildTag().Encode(); processor.ProcessReceivedData(data, data.Length); Assert.AreEqual(0, asyncResultCollection.Count(), "Invalid Async collection count."); Assert.IsTrue(Util.IsArrayEqual(data, asyncResult.ResultStream.ToArray()), "Invalid async result stream content."); Assert.IsTrue(asyncResult.IsCompleted, "Async result must be completed."); }
public void TlvTagBuilderRemoveTest() { RawTag child1 = new RawTag(0x1, true, false, new byte[] { 0x1, 0x2 }); RawTag child2 = new RawTag(0x2, true, false, new byte[] { 0x3, 0x4 }); CompositeTestTag tag = new CompositeTestTag(0x1, false, false, new ITlvTag[] { child1, child2 }); TlvTagBuilder builder = new TlvTagBuilder(tag); builder.RemoveChildTag(child1); CompositeTestTag newTag = new CompositeTestTag(builder.BuildTag()); Assert.AreEqual(1, newTag.Count, "Invalid child tag count."); CollectionAssert.AreEqual(newTag[0].EncodeValue(), child2.EncodeValue(), "Invalid first child."); }
private static CalendarHashChain GetCalendarHashChain(bool excludeLastRightLink = false, bool addExtraRightLink = false) { TlvTagBuilder builder = new TlvTagBuilder(Constants.CalendarHashChain.TagType, false, false); builder.AddChildTag(new IntegerTag(Constants.CalendarHashChain.PublicationTimeTagType, false, false, 1455494400)); builder.AddChildTag(new IntegerTag(Constants.CalendarHashChain.AggregationTimeTagType, false, false, 1455478441)); builder.AddChildTag(new ImprintTag(Constants.CalendarHashChain.InputHashTagType, false, false, new DataHash(Base16.Decode("012C8149F374FDDCD5443456BC7E8FFA310B7FE090DAA98C0980B81EC2407FD013")))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("011A039DE0761EEC75F6CCB4B17720E0565AC694BB8B2211BB30B22DD9AC45F931"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Left, false, false, Base16.Decode("013A23B4518A0A73BB2BED9087857D9D27E2B36BDEAE2BB75600D97A7FB278B93F"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Left, false, false, Base16.Decode("01AAFF5F7AC584B2BDDCC60F5920259D1726399EA5B72F3EE52F0F343FDEFBA44A"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01F7D776798EFF2A0B75FFD135D45F2717C25909BAF482A04CF15F70C4E2BD75A7"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Left, false, false, Base16.Decode("01F06569DB8E8370014BFDD867FBA440717D3207EA8629A15918EDD20772DF7ADF"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01E994F25C01928F616C1D4B5F3715CD70586FAC3DF056E40FC88B5E7F3D11FBBF"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Left, false, false, Base16.Decode("015251B1496CABF85D2FB6E7D029AE026FBAAF69018ECBD480C746174ACCF3974B"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01F5B1B5665B31B1CBE0EA66222E5905A43D7CB735ACDCF9D6C2931A23C1798797"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Left, false, false, Base16.Decode("011C392604BA9550C81028BFD12C41A8CD880FACF1970B2F1FE03F616D06257C19"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01E47589DA097DA8C79A2B79D98A4DEA1484F28DB52A513AFD92166BF4894379C3"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01F4C67A2D3BD0C46CF9064C3909A41A0D3178CCE6B729E700CFA240E4CF049841"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Left, false, false, Base16.Decode("0137E949ABAF6636312569F29CAB705E9A45DB96A15BFB26BC26403F60D4894162"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("0102459F392EBEE422991B251625C9E9E63C6394A8D1307EC9036BFCEB48E3F431"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Left, false, false, Base16.Decode("01255FE067AFB88E68FA9957626FD72553C3ADFC85B6072145DDFCDE94CC22FE51"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("0182E16E325B51C2D8B29494DDB9DE3CB2718A8F135D8F2B1D1D2AD240A60B306F"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("015234BB37CEAA00A36D44AABFC25215B1899573CE1A76827F070D7D2C68AF9DE6"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Left, false, false, Base16.Decode("015786F1B0135C3A37C66C3958A32F7E90123BB9C8137A98861C6307C70079842C"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("0136E2E89E8F3928F80A6D89AD666354E145473B2C6FF683F0796DAA68F2004545"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01E44F0A3EA272C03DEFC1825D3148F0DC4060CF6BAF04F3ACD0B9AFA9EE52CAD5"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01A0698E6B45EDEEAF9037E49F668114617CA60124F0FC416D017D06D78CA4295A"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01A6F082B82280F3A6AFB14C8E39B7F57860B857B70CA57AFD35F40395EEB32458"))); builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01496FC0120D854E7534B992AB32EC3045B20D4BEE1BFBE4564FD092CEAFA08B72"))); if (!excludeLastRightLink) { builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("01BB44FD36A5F3CDEE7B5C6DF3A6098A09E353335B6029F1477502588A7E37BE00"))); } if (addExtraRightLink) { builder.AddChildTag(new RawTag((uint)LinkDirection.Right, false, false, Base16.Decode("012C8149F374FDDCD5443456BC7E8FFA310B7FE090DAA98C0980B81EC2407FD013"))); } return(new CalendarHashChain(builder.BuildTag())); }
private static AggregationHashChain.Link CreateLinkWithLevelCorrection(AggregationHashChain.Link link, ulong levelCorrection) { TlvTagBuilder builder = new TlvTagBuilder(link); IntegerTag levelCorrectionTag = builder.GetChildByType(Constants.AggregationHashChain.Link.LevelCorrectionTagType) as IntegerTag; if (levelCorrectionTag != null) { IntegerTag newLevelCorrectionTag = new IntegerTag( levelCorrectionTag.Type, levelCorrectionTag.NonCritical, levelCorrectionTag.Forward, levelCorrection); builder.ReplaceChildTag(levelCorrectionTag, newLevelCorrectionTag); } else { builder.AddChildTag(new IntegerTag(Constants.AggregationHashChain.Link.LevelCorrectionTagType, false, false, levelCorrection)); } return(new AggregationHashChain.Link(builder.BuildTag())); }