示例#1
0
 public ContainerBuilderRiderConfigurator(ContainerBuilder builder, IContainerRegistrar registrar, HashSet <Type> riderTypes)
     : base(registrar)
 {
     Builder       = builder;
     _riderTypes   = riderTypes;
     Registrations = new RegistrationCache <object>();
 }
示例#2
0
 public ServiceCollectionRiderConfigurator(IServiceCollection collection, IContainerRegistrar registrar, HashSet <Type> riderTypes)
     : base(registrar)
 {
     _riderTypes   = riderTypes;
     Collection    = collection;
     Registrations = new RegistrationCache <object>();
 }
 public RegistrationHandler(IMessage message,
                            RegistrationCache registrationCache, ILineNotifySubscription lineNotifySubscription)
 {
     _message                = message;
     _registrationCache      = registrationCache;
     _lineNotifySubscription = lineNotifySubscription;
 }
示例#4
0
 public void Setup()
 {
     _message = Substitute.For <IMessage>();
     _lineNotifySubscription = Substitute.For <ILineNotifySubscription>();
     _registrationCache      = new RegistrationCache();
     _registrationHandler    = new StubRegistrationHandler(_message, _registrationCache, _lineNotifySubscription);
     _lineNotifySubscription.GenerateLink(Arg.Any <string>()).Returns(_link);
 }
示例#5
0
        public async Task Init(string email, CancellationToken token = default(CancellationToken))
        {
            _accountKey = new RSACryptoServiceProvider(4096);

            if (File.Exists(_path))
            {
                bool success;
                try
                {
                    lock (Locker)
                    {
                        _cache = JsonConvert.DeserializeObject <RegistrationCache>(File.ReadAllText(_path));
                    }

                    _accountKey.ImportCspBlob(_cache.AccountKey);

                    success = true;
                }
                catch
                {
                    success = false;
                    // if we failed for any reason, we'll just
                    // generate a new registration
                }

                if (success)
                {
                    _client = new AcmeClient(GetCachedClient(_url), _accountKey);

                    return;
                }
            }

            // need to generate new account
            _client = new AcmeClient(new HttpClient
            {
                BaseAddress = new Uri(_url)
            }, _accountKey);
            var registration = await _client.RegisterAsync(new NewRegistrationRequest
            {
                Contact = new[] { "mailto:" + email }
            }, token);

            lock (Locker)
            {
                _cache = new RegistrationCache
                {
                    Location   = registration.Location,
                    Id         = registration.Id,
                    Key        = registration.Key,
                    AccountKey = _accountKey.ExportCspBlob(true)
                };
                File.WriteAllText(_path,
                                  JsonConvert.SerializeObject(_cache, Formatting.Indented));
            }
        }
        public async Task Init(string email, CancellationToken token = default(CancellationToken))
        {
            _accountKey = new RSACryptoServiceProvider(4096);


            // retrieve the API directory
            (_directory, _) = await SendAsync <APIDirectory>(HttpMethod.Get, new Uri("directory", UriKind.Relative), null, token);

            // check for account
            if (File.Exists(_cachePath))
            {
                bool success;
                try
                {
                    RegistrationCache.SetInstance(RegistrationCache.LoadCacheFromFile(_cachePath));
                    _accountKey.ImportCspBlob(RegistrationCache.Instance.AccountKey);
                    _encryptor = new JsonWebSigner(_accountKey, RegistrationCache.Instance.Location.ToString());
                    success    = true;
                }
                catch
                {
                    success = false;
                }

                if (success)
                {
                    return;
                }
            }

            // no account found, create a new account
            _encryptor             = new JsonWebSigner(_accountKey, null);
            var(account, response) = await SendAsync <Account>(HttpMethod.Post, _directory.NewAccount, new Account
            {
                // we validate this in the UI before we get here, so that is fine
                TermsOfServiceAgreed = true,
                Contacts             = new[] { "mailto:" + email },
            }, token);

            _encryptor.SetKeyId(account);

            if (account.Status != "valid")
            {
                throw new InvalidOperationException("Account status is not valid, was: " + account.Status + Environment.NewLine + response);
            }

            RegistrationCache.SetInstance(new RegistrationCache
            {
                Location   = account.Location,
                AccountKey = _accountKey.ExportCspBlob(true),
                Id         = account.Id,
                Key        = account.Key
            });

            RegistrationCache.SaveInstance(_cachePath);
        }
示例#7
0
        public async Task Init(string email, CancellationToken token = default(CancellationToken))
        {
            _accountKey     = new RSACryptoServiceProvider(4096);
            _client         = GetCachedClient(_url);
            (_directory, _) = await SendAsync <Directory>(HttpMethod.Get, new Uri("directory", UriKind.Relative), null, token);

            // Use this when testing against pebble
            //(_directory, _) = await SendAsync<Directory>(HttpMethod.Get, new Uri("dir", UriKind.Relative), null, token);

            if (File.Exists(_path))
            {
                bool success;
                try
                {
                    lock (Locker)
                    {
                        _cache = JsonConvert.DeserializeObject <RegistrationCache>(File.ReadAllText(_path));
                    }

                    _accountKey.ImportCspBlob(_cache.AccountKey);

                    // From: https://community.letsencrypt.org/t/acme-v2-strict-jws-kid-header-processing/63321
                    // "KeyID headers contain the full account URL as returned by the Location header in a newAccount response"
                    var kid = _cache.Location.ToString();

                    _jws    = new Jws(_accountKey, kid);
                    success = true;
                }
                catch
                {
                    success = false;
                    // if we failed for any reason, we'll just
                    // generate a new registration
                }

                if (success)
                {
                    return;
                }
            }

            _jws = new Jws(_accountKey, null);
            var(account, response) = await SendAsync <Account>(HttpMethod.Post, _directory.NewAccount, new Account
            {
                // we validate this in the UI before we get here, so that is fine
                TermsOfServiceAgreed = true,
                Contacts             = new[] { "mailto:" + email },
            }, token);

            _jws.SetKeyId(account);

            if (account.Status != "valid")
            {
                throw new InvalidOperationException("Account status is not valid, was: " + account.Status + Environment.NewLine + response);
            }

            lock (Locker)
            {
                _cache = new RegistrationCache
                {
                    Location   = account.Location,
                    AccountKey = _accountKey.ExportCspBlob(true),
                    Id         = account.Id,
                    Key        = account.Key
                };
                File.WriteAllText(_path,
                                  JsonConvert.SerializeObject(_cache, Formatting.Indented));
            }
        }
 public RegistrationController(DatabaseAccess dal, RiotAPIWrapper wrapper, RegistrationCache registrationCache)
 {
     this.dal               = dal;
     this.wrapper           = wrapper;
     this.registrationCache = registrationCache;
 }
示例#9
0
 public StubRegistrationHandler(IMessage message,
                                RegistrationCache registrationCache, ILineNotifySubscription lineNotifySubscription) : base(message, registrationCache, lineNotifySubscription)
 {
 }
示例#10
0
 public ACMEWebAPIClient(string url)
 {
     //_url = url ?? throw new ArgumentNullException(nameof(url));
     _client    = HttpClientCache.GetCachedClient(url ?? throw new ArgumentNullException(nameof(url)));
     _cachePath = RegistrationCache.GetDefaultCacheFilename(url);
 }