Ejemplo n.º 1
0
        /// <summary>
        /// Import credentials from the "Login Data" file.
        /// </summary>
        /// <exception cref="FileNotFoundException">Thrown when the database is not present.</exception>
        /// <param name="param">The parameters for the import</param>
        public override void ImportCredentials(ImportParameter param)
        {
            var currentProfilePath = !string.IsNullOrEmpty(param.Profile) ? Path.Combine(ProfilePath, param.Profile) : ProfilePath;

            if (!Directory.Exists(currentProfilePath))
            {
                throw new FileNotFoundException(currentProfilePath);
            }

            var loginDataPath = Path.Combine(currentProfilePath, "Login Data");

            if (!File.Exists(loginDataPath))
            {
                throw new FileNotFoundException(loginDataPath);
            }

            using (var db = new DBHandler(loginDataPath))
            {
                DataTable dt;
                db.Query(out dt, "SELECT origin_url, username_value, password_value FROM logins");

                foreach (var row in dt.AsEnumerable())
                {
                    param.Database.CreateWebsiteEntry(
                        param.Group,
                        row["origin_url"] as string,
                        row["username_value"] as string,
                        Encoding.UTF8.GetString(Cryptography.DecryptUserData(row["password_value"] as byte[])),
                        param.ExtractTitle,
                        param.ExtractIcon,
                        param.Logger
                        );
                }
            }
        }
        /// <summary>
        /// Import credentials from the "Login Data" file.
        /// </summary>
        /// <exception cref="FileNotFoundException">Thrown when the database is not present.</exception>
        /// <param name="param">The parameters for the import</param>
        public override void ImportCredentials(ImportParameter param)
        {
            var currentProfilePath = !string.IsNullOrEmpty(param.CustomProfilePath)
                                ? param.CustomProfilePath
                                : !string.IsNullOrEmpty(param.Profile)
                                        ? Path.Combine(ProfilePath, param.Profile)
                                        : ProfilePath;

            if (!Directory.Exists(currentProfilePath))
            {
                throw new ProfileNotFoundException(currentProfilePath);
            }

            var loginDataPath = Path.Combine(currentProfilePath, "Login Data");

            if (!File.Exists(loginDataPath))
            {
                throw new ProfileNotFoundException(loginDataPath);
            }

            try
            {
                using (var db = new DBHandler(loginDataPath))
                {
                    DataTable dt;
                    db.Query(out dt, "SELECT origin_url, username_value, password_value, date_created FROM logins");

                    foreach (var row in dt.AsEnumerable())
                    {
                        var date = DateUtils.FromChromiumTime((long)row["date_created"]);

                        var entry = new EntryInfo
                        {
                            Hostname = row["origin_url"] as string,
                            Username = row["username_value"] as string,
                            Password = Encoding.UTF8.GetString(Cryptography.DecryptUserData(row["password_value"] as byte[])),
                            Created  = date,
                            Modified = date
                        };

                        param.Database.CreateWebsiteEntry(
                            param.Group,
                            entry,
                            param.CreationSettings,
                            param.Logger
                            );
                    }
                }
            }
            catch (DbException ex)
            {
                throw new Exception(string.Format("Error while using the browsers login database. It may help to close all running instances of the browser.\n\n{0}", StrUtil.FormatException(ex)), ex);
            }
        }
Ejemplo n.º 3
0
 public override void ImportCredentials(ImportParameter param)
 {
     foreach (var entry in ReadRegistryPasswords().Union(ReadCredentialStorePasswords()).Union(ReadVaultPasswords()))
     {
         param.Database.CreateWebsiteEntry(
             param.Group,
             entry,
             param.CreationSettings,
             param.Logger
             );
     }
 }
Ejemplo n.º 4
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
                                    IStatusLogger slLogger)
        {
            //Debugger.Launch();

            var pf = new ProviderForm(pwStorage);

            if (pf.ShowDialog() == DialogResult.OK)
            {
                var provider = pf.SelectedProvider;
                var parms    = new ImportParameter
                {
                    Logger = slLogger,

                    Database = pwStorage,
                    Group    = pf.SelectedGroup ?? pwStorage.RootGroup,

                    Profile           = pf.SelectedProfile,
                    CustomProfilePath = pf.CustomProfilePath,

                    Password = pf.MasterPassword,

                    CreationSettings = new CreationSettings
                    {
                        ExtractTitle = pf.ExtractTitle,
                        ExtractIcon  = pf.ExtractIcon,
                        UseDates     = pf.UseDates
                    }
                };

                //could take some time if the webpages need to get crawled
                var task = Task.Factory.StartNew(() => provider.ImportCredentials(parms));

                while (!task.IsCompleted)
                {
                    Thread.Sleep(100);
                    Application.DoEvents();
                }

                if (task.IsFaulted)
                {
                    var       message        = "Error while importing credentials from browser. Some credentials may have been imported.";
                    Exception innerException = null;
                    if (task.Exception != null)
                    {
                        message       += "\n\n" + task.Exception.Message;
                        innerException = task.Exception.InnerException;
                    }

                    throw new Exception(message, innerException);
                }
            }
        }
        public override void Import(PwDatabase pwStorage, Stream sInput,
                                    IStatusLogger slLogger)
        {
            //Debugger.Launch();

            var pf = new ProviderForm(pwStorage);

            if (pf.ShowDialog() == DialogResult.OK)
            {
                var provider = pf.SelectedProvider;
                var parms    = new ImportParameter
                {
                    Logger = slLogger,

                    Database = pwStorage,
                    Group    = pf.SelectedGroup ?? pwStorage.RootGroup,

                    Profile           = pf.SelectedProfile,
                    CustomProfilePath = pf.CustomProfilePath,

                    Password = pf.MasterPassword,

                    CreationSettings = new CreationSettings
                    {
                        ExtractTitle = pf.ExtractTitle,
                        ExtractIcon  = pf.ExtractIcon,
                        UseDates     = pf.UseDates
                    }
                };

                //could take some time if the webpages need to get crawled
                var task = Task.Factory.StartNew(() => provider.ImportCredentials(parms));

                while (!task.IsCompleted)
                {
                    Thread.Sleep(100);
                    Application.DoEvents();
                }

                var exp = task.Exception;
                if (exp != null)
                {
                    if (exp.InnerExceptions.Count > 0)
                    {
                        throw exp.InnerExceptions.First();
                    }

                    throw exp;
                }
            }
        }
 public override void ImportCredentials(ImportParameter param)
 {
     foreach (var t in ReadRegistryPasswords().Union(ReadCredentialStorePasswords()).Union(ReadVaultPasswords()))
     {
         param.Database.CreateWebsiteEntry(
             param.Group,
             t.Item1,
             t.Item2,
             t.Item3,
             param.ExtractTitle,
             param.ExtractIcon,
             param.Logger
             );
     }
 }
        public override void ImportCredentials(ImportParameter param)
        {
            var exceptions = new List <Exception>();

            ImportCredentialsImpl(param, ReadRegistryPasswords, ref exceptions);
            ImportCredentialsImpl(param, ReadCredentialStorePasswords, ref exceptions);
            ImportCredentialsImpl(param, ReadVaultPasswords, ref exceptions);

            if (exceptions.Any())
            {
                var combinedMessages = string.Join("\n\n", exceptions.Select(StrUtil.FormatException));

                throw new Exception(combinedMessages);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Imports the credentials provided by the <see cref="importFunc"/>.
 /// </summary>
 /// <param name="param">The parameters for the import</param>
 /// <param name="importFunc">The provider for the credential entries.</param>
 /// <param name="occuredExceptions">List with occured exceptions.</param>
 private static void ImportCredentialsImpl(ImportParameter param, Func <IEnumerable <EntryInfo> > importFunc, ref List <Exception> occuredExceptions)
 {
     try
     {
         foreach (var entry in importFunc())
         {
             param.Database.CreateWebsiteEntry(
                 param.Group,
                 entry,
                 param.CreationSettings,
                 param.Logger
                 );
         }
     }
     catch (Exception ex)
     {
         occuredExceptions.Add(ex);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Import the credentials with the Network Security Services methods.
        /// </summary>
        /// <exception cref="FileNotFoundException">Thrown when the requested profile is not present.</exception>
        /// <exception cref="NetworkSecurityServicesException">Thrown when a Network Security Services error condition occurs.</exception>
        /// <param name="param">The parameters for the import</param>
        public override void ImportCredentials(ImportParameter param)
        {
            var currentProfilePath = !string.IsNullOrEmpty(param.CustomProfilePath)
                                ? param.CustomProfilePath
                                : Path.Combine(profileDirectory, param.Profile);

            if (!Directory.Exists(currentProfilePath))
            {
                throw new ProfileNotFoundException(currentProfilePath);
            }

            var pluginPath        = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var nativeLibraryPath = Path.Combine(pluginPath, Environment.Is64BitProcess ? "x64" : "x86");

            SetDllDirectory(nativeLibraryPath);

            var nss3Handle = LoadLibrary(Path.Combine(nativeLibraryPath, NSS3_DLL));

            if (nss3Handle == IntPtr.Zero)
            {
                throw new Win32Exception();
            }

            IntPtr slot = IntPtr.Zero;

            try
            {
                if (NSS_Init(currentProfilePath) != SECStatus.Success)
                {
                    throw new NetworkSecurityServicesException("NSS_Init failed: Wrong profile path?\n\n" + currentProfilePath);
                }

                if ((slot = PK11_GetInternalKeySlot()) == IntPtr.Zero)
                {
                    throw new NetworkSecurityServicesException("PK11_GetInternalKeySlot failed");
                }

                if (PK11_CheckUserPassword(slot, param.Password) != SECStatus.Success)
                {
                    throw new NetworkSecurityServicesException("PK11_CheckUserPassword failed: Wrong Master Password?");
                }

                if (PK11_Authenticate(slot, false, IntPtr.Zero) != SECStatus.Success)
                {
                    throw new NetworkSecurityServicesException("PK11_Authenticate failed");
                }

                foreach (var entry in ReadLoginsFile(currentProfilePath).Union(ReadSignonsFile(currentProfilePath)))
                {
                    param.Database.CreateWebsiteEntry(
                        param.Group,
                        entry,
                        param.CreationSettings,
                        param.Logger
                        );
                }
            }
            finally
            {
                if (slot != IntPtr.Zero)
                {
                    PK11_FreeSlot(slot);
                }

                NSS_Shutdown();

                if (nss3Handle != IntPtr.Zero)
                {
                    FreeLibrary(nss3Handle);
                }
            }
        }
 /// <summary>Import the credentials from the browser.</summary>
 public abstract void ImportCredentials(ImportParameter param);
Ejemplo n.º 11
0
        /// <summary>
        /// Import the credentials with the Network Security Services methods.
        /// </summary>
        /// <exception cref="ProfileNotFoundException">Thrown when the requested profile is not present.</exception>
        /// <exception cref="NetworkSecurityServicesException">Thrown when a Network Security Services error condition occurs.</exception>
        /// <param name="param">The parameters for the import</param>
        public override void ImportCredentials(ImportParameter param)
        {
            var currentProfilePath = !string.IsNullOrEmpty(param.CustomProfilePath)
                                ? param.CustomProfilePath
                                : Path.Combine(profileDirectory, param.Profile);

            if (!Directory.Exists(currentProfilePath))
            {
                throw new ProfileNotFoundException(currentProfilePath);
            }

            var pluginPath        = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var nativeLibraryPath = Path.Combine(pluginPath, Environment.Is64BitProcess ? "x64" : "x86");

            SetDllDirectory(nativeLibraryPath);

            var nss3Handle = LoadLibrary(Path.Combine(nativeLibraryPath, NSS3_DLL));

            if (nss3Handle == IntPtr.Zero)
            {
                throw new Win32Exception(string.Format("Could not load file: {0}", Path.Combine(nativeLibraryPath, NSS3_DLL)));
            }

            var slot = IntPtr.Zero;

            try
            {
                if (NSS_Init(currentProfilePath) != SECStatus.Success)
                {
                    throw new NetworkSecurityServicesException("NSS_Init failed: Wrong profile path?\n\n" + currentProfilePath);
                }

                if ((slot = PK11_GetInternalKeySlot()) == IntPtr.Zero)
                {
                    throw new NetworkSecurityServicesException("PK11_GetInternalKeySlot failed");
                }

                if (PK11_CheckUserPassword(slot, param.Password) != SECStatus.Success)
                {
                    throw new NetworkSecurityServicesException("PK11_CheckUserPassword failed: Wrong Master Password?");
                }

                if (PK11_Authenticate(slot, false, IntPtr.Zero) != SECStatus.Success)
                {
                    throw new NetworkSecurityServicesException("PK11_Authenticate failed");
                }

                var exceptions = new List <Exception>();
                ImportCredentialsImpl(param, () => ReadLoginsFile(currentProfilePath), ref exceptions);
                ImportCredentialsImpl(param, () => ReadSignonsFile(currentProfilePath), ref exceptions);

                if (exceptions.Any())
                {
                    var combinedMessages = string.Join("\n\n", exceptions.Select(StrUtil.FormatException));

                    throw new Exception(combinedMessages);
                }
            }
            finally
            {
                if (slot != IntPtr.Zero)
                {
                    PK11_FreeSlot(slot);
                }

                NSS_Shutdown();

                if (nss3Handle != IntPtr.Zero)
                {
                    FreeLibrary(nss3Handle);
                }
            }
        }