예제 #1
0
        /// <see cref="VerificationRule.Verify" />
        public override VerificationResult Verify(IVerificationContext context)
        {
            CalendarHashChain calendarHashChain = GetSignature(context).CalendarHashChain;

            // If calendar hash chain is missing, verification successful
            if (calendarHashChain == null)
            {
                return(new VerificationResult(GetRuleName(), VerificationResultCode.Ok));
            }

            IEnumerator <CalendarHashChain.Link> linksEnumerator = calendarHashChain.GetLeftLinksEnumerator();

            CalendarHashChain.Link link = linksEnumerator.MoveNext() ? linksEnumerator.Current : null;

            while (link != null)
            {
                if (link.Value.Algorithm.IsObsolete(calendarHashChain.PublicationTime))
                {
                    Logger.Debug("Calendar hash chain contains obsolete aggregation algorithm at publication time. Algorithm: {0}; Publication time: {1}",
                                 link.Value.Algorithm.Name, calendarHashChain.PublicationTime);
                    return(new VerificationResult(GetRuleName(), VerificationResultCode.Fail, VerificationError.Int16));
                }

                link = linksEnumerator.MoveNext() ? linksEnumerator.Current : null;
            }

            return(new VerificationResult(GetRuleName(), VerificationResultCode.Ok));
        }
예제 #2
0
        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);
        }
예제 #3
0
        /// <summary>
        /// Get first deprecated hash algorithm from calendar hash chain.
        /// </summary>
        /// <param name="calendarHashChain"></param>
        /// <returns></returns>
        public static HashAlgorithm GetDeprecatedHashAlgorithm(CalendarHashChain calendarHashChain)
        {
            IEnumerator <CalendarHashChain.Link> linksEnumerator = calendarHashChain.GetLeftLinksEnumerator();

            CalendarHashChain.Link link = linksEnumerator.MoveNext() ? linksEnumerator.Current : null;

            while (link != null)
            {
                if (link.Value.Algorithm.IsDeprecated(calendarHashChain.PublicationTime))
                {
                    return(link.Value.Algorithm);
                }

                link = linksEnumerator.MoveNext() ? linksEnumerator.Current : null;
            }

            return(null);
        }