public void TestKsiSignatureExtendWithoutCalendarHashChain() { IKsiSignature signature = GetKsiSignatureFromFile(Resources.KsiSignature_Ok); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(delegate { signature.Extend(null); }); Assert.AreEqual("calendarHashChain", ex.ParamName); }
public void TestKsiSignatureExtendWithCalendarHashChainHasLessRightLinks() { IKsiSignature signature = GetKsiSignatureFromFile(Resources.KsiSignature_Ok); KsiException ex = Assert.Throws <KsiException>(delegate { signature.Extend(GetCalendarHashChain(true)); }); Assert.That(ex.Message, Does.StartWith("Right links of signature calendar hash chain and extended calendar hash chain do not match"), "Unexpected error message"); }
public void TestKsiSignatureExtendWithoutPublicationRecord() { IKsiSignature signature = GetKsiSignatureFromFile(Resources.KsiSignature_Ok); IKsiSignature extendedSignature = signature.Extend(GetCalendarHashChain()); Assert.True(extendedSignature.IsExtended, "IsExtended should be true."); Assert.AreEqual(1455494400, extendedSignature.PublicationRecord.PublicationData.PublicationTime, "Unexpected publication time"); VerificationResult result = new DefaultVerificationPolicy().Verify(extendedSignature, null, TestUtil.GetPublicationsFile()); Assert.AreEqual(VerificationResultCode.Ok, result.ResultCode, "Unexpected verification result code."); }
public void TestKsiSignatureExtendWithInvalidCalendarHashChain() { IKsiSignature signature = GetKsiSignatureFromFile(Resources.KsiSignature_Ok_AggregationHashChain_Only); KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { signature.Extend(GetCalendarHashChain()); }); Assert.That(ex.Message, Does.StartWith("Signature verification failed")); Assert.AreEqual(VerificationError.Int03, ex.VerificationResult.VerificationError, "Unexpected verificaton code"); }
/// <summary> /// Extend signature to publication. /// </summary> /// <param name="signature">KSI signature</param> /// <param name="publicationRecord">publication</param> /// <returns>extended KSI signature</returns> public IKsiSignature Extend(IKsiSignature signature, PublicationRecordInSignature publicationRecord) { if (signature == null) { throw new ArgumentNullException(nameof(signature)); } if (publicationRecord == null) { throw new ArgumentNullException(nameof(publicationRecord)); } CalendarHashChain calendarHashChain = _ksiService.Extend(signature.AggregationTime, publicationRecord.PublicationData.PublicationTime); return(signature.Extend(calendarHashChain, publicationRecord, _ksiSignatureFactoryForExtending)); }
public void TestKsiSignatureExtendWithPublicationRecordInSignature() { IKsiSignature signature = GetKsiSignatureFromFile(Resources.KsiSignature_Ok); PublicationRecordInSignature publicationRecord = new PublicationRecordInSignature(false, false, new ITlvTag[] { new PublicationData(1455494400, new DataHash(Base16.Decode("011878289E1A333DD85091D30F001B9F6F9ED4D428D57E049BD0EBD4DBC89BD210"))), new StringTag(Constants.PublicationRecord.PublicationRepositoryUriTagType, false, false, "Test uri (publication record in signature)") }); IKsiSignature extendedSignature = signature.Extend(GetCalendarHashChain(), publicationRecord); Assert.True(extendedSignature.IsExtended, "IsExtended should be true."); Assert.AreEqual(1455494400, extendedSignature.PublicationRecord.PublicationData.PublicationTime, "Unexpected publication time"); VerificationResult result = new DefaultVerificationPolicy().Verify(extendedSignature, null, TestUtil.GetPublicationsFile()); Assert.AreEqual(VerificationResultCode.Ok, result.ResultCode, "Unexpected verification result code."); Assert.AreEqual("Test uri (publication record in signature)", extendedSignature.PublicationRecord.RepositoryUri[0], "Unexpected repository uri."); }
public void TestKsiSignatureExtendWithPublicationRecordInPublicationsFile() { IKsiSignature signature = GetKsiSignatureFromFile(Resources.KsiSignature_Ok); byte[] publicationDataBytes = new PublicationData(1455494400, new DataHash(Base16.Decode("011878289E1A333DD85091D30F001B9F6F9ED4D428D57E049BD0EBD4DBC89BD210"))).Encode(); byte[] uriTagBytes = new StringTag(Constants.PublicationRecord.PublicationRepositoryUriTagType, false, false, "Test uri (publication record in publications file)") .Encode(); byte[] childBytes = new byte[publicationDataBytes.Length + uriTagBytes.Length]; Array.Copy(publicationDataBytes, childBytes, publicationDataBytes.Length); Array.Copy(uriTagBytes, 0, childBytes, publicationDataBytes.Length, uriTagBytes.Length); PublicationRecordInPublicationFile publicationRecord = new PublicationRecordInPublicationFile(new RawTag(Constants.PublicationRecord.TagTypeInPublicationsFile, false, false, childBytes)); IKsiSignature extendedSignature = signature.Extend(GetCalendarHashChain(), publicationRecord); Assert.True(extendedSignature.IsExtended, "IsExtended should be true."); Assert.AreEqual(1455494400, extendedSignature.PublicationRecord.PublicationData.PublicationTime, "Unexpected publication time"); VerificationResult result = new DefaultVerificationPolicy().Verify(extendedSignature, null, TestUtil.GetPublicationsFile()); Assert.AreEqual(VerificationResultCode.Ok, result.ResultCode, "Unexpected verification result code."); Assert.AreEqual("Test uri (publication record in publications file)", extendedSignature.PublicationRecord.RepositoryUri[0], "Unexpected repository uri."); }