예제 #1
0
        private byte[] KeyStoreDecrypt(PasswordRegistryTypes passwordIdentifier, string json)
        {
            var tries = 0;

            while (tries < MaxTries)
            {
                var securePassword =
                    _passwordManager.RetrieveOrPromptPassword(passwordIdentifier, "Please provide your node password");
                var password = StringFromSecureString(securePassword);

                try
                {
                    var keyBytes = DecryptKeyStoreFromJson(password, json);

                    if (keyBytes != null && keyBytes.Length > 0)
                    {
                        _passwordManager.AddPasswordToRegistry(passwordIdentifier, securePassword);
                        return(keyBytes);
                    }
                }
                catch (DecryptionException)
                {
                    securePassword.Dispose();
                    _logger.Error("Error decrypting keystore");
                }

                tries += 1;
            }

            throw new AuthenticationException("Password incorrect for keystore.");
        }
예제 #2
0
        /// <inheritdoc />
        public SecureString RetrieveOrPromptPassword(PasswordRegistryTypes passwordType, string promptMessage = null)
        {
            var password = _passwordRegistry.GetItemFromRegistry(passwordType) ??
                           _passwordReader.ReadSecurePassword(promptMessage ??
                                                              $"Please enter your {passwordType.Name}");

            return(password);
        }
예제 #3
0
        public static void AddPassword(PasswordRegistry passwordRegistry, PasswordRegistryTypes passwordRegistryTypes, string password)
        {
            var secureString = new SecureString();

            foreach (var character in password)
            {
                secureString.AppendChar(character);
            }

            passwordRegistry.AddItemToRegistry(passwordRegistryTypes, secureString);
        }
예제 #4
0
        /// <inheritdoc />
        public SecureString RetrieveOrPromptAndAddPasswordToRegistry(PasswordRegistryTypes passwordType, string promptMessage = null)
        {
            var password = RetrieveOrPromptPassword(passwordType, promptMessage ??
                                                    $"Please enter your {passwordType.Name}");

            if (password != null)
            {
                _passwordRegistry.AddItemToRegistry(passwordType, password);
            }

            return(password);
        }
예제 #5
0
        public Kernel WithPassword(PasswordRegistryTypes types, string password)
        {
            if (password == null)
            {
                return(this);
            }

            ContainerBuilder.RegisterBuildCallback(buildCallback =>
            {
                var passwordRegistry = buildCallback.Resolve <IPasswordRegistry>();
                var ss = new SecureString();
                foreach (var c in password)
                {
                    ss.AppendChar(c);
                }

                passwordRegistry.AddItemToRegistry(types, ss);
            });

            return(this);
        }
예제 #6
0
 /// <inheritdoc />
 public bool AddPasswordToRegistry(PasswordRegistryTypes passwordType, SecureString password)
 {
     return(_passwordRegistry.AddItemToRegistry(passwordType, password));
 }