diff --git a/CASA/gui/MiCasa.cs b/CASA/gui/MiCasa.cs index a445a7f3..1a7ab9ac 100644 --- a/CASA/gui/MiCasa.cs +++ b/CASA/gui/MiCasa.cs @@ -75,10 +75,12 @@ public class MiCasa : Store dialogConfirmDelete, dialogLogin, dialogLinkKeyValue, - dialogSpecialCharacter; + dialogSpecialCharacter, + dialogDecode; [Glade.Widget] - Gtk.Menu menuRightClick; + Gtk.Menu menuRightClick, + menuRightClickKeyValue; [Glade.Widget] Gtk.Entry entrySecretID, @@ -91,14 +93,17 @@ public class MiCasa : Store [Glade.Widget] Gtk.CheckButton cbuttonShowPassword, - checkbuttonShowDeleteDialog; - - [Glade.Widget] - Gtk.MenuItem cmiNewKey, - cmiDelete, - cmiView, - cmiLink, - cmiCopy; + checkbuttonShowDeleteDialog; + + [Glade.Widget] + Gtk.MenuItem cmiNewKey, + cmiDelete, + cmiView, + cmiLink, + cmiCopy, + menuItemLinkKey, + menuItemDecodeValue; + [Glade.Widget] Gtk.Notebook notebook2; @@ -112,7 +117,20 @@ public class MiCasa : Store labelSeconds; [Glade.Widget] - Gtk.SpinButton spinbuttonRememberFor; + Gtk.SpinButton spinbuttonRememberFor; + + [Glade.Widget] + Gtk.TextView textviewEncoded, + textviewClear; + + [Glade.Widget] + Gtk.Button bttnDecode, + bttnEncode, + bttnExpand, + bttnCloseDecode; + + [Glade.Widget] + Gtk.ScrolledWindow scrolledwindowEncoded; #endregion @@ -296,7 +314,10 @@ public class MiCasa : Store tvKeyValue.AppendColumn("Key",new CellRendererText(),"text",0); tvKeyValue.AppendColumn("Value",cellEditable,"text",2); tvKeyValue.AppendColumn("Linked", new CellRendererText(), "text", 4); - tvKeyValue.RowActivated += new RowActivatedHandler(tvKeyValue_RowActivated); + tvKeyValue.RowActivated += new RowActivatedHandler(tvKeyValue_RowActivated); + + + //tvKeyValue.ButtonReleaseEvent += new ButtonReleaseEventHandler(OnRightClickedKeyValue); entrySecretID.Text = selected; SecretStore ss = GetMiCasaStore(); @@ -514,6 +535,7 @@ public class MiCasa : Store 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) { @@ -541,6 +563,7 @@ public class MiCasa : Store tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1)); tvCol = new TreeViewColumn("Value", cellEditable, "text", 2); tvKeyValue.InsertColumn(tvCol, 1); + tvKeyValue.ButtonReleaseEvent -= (OnRightClickedKeyValue); } } } @@ -553,9 +576,10 @@ 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; @@ -626,7 +650,8 @@ public class MiCasa : Store tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1)); tvCol = new TreeViewColumn("Value", cellEditable, "text", 2); tvKeyValue.InsertColumn(tvCol, 1); - cbuttonShowPassword.Active = false; + cbuttonShowPassword.Active = false; + tvKeyValue.ButtonReleaseEvent -= (OnRightClickedKeyValue); } catch (Exception e) { @@ -1335,6 +1360,139 @@ 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(); + } + + } } } ///################################################################## diff --git a/CASA/gui/images/casa.glade b/CASA/gui/images/casa.glade index 95f48429..4c65a1fa 100644 --- a/CASA/gui/images/casa.glade +++ b/CASA/gui/images/casa.glade @@ -56,7 +56,7 @@ True - + True gtk-new 1 @@ -78,7 +78,7 @@ - + True gtk-new 1 @@ -99,7 +99,7 @@ - + True gtk-new 1 @@ -125,7 +125,7 @@ - + True gtk-refresh 1 @@ -152,7 +152,7 @@ - + True gtk-dialog-authentication 1 @@ -173,7 +173,7 @@ - + True gtk-open 1 @@ -194,7 +194,7 @@ - + True gtk-delete 1 @@ -221,7 +221,7 @@ - + True gtk-floppy 1 @@ -242,7 +242,7 @@ - + True gtk-open 1 @@ -264,13 +264,13 @@ True - _Exit + E_xit True - + True gtk-quit 1 @@ -306,7 +306,7 @@ - + True gtk-zoom-fit 1 @@ -327,7 +327,7 @@ - + True gtk-jump-to 1 @@ -348,7 +348,7 @@ - + True gtk-copy 1 @@ -376,7 +376,7 @@ - + True gtk-find-and-replace 1 @@ -404,7 +404,7 @@ - + True gtk-delete 1 @@ -438,7 +438,7 @@ True - + True gtk-execute 1 @@ -460,7 +460,7 @@ - + True gtk-execute 1 @@ -481,7 +481,7 @@ - + True gtk-execute 1 @@ -502,7 +502,7 @@ - + True gtk-execute 1 @@ -523,7 +523,7 @@ - + True gtk-execute 1 @@ -548,7 +548,7 @@ - + True gtk-revert-to-saved 1 @@ -575,7 +575,7 @@ - + True gtk-preferences 1 @@ -603,7 +603,7 @@ - + True gtk-properties 1 @@ -637,7 +637,7 @@ - + True gtk-add 1 @@ -658,7 +658,7 @@ - + True gtk-remove 1 @@ -724,7 +724,7 @@ - + True gtk-help 1 @@ -751,7 +751,7 @@ - + True gtk-dialog-info 1 @@ -15927,4 +15927,296 @@ All other conflicts will be ignored. + + True + Decoded value + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER_ON_PARENT + False + 500 + 500 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-help + True + GTK_RELIEF_NORMAL + True + -11 + + + + + + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-close + True + GTK_RELIEF_NORMAL + True + -7 + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + 3 + 2 + False + 0 + 0 + + + + True + False + 0 + + + + True + True + Encode + True + GTK_RELIEF_NORMAL + True + + + 9 + False + False + + + + + + True + True + Decode + True + GTK_RELIEF_NORMAL + True + + + 12 + False + False + + + + + + True + True + True + >> + True + GTK_RELIEF_NORMAL + True + + + 9 + False + False + GTK_PACK_END + + + + + 1 + 2 + 1 + 2 + fill + fill + + + + + + 8 + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_CHAR + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 1 + 2 + 0 + 1 + + + + + + 8 + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_WORD + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 1 + 2 + 2 + 3 + fill + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + 0 + True + True + + + + + + + + + + + True + Link key + True + + + + + + + True + + + + + + True + Decode value + True + + + + +