Skip to content

Commit 1d27d48

Browse files
committed
Use secure desktop when asking for full masterkey
LockAssist allows to define an expiry time for the SoftLock pin. Once expired, the full masterkey is requested. The "Enter master key on secure desktop" setting is considered now. Closes #16
1 parent 06c99df commit 1d27d48

File tree

4 files changed

+97
-15
lines changed

4 files changed

+97
-15
lines changed

src/Config/LockAssistConfig.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using System.Windows.Forms;
6+
using KeePass.UI;
57
using KeePassLib;
8+
using KeePassLib.Delegates;
69

710
namespace LockAssist
811
{
@@ -12,3 +15,56 @@ internal partial class LockAssistConfig
1215
public static KeePass.App.Configuration.AceCustomConfig _config = KeePass.Program.Config.CustomConfig;
1316
}
1417
}
18+
19+
namespace PluginTools
20+
{
21+
public static partial class Tools
22+
{
23+
public static DialogResult ShowDialog<TForm, TResult>(bool bProtect,
24+
GFunc<TForm> fnConstruct, GFunc<TForm, TResult> fnResultBuilder,
25+
out TResult r)
26+
where TForm : Form
27+
where TResult : class
28+
{
29+
if (fnConstruct == null) { throw new ArgumentNullException("fnConstruct"); }
30+
if (fnResultBuilder == null) { throw new ArgumentNullException("fnResultBuilder"); }
31+
32+
r = null;
33+
34+
if (!bProtect)
35+
{
36+
TForm tf = fnConstruct();
37+
if (tf == null) { return DialogResult.None; }
38+
39+
try
40+
{
41+
DialogResult drDirect = tf.ShowDialog();
42+
r = fnResultBuilder(tf); // Always
43+
return drDirect;
44+
}
45+
finally { UIUtil.DestroyForm(tf); }
46+
}
47+
48+
UIFormConstructor fnUifC = delegate (object objParam)
49+
{
50+
return fnConstruct();
51+
};
52+
53+
UIFormResultBuilder fnUifRB = delegate (Form f)
54+
{
55+
TForm tf = (f as TForm);
56+
if (tf == null) { return null; }
57+
58+
return fnResultBuilder(tf);
59+
};
60+
61+
ProtectedDialog dlg = new ProtectedDialog(fnUifC, fnUifRB);
62+
63+
object objResult;
64+
DialogResult dr = dlg.ShowDialog(out objResult, null);
65+
r = (objResult as TResult);
66+
return dr;
67+
}
68+
69+
}
70+
}

src/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
3333
// indem Sie "*" wie unten gezeigt eingeben:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("3.4")]
36-
[assembly: AssemblyFileVersion("3.4")]
35+
[assembly: AssemblyVersion("3.5")]
36+
[assembly: AssemblyFileVersion("3.5")]

src/SoftLock.cs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,48 @@ private void DisableSoftlockUsingQU()
217217

218218
private void DisableSoftlockUsingFullPassword()
219219
{
220-
using (KeyPromptForm kpf = new KeyPromptForm())
220+
ProtectedBinary pbKey = null;
221+
ProtectedBinary pbKeyDB = null;
222+
223+
try
221224
{
222-
kpf.InitEx(Program.MainForm.ActiveDatabase.IOConnectionInfo, false, false);
223-
kpf.Load += (o, e1) => { kpf.Text = "Softlock - " + kpf.Text; };
224-
if (kpf.ShowDialog(Program.MainForm) == DialogResult.OK)
225+
KeePassLib.Delegates.GFunc<KeyPromptForm> gfKeyPromptForm = delegate ()
225226
{
226-
ProtectedBinary pbKey = QuickUnlockKeyProv.CreateMasterKeyHash(kpf.CompositeKey);
227-
ProtectedBinary pbKeyDB = QuickUnlockKeyProv.CreateMasterKeyHash(Program.MainForm.ActiveDatabase.MasterKey);
228-
if (pbKey.Equals(pbKeyDB))
229-
{
230-
SetVisibility(true);
231-
if (LockAssistConfig.SL_IsActive) m_SLTimer.Interval = LockAssistConfig.SL_Seconds * 1000;
232-
}
233-
else PluginDebug.AddError("Deactivate SoftLock", "Deactivation failed", "Invalid key provided");
227+
var f = new KeyPromptForm();
228+
f.InitEx(Program.MainForm.ActiveDatabase.IOConnectionInfo, false, false);
229+
f.Load += (o, e1) => { f.Text = "Softlock - " + f.Text; };
230+
return f;
231+
};
232+
KeePassLib.Delegates.GFunc<KeyPromptForm, KeePassLib.Keys.CompositeKey> gfKeyPromptFormResult = delegate (KeyPromptForm f)
233+
{
234+
var rCK = f.CompositeKey;
235+
UIUtil.DestroyForm(f);
236+
return rCK;
237+
};
238+
239+
KeePassLib.Keys.CompositeKey ckMasterkey = null;
240+
var dr = Tools.ShowDialog(Program.Config.Security.MasterKeyOnSecureDesktop, gfKeyPromptForm, gfKeyPromptFormResult, out ckMasterkey);
241+
if (dr != DialogResult.OK) return;
242+
pbKey = QuickUnlockKeyProv.CreateMasterKeyHash(ckMasterkey);
243+
pbKeyDB = QuickUnlockKeyProv.CreateMasterKeyHash(Program.MainForm.ActiveDatabase.MasterKey);
244+
}
245+
catch
246+
{
247+
using (KeyPromptForm kpf = new KeyPromptForm())
248+
{
249+
kpf.InitEx(Program.MainForm.ActiveDatabase.IOConnectionInfo, false, false);
250+
kpf.Load += (o, e1) => { kpf.Text = "Softlock - " + kpf.Text; };
251+
if (kpf.ShowDialog(Program.MainForm) != DialogResult.OK) return;
252+
pbKey = QuickUnlockKeyProv.CreateMasterKeyHash(kpf.CompositeKey);
253+
pbKeyDB = QuickUnlockKeyProv.CreateMasterKeyHash(Program.MainForm.ActiveDatabase.MasterKey);
234254
}
235255
}
256+
if (pbKey.Equals(pbKeyDB))
257+
{
258+
SetVisibility(true);
259+
if (LockAssistConfig.SL_IsActive) m_SLTimer.Interval = LockAssistConfig.SL_Seconds * 1000;
260+
}
261+
else PluginDebug.AddError("Deactivate SoftLock", "Deactivation failed", "Invalid key provided");
236262
}
237263

238264
private bool RequestFullPassword()

version.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:
2-
LockAssist:3.4
2+
LockAssist:3.5
33
LockAssist!de:5
44
LockAssist!pt:4
55
LockAssist!zh:5

0 commit comments

Comments
 (0)