Esempio n. 1
0
        public async Task Run()
        {
            // Create client alias core object + specify which environment you want to use
            var acmeClient = new AcmeClient(EnviromentUri);

            // Create new Account
            var account = await acmeClient.CreateNewAccountAsync(ContactEmail);

            // Create new Order
            var order = await acmeClient.NewOrderAsync(account, Identifiers);

            // Create DNS challenge (DNS is required for wildcard certificate)
            var challenges = await acmeClient.GetDnsChallenges(account, order);

            // Creation of all DNS entries
            foreach (var challenge in challenges)
            {
                var dnsKey  = challenge.VerificationKey;
                var dnsText = challenge.VerificationValue;
                // value can be e.g.: eBAdFvukOz4Qq8nIVFPmNrMKPNlO8D1cr9bl8VFFsJM

                // Create DNS TXT record e.g.:
                // key: _acme-challenge.your.domain.com
                // value: eBAdFvukOz4Qq8nIVFPmNrMKPNlO8D1cr9bl8VFFsJM
            }

            // Validation of all DNS entries
            foreach (var challenge in challenges)
            {
                await acmeClient.ValidateChallengeAsync(account, challenge);

                // Verify status of challenge
                var freshChallenge = await acmeClient.GetChallengeAsync(account, challenge);

                if (freshChallenge.Status == ChallengeStatus.Invalid)
                {
                    throw new Exception("Something is wrong with your DNS TXT record(s)!");
                }
            }

            // Generate certificate
            var certificate = await acmeClient.GenerateCertificateAsync(account, order, "Suppo.biz");

            // Save files locally
            var password = "******";
            await LocalFileHandler.WriteAsync("Suppo.biz.pfx", certificate.GeneratePfx(password));

            await LocalFileHandler.WriteAsync("Suppo.biz.crt", certificate.GenerateCrt(password));

            await LocalFileHandler.WriteAsync("Suppo.biz.crt.pem", certificate.GenerateCrtPem(password));

            await LocalFileHandler.WriteAsync("Suppo.biz.key.pem", certificate.GenerateKeyPem());

            Assert.Pass();
        }
Esempio n. 2
0
        public async Task OrderCreation()
        {
            // Create client alias core object + specify which environment you want to use
            var acmeClient = new AcmeClient(EnviromentUri);

            // Create new Account
            var account = await acmeClient.CreateNewAccountAsync(ContactEmail);

            // Create new Order
            var order = await acmeClient.NewOrderAsync(account, Identifiers);

            // Create DNS challenge (DNS is required for wildcard certificate)
            var challenges = await acmeClient.GetDnsChallenges(account, order);

            // Creation of all DNS entries
            foreach (var challenge in challenges)
            {
                var dnsKey  = challenge.VerificationKey;
                var dnsText = challenge.VerificationValue;
                // value can be e.g.: eBAdFvukOz4Qq8nIVFPmNrMKPNlO8D1cr9bl8VFFsJM

                // Create DNS TXT record e.g.:
                // key: _acme-challenge.your.domain.com
                // value: eBAdFvukOz4Qq8nIVFPmNrMKPNlO8D1cr9bl8VFFsJM
            }

            // Validation of all DNS entries
            foreach (var challenge in challenges)
            {
                await acmeClient.ValidateChallengeAsync(account, challenge);

                var freshChallenge = await acmeClient.GetChallengeAsync(account, challenge);
            }

            Assert.Pass();
        }
Esempio n. 3
0
        private static async Task Run()
        {
            //
            Console.WriteLine("Step 1 - Order Creation");

            // Create client alias core object + specify which environment you want to use
            var acmeClient = new AcmeClient(ApiEnvironment.LetsEncryptV2);

            // Create new Account
            var account = await acmeClient.CreateNewAccountAsync(Settings.ContactEmail);

            // Create new Order
            var order = await acmeClient.NewOrderAsync(account, Settings.Domains);

            // Create DNS challenge (DNS is required for wildcard certificate)
            var challenges = await acmeClient.GetDnsChallenges(account, order);

            //
            Console.WriteLine("Step 1 - Done");
            Console.WriteLine("Step 2 - Verification by DNS challenge");

            // Creation of all DNS entries
            var sb = new StringBuilder(256);

            foreach (var challenge in challenges)
            {
                sb.AppendLine(string.Format("DNS TXT record Key: {0}", challenge.DnsKey));
                sb.AppendLine(string.Format("DNS TXT record Value: {0}", challenge.VerificationValue));
                sb.AppendLine();
            }
            await LocalFileHandler.WriteAsync("_Output.txt", sb.ToString());

            //
            Console.WriteLine("Step 2 - Open '_Output.txt' file and configure DNS TXT record(s)");
            Console.WriteLine("Step 2 - Press any key to continue ...");
            Console.Read();

            //
            Console.WriteLine("Step 2 - Done");
            Console.WriteLine("Step 3 - Verification of DNS TXT record(s)");

            // Validation of all DNS entries
            var failedCount = 3;
            var valid       = false;

            while (!valid)
            {
                try
                {
                    foreach (var challenge in challenges)
                    {
                        await acmeClient.ValidateChallengeAsync(account, challenge);

                        // Verify status of challenge
                        var freshChallenge = await acmeClient.GetChallengeAsync(account, challenge);

                        if (freshChallenge.Status == ChallengeStatus.Invalid)
                        {
                            throw new Exception("Something is wrong with your DNS TXT record(s)!");
                        }
                    }

                    valid = true;
                }
                catch (Exception ex)
                {
                    failedCount--;

                    if (failedCount == 0)
                    {
                        throw new Exception("Validation of DNS TXT record(s) is failed!", ex);
                    }

                    Thread.Sleep(5000);
                }
            }

            //
            Console.WriteLine("Step 3 - Done");
            Console.WriteLine("Step 4 - Certificate generation");

            Thread.Sleep(5000);

            // Generate certificate
            var certificate = await acmeClient.GenerateCertificateAsync(account, order, Settings.CertificateFileName);

            // Save files locally
            await LocalFileHandler.WriteAsync(Settings.CertificateFileName + ".pfx", certificate.GeneratePfx(Settings.CertificatePassword));

            await LocalFileHandler.WriteAsync(Settings.CertificateFileName + ".crt", certificate.GenerateCrt(Settings.CertificatePassword));

            await LocalFileHandler.WriteAsync(Settings.CertificateFileName + ".crt.pem", certificate.GenerateCrtPem(Settings.CertificatePassword));

            await LocalFileHandler.WriteAsync(Settings.CertificateFileName + ".key.pem", certificate.GenerateKeyPem());

            Console.WriteLine("Step 4 - Done");
        }
Esempio n. 4
0
        public async Task Run()
        {
            // Create client alias core object + specify which environment you want to use
            var acmeClient = new AcmeClient(EnviromentUri);

            // Create new Account
            var account = await acmeClient.CreateNewAccountAsync(ContactEmail);

            // Create new Order
            var order = await acmeClient.NewOrderAsync(account, Identifiers);

            // Create DNS challenge (DNS is required for wildcard certificate)
            var challenges = await acmeClient.GetDnsChallenges(account, order);

            try
            {
                // Creation of all DNS entries
                foreach (var challenge in challenges)
                {
                    var dnsKey  = challenge.VerificationKey;
                    var dnsText = challenge.VerificationValue;


                    await AddTxtEntry(challenge.DnsKey, dnsText);

                    // value can be e.g.: eBAdFvukOz4Qq8nIVFPmNrMKPNlO8D1cr9bl8VFFsJM

                    // Create DNS TXT record e.g.:
                    // key: _acme-challenge.your.domain.com
                    // value: eBAdFvukOz4Qq8nIVFPmNrMKPNlO8D1cr9bl8VFFsJM
                }

                await Task.Delay(60000);

                // Validation of all DNS entries
                foreach (var challenge in challenges)
                {
                    await acmeClient.ValidateChallengeAsync(account, challenge);

                    Challenge freshChallenge;
                    do
                    {
                        // Verify status of challenge
                        freshChallenge = await acmeClient.GetChallengeAsync(account, challenge);

                        if (freshChallenge.Status == ChallengeStatus.Invalid)
                        {
                            throw new Exception("Something is wrong with your DNS TXT record(s)!");
                        }

                        if (freshChallenge.Status != ChallengeStatus.Valid)
                        {
                            await Task.Delay(5000);
                        }
                    } while (freshChallenge.Status == ChallengeStatus.Valid);
                }
            }
            finally
            {
                foreach (var challenge in challenges)
                {
                    await ClearTxtEntries(challenge.DnsKey);
                }
            }

            var commonName = Identifiers.FirstOrDefault(i => !i.StartsWith("*"));

            // Generate certificate
            var certificate = await acmeClient.GenerateCertificateAsync(account, order, commonName);

            // Save files locally
            var password = "******";
            await LocalFileHandler.WriteAsync($"{commonName}.pfx", certificate.GeneratePfx(password));

            await LocalFileHandler.WriteAsync($"{commonName}.crt", certificate.GenerateCrt(password));

            await LocalFileHandler.WriteAsync($"{commonName}.crt.pem", certificate.GenerateCrtPem(password));

            await LocalFileHandler.WriteAsync($"{commonName}.key.pem", certificate.GenerateKeyPem());

            Assert.Pass();
        }