Esempio n. 1
0
        private async Task <byte[]> RequestNewCertificateV2(string domainName)
        {
            var context = new AcmeContext(_settings.AcmeUri);
            await context.NewAccount(_settings.EmailAddress, true);

            var order = await context.NewOrder(new[] { domainName });

            var auths = await order.Authorizations();

            var authZ = auths.First();

            var httpChallenge = await authZ.Http();

            var key = httpChallenge.KeyAuthz;

            var challenge = httpChallenge.KeyAuthz.Split('.')[0];

            await _storage.SetChallengeAndResponseAsync(challenge, key);

            await httpChallenge.Validate();

            await PollResultAsync(context, order, order.Location);

            try
            {
                var privateKey = KeyFactory.NewKey(KeyAlgorithm.RS256);
                var cert       = await order.Generate(new CsrInfo
                {
                    CountryName      = "USA",
                    State            = "FL",
                    Locality         = "TAMPA",
                    Organization     = "SOFTWARE LOGISTICS",
                    OrganizationUnit = "HOSTING",
                    CommonName       = domainName,
                }, privateKey);

                var certPem    = cert.ToPem();
                var pfxBuilder = cert.ToPfx(privateKey);
                var buffer     = pfxBuilder.Build(domainName, _settings.PfxPassword);

                AcmeCertificateManager._instanceLogger.AddCustomEvent(Core.PlatformSupport.LogLevel.Verbose, $"{Tag}_RequestNewCertificateV2", $"Created new certificate and returning byte array for {domainName}.");

                return(buffer);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                AcmeCertificateManager._instanceLogger.AddException($"{Tag}_RequestNewCertificateV2", ex, _settings.AcmeUri.ToString().ToKVP("acmeUri"), domainName.ToKVP("domainName"));
                Console.ResetColor();
                return(null);
            }
        }
Esempio n. 2
0
        private async Task <AcmeResult <Authorization> > GetAuthorizationAsync(AcmeClient client, string domainName)
        {
            var account = await client.NewRegistraton($"mailto:{_settings.EmailAddress}");

            account.Data.Agreement = account.GetTermsOfServiceUri();
            account = await client.UpdateRegistration(account);

            var auth = await client.NewAuthorization(new AuthorizationIdentifier
            {
                Type  = AuthorizationIdentifierTypes.Dns,
                Value = domainName
            });

            var challenge = auth.Data.Challenges.Where(c => c.Type == ChallengeTypes.Http01).First();
            var response  = client.ComputeKeyAuthorization(challenge);
            await _storage.SetChallengeAndResponseAsync(challenge.Token, response);

            var httpChallenge = await client.CompleteChallenge(challenge);

            return(await PollResultAsync(client, httpChallenge.Location));
        }