Пример #1
0
        /// <summary>
        /// Provides templating variable replacement for Config values
        /// </summary>
        /// <param name="template"></param>
        /// <param name="config"></param>
        /// <param name="forSuccess"></param>
        /// <returns></returns>
        private static string ParseValues(string template, CertRequestConfig config, bool forSuccess, bool url_encode)
        {
            // add all config properties to template vars
            var vars = new Dictionary <string, string>();

            foreach (var prop in config.GetType().GetProperties())
            {
                string value = prop.GetValue(config)?.ToString() ?? "";
                if (url_encode)
                {
                    value = WebUtility.UrlEncode(value);
                }
                else
                {
                    value = value.Replace(@"\", @"\\");
                }
                vars[prop.Name.ToLower()] = value;
            }

            // add special processing for these values
            vars["success"] = forSuccess ? "true" : "false";
            vars["subjectalternativenames"] = string.Join(",", config.SubjectAlternativeNames ?? new string[] { config.PrimaryDomain });

            // process the template and replace values
            return(Regex.Replace(template, @"\$(\w+)(?=[\W$])", m =>
            {
                // replace var if it can be found, otherwise don't
                string key = m.Groups[1].Value.ToLower();
                return vars.ContainsKey(key) ? vars[key] : "$" + key;
            },
                                 RegexOptions.IgnoreCase));
        }
Пример #2
0
        /// <summary>
        /// Sends an HTTP Request with the requested parameters
        /// </summary>
        /// <param name="url"></param>
        /// <param name="method"></param>
        /// <param name="contentType"></param>
        /// <param name="body"></param>
        /// <returns>A named Tuple with Success boolean and int StatusCode of the HTTP Request</returns>
        public async static Task <(bool Success, int StatusCode)> SendRequest(CertRequestConfig config, bool forSuccess)
        {
            using (var client = new HttpClient())
            {
                HttpRequestMessage message;
                string             Url = ParseValues(config.WebhookUrl, config, forSuccess, true);
                switch (config.WebhookMethod)
                {
                case METHOD_GET:
                    message = new HttpRequestMessage(HttpMethod.Get, Url);
                    break;

                case METHOD_POST:
                    message = new HttpRequestMessage(HttpMethod.Post, Url)
                    {
                        Content = new StringContent(
                            ParseValues(!string.IsNullOrEmpty(config.WebhookContentBody) ? config.WebhookContentBody : DEFAULT_BODY,
                                        config, forSuccess, false),
                            Encoding.UTF8,
                            string.IsNullOrEmpty(config.WebhookContentType) ? "application/json" : config.WebhookContentType)
                    };
                    break;

                default:
                    throw new ArgumentException("Method must be GET or POST", "method");
                }
                var resp = await client.SendAsync(message);

                return(resp.IsSuccessStatusCode, (int)resp.StatusCode);
            }
        }
Пример #3
0
        public ManagedCertificate()
        {
            Name = "New Managed Certificate";
            IncludeInAutoRenew = true;

            DomainOptions = new ObservableCollection <DomainOption>();
            RequestConfig = new CertRequestConfig();

            IncludeInAutoRenew = true;
        }
Пример #4
0
        public ManagedCertificate()
        {
            Name = "New Managed Certificate";
            IncludeInAutoRenew = true;

            DomainOptions = new ObservableCollection <DomainOption>();
            RequestConfig = new CertRequestConfig();

            IncludeInAutoRenew = true;

            CertificateAuthorityId = "letsencrypt.org";
        }
Пример #5
0
        public ManagedCertificate()
        {
            Name = "New Managed Certificate";
            IncludeInAutoRenew = true;

            DomainOptions = new ObservableCollection <DomainOption>();
            RequestConfig = new CertRequestConfig();

            IncludeInAutoRenew = true;

#if DEBUG
            UseStagingMode = true;
#else
            UseStagingMode = false;
#endif
        }