Ejemplo n.º 1
0
        KeyContainer CreateKey(TimeSpan?age = null, string alg = "RS256", bool x509 = false)
        {
            var key = _options.CreateRsaSecurityKey();

            var date = _mockClock.UtcNow.DateTime;

            if (age.HasValue)
            {
                date = date.Subtract(age.Value);
            }

            var container = x509 ?
                            new X509KeyContainer(key, alg, date, _options.KeyRetirementAge) :
                            (KeyContainer) new RsaKeyContainer(key, alg, date);

            return(container);
        }
Ejemplo n.º 2
0
        RsaKeyContainer CreateKey(TimeSpan?age = null, KeyType keyType = KeyType.RSA)
        {
            var key = _options.CreateRsaSecurityKey();

            var date = _mockClock.UtcNow.DateTime;

            if (age.HasValue)
            {
                date = date.Subtract(age.Value);
            }

            var container = keyType == KeyType.RSA ?
                            new RsaKeyContainer(key, date) :
                            new X509KeyContainer(key, date, _options.KeyRetirement);

            return(container);
        }
Ejemplo n.º 3
0
        internal async Task <RsaKeyContainer> CreateAndStoreNewKeyAsync()
        {
            _logger.LogDebug("Creating new key.");

            var rsa       = _options.CreateRsaSecurityKey();
            var now       = _clock.UtcNow.DateTime;
            var iss       = _httpContextAccessor?.HttpContext?.GetIdentityServerIssuerUri();
            var container = _options.KeyType == KeyType.RSA ?
                            new RsaKeyContainer(rsa, now) :
                            new X509KeyContainer(rsa, now, _options.KeyRetirement, iss);

            var key = _protector.Protect(container);
            await _store.StoreKeyAsync(key);

            _logger.LogInformation("Created and stored new key with kid {kid}.", container.Id);

            return(container);
        }