예제 #1
0
        public async Task<PendingChallenge> AcceptChallengeAsync(string domain, string siteName, AuthorizationResponse authorization)
        {
            var challenge = authorization?.Challenges.FirstOrDefault(c => c.Type == "http-01");
            if (challenge == null)
            {
                Error("the server does not accept challenge type http-01");
                return null;
            }
            Info($"accepting challenge {challenge.Type}");

            var keyAuthorization = client.GetKeyAuthorization(challenge.Token);

            if (siteName == null)
            {
                await AcceptChallengeForDomainAsync(domain, challenge.Token, keyAuthorization);
            }
            else
            {
                await AcceptChallengeForSiteAsync(siteName, challenge.Token, keyAuthorization);
            }

            return new PendingChallenge()
            {
                Instructions = $"using IIS integration to complete the challenge.",
                Complete = () => client.CompleteChallengeAsync(challenge)
            };
        }
예제 #2
0
        public async Task<PendingChallenge> AcceptChallengeAsync(string domain, string siteName, AuthorizationResponse authorization)
        {
            var challenge = authorization?.Challenges.FirstOrDefault(c => c.Type == "http-01");
            if (challenge == null)
            {
                Error("the server does not accept challenge type http-01");
                return null;
            }
            
            Info($"accepting challenge {challenge.Type}");

            var keyAuthorization = client.GetKeyAuthorization(challenge.Token);

            var acmeChallengePath = System.IO.Directory.GetCurrentDirectory();
            var challengeFile = Path.Combine(acmeChallengePath, challenge.Token);
            using (var fs = new FileStream(challengeFile, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                var data = Encoding.ASCII.GetBytes(keyAuthorization);
                await fs.WriteAsync(data, 0, data.Length);
            }

            return new PendingChallenge()
            {
                Instructions = $"Copy {challengeFile} to https://{domain ?? siteName}/.well-known/acme-challenge/{challenge.Token}",
                Complete = () => client.CompleteChallengeAsync(challenge)
            };
        }