479 lines
13 KiB
C#
479 lines
13 KiB
C#
///#################################################################
|
|
/// PROJECT : CASA - Common Authentication Services Adapter
|
|
/// FILE : GnomeKeyring.cs
|
|
/// DESCRIPTION : GUI implementation of GNOME-Keyring store.
|
|
/// AUTHORS : CSL.Manojna
|
|
/// UPDATED ON : 26 Sept, 05
|
|
///#################################################################
|
|
|
|
|
|
namespace Novell.CASA.GUI {
|
|
|
|
|
|
using System;
|
|
using Gtk;
|
|
using Glade;
|
|
using Novell.CASA.MiCasa.Common;
|
|
using Novell.CASA.MiCasa.Communication;
|
|
|
|
|
|
public class GnomeKeyring : Store
|
|
{
|
|
|
|
Gtk.TreeStore tsSecretIDGnomeKeyring,
|
|
tsNativeInfoGnomeKeyring,
|
|
tsKeyValue;
|
|
|
|
CellRendererText cellEditable;
|
|
|
|
public bool IS_STORE_AGGREGATED = false;
|
|
|
|
#region Glade Widgets
|
|
|
|
[Glade.Widget]
|
|
public Gtk.TreeView tvSecretIDGnomeKeyring;
|
|
|
|
[Glade.Widget]
|
|
Gtk.TreeView tvKeyValue,
|
|
tvNativeInfoGnomeKeyring;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Dialog dialogManageSecret,
|
|
dialogLogin;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Menu menuRightClick;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Entry entrySecretID,
|
|
entryKey,
|
|
entryValue,
|
|
entryMasterPassword3,
|
|
entryMasterPassword4;
|
|
|
|
[Glade.Widget]
|
|
Gtk.CheckButton cbuttonShowPassword;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Label label86,
|
|
label88;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Button buttonNewAdd,
|
|
buttonNewRemove,
|
|
buttonManageOk;
|
|
[Glade.Widget]
|
|
Gtk.MenuItem cmiNewSecret,
|
|
cmiNewKey,
|
|
cmiDelete,
|
|
cmiView,
|
|
cmiLink,
|
|
cmiCopy;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
///#######################################################################
|
|
/// CONSTRUCTOR
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public GnomeKeyring()
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.GnomeKeyring() - BEGIN");
|
|
|
|
/// SecretID TreeStore
|
|
tvSecretIDGnomeKeyring = (Gtk.TreeView)CasaMain.gxml.GetWidget("tvSecretIDGnomeKeyring");
|
|
tsSecretIDGnomeKeyring = new TreeStore(typeof(string), typeof(string[]), typeof(string[]), typeof(string), typeof(string[]), typeof(string[]));
|
|
tvSecretIDGnomeKeyring.AppendColumn("Secret-ID",new CellRendererText(),"text",0);
|
|
tvSecretIDGnomeKeyring.Model = tsSecretIDGnomeKeyring;
|
|
tvSecretIDGnomeKeyring.RowActivated += new RowActivatedHandler(OntvSecretIDGnomeKeyringRowActivated);
|
|
tvSecretIDGnomeKeyring.ButtonReleaseEvent += new ButtonReleaseEventHandler(OnRightClicked);
|
|
tvSecretIDGnomeKeyring.CursorChanged += new EventHandler(OnCursorChanged);
|
|
/// NativeInfo TreeStore
|
|
tvNativeInfoGnomeKeyring = (Gtk.TreeView)CasaMain.gxml.GetWidget("tvNativeInfoGnomeKeyring");
|
|
tsNativeInfoGnomeKeyring = new TreeStore(typeof(string), typeof(string));
|
|
tvNativeInfoGnomeKeyring.AppendColumn("NativeKey",new CellRendererText(),"text",0);
|
|
tvNativeInfoGnomeKeyring.AppendColumn("NativeValue",new CellRendererText(),"text",1);
|
|
tvNativeInfoGnomeKeyring.Model = tsNativeInfoGnomeKeyring;
|
|
tvNativeInfoGnomeKeyring.ModifyBase(StateType.Normal,new Gdk.Color(0xff,0xff,0xe6));
|
|
/// Aggregate the store
|
|
//AggregateStore();
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.GnomeKeyring() - END");
|
|
}
|
|
|
|
|
|
|
|
///#######################################################################
|
|
/// AGGREGATE STORE
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override void AggregateStore()
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.AggregateStore() - BEGIN");
|
|
|
|
try
|
|
{
|
|
tsSecretIDGnomeKeyring.Clear();
|
|
tsNativeInfoGnomeKeyring.Clear();
|
|
StoreDataInterface.AggregateStore(Common.STORE_GNOMEKEYRING);
|
|
StoreDataInterface.ReadStore(Common.STORE_GNOMEKEYRING,ref tsSecretIDGnomeKeyring);
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.AggregateStore() - EXCEPTION" + exp.ToString());
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.AggregateStore() - END");
|
|
}
|
|
|
|
|
|
|
|
///#######################################################################
|
|
/// DISPLAY NATIVE INFO
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void OnCursorChanged(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnCursorChanged() - BEGIN");
|
|
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
string selected = null;
|
|
string[] NativeKeys = null,
|
|
NativeValues = null;
|
|
|
|
if( tvSecretIDGnomeKeyring.Selection.GetSelected (out model, out iter) )
|
|
selected = (string) model.GetValue(iter, 0);
|
|
|
|
if( (null != selected) && (selected.Length > 0) )
|
|
{
|
|
tsNativeInfoGnomeKeyring.Clear();
|
|
/// Populate NativeInfo
|
|
tsNativeInfoGnomeKeyring.AppendValues("Keyring Name","= "+ model.GetValue(iter,3));
|
|
NativeKeys = (string[]) model.GetValue(iter, 4);
|
|
NativeValues= (string[]) model.GetValue(iter, 5);
|
|
for( int i=0; i< NativeKeys.Length; i++ )
|
|
if( (NativeValues[i] != null) && (NativeValues[i] != "") )
|
|
tsNativeInfoGnomeKeyring.AppendValues(NativeKeys[i], "= "+NativeValues[i]);
|
|
tvNativeInfoGnomeKeyring.ShowAll();
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnCursorChanged() - END");
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
/// RIGHT-CLICK CONTEXT MENU
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void OnRightClicked(object obj, ButtonReleaseEventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnRightClicked() - BEGIN");
|
|
|
|
if( 3 == args.Event.Button )
|
|
{
|
|
try
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnRightClicked() - Context menu opened.");
|
|
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "menuRightClick", null);
|
|
gxmlTemp.Autoconnect (this);
|
|
menuRightClick.Popup(null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime);
|
|
if( 0 != tvSecretIDGnomeKeyring.Selection.CountSelectedRows() )
|
|
cmiNewSecret.Sensitive = cmiNewKey.Sensitive = cmiLink.Sensitive = cmiCopy.Sensitive = cmiDelete.Sensitive = false;
|
|
else
|
|
cmiNewSecret.Sensitive = cmiNewKey.Sensitive = cmiView.Sensitive = cmiLink.Sensitive = cmiCopy.Sensitive = cmiDelete.Sensitive = false;
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnRightClicked() - EXCEPTION" + exp.ToString());
|
|
}
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnRightClicked() - END");
|
|
}
|
|
|
|
///#######################################################################
|
|
/// VIEW KEY-VALUES
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override void ViewKeyValues()
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.ViewKeyValues() - BEGIN");
|
|
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
string selected= null;
|
|
string[] keys = null,
|
|
values = null;
|
|
try
|
|
{
|
|
if( tvSecretIDGnomeKeyring.Selection.GetSelected (out model, out iter) )
|
|
{
|
|
selected = (string) model.GetValue(iter, 0);
|
|
keys = (string[]) model.GetValue(iter, 1);
|
|
values = (string[]) model.GetValue(iter, 2);
|
|
|
|
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogManageSecret", null);
|
|
gxmlTemp.Autoconnect (this);
|
|
dialogManageSecret.TransientFor = (Gtk.Window)CasaMain.gxml.GetWidget("windowMain");
|
|
dialogManageSecret.Title = "VIEW";
|
|
|
|
cellEditable = new CellRendererText();
|
|
cellEditable.Editable = false;
|
|
//cellEditable.Edited += new EditedHandler(OnKeyValueEdited);
|
|
/// KEY:0 VALUE:1 VALUE-DUP:2 DIRTY-BIT:3
|
|
tsKeyValue = new TreeStore(typeof(string),typeof(string), typeof(string), typeof(bool));
|
|
tvKeyValue.AppendColumn("Key",new CellRendererText(),"text",0);
|
|
tvKeyValue.AppendColumn("Value",cellEditable,"text",2);
|
|
|
|
entrySecretID.Text=selected;
|
|
for( int i=0; i< keys.Length; i++ )
|
|
{
|
|
if( (null != keys[i]) && (null != values[i]) )
|
|
tsKeyValue.AppendValues(keys[i], values[i], "********", false);
|
|
|
|
}
|
|
tvKeyValue.Model = tsKeyValue;
|
|
entryKey.Sensitive = entryValue.Sensitive = buttonNewAdd.Sensitive = buttonNewRemove.Sensitive = buttonManageOk.Sensitive = false;
|
|
}
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.ViewKeyValues() - EXCEPTION" + exp.ToString());
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.ViewKeyValues() - END");
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// EDIT KEY-VALUE
|
|
/// </summary>
|
|
public void OnKeyValueEdited(object obj, EditedArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// ADD BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_buttonNewAdd_clicked(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// REMOVE BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_buttonNewRemove_clicked(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// SHOW PASSWORD CHECK BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_cbuttonShowPassword_toggled(object obj, EventArgs args)
|
|
{
|
|
TreeViewColumn tvCol;
|
|
|
|
if( tvKeyValue.Model.IterNChildren() > 0 )
|
|
if( true == cbuttonShowPassword.Active)
|
|
{
|
|
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogLogin", null);
|
|
gxmlTemp.Autoconnect (this);
|
|
dialogLogin.TransientFor = dialogManageSecret;
|
|
|
|
label86.Text = "Enter your Master Password to view passwords";
|
|
entryMasterPassword3.Text="";
|
|
entryMasterPassword3.HasFocus = true;
|
|
label88.Hide();
|
|
entryMasterPassword4.Hide();
|
|
dialogLogin.Show();
|
|
}
|
|
else
|
|
{
|
|
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
|
|
tvCol = new TreeViewColumn("Value", cellEditable, "text", 2);
|
|
tvKeyValue.InsertColumn(tvCol, 1);
|
|
}
|
|
|
|
}
|
|
|
|
public void okbuttonLogin_clicked(object abj, EventArgs args)
|
|
{
|
|
TreeViewColumn tvCol;
|
|
|
|
if( tvKeyValue.Model.IterNChildren() > 0 )
|
|
|
|
if( 0 == miCASA.SetMasterPassword(0, entryMasterPassword3.Text) )
|
|
{
|
|
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
|
|
tvCol = new TreeViewColumn("Value", cellEditable, "text", 1);
|
|
tvKeyValue.InsertColumn(tvCol, 1);
|
|
dialogLogin.Destroy();
|
|
}
|
|
else
|
|
{
|
|
// prompt user
|
|
MessageDialog md=new MessageDialog(dialogLogin,Gtk.DialogFlags.Modal,
|
|
Gtk.MessageType.Warning,
|
|
Gtk.ButtonsType.Ok,
|
|
"Master Password incorrect");
|
|
|
|
md.Response +=new ResponseHandler(md_Response2);
|
|
md.SetPosition(Gtk.WindowPosition.CenterOnParent);
|
|
md.Modal = true;
|
|
md.Show();
|
|
}
|
|
}
|
|
|
|
public void closebuttonLogin_clicked(object abj, EventArgs args)
|
|
{
|
|
cbuttonShowPassword.Active = false;
|
|
dialogLogin.Destroy();
|
|
}
|
|
|
|
|
|
public void OnDialogLoginDeleted(object obj, DeleteEventArgs args)
|
|
{
|
|
cbuttonShowPassword.Active = false;
|
|
dialogLogin.Destroy();
|
|
args.RetVal = true;
|
|
}
|
|
|
|
public void on_entryMasterPassword3_activate(object obj, EventArgs args)
|
|
{
|
|
if( "" != entryMasterPassword3.Text )
|
|
okbuttonLogin_clicked(obj, args);
|
|
}
|
|
|
|
public void on_entryMasterPassword4_activate(object obj, EventArgs args)
|
|
{
|
|
okbuttonLogin_clicked(obj, args);
|
|
}
|
|
|
|
private void md_Response2(object o, ResponseArgs args)
|
|
{
|
|
MessageDialog md = (MessageDialog)o;
|
|
if (md != null)
|
|
{
|
|
md.Destroy();
|
|
entryMasterPassword3.Text="";
|
|
entryMasterPassword3.HasFocus = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// MANAGE SECRET-ID DIALOG OK-BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_buttonManageOk_clicked(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// MANAGE SECRET-ID DIALOG CANCEL-BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_buttonManageCancel_clicked(object obj, EventArgs args)
|
|
{
|
|
tsKeyValue.Dispose();
|
|
dialogManageSecret.Destroy();
|
|
}
|
|
|
|
/// <summary>
|
|
/// SECRET-ID DOUBLE CLICKED
|
|
/// </summary>
|
|
private void OntvSecretIDGnomeKeyringRowActivated( object obj, RowActivatedArgs args )
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OntvSecretIDGnomeKeyringRowActivated() - ViewKeyValues() called.");
|
|
ViewKeyValues();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// VIEW KEY-VALUES CALLED VIA MAIN-MENU/CONTEXT-MENU
|
|
/// </summary>
|
|
public void OnViewActivated(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:KdeWallet.OnViewActivated() - ViewKeyValues() called.");
|
|
ViewKeyValues();
|
|
}
|
|
|
|
|
|
|
|
///#######################################################################
|
|
/// ADD NEW SECRET
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void OnNewSecretActivated(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
/// ADD NEW KEY-VALUES TO EXISTING SECRET
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void OnNewKeyActivated(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
/// LINK
|
|
|
|
/// <summary>
|
|
/// LINK Key-Values
|
|
/// </summary>
|
|
public void OnLinkActivated(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
/// COPY
|
|
|
|
/// <summary>
|
|
/// COPY Key-Values
|
|
/// </summary>
|
|
public void OnCopyActivated(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
// DELETE SECRET
|
|
|
|
/// <summary>
|
|
/// DELETE Secret
|
|
/// </summary>
|
|
public void OnDeleteActivated(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
///##################################################################
|
|
/// END OF FILE
|
|
///################################################################## |