Esempio n. 1
0
        public void TestKsiSignatureExtendWithoutCalendarHashChain()
        {
            IKsiSignature         signature = GetKsiSignatureFromFile(Resources.KsiSignature_Ok);
            ArgumentNullException ex        = Assert.Throws <ArgumentNullException>(delegate
            {
                signature.Extend(null);
            });

            Assert.AreEqual("calendarHashChain", ex.ParamName);
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
        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.");
        }
Esempio n. 4
0
        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");
        }
Esempio n. 5
0
        /// <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));
        }
Esempio n. 6
0
        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.");
        }
Esempio n. 7
0
        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.");
        }