public async Task TestEndToEndGoDaddy() { var dnsProvider = new GoDaddyDnsProviderTest().DnsService; var manager = new AcmeClient(dnsProvider, new DnsLookupService(), new NullCertificateStore()); var dnsRequest = new AcmeDnsRequest() { Host = "*.åbningstider.info", PFXPassword = "******", RegistrationEmail = "*****@*****.**", AcmeEnvironment = new LetsEncryptStagingV2(), CsrInfo = new CsrInfo() { CountryName = "DK", Locality = "Copenhagen", Organization = "Sjkp", OrganizationUnit = "", State = "DK" } }; var res = await manager.RequestDnsChallengeCertificate(dnsRequest); Assert.IsNotNull(res); File.WriteAllBytes($"{dnsRequest.Host.Substring(2)}.pfx", res.CertificateInfo.PfxCertificate); var certService = new AzureWebAppService(new[] { TestHelper.AzureWebAppSettings }); await certService.Install(res); }
public async Task TestEndToEndAzure() { var config = TestHelper.AzureDnsSettings; var manager = new AcmeClient(new AzureDnsProvider(config), new DnsLookupService(), null, this.logger); var dnsRequest = new AcmeDnsRequest() { Host = "*.ai4bots.com", PFXPassword = "******", RegistrationEmail = "*****@*****.**", AcmeEnvironment = new LetsEncryptStagingV2(), CsrInfo = new CsrInfo() { CountryName = "DK", Locality = "DK", Organization = "SJKP", OrganizationUnit = "", State = "DK" } }; var res = await manager.RequestDnsChallengeCertificate(dnsRequest); Assert.IsNotNull(res); File.WriteAllBytes($"{dnsRequest.Host.Substring(2)}.pfx", res.CertificateInfo.PfxCertificate); var pass = new System.Security.SecureString(); Array.ForEach(dnsRequest.PFXPassword.ToCharArray(), c => { pass.AppendChar(c); }); File.WriteAllBytes($"exported-{dnsRequest.Host.Substring(2)}.pfx", res.CertificateInfo.Certificate.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Pkcs12, pass)); var certService = new AzureWebAppService(new[] { TestHelper.AzureWebAppSettings }); await certService.Install(res); }
public async Task Run(AcmeDnsRequest acmeDnsRequest, int renewXNumberOfDaysBeforeExpiration) { try { CertificateInstallModel model = null; var certname = acmeDnsRequest.Host + "-" + acmeDnsRequest.AcmeEnvironment.Name + ".pfx"; CertificateInfo cert = await certificateStore.GetCertificate(certname, acmeDnsRequest.PFXPassword); if (cert == null || cert.Certificate.NotAfter < DateTime.UtcNow.AddDays(renewXNumberOfDaysBeforeExpiration)) //Cert doesnt exist or expires in less than 21 days, lets renew. { logger.LogInformation("Certificate store didn't contain certificate or certificate was expired starting renewing"); model = await acmeClient.RequestDnsChallengeCertificate(acmeDnsRequest); model.CertificateInfo.Name = certname; await certificateStore.SaveCertificate(model.CertificateInfo); } else { logger.LogInformation("Certificate expires in more than {renewXNumberOfDaysBeforeExpiration} days, reusing certificate from certificate store", renewXNumberOfDaysBeforeExpiration); model = new CertificateInstallModel() { CertificateInfo = cert, Host = acmeDnsRequest.Host }; } await azureWebAppService.Install(model); logger.LogInformation("Removing expired certificates"); System.Collections.Generic.List <string> expired = azureWebAppService.RemoveExpired(); logger.LogInformation("The following certificates was removed {Thumbprints}", string.Join(", ", expired.ToArray())); } catch (Exception e) { logger.LogError(e, "Failed"); throw; } }