예제 #1
0
        async Task ArcSignAsync(FormatOptions options, MimeMessage message, IList <string> headers, bool doAsync, CancellationToken cancellationToken)
        {
            ArcVerifier.GetArcHeaderSets(message, true, out ArcHeaderSet[] sets, out int count, out var errors);
            AuthenticationResults authres;
            int    instance = count + 1;
            string cv;

            // do not sign if there is already a failed/invalid ARC-Seal.
            if (count > 0 && (errors & ArcValidationErrors.InvalidArcSealChainValidationValue) != 0)
            {
                return;
            }

            options = options.Clone();
            options.NewLineFormat = NewLineFormat.Dos;
            options.EnsureNewLine = true;

            if (doAsync)
            {
                authres = await GenerateArcAuthenticationResultsAsync(options, message, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                authres = GenerateArcAuthenticationResults(options, message, cancellationToken);
            }

            if (authres == null)
            {
                return;
            }

            authres.Instance = instance;

            var aar = new Header(HeaderId.ArcAuthenticationResults, authres.ToString());

            cv = "none";

            if (count > 0)
            {
                cv = "pass";

                foreach (var method in authres.Results)
                {
                    if (method.Method.Equals("arc", StringComparison.OrdinalIgnoreCase))
                    {
                        cv = method.Result;
                        break;
                    }
                }
            }

            var t    = GetTimestamp();
            var ams  = GenerateArcMessageSignature(options, message, instance, t, headers);
            var seal = GenerateArcSeal(options, instance, cv, t, sets, count, aar, ams);

            message.Headers.Insert(0, aar);
            message.Headers.Insert(0, ams);
            message.Headers.Insert(0, seal);
        }
예제 #2
0
파일: ArcSigner.cs 프로젝트: Dano7/MimeKit
        async Task ArcSignAsync(FormatOptions options, MimeMessage message, IList <string> headers, bool doAsync, CancellationToken cancellationToken)
        {
            ArcVerifier.GetArcHeaderSets(message, true, out ArcHeaderSet[] sets, out int count);
            int    instance = count + 1;
            Header aar;

            if (doAsync)
            {
                aar = await GenerateArcAuthenticationResultsAsync(options, message, instance, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                aar = GenerateArcAuthenticationResults(options, message, instance, cancellationToken);
            }

            var t    = DateTime.UtcNow - DateUtils.UnixEpoch;
            var ams  = GenerateArcMessageSignature(options, message, instance, t, headers);
            var seal = GenerateArcSeal(options, instance, t, sets, count, aar, ams);

            message.Headers.Insert(0, aar);
            message.Headers.Insert(0, ams);
            message.Headers.Insert(0, seal);
        }