/// <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> /// Enumerates the entries of the signons.sqlite file. /// </summary> /// <param name="profilePath">Path of the profile folder</param> /// <returns></returns> private IEnumerable <Tuple <string, string, string> > ReadSignonsFile(string profilePath) { using (var db = new DBHandler(Path.Combine(profilePath, "signons.sqlite"))) { DataTable dt = null; try { db.Query(out dt, "SELECT hostname, encryptedUsername, encryptedPassword FROM moz_logins"); } catch { yield break; } foreach (var row in dt.AsEnumerable()) { Tuple <string, string, string> data; try { data = Tuple.Create( (row["hostname"] as string).Trim(), PK11_Decrypt(row["encryptedUsername"] as string).Trim(), PK11_Decrypt(row["encryptedPassword"] as string) ); } catch { continue; } yield return(data); } } }
/// <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); } }
/// <summary> /// Enumerates the entries of the signons.sqlite file. /// </summary> /// <param name="profilePath">Path of the profile folder</param> /// <returns></returns> private static IEnumerable <EntryInfo> ReadSignonsFile(string profilePath) { var entries = new List <EntryInfo>(); var dbPath = Path.Combine(profilePath, "signons.sqlite"); if (File.Exists(dbPath)) { try { using (var db = new DBHandler(dbPath)) { DataTable dt; db.Query(out dt, "SELECT hostname, encryptedUsername, encryptedPassword, timeCreated, timePasswordChanged FROM moz_logins"); foreach (var row in dt.AsEnumerable()) { try { entries.Add(new EntryInfo { Hostname = (row["hostname"] as string).Trim(), Username = PK11_Decrypt(row["encryptedUsername"] as string).Trim(), Password = PK11_Decrypt(row["encryptedPassword"] as string), Created = DateUtils.FromUnixTimeMilliseconds((long)row["timeCreated"]), Modified = DateUtils.FromUnixTimeMilliseconds((long)row["timePasswordChanged"]) }); } catch { // Skip faulty entries } } } } 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); } } return(entries); }
/// <summary> /// Enumerates the entries of the signons.sqlite file. /// </summary> /// <param name="profilePath">Path of the profile folder</param> /// <returns></returns> private IEnumerable <EntryInfo> ReadSignonsFile(string profilePath) { using (var db = new DBHandler(Path.Combine(profilePath, "signons.sqlite"))) { DataTable dt = null; try { db.Query(out dt, "SELECT hostname, encryptedUsername, encryptedPassword, timeCreated, timePasswordChanged FROM moz_logins"); } catch { yield break; } foreach (var row in dt.AsEnumerable()) { EntryInfo entry; try { entry = new EntryInfo { Hostname = (row["hostname"] as string).Trim(), Username = PK11_Decrypt(row["encryptedUsername"] as string).Trim(), Password = PK11_Decrypt(row["encryptedPassword"] as string), Created = DateUtils.FromUnixTimeMilliseconds((long)row["timeCreated"]), Modified = DateUtils.FromUnixTimeMilliseconds((long)row["timePasswordChanged"]) }; } catch { continue; } yield return(entry); } } }