예제 #1
0
        public void VerifyExtendedSignatureUsingPublicationsCode()
        {
            // Read the existing signature, assume it is extended
            IKsiSignature signature = LoadExtendedSignature();

            IDataHasher dataHasher = new DataHasher(signature.GetAggregationHashChains()[0].InputHash.Algorithm);

            dataHasher.AddData(File.ReadAllBytes("Resources/infile.txt"));

            // The trust anchor in this example is the publication code in Financial Times or on Twitter
            PublicationData publicationData = new PublicationData("AAAAAA-CWYEKQ-AAIYPA-UJ4GRT-HXMFBE-OTB4AB-XH3PT3-KNIKGV-PYCJXU-HL2TN4-RG6SCC-3ZGSBM");

            // Do the verification and check the result
            VerificationPolicy policy = new PublicationBasedVerificationPolicy();

            VerificationContext context = new VerificationContext(signature)
            {
                DocumentHash    = dataHasher.GetHash(),
                UserPublication = publicationData
            };
            VerificationResult verificationResult = policy.Verify(context);

            if (verificationResult.ResultCode == VerificationResultCode.Ok)
            {
                Console.WriteLine("VerifyExtendedSignatureUsingPublicationsCode > signature valid");
            }
            else
            {
                Console.WriteLine("VerifyExtendedSignatureUsingPublicationsCode > signature verification failed with error > " + verificationResult.VerificationError);
            }
        }
예제 #2
0
        public void VerifyExtendedSignatureUsingPublicationsFile()
        {
            KSI.Ksi ksi = GetKsi();

            // Read the existing signature, assume it is extended
            IKsiSignature signature = LoadExtendedSignature();

            // We need to compute the hash from the original data, to make sure it
            // matches the one in the signature and has not been changed
            // Use the same algorithm as the input hash in the signature
            IDataHasher dataHasher = new DataHasher(signature.GetAggregationHashChains()[0].InputHash.Algorithm);

            dataHasher.AddData(File.ReadAllBytes("Resources/infile.txt"));

            // Do the verification and check the result
            VerificationPolicy  policy  = new PublicationBasedVerificationPolicy();
            VerificationContext context = new VerificationContext(signature)
            {
                DocumentHash     = dataHasher.GetHash(),
                PublicationsFile = ksi.GetPublicationsFile(),
            };
            VerificationResult verificationResult = policy.Verify(context);

            if (verificationResult.ResultCode == VerificationResultCode.Ok)
            {
                Console.WriteLine("VerifyExtendedSignatureUsingPublicationsFile > signature valid");
            }
            else
            {
                Console.WriteLine("VerifyExtendedSignatureUsingPublicationsFile > verification failed with error > " + verificationResult.VerificationError);
            }
        }
예제 #3
0
        public void VerifyKeyBased()
        {
            KSI.Ksi ksi = GetKsi();

            // Read signature, assume to be not extended
            IKsiSignature signature = LoadUnextendedSignature();

            IDataHasher dataHasher = new DataHasher(signature.GetAggregationHashChains()[0].InputHash.Algorithm);

            dataHasher.AddData(File.ReadAllBytes("Resources/infile.txt"));

            VerificationPolicy  policy  = new KeyBasedVerificationPolicy(new X509Store(StoreName.Root), GetCertificateSubjectRdnSelector());
            VerificationContext context = new VerificationContext(signature)
            {
                DocumentHash     = dataHasher.GetHash(),
                PublicationsFile = ksi.GetPublicationsFile(),
            };

            VerificationResult verificationResult = policy.Verify(context);

            if (verificationResult.ResultCode == VerificationResultCode.Ok)
            {
                Console.WriteLine("VerifyKeyBased > signature valid");
            }
            else
            {
                Console.WriteLine("VerifyKeyBased > signature verification failed with error > " + verificationResult.VerificationError);
            }
        }
예제 #4
0
        public void VerifyCalendarBasedUnextended()
        {
            IKsiSignature signature = LoadUnextendedSignature();

            IDataHasher dataHasher = new DataHasher(signature.GetAggregationHashChains()[0].InputHash.Algorithm);

            dataHasher.AddData(File.ReadAllBytes("Resources/infile.txt"));

            VerificationPolicy  policy  = new CalendarBasedVerificationPolicy();
            VerificationContext context = new VerificationContext(signature)
            {
                DocumentHash = dataHasher.GetHash(),
                KsiService   = GetKsiService(),
            };

            VerificationResult verificationResult = policy.Verify(context);

            if (verificationResult.ResultCode == VerificationResultCode.Ok)
            {
                Console.WriteLine("VerifyCalendarBasedUnextended > signature valid");
            }
            else
            {
                Console.WriteLine("VerifyCalendarBasedUnextended > signature verification failed with error > " + verificationResult.VerificationError);
            }
        }
예제 #5
0
        public void VerifyExtendedSignatureUsingPublicationsCodeAutoExtend()
        {
            // Read signature, assume to be not extended
            IKsiSignature signature = LoadUnextendedSignature();

            IDataHasher dataHasher = new DataHasher(signature.GetAggregationHashChains()[0].InputHash.Algorithm);

            dataHasher.AddData(File.ReadAllBytes("Resources/infile.txt"));

            PublicationData publicationData = new PublicationData("AAAAAA-CWYEKQ-AAIYPA-UJ4GRT-HXMFBE-OTB4AB-XH3PT3-KNIKGV-PYCJXU-HL2TN4-RG6SCC-3ZGSBM");

            // Do the verification and check the result
            VerificationPolicy policy = new PublicationBasedVerificationPolicy();

            VerificationContext context = new VerificationContext(signature)
            {
                DocumentHash       = dataHasher.GetHash(),
                UserPublication    = publicationData,
                IsExtendingAllowed = true,
                KsiService         = GetKsiService(),
            };

            VerificationResult verificationResult = policy.Verify(context);

            if (verificationResult.ResultCode == VerificationResultCode.Ok)
            {
                Console.WriteLine("VerifyExtendedSignatureUsingPublicationsCodeAutoExtend > signature valid");
            }
            else
            {
                Console.WriteLine("VerifyExtendedSignatureUsingPublicationsCodeAutoExtend > signature verification failed with error > " + verificationResult.VerificationError);
            }
        }