本文整理汇总了C#中KeePassHttp.Request类的典型用法代码示例。如果您正苦于以下问题:C# Request类的具体用法?C# Request怎么用?C# Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于KeePassHttp命名空间,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllLoginsHandler
private void GetAllLoginsHandler(Request r, Response resp, Aes aes)
{
if (!VerifyRequest(r, aes))
return;
var list = new PwObjectList<PwEntry>();
var root = host.Database.RootGroup;
var parms = MakeSearchParameters();
parms.SearchString = @"^[A-Za-z0-9:/-]+\.[A-Za-z0-9:/-]+$"; // match anything looking like a domain or url
root.SearchEntries(parms, list);
foreach (var entry in list)
{
var name = entry.Strings.ReadSafe(PwDefs.TitleField);
var login = GetUserPass(entry)[0];
var uuid = entry.Uuid.ToHexString();
var e = new ResponseEntry(name, login, null, uuid, null);
resp.Entries.Add(e);
}
resp.Success = true;
resp.Id = r.Id;
SetResponseVerifier(resp, aes);
foreach (var entry in resp.Entries)
{
entry.Name = CryptoTransform(entry.Name, false, true, aes, CMode.ENCRYPT);
entry.Login = CryptoTransform(entry.Login, false, true, aes, CMode.ENCRYPT);
entry.Uuid = CryptoTransform(entry.Uuid, false, true, aes, CMode.ENCRYPT);
}
}
示例2: AssociateHandler
private void AssociateHandler(Request r, Response resp, Aes aes)
{
if (!TestRequestVerifier(r, aes, r.Key))
return;
// key is good, prompt user to save
using (var f = new ConfirmAssociationForm())
{
var win = host.MainWindow;
win.Invoke((MethodInvoker)delegate
{
ShowNotification("New key association requested", (s, e) => f.Activate());
f.Icon = win.Icon;
f.Key = r.Key;
f.Load += delegate { f.Activate(); };
f.ShowDialog(win);
if (f.KeyId != null)
{
var entry = GetConfigEntry(true);
entry.Strings.Set(ASSOCIATE_KEY_PREFIX + f.KeyId, new ProtectedString(true, r.Key));
entry.Touch(true);
resp.Id = f.KeyId;
resp.Success = true;
SetResponseVerifier(resp, aes);
UpdateUI(null);
}
});
}
}
示例3: FindMatchingEntries
private IEnumerable<PwEntry> FindMatchingEntries(Request r, Aes aes)
{
string submithost = null;
string realm = null;
var list = new PwObjectList<PwEntry>();
string formhost, searchHost;
formhost = searchHost = GetHost(CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT));
if (r.SubmitUrl != null) {
submithost = GetHost(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
}
if (r.Realm != null)
realm = CryptoTransform(r.Realm, true, false, aes, CMode.DECRYPT);
var origSearchHost = searchHost;
var parms = MakeSearchParameters();
var root = host.Database.RootGroup;
while (list.UCount == 0 && (origSearchHost == searchHost || searchHost.IndexOf(".") != -1))
{
parms.SearchString = String.Format("^{0}$|/{0}/?", searchHost);
root.SearchEntries(parms, list);
searchHost = searchHost.Substring(searchHost.IndexOf(".") + 1);
if (searchHost == origSearchHost)
break;
}
Func<PwEntry, bool> filter = delegate(PwEntry e)
{
var title = e.Strings.ReadSafe(PwDefs.TitleField);
var entryUrl = e.Strings.ReadSafe(PwDefs.UrlField);
var c = GetEntryConfig(e);
if (c != null)
{
if (c.Allow.Contains(formhost) && (submithost == null || c.Allow.Contains(submithost)))
return true;
if (c.Deny.Contains(formhost) || (submithost != null && c.Deny.Contains(submithost)))
return false;
if (realm != null && c.Realm != realm)
return false;
}
if (title.StartsWith("http://") || title.StartsWith("https://"))
{
var u = new Uri(title);
if (formhost.Contains(u.Host))
return true;
}
if (entryUrl != null && entryUrl.StartsWith("http://") || entryUrl.StartsWith("https://"))
{
var u = new Uri(entryUrl);
if (formhost.Contains(u.Host))
return true;
}
return formhost.Contains(title) || (entryUrl != null && formhost.Contains(entryUrl));
};
return from e in list where filter(e) select e;
}
示例4: VerifyRequest
private bool VerifyRequest(Request r, Aes aes)
{
var entry = GetConfigEntry(false);
if (entry == null)
return false;
var s = entry.Strings.Get(ASSOCIATE_KEY_PREFIX + r.Id);
if (s == null)
return false;
return TestRequestVerifier(r, aes, s.ReadString());
}
示例5: TestRequestVerifier
private bool TestRequestVerifier(Request r, Aes aes, string key)
{
var success = false;
var crypted = decode64(r.Verifier);
aes.Key = decode64(key);
aes.IV = decode64(r.Nonce);
using (var dec = aes.CreateDecryptor())
{
try {
var buf = dec.TransformFinalBlock(crypted, 0, crypted.Length);
var value = Encoding.UTF8.GetString(buf);
success = value == r.Nonce;
} catch (CryptographicException) { } // implicit failure
}
return success;
}
示例6: SetLoginHandler
private void SetLoginHandler(Request r, Response resp, Aes aes)
{
if (!VerifyRequest(r, aes))
return;
string submithost = null;
PwUuid uuid = null;
string username, password, url;
string realm = null;
url = CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT);
var formhost = GetHost(url);
if (r.SubmitUrl != null)
submithost = GetHost(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
if (r.Realm != null)
realm = CryptoTransform(r.Realm, true, false, aes, CMode.DECRYPT);
username = CryptoTransform(r.Login, true, false, aes, CMode.DECRYPT);
password = CryptoTransform(r.Password, true, false, aes, CMode.DECRYPT);
if (r.Uuid != null)
{
uuid = new PwUuid(MemUtil.HexStringToByteArray(
CryptoTransform(r.Uuid, true, false, aes, CMode.DECRYPT)));
}
if (uuid != null)
{
// modify existing entry
PwEntry entry = host.Database.RootGroup.FindEntry(uuid, true);
string[] up = GetUserPass(entry);
var u = up[0];
var p = up[1];
var configOpt = new ConfigOpt(this.host.CustomConfig);
if (u != username || p != password)
{
bool allowUpdate = configOpt.AlwaysAllowUpdates;
if (!allowUpdate)
{
if (canShowBalloonTips())
{
ShowNotification(String.Format(
"{0}: You have an entry change prompt waiting, click to activate", r.Id),
(s, e) => host.MainWindow.Activate());
}
DialogResult result;
if (host.MainWindow.IsTrayed())
{
result = MessageBox.Show(
String.Format("Do you want to update the information in {0} - {1}?", formhost, u),
"Update Entry", MessageBoxButtons.YesNo,
MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
else
{
result = MessageBox.Show(
host.MainWindow,
String.Format("Do you want to update the information in {0} - {1}?", formhost, u),
"Update Entry", MessageBoxButtons.YesNo,
MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
if (result == DialogResult.Yes)
{
allowUpdate = true;
}
}
if (allowUpdate)
{
PwObjectList<PwEntry> m_vHistory = entry.History.CloneDeep();
entry.History = m_vHistory;
entry.CreateBackup(null);
entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, username));
entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(true, password));
entry.Touch(true, false);
UpdateUI(entry.ParentGroup);
}
}
}
else
{
// creating new entry
var root = host.Database.RootGroup;
var group = root.FindCreateGroup(KEEPASSHTTP_GROUP_NAME, false);
if (group == null)
{
group = new PwGroup(true, true, KEEPASSHTTP_GROUP_NAME, PwIcon.WorldComputer);
root.AddGroup(group, true);
UpdateUI(null);
}
PwEntry entry = new PwEntry(true, true);
entry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, formhost));
entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, username));
entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(true, password));
entry.Strings.Set(PwDefs.UrlField, new ProtectedString(true, url));
if ((submithost != null && formhost != submithost) || realm != null)
{
//.........这里部分代码省略.........
示例7: GetLoginsHandler
private void GetLoginsHandler(Request r, Response resp, Aes aes)
{
if (!VerifyRequest(r, aes))
return;
string submithost = null;
var host = GetHost(CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT));
if (r.SubmitUrl != null)
submithost = GetHost(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
var items = FindMatchingEntries(r, aes);
if (items.ToList().Count > 0)
{
Func<PwEntry, bool> filter = delegate(PwEntry e)
{
var c = GetEntryConfig(e);
var title = e.Strings.ReadSafe(PwDefs.TitleField);
var entryUrl = e.Strings.ReadSafe(PwDefs.UrlField);
if (c != null)
{
return title != host && entryUrl != host && !c.Allow.Contains(host) || (submithost != null && !c.Allow.Contains(submithost) && submithost != title && submithost != entryUrl);
}
return title != host && entryUrl != host || (submithost != null && title != submithost && entryUrl != submithost);
};
var configOpt = new ConfigOpt(this.host.CustomConfig);
var config = GetConfigEntry(true);
var autoAllowS = config.Strings.ReadSafe("Auto Allow");
var autoAllow = autoAllowS != null && autoAllowS.Trim() != "";
autoAllow = autoAllow || configOpt.AlwaysAllowAccess;
var needPrompting = from e in items where filter(e.entry) select e;
if (needPrompting.ToList().Count > 0 && !autoAllow)
{
var clicked = true;
if (canShowBalloonTips())
{
clicked = false;
var wait = new ManualResetEvent(false);
var delegated = false;
EventHandler onclick = delegate { delegated = true; clicked = true; wait.Set(); };
EventHandler onclose = delegate { delegated = true; wait.Set(); };
ShowNotification(String.Format(
"{0}: {1} is requesting access, click to allow or deny",
r.Id, submithost != null ? submithost : host), onclick, onclose);
wait.WaitOne(GetNotificationTime() + 5000); // give a little time to fade
if (!delegated)
resp.Error = "Notification bubble did not appear";
}
if (clicked)
{
var win = this.host.MainWindow;
using (var f = new AccessControlForm())
{
win.Invoke((MethodInvoker)delegate
{
f.Icon = win.Icon;
f.Plugin = this;
f.Entries = (from e in items where filter(e.entry) select e.entry).ToList();
//f.Entries = needPrompting.ToList();
f.Host = submithost != null ? submithost : host;
f.Load += delegate { f.Activate(); };
f.ShowDialog(win);
if (f.Remember && (f.Allowed || f.Denied))
{
foreach (var e in needPrompting)
{
var c = GetEntryConfig(e.entry);
if (c == null)
c = new KeePassHttpEntryConfig();
var set = f.Allowed ? c.Allow : c.Deny;
set.Add(host);
if (submithost != null && submithost != host)
set.Add(submithost);
SetEntryConfig(e.entry, c);
}
}
if (!f.Allowed)
{
items = items.Except(needPrompting);
}
});
}
}
else
{
items = items.Except(needPrompting);
}
}
if (r.SortSelection == "true" || configOpt.SpecificMatchingOnly)
{
string sortHost = CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT);
if (sortHost.EndsWith("/"))
//.........这里部分代码省略.........
示例8: GetLoginsCountHandler
private void GetLoginsCountHandler(Request r, Response resp, Aes aes)
{
if (!VerifyRequest(r, aes))
return;
resp.Success = true;
resp.Id = r.Id;
var items = FindMatchingEntries(r, aes);
SetResponseVerifier(resp, aes);
resp.Count = items.ToList().Count;
}
示例9: FindMatchingEntriesLikeSearchbox
private IEnumerable<PwEntryDatabase> FindMatchingEntriesLikeSearchbox(Request r, Aes aes)
{
string searchString = null;
string realm = null;
var listResult = new List<PwEntryDatabase>();
if (r.SearchString != null)
{
searchString = CryptoTransform(r.SearchString, true, false, aes, CMode.DECRYPT);
}
if (r.Realm != null)
realm = CryptoTransform(r.Realm, true, false, aes, CMode.DECRYPT);
var parms = MakeSearchParametersLikeSearchBox();
List<PwDatabase> listDatabases = new List<PwDatabase>();
var configOpt = new ConfigOpt(this.host.CustomConfig);
if (configOpt.SearchInAllOpenedDatabases)
{
foreach (PwDocument doc in host.MainWindow.DocumentManager.Documents)
{
if (doc.Database.IsOpen)
{
listDatabases.Add(doc.Database);
}
}
}
else
{
listDatabases.Add(host.Database);
}
int listCount = 0;
foreach (PwDatabase db in listDatabases)
{
parms.SearchString = searchString;
var listEntries = new PwObjectList<PwEntry>();
db.RootGroup.SearchEntries(parms, listEntries);
foreach (var le in listEntries)
{
listResult.Add(new PwEntryDatabase(le, db));
}
}
return listResult;
}
示例10: GetLoginsHandler
private void GetLoginsHandler(Request r, Response resp, Aes aes)
{
if (!VerifyRequest(r, aes))
return;
string submithost = null;
var host = GetHost(CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT));
if (r.SubmitUrl != null)
submithost = GetHost(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
var items = FindMatchingEntries(r, aes);
if (items.ToList().Count > 0)
{
Func<PwEntry, bool> filter = delegate(PwEntry e)
{
var c = GetEntryConfig(e);
var title = e.Strings.ReadSafe(PwDefs.TitleField);
var entryUrl = e.Strings.ReadSafe(PwDefs.UrlField);
if (c != null)
{
return title != host && entryUrl != host && !c.Allow.Contains(host) || (submithost != null && !c.Allow.Contains(submithost) && submithost != title && submithost != entryUrl);
}
return title != host && entryUrl != host || (submithost != null && title != submithost && entryUrl != submithost);
};
var configOpt = new ConfigOpt(this.host.CustomConfig);
var config = GetConfigEntry(true);
var autoAllowS = config.Strings.ReadSafe("Auto Allow");
var autoAllow = autoAllowS != null && autoAllowS.Trim() != "";
autoAllow = autoAllow || configOpt.AlwaysAllowAccess;
var needPrompting = from e in items where filter(e.entry) select e;
if (needPrompting.ToList().Count > 0 && !autoAllow)
{
var win = this.host.MainWindow;
using (var f = new AccessControlForm())
{
win.Invoke((MethodInvoker)delegate
{
f.Icon = win.Icon;
f.Plugin = this;
f.Entries = (from e in items where filter(e.entry) select e.entry).ToList();
//f.Entries = needPrompting.ToList();
f.Host = submithost != null ? submithost : host;
f.Load += delegate { f.Activate(); };
f.ShowDialog(win);
if (f.Remember && (f.Allowed || f.Denied))
{
foreach (var e in needPrompting)
{
var c = GetEntryConfig(e.entry);
if (c == null)
c = new KeePassHttpEntryConfig();
var set = f.Allowed ? c.Allow : c.Deny;
set.Add(host);
if (submithost != null && submithost != host)
set.Add(submithost);
SetEntryConfig(e.entry, c);
}
}
if (!f.Allowed)
{
items = items.Except(needPrompting);
}
});
}
}
string compareToUrl = null;
if (r.SubmitUrl != null)
{
compareToUrl = CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT);
}
if(String.IsNullOrEmpty(compareToUrl))
compareToUrl = CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT);
compareToUrl = compareToUrl.ToLower();
foreach (var entryDatabase in items)
{
string entryUrl = String.Copy(entryDatabase.entry.Strings.ReadSafe(PwDefs.UrlField));
if (String.IsNullOrEmpty(entryUrl))
entryUrl = entryDatabase.entry.Strings.ReadSafe(PwDefs.TitleField);
entryUrl = entryUrl.ToLower();
entryDatabase.entry.UsageCount = (ulong)LevenshteinDistance(compareToUrl, entryUrl);
}
var itemsList = items.ToList();
if (configOpt.SpecificMatchingOnly)
{
itemsList = (from e in itemsList
orderby e.entry.UsageCount ascending
select e).ToList();
//.........这里部分代码省略.........
示例11: GeneratePassword
private void GeneratePassword(Request r, Response resp, Aes aes)
{
if (!VerifyRequest(r, aes))
return;
byte[] pbEntropy = null;
ProtectedString psNew;
PwProfile autoProfile = Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile;
PwGenerator.Generate(out psNew, autoProfile, pbEntropy, Program.PwGeneratorPool);
byte[] pbNew = psNew.ReadUtf8();
if (pbNew != null)
{
uint uBits = QualityEstimation.EstimatePasswordBits(pbNew);
ResponseEntry item = new ResponseEntry(Request.GENERATE_PASSWORD, uBits.ToString(), StrUtil.Utf8.GetString(pbNew), Request.GENERATE_PASSWORD, null);
resp.Entries.Add(item);
resp.Success = true;
resp.Count = 1;
MemUtil.ZeroByteArray(pbNew);
}
resp.Id = r.Id;
SetResponseVerifier(resp, aes);
foreach (var entry in resp.Entries)
{
entry.Name = CryptoTransform(entry.Name, false, true, aes, CMode.ENCRYPT);
entry.Login = CryptoTransform(entry.Login, false, true, aes, CMode.ENCRYPT);
entry.Uuid = CryptoTransform(entry.Uuid, false, true, aes, CMode.ENCRYPT);
entry.Password = CryptoTransform(entry.Password, false, true, aes, CMode.ENCRYPT);
}
}
示例12: AssociateHandler
private void AssociateHandler(Request r, Response resp, Aes aes)
{
if (!TestRequestVerifier(r, aes, r.Key))
return;
// key is good, prompt user to save
using (var f = new ConfirmAssociationForm())
{
var win = host.MainWindow;
win.Invoke((MethodInvoker)delegate
{
f.Activate();
f.Icon = win.Icon;
f.Key = r.Key;
f.Load += delegate { f.Activate(); };
f.ShowDialog(win);
if (f.KeyId != null)
{
var entry = GetConfigEntry(true);
bool keyNameExists = true;
while (keyNameExists)
{
DialogResult keyExistsResult = DialogResult.Yes;
foreach (var s in entry.Strings)
{
if (s.Key == ASSOCIATE_KEY_PREFIX + f.KeyId)
{
keyExistsResult = MessageBox.Show(
win,
"A shared encryption-key with the name \"" + f.KeyId + "\" already exists.\nDo you want to overwrite it?",
"Overwrite existing key?",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1
);
break;
}
}
if (keyExistsResult == DialogResult.No)
{
f.ShowDialog(win);
}
else
{
keyNameExists = false;
}
}
if (f.KeyId != null)
{
entry.Strings.Set(ASSOCIATE_KEY_PREFIX + f.KeyId, new ProtectedString(true, r.Key));
entry.Touch(true);
resp.Id = f.KeyId;
resp.Success = true;
SetResponseVerifier(resp, aes);
UpdateUI(null);
}
}
});
}
}
示例13: CreateEntry
private bool CreateEntry(string username, string password, string urlHost, string url, Request r, Aes aes)
{
string realm = null;
if (r.Realm != null)
realm = CryptoTransform(r.Realm, true, false, aes, CMode.DECRYPT);
var root = host.Database.RootGroup;
var group = root.FindCreateGroup(KEEPASSHTTP_GROUP_NAME, false);
if (group == null)
{
group = new PwGroup(true, true, KEEPASSHTTP_GROUP_NAME, PwIcon.WorldComputer);
root.AddGroup(group, true);
UpdateUI(null);
}
string submithost = null;
if (r.SubmitUrl != null)
submithost = GetHost(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
string baseUrl = url;
// index bigger than https:// <-- this slash
if (baseUrl.LastIndexOf("/") > 9)
{
baseUrl = baseUrl.Substring(0, baseUrl.LastIndexOf("/") + 1);
}
PwEntry entry = new PwEntry(true, true);
entry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, urlHost));
entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, username));
entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(true, password));
entry.Strings.Set(PwDefs.UrlField, new ProtectedString(true, baseUrl));
if ((submithost != null && urlHost != submithost) || realm != null)
{
var config = new KeePassHttpEntryConfig();
if (submithost != null)
config.Allow.Add(submithost);
if (realm != null)
config.Realm = realm;
var serializer = NewJsonSerializer();
var writer = new StringWriter();
serializer.Serialize(writer, config);
entry.Strings.Set(KEEPASSHTTP_NAME, new ProtectedString(false, writer.ToString()));
}
group.AddEntry(entry, true);
UpdateUI(group);
return true;
}
示例14: GetLoginsHandler
private void GetLoginsHandler(Request r, Response resp, Aes aes)
{
if (!VerifyRequest(r, aes))
return;
string submithost = null;
var host = GetHost(CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT));
if (r.SubmitUrl != null)
submithost = GetHost(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
var items = FindMatchingEntries(r, aes);
if (items.ToList().Count > 0)
{
Func<PwEntry, bool> filter = delegate(PwEntry e)
{
var c = GetEntryConfig(e);
var title = e.Strings.ReadSafe(PwDefs.TitleField);
var entryUrl = e.Strings.ReadSafe(PwDefs.UrlField);
if (c != null)
{
return title != host && entryUrl != host && !c.Allow.Contains(host) || (submithost != null && !c.Allow.Contains(submithost) && submithost != title && submithost != entryUrl);
}
return title != host && entryUrl != host || (submithost != null && title != submithost && entryUrl != submithost);
};
var needPrompting = from e in items where filter(e) select e;
if (needPrompting.ToList().Count > 0)
{
var wait = new ManualResetEvent(false);
var clicked = false;
var delegated = false;
EventHandler onclick = delegate { delegated = true; clicked = true; wait.Set(); };
EventHandler onclose = delegate { delegated = true; wait.Set(); };
ShowNotification(String.Format(
"{0}: {1} is requesting access, click to allow or deny",
r.Id, submithost != null ? submithost : host), onclick, onclose);
wait.WaitOne(GetNotificationTime() + 5000); // give a little time to fade
if (!delegated)
resp.Error = "Notification bubble did not appear";
if (clicked)
{
var win = this.host.MainWindow;
using (var f = new AccessControlForm())
{
win.Invoke((MethodInvoker)delegate
{
f.Icon = win.Icon;
f.Plugin = this;
f.Entries = needPrompting.ToList();
f.Host = submithost != null ? submithost : host;
f.Load += delegate { f.Activate(); };
f.ShowDialog(win);
if (f.Remember && (f.Allowed || f.Denied))
{
foreach (var e in needPrompting)
{
var c = GetEntryConfig(e);
if (c == null)
c = new KeePassHttpEntryConfig();
var set = f.Allowed ? c.Allow : c.Deny;
set.Add(host);
if (submithost != null && submithost != host)
set.Add(submithost);
SetEntryConfig(e, c);
}
}
if (!f.Allowed)
items = items.Except(needPrompting);
});
}
}
else
{
items = items.Except(needPrompting);
}
}
foreach (var entry in items)
{
var name = entry.Strings.ReadSafe(PwDefs.TitleField);
var loginpass = GetUserPass(entry);
var login = loginpass[0];
var passwd = loginpass[1];
var uuid = entry.Uuid.ToHexString();
var e = new ResponseEntry(name, login, passwd, uuid);
resp.Entries.Add(e);
}
if (items.ToList().Count > 0)
{
var names = (from e in resp.Entries select e.Name).Distinct<string>();
var n = String.Join("\n ", names.ToArray<string>());
ShowNotification(String.Format("{0}: {1} is receiving credentials for:\n {2}", r.Id, host, n));
}
//.........这里部分代码省略.........
示例15: SetLoginHandler
private void SetLoginHandler(Request r, Response resp, Aes aes)
{
if (!VerifyRequest(r, aes))
return;
string formhost, submithost = null;
PwUuid uuid = null;
string username, password;
string realm = null;
Uri url = new Uri(CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT));
if (r.SubmitUrl != null)
{
Uri submiturl = new Uri(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
submithost = submiturl.Host;
}
if (r.Realm != null)
realm = CryptoTransform(r.Realm, true, false, aes, CMode.DECRYPT);
username = CryptoTransform(r.Login, true, false, aes, CMode.DECRYPT);
password = CryptoTransform(r.Password, true, false, aes, CMode.DECRYPT);
if (r.Uuid != null)
{
uuid = new PwUuid(MemUtil.HexStringToByteArray(
CryptoTransform(r.Uuid, true, false, aes, CMode.DECRYPT)));
}
formhost = url.Host;
if (uuid != null)
{
// modify existing entry
PwEntry entry = host.Database.RootGroup.FindEntry(uuid, true);
string[] up = GetUserPass(entry);
var u = up[0];
var p = up[1];
if (u != username || p != password)
{
ShowNotification(String.Format(
"{0}: You have an entry change prompt waiting, click to activate", r.Id),
(s, e) => host.MainWindow.Activate());
var result = MessageBox.Show(host.MainWindow,
String.Format("Do you want to update the information in {0} - {1}?", formhost, u),
"Update Entry", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, username));
entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(true, password));
entry.Touch(true);
UpdateUI(entry.ParentGroup);
}
}
}
else
{
var root = host.Database.RootGroup;
var group = root.FindCreateGroup(KEEPASSHTTP_GROUP_NAME, false);
if (group == null)
{
group = new PwGroup(true, true, KEEPASSHTTP_GROUP_NAME, PwIcon.WorldComputer);
root.AddGroup(group, true);
UpdateUI(null);
}
PwEntry entry = new PwEntry(true, true);
entry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, formhost));
entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, username));
entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(true, password));
if ((submithost != null && formhost != submithost) || realm != null)
{
var config = new KeePassHttpEntryConfig();
if (submithost != null)
config.Allow.Add(submithost);
if (realm != null)
config.Realm = realm;
var serializer = NewJsonSerializer();
var writer = new StringWriter();
serializer.Serialize(writer, config);
entry.Strings.Set(KEEPASSHTTP_NAME, new ProtectedString(false, writer.ToString()));
}
group.AddEntry(entry, true);
UpdateUI(group);
}
resp.Success = true;
resp.Id = r.Id;
SetResponseVerifier(resp, aes);
}