-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathChromiumBase.cs
90 lines (78 loc) · 2.46 KB
/
ChromiumBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Data;
using System.Data.Common;
using System.Diagnostics.Contracts;
using System.IO;
using System.Text;
using KeePassLib.Utility;
namespace KeePassBrowserImporter
{
internal abstract class ChromiumBase : IBrowserImporter
{
private string path;
public string ProfilePath { get { return path; } }
protected ChromiumBase(string path)
{
Contract.Requires(!string.IsNullOrEmpty(path));
this.path = path;
}
public override bool SupportsProfiles { get { return true; } }
public override string GetProfilePath(string profile)
{
return Path.Combine(ProfilePath, profile);
}
public override bool UsesMasterPassword { get { return false; } }
/// <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);
}
}
}
}