コード例 #1
0
        public override void CreateRule(SecretEncryptionContext encryptionContext, ClaimsPrincipal principal)
        {
            if (IsRequired && (string.IsNullOrEmpty(encryptionContext.GetInput(UserInputConstants.EmailAddress))))
            {
                throw new ArgumentException("Email is required");
            }
            if (encryptionContext.GetInput(UserInputConstants.EmailAddress) == null)
            {
                return;
            }

            var email     = encryptionContext.GetInput(UserInputConstants.EmailAddress);
            var emailData = new UserEmailValidationData
            {
                Email     = email,
                MustLogin = encryptionContext.GetInput <bool>(UserInputConstants.ForceAuthentication)
            };

            _logger.LogDebug($"Setting user email to {email}");
            encryptionContext.AddValidationRule(new SecretValidationRule
            {
                Validator      = this.Name,
                ValidationData = SerializeData(emailData)
            });
        }
コード例 #2
0
        public override void CreateRule(SecretEncryptionContext encryptionContext, ClaimsPrincipal principal)
        {
            if (IsRequired && (string.IsNullOrEmpty(encryptionContext.GetInput(UserInputConstants.Passphrase))))
            {
                throw new ArgumentException("Passphrase is required");
            }

            var passphrase = encryptionContext.GetInput(UserInputConstants.Passphrase) ?? "";

            var passphraseData = new PassphraseValidationData
            {
                Algorithm      = PassphraseAlgorithm.Pbkdf2Sha1,
                IterationCount = 10000,
                Salt           = _keyGenerator.GenerateSalt()
            };

            if (!string.IsNullOrEmpty(passphrase))
            {
                encryptionContext.EncryptionKey = GetEncryptionKey(passphrase, passphraseData);
            }
            _logger.LogDebug($"Using passphrase {passphrase} to set encryption key to {encryptionContext.EncryptionKey}");
            encryptionContext.AddValidationRule(new SecretValidationRule
            {
                Validator      = this.Name,
                ValidationData = SerializeData(passphraseData)
            });
        }
コード例 #3
0
        public override void CreateRule(SecretEncryptionContext encryptionContext, ClaimsPrincipal principal)
        {
            if (IsRequired && (string.IsNullOrEmpty(encryptionContext.GetInput(UserInputConstants.IpRegex))))
            {
                throw new ArgumentException("IP is required");
            }
            if (encryptionContext.GetInput(UserInputConstants.IpRegex) == null)
            {
                return;
            }

            var ip     = encryptionContext.GetInput(UserInputConstants.IpRegex);
            var ipData = new UserIpValidationData
            {
                IpRegex = ip
            };

            _logger.LogDebug($"Setting IP regex to {ip}");
            encryptionContext.AddValidationRule(new SecretValidationRule
            {
                Validator      = this.Name,
                ValidationData = SerializeData(ipData)
            });
        }
コード例 #4
0
        public override void CreateRule(SecretEncryptionContext encryptionContext, ClaimsPrincipal principal)
        {
            if (IsRequired && (!encryptionContext.GetInput <DateTime?>(UserInputConstants.Expiry).HasValue))
            {
                throw new ArgumentException("Expiry is required");
            }
            if (!encryptionContext.GetInput <DateTime?>(UserInputConstants.Expiry).HasValue)
            {
                return;
            }

            var expiry = encryptionContext.GetInput <DateTime>(UserInputConstants.Expiry);

            var expiryData = new ExpiryValidationData
            {
                Expiry = expiry
            };

            encryptionContext.AddValidationRule(new SecretValidationRule
            {
                Validator      = this.Name,
                ValidationData = SerializeData(expiryData)
            });
        }