private static void Verify(Ksi ksi, IKsiSignature signature, DataHash documentHash) { VerificationContext verificationContext = new VerificationContext(signature) { DocumentHash = documentHash, PublicationsFile = ksi.GetPublicationsFile() }; AggregationHashChain.Link firstChainLink = signature.GetAggregationHashChains()[0].GetChainLinks()[0]; if (firstChainLink.Metadata != null && firstChainLink.Metadata.Padding == null) { throw new Exception("Metadata padding is missing."); } KeyBasedVerificationPolicy policy = new KeyBasedVerificationPolicy(); VerificationResult verificationResult = policy.Verify(verificationContext); if (verificationResult.ResultCode != VerificationResultCode.Ok) { Console.WriteLine("Verification result code: " + verificationResult.ResultCode); Console.WriteLine("Verification rule name: " + verificationResult.RuleName); Console.WriteLine("Verification error: " + verificationResult.VerificationError); } Assert.AreEqual(VerificationResultCode.Ok, verificationResult.ResultCode, "Signature should verify with key based policy"); }
public void AggregationHashChainLinkSequenceNumberMissingTest() { AggregationHashChain.Link aggregationHashChain = new AggregationHashChain.Link(LinkDirection.Left, new AggregationHashChain.Metadata("test client")); AggregationHashChain.Metadata metadata = aggregationHashChain.Metadata; Assert.IsNull(metadata.MachineId, "Aggregation hash chain link machine id should match"); Assert.IsNull(metadata.SequenceNumber, "Aggregation hash chain link metadata sequnece number should match"); Assert.IsNull(metadata.RequestTime, "Aggregation hash chain link metadata request time should match"); }
public void AggregationHashChainLinkSequenceNumberTest() { AggregationHashChain.Link aggregationHashChain = new AggregationHashChain.Link(LinkDirection.Left, "test client", "test machine id", 1, 2); AggregationHashChain.Metadata metadata = aggregationHashChain.Metadata; Assert.AreEqual(1, metadata.SequenceNumber, "Aggregation hash chain link metadata sequnece number should match"); Assert.AreEqual(2, metadata.RequestTime, "Aggregation hash chain link metadata request time should match"); }