Bug 228046. Prompt user for MasterPassword prior to

displaying the Find and Replace dialog.
This commit is contained in:
Jim Norman 2007-01-09 08:41:54 +00:00
parent 434bc49a50
commit bdc46f5639
2 changed files with 292 additions and 282 deletions

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Jan 9 13:25:55 MST 2007 - jnorman@novell.com
- Bug 228046. Prompt user for MasterPassword prior to displaying
the Find and Replace dialog.
-------------------------------------------------------------------
Tue Jan 9 12:27:57 MST 2007 - jnorman@novell.com

View File

@ -25,7 +25,7 @@ namespace Novell.CASA.GUI {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Specialized;
using System.Threading;
using Gtk;
@ -47,11 +47,11 @@ public class MiCasa : Store
ArrayList arrDeletedKeys = null;
private SecretStore m_store = null;
private int m_iRememberSeconds = 5;
private String m_sRememberFor = "5";
private SecretStore m_store = null;
private int m_iRememberSeconds = 5;
private String m_sRememberFor = "5";
private Config m_config = null;
#region Glade Widgets
@ -79,7 +79,7 @@ public class MiCasa : Store
dialogDecode;
[Glade.Widget]
Gtk.Menu menuRightClick,
Gtk.Menu menuRightClick,
menuRightClickKeyValue;
[Glade.Widget]
@ -93,15 +93,15 @@ public class MiCasa : Store
[Glade.Widget]
Gtk.CheckButton cbuttonShowPassword,
checkbuttonShowDeleteDialog;
[Glade.Widget]
Gtk.MenuItem cmiNewKey,
cmiDelete,
cmiView,
cmiLink,
cmiCopy,
menuItemLinkKey,
checkbuttonShowDeleteDialog;
[Glade.Widget]
Gtk.MenuItem cmiNewKey,
cmiDelete,
cmiView,
cmiLink,
cmiCopy,
menuItemLinkKey,
menuItemDecodeValue;
@ -112,24 +112,24 @@ public class MiCasa : Store
Gtk.Label labelLinkSecretID,
labelLinkKeyID,
label86,
label88,
labelRememberFor,
labelSeconds;
[Glade.Widget]
Gtk.SpinButton spinbuttonRememberFor;
[Glade.Widget]
Gtk.TextView textviewEncoded,
textviewClear;
[Glade.Widget]
Gtk.Button bttnDecode,
label88,
labelRememberFor,
labelSeconds;
[Glade.Widget]
Gtk.SpinButton spinbuttonRememberFor;
[Glade.Widget]
Gtk.TextView textviewEncoded,
textviewClear;
[Glade.Widget]
Gtk.Button bttnDecode,
bttnEncode,
bttnExpand,
bttnCloseDecode;
[Glade.Widget]
bttnExpand,
bttnCloseDecode;
[Glade.Widget]
Gtk.ScrolledWindow scrolledwindowEncoded;
#endregion
@ -148,9 +148,9 @@ public class MiCasa : Store
m_config = config;
/// SecretID TreeStore
tvSecretIDMiCasa = (Gtk.TreeView)CasaMain.gxmlMain.GetWidget("tvSecretIDMiCasa");
tvSecretIDMiCasa = (Gtk.TreeView)CasaMain.gxmlMain.GetWidget("tvSecretIDMiCasa");
tsSecretIDMiCasa = new TreeStore(typeof(string), typeof(string[]), typeof(string[]), typeof(string), typeof(string[]), typeof(string[]));
tvSecretIDMiCasa.AppendColumn("Secret ID",new CellRendererText(),"text",0);
tvSecretIDMiCasa.AppendColumn("Secret ID",new CellRendererText(),"text",0);
tvSecretIDMiCasa.Model = tsSecretIDMiCasa;
tsSecretIDMiCasa.SetSortColumnId(0, Gtk.SortType.Ascending);
tvSecretIDMiCasa.RowActivated += new RowActivatedHandler(OntvSecretIDMiCasaRowActivated);
@ -311,17 +311,17 @@ public class MiCasa : Store
cellEditable = new CellRendererText();
cellEditable.Editable = true;
cellEditable.Edited += new EditedHandler(OnKeyValueEdited);
/// KEY:0 VALUE:1 VALUE-DUP:2 DIRTY-BIT:3 LINK:4
/// KEY:0 VALUE:1 VALUE-DUP:2 DIRTY-BIT:3 LINK:4
tsKeyValue = new TreeStore(typeof(string), typeof(string), typeof(string), typeof(bool), typeof(string), typeof(string), typeof(string));
tvKeyValue.AppendColumn("Key",new CellRendererText(),"text",0);
tvKeyValue.AppendColumn("Value",cellEditable,"text",2);
tvKeyValue.AppendColumn("Linked", new CellRendererText(), "text", 4);
tvKeyValue.AppendColumn("Created", new CellRendererText(), "text", 5);
tvKeyValue.AppendColumn("Linked", new CellRendererText(), "text", 4);
tvKeyValue.AppendColumn("Created", new CellRendererText(), "text", 5);
tvKeyValue.AppendColumn("Modified", new CellRendererText(), "text", 6);
tvKeyValue.RowActivated += new RowActivatedHandler(tvKeyValue_RowActivated);
tvKeyValue.RowActivated += new RowActivatedHandler(tvKeyValue_RowActivated);
//tvKeyValue.ButtonReleaseEvent += new ButtonReleaseEventHandler(OnRightClickedKeyValue);
entrySecretID.Text = selected;
@ -330,11 +330,11 @@ public class MiCasa : Store
for( int i=0; i< keys.Length; i++ )
{
Secret secret = ss.GetSecret(selected);
Secret secret = ss.GetSecret(selected);
Hashtable ht = secret.GetLinkedKeys(keys[i]);
DateTime dtCreated = secret.GetCreateTimeForKey(keys[i]);
Hashtable ht = secret.GetLinkedKeys(keys[i]);
DateTime dtCreated = secret.GetCreateTimeForKey(keys[i]);
DateTime dtModified = secret.GetModifiedTimeForKey(keys[i]);
if (ht != null && ht.Count > 0)
@ -350,17 +350,17 @@ public class MiCasa : Store
"********",
false,
"Yes",
dtCreated.ToShortDateString() + " " + dtCreated.ToShortTimeString(),
dtCreated.ToShortDateString() + " " + dtCreated.ToShortTimeString(),
dtModified.ToShortDateString() + " " + dtModified.ToShortTimeString());
}
else
{
{
tsKeyValue.AppendValues(keys[i],
values[i],
"********",
false,
"No",
dtCreated.ToShortDateString() + " " + dtCreated.ToShortTimeString(),
"No",
dtCreated.ToShortDateString() + " " + dtCreated.ToShortTimeString(),
dtModified.ToShortDateString() + " " + dtModified.ToShortTimeString());
}
}
@ -540,52 +540,52 @@ public class MiCasa : Store
/// </summary>
public void on_cbuttonShowPassword_toggled(object obj, EventArgs args)
{
TreeViewColumn tvCol;
if (tvKeyValue.Model.IterNChildren() > 0)
{
if ((true == cbuttonShowPassword.Active)
&& (CommonGUI.GetRememberMPUntil().CompareTo(DateTime.Now) > 0))
{
// set and start the timer if needed
TimeSpan ts = CommonGUI.GetRememberMPUntil().Subtract(DateTime.Now);
m_iRememberSeconds = ts.Seconds;
StartRememberTimer();
// display the values
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
tvCol = new TreeViewColumn("Value", cellEditable, "text", 1);
tvKeyValue.InsertColumn(tvCol, 1);
tvKeyValue.ButtonReleaseEvent += new ButtonReleaseEventHandler(OnRightClickedKeyValue);
}
else if (true == cbuttonShowPassword.Active)
{
// prompt user for MasterPassword
Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogLogin", null);
gxmlTemp.Autoconnect(this);
dialogLogin.TransientFor = dialogManageSecret;
label86.Text = "Enter your Master Password to view values";
entryMasterPassword3.Text = "";
entryMasterPassword3.HasFocus = true;
label88.Hide();
entryMasterPassword4.Hide();
labelRememberFor.Visible = true;
labelSeconds.Visible = true;
spinbuttonRememberFor.Visible = true;
spinbuttonRememberFor.Text = m_config.GetConfigSetting(CommonGUI.REMEMBER_SETTING, m_sRememberFor);
dialogLogin.Show();
}
else
{
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
tvCol = new TreeViewColumn("Value", cellEditable, "text", 2);
tvKeyValue.InsertColumn(tvCol, 1);
tvKeyValue.ButtonReleaseEvent -= (OnRightClickedKeyValue);
}
TreeViewColumn tvCol;
if (tvKeyValue.Model.IterNChildren() > 0)
{
if ((true == cbuttonShowPassword.Active)
&& (CommonGUI.GetRememberMPUntil().CompareTo(DateTime.Now) > 0))
{
// set and start the timer if needed
TimeSpan ts = CommonGUI.GetRememberMPUntil().Subtract(DateTime.Now);
m_iRememberSeconds = ts.Seconds;
StartRememberTimer();
// display the values
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
tvCol = new TreeViewColumn("Value", cellEditable, "text", 1);
tvKeyValue.InsertColumn(tvCol, 1);
tvKeyValue.ButtonReleaseEvent += new ButtonReleaseEventHandler(OnRightClickedKeyValue);
}
else if (true == cbuttonShowPassword.Active)
{
// prompt user for MasterPassword
Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogLogin", null);
gxmlTemp.Autoconnect(this);
dialogLogin.TransientFor = dialogManageSecret;
label86.Text = "Enter your Master Password to view values";
entryMasterPassword3.Text = "";
entryMasterPassword3.HasFocus = true;
label88.Hide();
entryMasterPassword4.Hide();
labelRememberFor.Visible = true;
labelSeconds.Visible = true;
spinbuttonRememberFor.Visible = true;
spinbuttonRememberFor.Text = m_config.GetConfigSetting(CommonGUI.REMEMBER_SETTING, m_sRememberFor);
dialogLogin.Show();
}
else
{
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
tvCol = new TreeViewColumn("Value", cellEditable, "text", 2);
tvKeyValue.InsertColumn(tvCol, 1);
tvKeyValue.ButtonReleaseEvent -= (OnRightClickedKeyValue);
}
}
}
@ -597,18 +597,18 @@ public class MiCasa : Store
if( 0 == miCASA.SetMasterPassword(0, entryMasterPassword3.Text) )
{
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
tvCol = new TreeViewColumn("Value", cellEditable, "text", 1);
tvKeyValue.InsertColumn(tvCol, 1);
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
tvCol = new TreeViewColumn("Value", cellEditable, "text", 1);
tvKeyValue.InsertColumn(tvCol, 1);
tvKeyValue.ButtonReleaseEvent += new ButtonReleaseEventHandler(OnRightClickedKeyValue);
// get seconds to remember
m_sRememberFor = spinbuttonRememberFor.Text;
if (m_sRememberFor != null)
{
DateTime dtNow = DateTime.Now;
m_iRememberSeconds = int.Parse(m_sRememberFor);
CommonGUI.SetRememberMPUntil(dtNow.AddSeconds(m_iRememberSeconds));
// get seconds to remember
m_sRememberFor = spinbuttonRememberFor.Text;
if (m_sRememberFor != null)
{
DateTime dtNow = DateTime.Now;
m_iRememberSeconds = int.Parse(m_sRememberFor);
CommonGUI.SetRememberMPUntil(dtNow.AddSeconds(m_iRememberSeconds));
}
// save off remember time if user changed it
@ -619,9 +619,9 @@ public class MiCasa : Store
m_config.WriteConfig();
}
dialogLogin.Destroy();
if (m_iRememberSeconds > 0)
dialogLogin.Destroy();
if (m_iRememberSeconds > 0)
StartRememberTimer();
}
else
@ -651,38 +651,38 @@ public class MiCasa : Store
cbuttonShowPassword.Active = false;
dialogLogin.Destroy();
args.RetVal = true;
}
private bool bTimerActive = false;
public void StartRememberTimer()
{
if (!bTimerActive)
{
GLib.Timeout.Add ((uint)(m_iRememberSeconds * 1000), new GLib.TimeoutHandler (update_gui));
bTimerActive = true;
}
}
private bool update_gui()
{
TreeViewColumn tvCol;
try
{
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
tvCol = new TreeViewColumn("Value", cellEditable, "text", 2);
tvKeyValue.InsertColumn(tvCol, 1);
cbuttonShowPassword.Active = false;
tvKeyValue.ButtonReleaseEvent -= (OnRightClickedKeyValue);
}
catch (Exception e)
{
//Console.WriteLine(e.ToString());
}
bTimerActive = false;
return false;
}
}
private bool bTimerActive = false;
public void StartRememberTimer()
{
if (!bTimerActive)
{
GLib.Timeout.Add ((uint)(m_iRememberSeconds * 1000), new GLib.TimeoutHandler (update_gui));
bTimerActive = true;
}
}
private bool update_gui()
{
TreeViewColumn tvCol;
try
{
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
tvCol = new TreeViewColumn("Value", cellEditable, "text", 2);
tvKeyValue.InsertColumn(tvCol, 1);
cbuttonShowPassword.Active = false;
tvKeyValue.ButtonReleaseEvent -= (OnRightClickedKeyValue);
}
catch (Exception e)
{
//Console.WriteLine(e.ToString());
}
bTimerActive = false;
return false;
}
public void on_entryMasterPassword3_activate(object obj, EventArgs args)
{
@ -1019,7 +1019,7 @@ public class MiCasa : Store
if (selected.StartsWith("SS_CredSet"))
selected = selected.Substring(11);
saKeys = (string[]) model.GetValue(iter, 1);
saKeys = (string[]) model.GetValue(iter, 1);
saValues = (string[]) model.GetValue(iter, 2);
CopySecret cs = new CopySecret(selected, saKeys, saValues);
@ -1031,13 +1031,17 @@ public class MiCasa : Store
public void on_helpbuttonLinkKeys_clicked(object obj, EventArgs args)
{
Common.ShowHelpUrl("LinkingSecrets.htm");
}
internal void FindAndReplaceValues()
{
FindAndReplace fr = new FindAndReplace(this, tvSecretIDMiCasa.Model, tsSecretIDMiCasa);
fr.ShowDialog();
}
internal void FindAndReplaceValues()
{
CommonGUI cg = new CommonGUI();
if (cg.VerifyMasterPasswordWithUser())
{
FindAndReplace fr = new FindAndReplace(this, tvSecretIDMiCasa.Model, tsSecretIDMiCasa);
fr.ShowDialog();
}
}
///#######################################################################
@ -1380,140 +1384,140 @@ public class MiCasa : Store
{
md.Destroy();
}
}
// handlers for keyvalue context menu
public void OnRightClickedKeyValue(object obj, ButtonReleaseEventArgs args)
{
Logger.DbgLog("GUI:MiCasa.OnRightClickedKeyValue() - BEGIN");
if (3 == args.Event.Button)
{
try
{
Logger.DbgLog("GUI:MiCasa.OnRightClickedKeyValue() - Context menu opened.");
Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "menuRightClickKeyValue", null);
gxmlTemp.Autoconnect(this);
menuRightClickKeyValue.Popup(null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime);
}
catch (Exception exp)
{
Logger.DbgLog("GUI:MiCasa.OnRightClickedKeyValue() - EXCEPTION:" + exp.ToString());
}
}
Logger.DbgLog("GUI:MiCasa.OnRightClickedKeyValue() - BEGIN");
}
private void on_menuItemLinkKey_activate(object o, EventArgs args)
{
// display link dialog
tvKeyValue_RowActivated(o, null);
}
private void on_menuItemDecodeValue_activate(object o, EventArgs args)
{
// get selected key/value
// display decode window
TreeModel model;
TreeIter iter;
string selected=null;
string value = null;
if (tvKeyValue.Selection.GetSelected(out model, out iter))
{
selected = (string)model.GetValue(iter, 0);
value = (string)model.GetValue(iter, 1);
if ((value == null) || (value.Length <1))
{
// read value from store
SecretStore ss = GetMiCasaStore();
Secret secret = ss.GetSecret(entrySecretID.Text);
value = secret.GetKeyValue(selected);
// strip of header data
byte[] baValue = System.Text.Encoding.ASCII.GetBytes(value);
byte[] baTarget = new byte[baValue.Length - 16];
Array.Copy(baValue, 13, baTarget, 0, baValue.Length - 16);
try
{
baValue = Convert.FromBase64String(System.Text.Encoding.ASCII.GetString(baTarget));
value = System.Text.Encoding.ASCII.GetString(baValue);
}
catch (Exception e)
{
value = e.ToString();
}
}
if (selected != null && selected.Length > 0)
{
Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogDecode", null);
gxmlTemp.Autoconnect(this);
// display values
textviewClear.Buffer.Text = value;
// hook up button handlers
bttnDecode.Clicked += new EventHandler(bttnDecode_Clicked);
bttnEncode.Clicked += new EventHandler(bttnEncode_Clicked);
bttnExpand.Clicked += new EventHandler(bttnExpand_Clicked);
dialogDecode.TransientFor = (Gtk.Window)CasaMain.gxmlMain.GetWidget("dialogManageSecret");
dialogDecode.Modal = true;
dialogDecode.Show();
}
}
}
void bttnExpand_Clicked(object sender, EventArgs e)
{
bttnDecode.Visible =
bttnEncode.Visible =
textviewEncoded.Visible =
scrolledwindowEncoded.Visible = !bttnDecode.Visible;
if (bttnDecode.Visible)
{
bttnExpand.Label = " << ";
}
else
{
bttnExpand.Label = " >> ";
}
}
void bttnEncode_Clicked(object sender, EventArgs e)
{
string sClear = textviewClear.Buffer.Text.Trim();
if (sClear.Length > 0)
{
textviewEncoded.Buffer.Clear();
textviewEncoded.Buffer.Text = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(sClear));
}
}
void bttnDecode_Clicked(object sender, EventArgs e)
{
string sEncoded = textviewEncoded.Buffer.Text.Trim();
if (sEncoded.Length > 0)
{
char[] array = sEncoded.ToCharArray();
byte[] bytes = Convert.FromBase64CharArray(array, 0, array.Length);
textviewClear.Buffer.Text = System.Text.Encoding.ASCII.GetString(bytes);
}
}
private void on_bttnCloseDecode_clicked(object sender, EventArgs args)
{
if (dialogDecode != null)
{
dialogDecode.Destroy();
}
}
}
// handlers for keyvalue context menu
public void OnRightClickedKeyValue(object obj, ButtonReleaseEventArgs args)
{
Logger.DbgLog("GUI:MiCasa.OnRightClickedKeyValue() - BEGIN");
if (3 == args.Event.Button)
{
try
{
Logger.DbgLog("GUI:MiCasa.OnRightClickedKeyValue() - Context menu opened.");
Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "menuRightClickKeyValue", null);
gxmlTemp.Autoconnect(this);
menuRightClickKeyValue.Popup(null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime);
}
catch (Exception exp)
{
Logger.DbgLog("GUI:MiCasa.OnRightClickedKeyValue() - EXCEPTION:" + exp.ToString());
}
}
Logger.DbgLog("GUI:MiCasa.OnRightClickedKeyValue() - BEGIN");
}
private void on_menuItemLinkKey_activate(object o, EventArgs args)
{
// display link dialog
tvKeyValue_RowActivated(o, null);
}
private void on_menuItemDecodeValue_activate(object o, EventArgs args)
{
// get selected key/value
// display decode window
TreeModel model;
TreeIter iter;
string selected=null;
string value = null;
if (tvKeyValue.Selection.GetSelected(out model, out iter))
{
selected = (string)model.GetValue(iter, 0);
value = (string)model.GetValue(iter, 1);
if ((value == null) || (value.Length <1))
{
// read value from store
SecretStore ss = GetMiCasaStore();
Secret secret = ss.GetSecret(entrySecretID.Text);
value = secret.GetKeyValue(selected);
// strip of header data
byte[] baValue = System.Text.Encoding.ASCII.GetBytes(value);
byte[] baTarget = new byte[baValue.Length - 16];
Array.Copy(baValue, 13, baTarget, 0, baValue.Length - 16);
try
{
baValue = Convert.FromBase64String(System.Text.Encoding.ASCII.GetString(baTarget));
value = System.Text.Encoding.ASCII.GetString(baValue);
}
catch (Exception e)
{
value = e.ToString();
}
}
if (selected != null && selected.Length > 0)
{
Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogDecode", null);
gxmlTemp.Autoconnect(this);
// display values
textviewClear.Buffer.Text = value;
// hook up button handlers
bttnDecode.Clicked += new EventHandler(bttnDecode_Clicked);
bttnEncode.Clicked += new EventHandler(bttnEncode_Clicked);
bttnExpand.Clicked += new EventHandler(bttnExpand_Clicked);
dialogDecode.TransientFor = (Gtk.Window)CasaMain.gxmlMain.GetWidget("dialogManageSecret");
dialogDecode.Modal = true;
dialogDecode.Show();
}
}
}
void bttnExpand_Clicked(object sender, EventArgs e)
{
bttnDecode.Visible =
bttnEncode.Visible =
textviewEncoded.Visible =
scrolledwindowEncoded.Visible = !bttnDecode.Visible;
if (bttnDecode.Visible)
{
bttnExpand.Label = " << ";
}
else
{
bttnExpand.Label = " >> ";
}
}
void bttnEncode_Clicked(object sender, EventArgs e)
{
string sClear = textviewClear.Buffer.Text.Trim();
if (sClear.Length > 0)
{
textviewEncoded.Buffer.Clear();
textviewEncoded.Buffer.Text = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(sClear));
}
}
void bttnDecode_Clicked(object sender, EventArgs e)
{
string sEncoded = textviewEncoded.Buffer.Text.Trim();
if (sEncoded.Length > 0)
{
char[] array = sEncoded.ToCharArray();
byte[] bytes = Convert.FromBase64CharArray(array, 0, array.Length);
textviewClear.Buffer.Text = System.Text.Encoding.ASCII.GetString(bytes);
}
}
private void on_bttnCloseDecode_clicked(object sender, EventArgs args)
{
if (dialogDecode != null)
{
dialogDecode.Destroy();
}
}
}
}
///##################################################################