Skip to content

Commit 7413e5f

Browse files
committedMay 1, 2023
Softlock: Improvements
You can now define how long Softlock will accept the QuickUnlock PIN. When this timespan is exceeded, you need to provide the complete masterkey to deactivate Softlock. This is an opt-in feature. Improved display of information text "SoftLock active. Click topmost form to deactivate" Closes #12
1 parent 66a1fe5 commit 7413e5f

8 files changed

+148
-14
lines changed
 

‎src/Config/LockAssistConfig_SL.cs

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ internal partial class LockAssistConfig
1313
private const string LockAssistSoftLockSeconds = "LockAssist.SoftLockSeconds";
1414
private const string LockAssistSoftlockOnMinimize = "LockAssist.SoftlockOnMinimize";
1515
private const string LockAssistSoftlockExcludeForms = "LockAssist.SoftlockExcludeForms";
16+
private const string LockAssistSoftlockValidityActive = "LockAssist.SoftlockValidityActive";
17+
private const string LockAssistSoftlockValiditySeconds = "LockAssist.SoftlockValiditySeconds";
18+
19+
public static bool SL_ValidityActive
20+
{
21+
get { return _config.GetBool(LockAssistSoftlockValidityActive, false); }
22+
set { _config.SetBool(LockAssistSoftlockValidityActive, value); }
23+
}
24+
25+
public static int SL_ValiditySeconds
26+
{
27+
get { return (int)_config.GetLong(LockAssistSoftlockValiditySeconds, 1800); }
28+
set { _config.SetLong(LockAssistSoftlockValiditySeconds, value); }
29+
}
30+
1631
public static bool SL_Active
1732
{
1833
get { return _config.GetBool(LockAssistSoftLockActive, true); }

‎src/LockAssist.cs

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ private void OptionsFormClosed(object sender, Tools.OptionsFormsEventArgs e)
145145
LockAssistConfig.SL_Active = slsResult.Active;
146146
LockAssistConfig.SL_Seconds = slsResult.Seconds;
147147
LockAssistConfig.SL_OnMinimize = slsResult.SoftLockOnMinimize;
148+
LockAssistConfig.SL_ValidityActive = slsResult.ValidityActive;
149+
LockAssistConfig.SL_ValiditySeconds = slsResult.ValiditySeconds;
148150
_sl.CheckSoftlockMode();
149151
}
150152
#endregion

‎src/OptionsForm.Designer.cs

+47-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/OptionsForm.cs

+22-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public OptionsForm()
5454
cbSLInterval.Items.Add(PluginTranslate.Minutes);
5555
cbSLInterval.SelectedIndex = 0;
5656

57+
cbSLValidityActive.Text = KPRes.ExpiryTime;
58+
59+
cbSLValidityInterval.Items.Add(PluginTranslate.Seconds);
60+
cbSLValidityInterval.Items.Add(PluginTranslate.Minutes);
61+
cbSLValidityInterval.SelectedIndex = 0;
62+
5763
}
5864

5965
internal void InitEx(LockAssistConfig options)
@@ -105,7 +111,19 @@ private void Init_SoftLock()
105111
nSLSeconds.Value = LockAssistConfig.SL_Seconds / 60;
106112
}
107113
cbSLOnMinimize.Checked = LockAssistConfig.SL_OnMinimize;
108-
}
114+
115+
if (LockAssistConfig.SL_ValiditySeconds < 60)
116+
{
117+
cbSLValidityInterval.SelectedIndex = 0;
118+
nSLValiditySeconds.Value = LockAssistConfig.SL_ValiditySeconds;
119+
}
120+
else
121+
{
122+
cbSLValidityInterval.SelectedIndex = 1;
123+
nSLValiditySeconds.Value = LockAssistConfig.SL_ValiditySeconds / 60;
124+
}
125+
cbSLValidityActive.Checked = LockAssistConfig.SL_ValidityActive;
126+
}
109127

110128
internal LockAssistConfig GetQuickUnlockOptions()
111129
{
@@ -137,6 +155,9 @@ internal SoftLockSettings GetSoftLockOptions()
137155
slsResult.Seconds = (int)nSLSeconds.Value;
138156
if (cbSLInterval.SelectedIndex == 1) slsResult.Seconds *= 60;
139157
slsResult.SoftLockOnMinimize = cbSLOnMinimize.Checked;
158+
slsResult.ValidityActive = cbSLValidityActive.Checked;
159+
slsResult.ValiditySeconds = (int)nSLValiditySeconds.Value;
160+
if (cbSLValidityInterval.SelectedIndex == 1) slsResult.ValiditySeconds *= 60;
140161
return slsResult;
141162
}
142163

‎src/Properties/AssemblyInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("Rookiestyle")]
1212
[assembly: AssemblyProduct("KeePass Plugin")]
13-
[assembly: AssemblyCopyright("Copyright © 2021-2022")]
13+
[assembly: AssemblyCopyright("Copyright © 2021-2023")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -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.2.2")]
36-
[assembly: AssemblyFileVersion("3.2.2")]
35+
[assembly: AssemblyVersion("3.3")]
36+
[assembly: AssemblyFileVersion("3.3")]

‎src/QuickUnlockKeyProv.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private static void RemoveDb(string ioc)
288288
if (bRemoved) PluginDebug.AddInfo("Quick Unlock - Removed Quick Unlock data", 10, "Database: " + ioc);
289289
}
290290

291-
private static ProtectedBinary CreateMasterKeyHash(CompositeKey mk)
291+
internal static ProtectedBinary CreateMasterKeyHash(CompositeKey mk)
292292
{
293293
List<byte[]> keys = new List<byte[]>();
294294
int keysLength = 0;

‎src/SoftLock.cs

+57-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ internal struct SoftLockSettings
2121
internal bool Active;
2222
internal int Seconds;
2323
internal bool SoftLockOnMinimize;
24+
internal bool ValidityActive;
25+
internal int ValiditySeconds;
2426
}
2527

2628
internal class SoftLock : IMessageFilter
@@ -181,9 +183,22 @@ private void OnTimerTick(object sender, EventArgs e)
181183
//if ((GlobalWindowManager.WindowCount > 0) && LockAssistConfig.SL_ExcludeForms.Contains(GlobalWindowManager.TopWindow.GetType().Name)) return;
182184

183185
Application.RemoveMessageFilter(this);
186+
187+
if (RequestFullPassword())
188+
{
189+
DisableSoftlockUsingFullPassword();
190+
}
191+
else
192+
{
193+
DisableSoftlockUsingQU();
194+
}
195+
Application.AddMessageFilter(this);
196+
}
197+
198+
private void DisableSoftlockUsingQU()
199+
{
184200
m_UnlockForm = new UnlockForm();
185201
m_UnlockForm.Text = PluginTranslate.PluginName + " - Softlock";
186-
187202
if (m_UnlockForm.ShowDialog(Program.MainForm) == DialogResult.OK)
188203
{
189204
ProtectedString CheckQuickUnlockKey = m_UnlockForm.QuickUnlockKey;
@@ -194,11 +209,37 @@ private void OnTimerTick(object sender, EventArgs e)
194209
SetVisibility(true);
195210
if (LockAssistConfig.SL_IsActive) m_SLTimer.Interval = LockAssistConfig.SL_Seconds * 1000;
196211
}
197-
else PluginDebug.AddError("Deactivate SoftLock", "Deactivation failed", "INvalid Quick Unlock key provided");
212+
else PluginDebug.AddError("Deactivate SoftLock", "Deactivation failed", "Invalid Quick Unlock key provided");
198213
}
199214
if (m_UnlockForm != null) m_UnlockForm.Dispose();
200215
m_UnlockForm = null;
201-
Application.AddMessageFilter(this);
216+
}
217+
218+
private void DisableSoftlockUsingFullPassword()
219+
{
220+
using (KeyPromptForm kpf = new KeyPromptForm())
221+
{
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+
{
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");
234+
}
235+
}
236+
}
237+
238+
private bool RequestFullPassword()
239+
{
240+
if (!LockAssistConfig.SL_ValidityActive) return false;
241+
var dtCheck = m_dtSoftlockActivation + new TimeSpan(0, 0, LockAssistConfig.SL_ValiditySeconds);
242+
return dtCheck < DateTime.Now;
202243
}
203244

204245
internal void CheckSoftlockMode()
@@ -226,13 +267,15 @@ private void CheckSoftlockMode(object sender, EventArgs e)
226267
}
227268
}
228269

270+
private DateTime m_dtSoftlockActivation = DateTime.MaxValue;
229271
internal void SetVisibility(bool bVisible)
230272
{
231273
List<string> lMsg = new List<string>();
232274
m_SoftLocked = !bVisible;
233275
lMsg.Add("SoftLock active: " + m_SoftLocked.ToString());
234276
if (m_SoftLocked)
235277
{
278+
m_dtSoftlockActivation = DateTime.Now;
236279
m_dHiddenForms.Clear();
237280
foreach (Form f in Application.OpenForms)
238281
{
@@ -260,7 +303,11 @@ internal void SetVisibility(bool bVisible)
260303
try { HandleForm(kvp.Key, kvp.Value, !m_SoftLocked, lMsg); }
261304
catch (Exception ex) { lMsg.Add("Ex:" + ex.Message); }
262305
}
263-
if (!m_SoftLocked) m_dHiddenForms.Clear();
306+
if (!m_SoftLocked)
307+
{
308+
m_dHiddenForms.Clear();
309+
m_dtSoftlockActivation = DateTime.MaxValue;
310+
}
264311
PluginDebug.AddInfo("Toggle SoftLock", lMsg.ToArray());
265312
}
266313

@@ -370,9 +417,13 @@ private void HandlePanel(bool bVisible, Control c)
370417

371418
bHide = new Button();
372419
bHide.Name = buttonName;
420+
//ONLY the button shown on the MainForm shall have a text
421+
//Adjust the text based on the number of hidden forms
373422
if (m_dHiddenForms.Count == 0)
374-
bHide.Text = PluginTranslate.SoftlockModeUnhide; //Display button on MainForm only, set text
375-
else if (Application.OpenForms.Count > 1 && c == Application.OpenForms[Application.OpenForms.Count - 1]) //Display button on topmost form, set text
423+
bHide.Text = PluginTranslate.SoftlockModeUnhide; //Display button on MainForm only, set text
424+
//else if (Application.OpenForms.Count > 1 && c == Application.OpenForms[Application.OpenForms.Count - 1]) //Display button on topmost form, set text
425+
// bHide.Text = PluginTranslate.SoftlockModeUnhideForms;
426+
else if (Application.OpenForms.Count > 1 && c == Program.MainForm) //Display button on topmost form, set text
376427
bHide.Text = PluginTranslate.SoftlockModeUnhideForms;
377428

378429
bHide.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

‎version.info

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:
2-
LockAssist:3.2.2
2+
LockAssist:3.3
33
LockAssist!de:5
44
LockAssist!pt:4
55
:

0 commit comments

Comments
 (0)
Please sign in to comment.