public void Run() { try { EnsureCertificate(); } catch (LetsEncryptException ex) { Logger?.LogError(ex, ex.InnerException?.Message); if (ErrorHandler != null) { var errorInfo = new ErrorInfo { Continue = ContinueHandler != null, Exception = ex }; ErrorHandler(errorInfo); if (!errorInfo.Continue) { ContinueHandler = null; } } } // Retrieve the certificate from loader CertificateLoader.TryLoad(Options.Hostname, out var certificate); // This starts the actual web app ContinueHandler ?.Invoke(certificate) ?.Run(); }
public async Task RunAsync() { try { await EnsureCertificateAsync(); } catch (LetsEncryptException ex) { if (ErrorHandler != null) { var errorInfo = new ErrorInfo { Continue = ContinueHandler != null, Exception = ex }; ErrorHandler(errorInfo); if (!errorInfo.Continue) { ContinueHandler = null; } } } // Retrieve the certificate from loader CertificateLoader.TryLoad(Options.Hostname, out var certificate); // This starts the actual web app await ContinueHandler ?.Invoke(certificate) ?.RunAsync(); }
private bool CheckForValidCertificate() { Logger?.LogDebug("Try loading existing SSL certificate..."); if (!CertificateLoader.TryLoad(Options.Hostname, out var certificate)) { Logger?.LogWarning("Certificate loader found no existing SSL certificate."); // Certificate does not exist yet return(false); } Logger?.LogInformation("Existing certificate found. Issuer: '{issuer}'; Expires (local time): {expiring}", certificate.Issuer, certificate.NotAfter); // Test if the certificate is issued by the specified authority and whether it's not expired // Todo: Maybe call certificate.Verify return(certificate.Issuer.Equals(Options.Authority.Name, StringComparison.InvariantCultureIgnoreCase) && (certificate.NotAfter - Options.RenewalBuffer) > DateTime.Now && certificate.NotBefore < DateTime.Now); }