示例#1
0
 public WebDavClientWrapper(NetworkCredentialOptions options, ILogService log, ProxyService proxy)
 {
     _log        = log;
     _credential = options.GetCredential();
     _proxy      = proxy;
     _client     = new WebDavClient(new WebDavClientParams()
     {
         Proxy = _proxy.GetWebProxy(),
         UseDefaultCredentials = _proxy.UseSystemProxy,
         Credentials           = string.IsNullOrEmpty(_credential.UserName) ? null : _credential
     });
 }
        /// <summary>
        /// Read content from Uri
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        protected string GetContent(Uri uri)
        {
            var request = WebRequest.Create(uri);

            request.Proxy = _proxy.GetWebProxy();
            using (var response = request.GetResponse())
                using (var responseStream = response.GetResponseStream())
                    using (var responseReader = new StreamReader(responseStream))
                    {
                        return(responseReader.ReadToEnd());
                    }
        }
        /// <summary>
        /// Warm up the target site, giving the application a little
        /// time to start up before the validation request comes in.
        /// Mostly relevant to classic FileSystem validation
        /// </summary>
        /// <param name="uri"></param>
        private void WarmupSite()
        {
            var request = WebRequest.Create(new Uri(_challenge.FileUrl));

            request.Proxy = _proxy.GetWebProxy();
            try
            {
                using (var response = request.GetResponse()) { }
            }
            catch (Exception ex)
            {
                _log.Error("Error warming up site: {@ex}", ex);
            }
        }
示例#4
0
        private void ConfigureAcmeClient()
        {
            _client.Proxy = _proxyService.GetWebProxy();

            var signerPath = Path.Combine(_settings.ConfigPath, "Signer");

            if (File.Exists(signerPath))
            {
                LoadSignerFromFile(_client.Signer, signerPath);
            }

            _client.Init();
            _client.BeforeGetResponseAction = (x) =>
            {
                _log.Debug("Send {method} request to {uri}", x.Method, x.RequestUri);
            };
            _log.Debug("Getting AcmeServerDirectory");
            _client.GetDirectory(true);

            var registrationPath = Path.Combine(_settings.ConfigPath, "Registration");

            if (File.Exists(registrationPath))
            {
                LoadRegistrationFromFile(registrationPath);
            }
            else
            {
                string email = _optionsService.Options.EmailAddress;
                if (string.IsNullOrWhiteSpace(email))
                {
                    email = _input.RequestString("Enter an email address (not public, used for renewal fail notices)");
                }

                string[] contacts = GetContacts(email);

                AcmeRegistration registration = CreateRegistration(contacts);

                if (!_optionsService.Options.AcceptTos && !_optionsService.Options.Renew)
                {
                    if (!_input.PromptYesNo($"Do you agree to {registration.TosLinkUri}?"))
                    {
                        return;
                    }
                }

                UpdateRegistration();
                SaveRegistrationToFile(registrationPath);
                SaveSignerToFile(_client.Signer, signerPath);
            }
        }
示例#5
0
        /// <summary>
        /// Warm up the target site, giving the application a little
        /// time to start up before the validation request comes in.
        /// Mostly relevant to classic FileSystem validation
        /// </summary>
        /// <param name="uri"></param>
        private string WarmupSite()
        {
            var uri     = new Uri(_challenge.HttpResourceUrl);
            var request = WebRequest.Create(uri);

            request.Proxy = _proxy.GetWebProxy();
            using (var response = request.GetResponse())
            {
                var responseStream = response.GetResponseStream();
                using (var responseReader = new StreamReader(responseStream))
                {
                    return(responseReader.ReadToEnd());
                }
            }
        }
示例#6
0
 public WebDavClientWrapper(NetworkCredentialOptions?options, ILogService log, ProxyService proxy)
 {
     _log = log;
     if (options != null && options.UserName != null)
     {
         _credential = options.GetCredential();
     }
     _proxy  = proxy;
     _client = new WebDavClient(new WebDavClientParams()
     {
         Proxy = _proxy.GetWebProxy(),
         UseDefaultCredentials = _proxy.UseSystemProxy,
         Credentials           = _credential
     });
 }
示例#7
0
        public Route53(
            LookupClientProvider dnsClient,
            ILogService log,
            ProxyService proxy,
            ISettingsService settings,
            Route53Options options) : base(dnsClient, log, settings)
        {
            var region = RegionEndpoint.USEast1;
            var config = new AmazonRoute53Config()
            {
                RegionEndpoint = region
            };

            config.SetWebProxy(proxy.GetWebProxy());
            _route53Client = !string.IsNullOrWhiteSpace(options.IAMRole)
                ? new AmazonRoute53Client(new InstanceProfileAWSCredentials(options.IAMRole), config)
                : !string.IsNullOrWhiteSpace(options.AccessKeyId) && !string.IsNullOrWhiteSpace(options.SecretAccessKey.Value)
                    ? new AmazonRoute53Client(options.AccessKeyId, options.SecretAccessKey.Value, config)
                    : new AmazonRoute53Client(config);
        }
示例#8
0
        private async Task <bool> ConfigureAcmeClient()
        {
            var httpClientHandler = new HttpClientHandler()
            {
                Proxy = _proxyService.GetWebProxy(),
            };
            var httpClient = new HttpClient(httpClientHandler)
            {
                BaseAddress = new Uri(_arguments.MainArguments.GetBaseUri())
            };

            _log.Verbose("Loading ACME account signer...");
            IJwsTool signer        = null;
            var      accountSigner = AccountSigner;

            if (accountSigner != null)
            {
                signer = accountSigner.JwsTool();
            }

            _log.Verbose("Constructing ACME protocol client...");
            _client = new AcmeProtocolClient(httpClient, signer: signer)
            {
                BeforeHttpSend = (x, r) =>
                {
                    _log.Debug("Send {method} request to {uri}", r.Method, r.RequestUri);
                },
            };

            _client.Directory = await _client.GetDirectoryAsync();

            await _client.GetNonceAsync();

            _client.Account = await LoadAccount(signer);

            if (_client.Account == null)
            {
                throw new Exception("AcmeClient was unable to find or create an account");
            }
            return(true);
        }
示例#9
0
        private async Task <bool> ConfigureAcmeClient()
        {
            var httpClientHandler = new HttpClientHandler()
            {
                Proxy = _proxyService.GetWebProxy(),
            };
            var httpClient = new HttpClient(httpClientHandler)
            {
                BaseAddress = new Uri(_arguments.MainArguments.GetBaseUri())
            };

            _log.Verbose("Loading ACME account signer...");
            IJwsTool signer        = null;
            var      accountSigner = AccountSigner;

            if (accountSigner != null)
            {
                signer = accountSigner.JwsTool();
            }

            _log.Verbose("Constructing ACME protocol client...");
            try
            {
                _client = new AcmeProtocolClient(httpClient, signer: signer);
            }
            catch (CryptographicException)
            {
                if (signer == null)
                {
                    // There has been a problem generate a signer for the
                    // new account, possibly because some EC curve is not
                    // on available on the system? So we give it another
                    // shot with a less fancy RSA signer
                    _log.Verbose("First chance error generating new signer, retrying with RSA instead of ECC");
                    signer = new RSJwsTool {
                        KeySize = new Rsa(_log, new RsaOptions()).GetRsaKeyBits()
                    };
                    signer.Init();
                    _client = new AcmeProtocolClient(httpClient, signer: signer);
                }
                else
                {
                    throw;
                }
            }
            _client.BeforeHttpSend = (x, r) =>
            {
                _log.Debug("Send {method} request to {uri}", r.Method, r.RequestUri);
            };
            _client.AfterHttpSend = (x, r) =>
            {
                _log.Verbose("Request completed with status {s}", r.StatusCode);
            };
            _client.Directory = await _client.GetDirectoryAsync();

            await _client.GetNonceAsync();

            _client.Account = await LoadAccount(signer);

            if (_client.Account == null)
            {
                throw new Exception("AcmeClient was unable to find or create an account");
            }
            return(true);
        }