Exemplo n.º 1
0
        // This must run on server port 80 - Let's encrypt does not allow anything else
        public static Func<IDictionary<string, object>, Task> Use(Func<IDictionary<string, object>, Task> next, IAcmeConfiguration cfg)
        {
            string challengePath = null;
            byte[] challengeContent = null;
            Log.Level = LogLevel.Verbose;
            Log.Current = new LoggerProxy(cfg);
            Func<Task, Task> updateWorker = null;
            updateWorker=async task =>
                {
                    var utcNow = DateTime.UtcNow;
                    var lastUpdate = cfg.LastUpdate;
                    if (utcNow - lastUpdate > TimeSpan.FromDays(30))
                    {
                        await new AcmeProcess(cfg.Email, cfg.Domain, cfg.UpdateCertificate, (path, content) =>
                        {
                            Log.Info($"SET {path} = {content}");

                            challengePath = path;
                            challengeContent = content;
                        }).StartAsync();
                    }
#pragma warning disable 4014
                    // This cannot be awaited because it has to run once in a while without holding any resources.
                    // ReSharper disable once AssignNullToNotNullAttribute
                    Task.Delay(TimeSpan.FromMinutes(15)).ContinueWith(updateWorker);
#pragma warning restore 4014
                };
            Task.Delay(1).ContinueWith(updateWorker);
            return env =>
            {
                var path = (string)env["owin.RequestPath"];
                if (path == challengePath)
                {
                    var respBody = (Stream)env["owin.ResponseBody"];
                    respBody.Write(challengeContent, 0, challengeContent.Length);
                    return Task.CompletedTask;
                }
                return next(env);
            };
        }
Exemplo n.º 2
0
        // This must run on server port 80 - Let's encrypt does not allow anything else
        public static Func <IDictionary <string, object>, Task> Use(Func <IDictionary <string, object>, Task> next, IAcmeConfiguration cfg)
        {
            string challengePath = null;

            byte[] challengeContent = null;
            Log.Level   = LogLevel.Verbose;
            Log.Current = new LoggerProxy(cfg);
            Func <Task, Task> updateWorker = null;

            updateWorker = async task =>
            {
                var utcNow     = DateTime.UtcNow;
                var lastUpdate = cfg.LastUpdate;
                if (utcNow - lastUpdate > TimeSpan.FromDays(30))
                {
                    await new AcmeProcess(cfg.Email, cfg.Domain, cfg.UpdateCertificate, (path, content) =>
                    {
                        Log.Info($"SET {path} = {content}");

                        challengePath    = path;
                        challengeContent = content;
                    }).StartAsync();
                }
#pragma warning disable 4014
                // This cannot be awaited because it has to run once in a while without holding any resources.
                // ReSharper disable once AssignNullToNotNullAttribute
                Task.Delay(TimeSpan.FromMinutes(15)).ContinueWith(updateWorker);
#pragma warning restore 4014
            };
            Task.Delay(1).ContinueWith(updateWorker);
            return(env =>
            {
                var path = (string)env["owin.RequestPath"];
                if (path == challengePath)
                {
                    var respBody = (Stream)env["owin.ResponseBody"];
                    respBody.Write(challengeContent, 0, challengeContent.Length);
                    return Task.CompletedTask;
                }
                return next(env);
            });
        }
Exemplo n.º 3
0
 public LoggerProxy(IAcmeConfiguration cfg)
 {
     _cfg = cfg;
 }
Exemplo n.º 4
0
 public LoggerProxy(IAcmeConfiguration cfg)
 {
     _cfg = cfg;
 }