Beispiel #1
0
        public Challenge Decode(IdentifierPart ip, ChallengePart cp, ISigner signer)
        {
            if (cp.Type != AcmeProtocol.CHALLENGE_TYPE_DNS)
            {
                throw new InvalidDataException("unsupported Challenge type")
                      .With("challengeType", cp.Type)
                      .With("supportedChallengeTypes", AcmeProtocol.CHALLENGE_TYPE_DNS);
            }

            //var token = (string)cp["token"];
            var token = cp.Token;

            // This response calculation is described in:
            //    https://tools.ietf.org/html/draft-ietf-acme-acme-01#section-7.5

            var keyAuthz    = JwsHelper.ComputeKeyAuthorization(signer, token);
            var keyAuthzDig = JwsHelper.ComputeKeyAuthorizationDigest(signer, token);

            var ca = new DnsChallengeAnswer
            {
                KeyAuthorization = keyAuthz,
            };

            var c = new DnsChallenge(cp.Type, ca)
            {
                Token       = token,
                RecordName  = $"{AcmeProtocol.DNS_CHALLENGE_NAMEPREFIX}{ip.Value}",
                RecordValue = keyAuthzDig,
            };

            return(c);
        }
        public Challenge Decode(IdentifierPart ip, ChallengePart cp, ISigner signer)
        {
            if (cp.Type != AcmeProtocol.CHALLENGE_TYPE_HTTP)
            {
                throw new InvalidDataException("unsupported Challenge type")
                      .With("challengeType", cp.Type)
                      .With("supportedChallengeTypes", AcmeProtocol.CHALLENGE_TYPE_HTTP);
            }

            //var token = (string)cp["token"];
            var token = cp.Token;

            // This response calculation is described in:
            //    https://tools.ietf.org/html/draft-ietf-acme-acme-01#section-7.2

            var keyAuthz = JwsHelper.ComputeKeyAuthorization(signer, token);
            var path     = $"{AcmeProtocol.HTTP_CHALLENGE_PATHPREFIX}{token}";
            var url      = $"http://{ip.Value}/{path}";


            var ca = new HttpChallengeAnswer
            {
                KeyAuthorization = keyAuthz,
            };

            var c = new HttpChallenge(cp.Type, ca)
            {
                Token       = token,
                FileUrl     = url,
                FilePath    = path,
                FileContent = keyAuthz,
            };

            return(c);
        }
Beispiel #3
0
        public Challenge Decode(IdentifierPart ip, ChallengePart cp, ISigner signer)
        {
            if (cp.Type != AcmeProtocol.CHALLENGE_TYPE_SNI)
            {
                throw new InvalidDataException("unsupported Challenge type")
                      .With("challengeType", cp.Type)
                      .With("supportedChallengeTypes", AcmeProtocol.CHALLENGE_TYPE_SNI);
            }

            var token = cp.Token;

            // This response calculation is described in:
            //    https://tools.ietf.org/html/draft-ietf-acme-acme-01#section-7.3

            var keyAuthz    = JwsHelper.ComputeKeyAuthorization(signer, token);
            var keyAuthzDig = JwsHelper.ComputeKeyAuthorizationDigest(signer, token);

            LOG.Debug("Computed key authorization {0} and digest {1}", keyAuthz, keyAuthzDig);

            var ca = new TlsSniChallengeAnswer
            {
                KeyAuthorization = keyAuthz,
            };

            var c = new TlsSniChallenge(cp.Type, ca)
            {
                Token          = token,
                IterationCount = 1 // see: https://github.com/ietf-wg-acme/acme/pull/22 for reason n=1
            };

            return(c);
        }
Beispiel #4
0
        private static void TestPart(BaseChallenge challenge, ChallengePart part)
        {
            Console.SetOut(new StringWriter()); // Discard all output during part execution
            Results results = Execute(challenge, part, fullStackTrace: false);

            ConsoleUtil.RestoreDefaultOutput();

            Console.ForegroundColor = (part == ChallengePart.Part1 ? ConsoleColor.Blue : ConsoleColor.DarkCyan);
            Console.Write($"{challenge.day:00}-{(int)part} ");

            results.SetStatusColor();
            switch (results.status)
            {
            case ResultStatus.Development:
            case ResultStatus.Candidate:
                Console.Write("WIP ");
                break;

            case ResultStatus.WrongAnswer:
            case ResultStatus.Exception:
                Console.Write("FAIL");
                break;

            case ResultStatus.Success:
                Console.Write("PASS");
                break;
            }
            Console.ResetColor();
            Console.Write(" ");

            WriteBenchmark();

            Console.ResetColor();
            Console.WriteLine(results.status == ResultStatus.Exception ? results.message : results.givenAnswer);
        }
Beispiel #5
0
        private static void RunPart(BaseChallenge challenge, ChallengePart part)
        {
            Results results = Execute(challenge, part);

            results.SetStatusColor();
            Console.Write($"[Part {(int)part}]");
            Console.ResetColor();
            Console.Write(" ");

            WriteBenchmark();

            Console.ResetColor();
            string[] messageParts = (results.message ?? string.Empty).Split("{0}");
            if (messageParts.Length > 0)
            {
                Console.Write(messageParts[0]);
            }
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(results.givenAnswer);
            Console.ResetColor();
            if (messageParts.Length > 1)
            {
                Console.Write(messageParts[1]);
            }
            Console.WriteLine();
        }
Beispiel #6
0
        private static Results Execute(BaseChallenge challenge, ChallengePart part, bool fullStackTrace = true)
        {
            Results data = new Results();

            try
            {
                Stopwatch.Restart();
                ResetMethod.Invoke(challenge, null);
                object output = SolvePartMethods[part].Invoke(challenge, null);
                Stopwatch.Stop();

                (string message, object answer) = ((string, object)?)output ?? (null, null);

                data.message     = message;
                data.givenAnswer = answer?.ToString();

                string expected = ExpectedAnswerProps[part].GetValue(challenge)?.ToString();
                if (!string.IsNullOrEmpty(expected))
                {
                    data.status = (data.givenAnswer == $"{expected}" ? ResultStatus.Success : ResultStatus.WrongAnswer);
                }
                else if (!string.IsNullOrEmpty(data.givenAnswer))
                {
                    data.status = ResultStatus.Candidate;
                }
                else
                {
                    data.status = ResultStatus.Development;
                    Stopwatch.Reset();
                }
            } catch (Exception ex)
            {
                data.status = ResultStatus.Exception;
                Stopwatch.Reset();

                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;                               // Skip Invoke() and nested exceptions
                }
                data.message = ex.Message;
                if (fullStackTrace)
                {
                    data.message += "\n" + FormatStackTrace(ex.StackTrace);
                }
            }

            return(data);
        }
 public IChallengeDecoder GetDecoder(IdentifierPart ip, ChallengePart cp)
 {
     return(new TlsSniChallengeDecoder());
 }
 public bool IsSupported(IdentifierPart ip, ChallengePart cp)
 {
     return(AcmeProtocol.CHALLENGE_TYPE_SNI == cp.Type);
 }