Skip to content

Commit

Permalink
Restore key sources
Browse files Browse the repository at this point in the history
When Quick Unlock fails to open the database, the actual key sources are restored.
As a consequence, all fields in the key prompt form are checked as if the database would be opened without Quick Unlock being installed.
  • Loading branch information
Rookiestyle committed Aug 29, 2021
1 parent ef22ce3 commit 5ad20d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0")]
[assembly: AssemblyFileVersion("2.0")]
[assembly: AssemblyVersion("2.1")]
[assembly: AssemblyFileVersion("2.1")]
37 changes: 27 additions & 10 deletions src/QuickUnlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ namespace LockAssist
*/
internal partial class QuickUnlock
{
private QuickUnlockKeyProv m_kp = null;
private QuickUnlockKeyProv m_kp = null;

public QuickUnlock()
{
{
Init();
}
}
private void Init()
{
m_kp = new QuickUnlockKeyProv();
Program.KeyProviderPool.Add(m_kp);
Program.MainForm.FileClosingPre += OnFileClosePre_QU;
Program.MainForm.FileClosingPost += OnFileClosePost_QU;
Program.MainForm.FileOpened += OnFileOpened_QU;
PluginDebug.AddInfo("Quick Unlock: Initialized", 0);
}
Expand Down Expand Up @@ -65,7 +65,7 @@ private void OnFileOpened_QU(object sender, FileOpenedEventArgs e)
QuickUnlockKeyProv.RestoreOldMasterKey(e.Database, quOldKey);
}

private void OnFileClosePre_QU(object sender, FileClosingEventArgs e)
private void OnFileClosePost_QU(object sender, FileClosingEventArgs e)
{
//Do quick unlock only in case of locking
//Do NOT do quick unlock in case of closing the database
Expand Down Expand Up @@ -95,7 +95,7 @@ private void OnFileClosePre_QU(object sender, FileClosingEventArgs e)

#region Unlock / KeyPromptForm

public static void OnKeyFormShown(Form f, bool resetFile)
public static void OnKeyFormShown(Form f, bool bRestoreKeySources)
{
try
{
Expand Down Expand Up @@ -134,7 +134,7 @@ public static void OnKeyFormShown(Form f, bool resetFile)
}
else
{
PluginDebug.AddError("Quick Unlock form cannot be shown", 0,
PluginDebug.AddError("Quick Unlock form cannot be shown", 0,
"Form: " + f.GetType().Name,
"Password checkbox: " + (cbPassword == null ? "null" : cbPassword.Name + " / " + cbPassword.GetType().Name),
"Account checkbox: " + (cbAccount == null ? "null" : cbAccount.Name + " / " + cbAccount.GetType().Name),
Expand All @@ -145,12 +145,29 @@ public static void OnKeyFormShown(Form f, bool resetFile)
}

//Quick Unlock is not possible => Remove it from list of key providers
if ((resetFile || ((dbIOInfo != null) && !QuickUnlockKeyProv.HasDB(dbIOInfo.Path))) && (index != -1))
if ((bRestoreKeySources || ((dbIOInfo != null) && !QuickUnlockKeyProv.HasDB(dbIOInfo.Path))) && (index != -1))
{
cmbKeyFile.Items.RemoveAt(index);
List<string> keyfiles = (List<string>)Tools.GetField("m_lKeyFileNames", f);
if (keyfiles != null) keyfiles.Remove(QuickUnlockKeyProv.KeyProviderName);
if (resetFile) cmbKeyFile.SelectedIndex = 0;

//Restore previously saved key sources in case Quick Unlock failed
if (bRestoreKeySources)
{
var ks = Program.Config.Defaults.GetKeySources(dbIOInfo);
if (ks == null)
{
cmbKeyFile.SelectedIndex = 0;
}
else
{
string sItem = ks.KeyFilePath;
if (string.IsNullOrEmpty(sItem)) sItem = ks.KeyProvider;
cmbKeyFile.SelectedIndex = Math.Max(0, cmbKeyFile.Items.IndexOf(sItem));
if (ks.UserAccount) (Tools.GetControl("m_cbUserAccount", f) as CheckBox).Checked = true;
if (ks.Password) (Tools.GetControl("m_cbPassword", f) as CheckBox).Checked = true;
}
}
}
}
catch (Exception ex)
Expand Down Expand Up @@ -229,7 +246,7 @@ internal void Clear()
Program.KeyProviderPool.Remove(m_kp);
m_kp = null;
QuickUnlockKeyProv.Clear();
Program.MainForm.FileClosingPre -= OnFileClosePre_QU;
Program.MainForm.FileClosingPost -= OnFileClosePost_QU;
Program.MainForm.FileOpened -= OnFileOpened_QU;
PluginDebug.AddInfo("Quick Unlock: Terminated", 0);
}
Expand Down
2 changes: 1 addition & 1 deletion version.info
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:
LockAssist:2.0
LockAssist:2.1
LockAssist!de:3
:

0 comments on commit 5ad20d6

Please sign in to comment.