From 37f6bf209814efee3daa0429d385573e1a90de33 Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Mon, 6 Nov 2006 06:46:05 +0000 Subject: [PATCH] Find and Replace feature added. Resolve conflicts on Import added. --- CASA/CASA.changes | 6 + CASA/gui/CASAManager.csproj | 1 + CASA/gui/CasaMain.cs | 10 +- CASA/gui/CommonGUI.cs | 34 +- CASA/gui/FileChooser.cs | 4 +- CASA/gui/FindAndReplace.cs | 397 ++++++++++++++ CASA/gui/ImportSecrets.cs | 265 ++++++++- CASA/gui/Makefile.am | 1 + CASA/gui/MiCasa.cs | 12 +- CASA/gui/StoreDataInterface.cs | 65 ++- CASA/gui/images/casa.glade | 898 ++++++++++++++++++++++++++++++- CASA/micasad/common/Constants.cs | 4 +- CASA/micasad/lss/LocalStorage.cs | 317 ++++++----- CASA/micasad/verbs/ReadSecret.cs | 12 +- CASA/micasad/verbs/WriteKey.cs | 12 +- 15 files changed, 1830 insertions(+), 208 deletions(-) create mode 100644 CASA/gui/FindAndReplace.cs diff --git a/CASA/CASA.changes b/CASA/CASA.changes index ed42e9e6..7dea0af2 100644 --- a/CASA/CASA.changes +++ b/CASA/CASA.changes @@ -1,3 +1,9 @@ +Mon Nov 06 11:41:13 MDT 2006 - jnorman@novell.com + +- Find and Replace feature added. Resolve conflicts on Import + added. + +------------------------------------------------------------------- Thu Oct 12 16:26:13 MDT 2006 - jnorman@novell.com - Copy feature added. Users can copy secrets from one store diff --git a/CASA/gui/CASAManager.csproj b/CASA/gui/CASAManager.csproj index 42b3673a..48e5d7b5 100644 --- a/CASA/gui/CASAManager.csproj +++ b/CASA/gui/CASAManager.csproj @@ -178,6 +178,7 @@ Code + Code diff --git a/CASA/gui/CasaMain.cs b/CASA/gui/CasaMain.cs index 8aa41fa7..f6ef6440 100644 --- a/CASA/gui/CasaMain.cs +++ b/CASA/gui/CasaMain.cs @@ -2247,7 +2247,15 @@ namespace Novell.CASA.GUI { PersistentPolicyDialog ppd = new PersistentPolicyDialog(); ppd.ShowDialog(); - } + } + + public void on_mmiFindAndReplace_activate(object obj, EventArgs args) + { + objMiCasa.FindAndReplaceValues(); + } + + + /// /// ******************************************************************** diff --git a/CASA/gui/CommonGUI.cs b/CASA/gui/CommonGUI.cs index f3ed3a3a..367bf8a7 100644 --- a/CASA/gui/CommonGUI.cs +++ b/CASA/gui/CommonGUI.cs @@ -20,7 +20,9 @@ * ***********************************************************************/ -using System; +using System; +using System.Threading; + using Gtk; using Glade; @@ -151,8 +153,12 @@ namespace Novell.CASA.GUI if( 0 == miCASA.SetMasterPassword(0, entryMasterPassword3.Text) ) { // unlock it - MiCasaRequestReply.Send(MiCasaRequestReply.VERB_UNLOCK_STORE, entryMasterPassword3.Text); - dialogLogin.Destroy(); + MiCasaRequestReply.Send(MiCasaRequestReply.VERB_UNLOCK_STORE, entryMasterPassword3.Text); + m_bPasswordVerified = true; + dialogLogin.Destroy(); + + //signal now + m_bIsVerifing = false; } else @@ -214,7 +220,9 @@ namespace Novell.CASA.GUI mTrayInstance.UpdateTrayIcon(true); else mTrayInstance.UpdateTrayIcon(false); - } + } + + m_bIsVerifing = false; } // remember MP until functions @@ -282,7 +290,12 @@ namespace Novell.CASA.GUI /// /// VerifyMasterPasswordWithUser dialog /// - public void VerifyMasterPasswordWithUser() + /// + + private bool m_bPasswordVerified = false; + private bool m_bIsVerifing = true; + + public bool VerifyMasterPasswordWithUser() { //Logger.DbgLog("GUI:CasaMain.Login() - IsMasterPasswordSet returned false"); @@ -303,7 +316,16 @@ namespace Novell.CASA.GUI //dialogLogin.SetPosition(Gtk.WindowPosition.Center); dialogLogin.Destroyed += new EventHandler(dialogLogin_Destroyed); dialogLogin.Modal = true; - dialogLogin.Show(); + dialogLogin.Show(); + + while (m_bIsVerifing) + { + // Flush pending events to keep the GUI reponsive + while (Gtk.Application.EventsPending()) + Gtk.Application.RunIteration(); + Thread.Sleep(100); + } + return m_bPasswordVerified; } public static void DisplayMessage(Gtk.MessageType messageType, String sMessage) diff --git a/CASA/gui/FileChooser.cs b/CASA/gui/FileChooser.cs index 334900c5..30433137 100644 --- a/CASA/gui/FileChooser.cs +++ b/CASA/gui/FileChooser.cs @@ -26,9 +26,7 @@ namespace Novell.CASA.GUI private int m_iAction = 1; public const int ACTION_OPEN = 1; public const int ACTION_SAVE = 2; - public const int ACTION_CHOOSE_DIR = 3; - - Thread tChooserThread = null; + public const int ACTION_CHOOSE_DIR = 3; #region Glade Widgets diff --git a/CASA/gui/FindAndReplace.cs b/CASA/gui/FindAndReplace.cs new file mode 100644 index 00000000..46e45234 --- /dev/null +++ b/CASA/gui/FindAndReplace.cs @@ -0,0 +1,397 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using Gtk; +using Glade; + +namespace Novell.CASA.GUI +{ + class FindAndReplace + { + #region Glade Widgets + + [Glade.Widget] + Gtk.TreeView tvResults; + + + [Glade.Widget] + Gtk.Dialog dialogFindAndReplace, + dialogLogin; + + [Glade.Widget] + Gtk.Button bttnFind, + bttnReplaceAll, + bttnApply, + bttnCancel, + bttnRevert, + bttnOk; + + [Glade.Widget] + Gtk.Entry entryFind, + entryNewValue, + entryMasterPassword3, + entryMasterPassword4; + + [Glade.Widget] + Gtk.CheckButton cbShowValues; + + [Glade.Widget] + Gtk.Label label86, + label88, + labelRememberFor, + labelSeconds; + + [Glade.Widget] + Gtk.SpinButton spinbuttonRememberFor; + + #endregion + + private TreeModel m_tmCASA; + private TreeStore m_tsCASA; + private TreeStore tsResults; + private Store m_store; + + private int m_iRememberSeconds = 5; + + public FindAndReplace(Store store, TreeModel tmCASA, TreeStore tsCASA) + { + m_store = store; + m_tmCASA = tmCASA; + m_tsCASA = tsCASA; + } + + public void ShowDialog() + { + Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogFindAndReplace", null); + gxmlTemp.Autoconnect(this); + + dialogFindAndReplace.SetPosition(WindowPosition.CenterOnParent); + + tvResults.AppendColumn("SecretID", new Gtk.CellRendererText(), "text", 0); + tvResults.AppendColumn("Key", new Gtk.CellRendererText(), "text", 1); + tvResults.AppendColumn("Value", new Gtk.CellRendererText(), "text", 2); + + tvResults.Selection.Mode = SelectionMode.Multiple; + + // 0:secretID, 1:Key, 2:Value****, 3:ValueClear, 4:dirtyBit + tsResults = new TreeStore(typeof(string), typeof(string), typeof(string), typeof(string), typeof(bool)); + tvResults.Model = tsResults; + + // hook up event handles + bttnApply.Clicked += new EventHandler(bttnApply_Clicked); + bttnCancel.Clicked += new EventHandler(bttnCancel_Clicked); + bttnRevert.Clicked += new EventHandler(bttnRevert_Clicked); + bttnFind.Clicked += new EventHandler(bttnFind_Clicked); + bttnOk.Clicked += new EventHandler(bttnOk_Clicked); + bttnReplaceAll.Clicked += new EventHandler(bttnReplaceAll_Clicked); + + cbShowValues.Toggled += new EventHandler(cbShowValues_Toggled); + + } + + + + public void okbuttonLogin_clicked(object abj, EventArgs args) + { + TreeViewColumn tvCol; + + if (0 == miCASA.SetMasterPassword(0, entryMasterPassword3.Text)) + { + tvResults.RemoveColumn(tvResults.GetColumn(2)); + tvCol = new TreeViewColumn("Value", new CellRendererText(), "text", 3); + tvResults.InsertColumn(tvCol, 2); + + // 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 + //string sSaveTimed = m_config.GetConfigSetting(CommonGUI.REMEMBER_SETTING, "5"); + //if (!sSaveTimed.Equals(m_sRememberFor)) + // { + // m_config.SetConfigSetting(CommonGUI.REMEMBER_SETTING, m_sRememberFor); + // m_config.WriteConfig(); + //} + + dialogLogin.Destroy(); + + //if (m_iRememberSeconds > 0) + // StartRememberTimer(); + } + else + { + // warn user + CommonGUI.DisplayMessage(MessageType.Warning, "Master Password incorrect"); + } + } + + 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); + } + + + public void on_helpbuttonAuthentication_clicked(object obj, EventArgs args) + { + Common.ShowHelpUrl("CASAMasterPasswordAuthentication.htm"); + } + + + void cbShowValues_Toggled(object sender, EventArgs e) + { + TreeViewColumn tvCol; + + if ((true == cbShowValues.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 + tvResults.RemoveColumn(tvResults.GetColumn(2)); + tvCol = new TreeViewColumn("Value", new CellRendererText(), "text", 3); + tvResults.InsertColumn(tvCol, 2); + } + else if (true == cbShowValues.Active) + { + // prompt user for MasterPassword + + Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogLogin", null); + gxmlTemp.Autoconnect(this); + dialogLogin.TransientFor = dialogFindAndReplace; + + label86.Text = "Enter your Master Password to view values"; + entryMasterPassword3.Text = ""; + entryMasterPassword3.HasFocus = true; + label88.Hide(); + entryMasterPassword4.Hide(); + + labelRememberFor.Visible = false; + labelSeconds.Visible = false; + spinbuttonRememberFor.Visible = false; + //spinbuttonRememberFor.Text = m_config.GetConfigSetting(CommonGUI.REMEMBER_SETTING, m_sRememberFor); + + //dialogLogin.Show(); + } + else + { + tvResults.RemoveColumn(tvResults.GetColumn(2)); + tvCol = new TreeViewColumn("Value", new CellRendererText(), "text", 2); + tvResults.InsertColumn(tvCol, 2); + } + + } + + public void closebuttonLogin_clicked(object abj, EventArgs args) + { + cbShowValues.Active = false; + dialogLogin.Destroy(); + } + + + public void OnDialogLoginDeleted(object obj, DeleteEventArgs args) + { + cbShowValues.Active = false; + dialogLogin.Destroy(); + args.RetVal = true; + } + + + + void bttnOk_Clicked(object sender, EventArgs e) + { + if (bttnApply.Sensitive) + { + bttnApply_Clicked(sender, e); + } + CloseDialog(); + } + + void bttnFind_Clicked(object sender, EventArgs e) + { + if (entryFind.Text != null && entryFind.Text.Length > 0) + { + DoFind(); + } + else + { + CommonGUI.DisplayMessage(MessageType.Error, "You must enter a value to find"); + } + } + + void bttnRevert_Clicked(object sender, EventArgs e) + { + // show cancel + bttnCancel.Visible = true; + + // hide revert + bttnRevert.Visible = false; + + bttnApply.Sensitive = bttnOk.Sensitive = false; + + // reload + DoFind(); + } + + void bttnCancel_Clicked(object sender, EventArgs e) + { + CloseDialog(); + } + + void bttnApply_Clicked(object sender, EventArgs e) + { + TreeIter iter; + + // iterate thru store, update all values with dirtybit=true + if (tsResults.GetIterFirst(out iter)) + { + do + { + bool bDirty = (bool)tsResults.GetValue(iter, 4); + if (bDirty) + { + String sID = (string)tsResults.GetValue(iter, 0); + String sKey = (string)tsResults.GetValue(iter, 1); + String sValue = (string)tsResults.GetValue(iter, 3); + + if (StoreDataInterface.ModifyCASASecretKey(sID, sKey, sValue)) + { + Console.WriteLine("Updating {0} : {1} : {2}", sID, sKey, sValue); + } + + // Update CASAManager view + m_store.AggregateStore(); + + } + } while (tsResults.IterNext(ref iter)); + + } + + + // hide revert + bttnRevert.Visible = false; + bttnCancel.Visible = true; + + bttnApply.Sensitive = false; + bttnOk.Sensitive = false; + + } + + private void CloseDialog() + { + if (dialogFindAndReplace != null) + { + dialogFindAndReplace.Destroy(); + } + } + + private void DoFind() + { + + string selected = null; + string[] keys = null, + values = null; + + // clear current vies + tsResults.Clear(); + + // iterate thru CASA TreeStore, finding matches + TreeIter iter; + + if (m_tsCASA.GetIterFirst(out iter)) + { + do + { + selected = (string)m_tmCASA.GetValue(iter, 0); + keys = (string[])m_tmCASA.GetValue(iter, 1); + values = (string[])m_tmCASA.GetValue(iter, 2); + + // add matches to the results + for (int i = 0; i < keys.Length; i++) + { + if ((entryFind.Text.Equals("*")) || + (values[i].IndexOf(entryFind.Text) > -1)) + { + tsResults.AppendValues(selected, keys[i], "*******", values[i], false); + } + } + } while (m_tsCASA.IterNext(ref iter)); + + //tvResults.Selection.SelectAll(); + } + } + + void bttnReplaceAll_Clicked(object sender, EventArgs e) + { + TreePath[] treePaths = tvResults.Selection.GetSelectedRows(); + TreeIter iter; + + if (entryNewValue.Text == null || entryNewValue.Text.Length == 0) + { + CommonGUI.DisplayMessage(MessageType.Warning, "Enter a new value"); + return; + } + + if (treePaths.Length == 0) + { + CommonGUI.DisplayMessage(MessageType.Warning, "You must select at least one row"); + return; + } + + if (entryNewValue.Text != null && entryNewValue.Text.Length > 0) + { + // iterate thru those to change + for (int i = 0; i < treePaths.Length; i++) + { + if (tsResults.GetIter(out iter, treePaths[i])) + { + string sCurrentValue = (string)tsResults.GetValue(iter, 3); + + // change if newValue is different + if (!sCurrentValue.Equals(entryNewValue.Text)) + { + tsResults.SetValue(iter, 2, entryNewValue.Text); + tsResults.SetValue(iter, 3, entryNewValue.Text); + + // set the dirty bit + tsResults.SetValue(iter, 4, true); + } + } + } + + bttnApply.Sensitive = bttnOk.Sensitive = true; + + bttnRevert.Visible = true; + bttnCancel.Visible = false; + } + } + + /* + private bool bTimerActive = false; + public void StartRememberTimer() + { + if (!bTimerActive) + { + GLib.Timeout.Add((uint)(m_iRememberSeconds * 1000), new GLib.TimeoutHandler(update_gui)); + bTimerActive = true; + } + } + * */ + } + +} diff --git a/CASA/gui/ImportSecrets.cs b/CASA/gui/ImportSecrets.cs index 3aaac29e..30232e6b 100644 --- a/CASA/gui/ImportSecrets.cs +++ b/CASA/gui/ImportSecrets.cs @@ -1,5 +1,8 @@ using System; -using System.IO; +using System.IO; +using System.Collections.Specialized; + +using Gtk; using Novell.CASA.MiCasa.Communication; using Novell.CASA.MiCasa.Common; @@ -14,16 +17,33 @@ namespace Novell.CASA.GUI Config m_config = null; public MiCasa m_objMiCasa = null; string sFile = null; - byte[] buffer = null; - - [Glade.Widget] + byte[] buffer = null; + TreeStore tsConflicts; + + SecretStore m_ss = null; + StringCollection m_scConflicts; + + #region GladeWidgets + [Glade.Widget] Gtk.Entry entryMasterPassword; [Glade.Widget] Gtk.Dialog dialogImport, - dialogLogin; - - public ImportSecrets(Config config, MiCasa objMiCasa) + dialogLogin, + dialogResolveConflict; + + [Glade.Widget] + Gtk.TreeView tvConflicts; + + [Glade.Widget] + Gtk.Button bttnImport, + bttnIgnore; + + [Glade.Widget] + Gtk.CheckButton cbShowValues; + #endregion + + public ImportSecrets(Config config, MiCasa objMiCasa) { m_config = config; m_objMiCasa = objMiCasa; @@ -75,7 +95,20 @@ namespace Novell.CASA.GUI { ImportXMLSecrets addSecrets = new ImportXMLSecrets(null, null, sFile); MiCasaRequestReply.Send(MiCasaRequestReply.VERB_ADD_XML_SECRETS, null, null, null, addSecrets); - CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Import complete"); + + // check for conflicts + if (m_ss == null) + m_ss = SecretStore.getInstance(); + + m_scConflicts = m_ss.enumerateSecretIDs(SecretStore.SSCS_CONFLICT_KEYCHAIN); + if (m_scConflicts.Count > 0) + { + HandleConficts(m_ss, m_scConflicts); + } + else + { + CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Import complete"); + } } else { @@ -104,7 +137,7 @@ namespace Novell.CASA.GUI gxmlTemp.Autoconnect (this); dialogImport.TransientFor = (Gtk.Window)CasaMain.gxmlMain.GetWidget("windowMain");; - dialogImport.Modal = true; + dialogImport.Modal = true; dialogImport.Show(); } @@ -166,6 +199,218 @@ namespace Novell.CASA.GUI { dialogImport.Destroy(); } - } + } + + private void HandleConficts(SecretStore store, StringCollection scConflicts) + { + + bool bShowConflictDialog = false; + + // 0:secretID, 1:keyID, 2:importValue, 3:currentValue + tsConflicts = new TreeStore(typeof(string), typeof(string), typeof(string), typeof(string), typeof(string)); + + StringEnumerator sEnum = scConflicts.GetEnumerator(); + { + while (sEnum.MoveNext()) + { + string sSecretID = sEnum.Current; + Secret currentSecret = store.getSecret(sSecretID); + + string sConflictSecretID; + if (sSecretID.StartsWith("SS_CredSet")) + { + sConflictSecretID = sSecretID.Substring(11); + } + else + { + sConflictSecretID = sSecretID; + } + Secret conflictSecret = store.getSecret(SecretStore.SSCS_CONFLICT_KEYCHAIN, 0, sConflictSecretID, Secret.SS_CREDSET, ""); + + // add this conflict to the treestore + NameValueCollection nvcConflict = conflictSecret.getKeyValueCollection(); + NameValueCollection nvcCurrent = currentSecret.getKeyValueCollection(); + for (int i = 0; i < nvcConflict.Count; i++) + { + String sConflictKey = nvcConflict.GetKey(i); + String sConflictValue = nvcConflict.Get(sConflictKey); + String sCurrentValue = nvcCurrent.Get(sConflictKey); + + if (sCurrentValue != null) + { + if (sCurrentValue != sConflictValue) + { + tsConflicts.AppendValues(sSecretID, sConflictKey, sConflictValue, sCurrentValue, "*********"); + bShowConflictDialog = true; + } + } + else + { + tsConflicts.AppendValues(sSecretID, sConflictKey, sConflictValue, "", "*********"); + bShowConflictDialog = true; + } + } + } + + if (bShowConflictDialog == true) + { + // show dialog + Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogResolveConflict", null); + gxmlTemp.Autoconnect(this); + + dialogResolveConflict.SetPosition(WindowPosition.CenterOnParent); + + tvConflicts.AppendColumn("SecretID", new Gtk.CellRendererText(), "text", 0); + tvConflicts.AppendColumn("Key", new Gtk.CellRendererText(), "text", 1); + if (cbShowValues.Active) + { + tvConflicts.AppendColumn("Import value", new Gtk.CellRendererText(), "text", 2); + tvConflicts.AppendColumn("Current value", new Gtk.CellRendererText(), "text", 3); + } + else + { + tvConflicts.AppendColumn("Import value", new Gtk.CellRendererText(), "text", 4); + tvConflicts.AppendColumn("Current value", new Gtk.CellRendererText(), "text", 4); + } + + tvConflicts.Selection.Mode = SelectionMode.Multiple; + + // hook up event handlers + bttnImport.Clicked += new EventHandler(bttnImport_Clicked); + bttnIgnore.Clicked += new EventHandler(bttnIgnore_Clicked); + cbShowValues.Toggled += new EventHandler(cbShowValues_Toggled); + + tvConflicts.Model = tsConflicts; + dialogResolveConflict.Show(); + } + else + { + ClearConflicts(); + CommonGUI.DisplayMessage(MessageType.Info, "Import complete"); + } + } + } + + void cbShowValues_Toggled(object sender, EventArgs e) + { + TreeViewColumn tvCol; + + if (cbShowValues.Active) + { + // verify MasterPassword + CommonGUI cg = new CommonGUI(); + if (cg.VerifyMasterPasswordWithUser()) + { + tvConflicts.RemoveColumn(tvConflicts.GetColumn(3)); + tvConflicts.RemoveColumn(tvConflicts.GetColumn(2)); + + // add columns + tvCol = new TreeViewColumn("Import value", new CellRendererText(), "text", 2); + tvConflicts.InsertColumn(tvCol, 2); + + tvCol = new TreeViewColumn("Current value", new CellRendererText(), "text", 3); + tvConflicts.InsertColumn(tvCol, 3); + } + else + { + cbShowValues.Active = false; + } + } + else + { + tvConflicts.RemoveColumn(tvConflicts.GetColumn(3)); + tvConflicts.RemoveColumn(tvConflicts.GetColumn(2)); + + // add columns + tvCol = new TreeViewColumn("Import value", new CellRendererText(), "text", 4); + tvConflicts.InsertColumn(tvCol, 2); + + tvCol = new TreeViewColumn("Current value", new CellRendererText(), "text", 4); + tvConflicts.InsertColumn(tvCol, 3); + } + } + + void bttnIgnore_Clicked(object sender, EventArgs e) + { + ClearConflicts(); + dialogResolveConflict.Destroy(); + } + + void bttnImport_Clicked(object sender, EventArgs e) + { + DoImport(); + } + + void DoImport() + { + // get selected rows + TreePath[] treePaths = tvConflicts.Selection.GetSelectedRows(); + TreeIter iter; + + if (treePaths.Length > 0) + { + // iterate thru those to change + for (int i = 0; i < treePaths.Length; i++) + { + if (tsConflicts.GetIter(out iter, treePaths[i])) + { + string sSecretID = (string)tsConflicts.GetValue(iter, 0); + string sKey = (string)tsConflicts.GetValue(iter, 1); + string sNewValue = (string)tsConflicts.GetValue(iter, 2); + string sCurValue = (string)tsConflicts.GetValue(iter, 3); + + if ((sCurValue == null) || (sCurValue.Length == 0)) + { + StoreDataInterface.AddCASASecretKey(sSecretID, sKey, sNewValue); + } + else + { + StoreDataInterface.ModifyCASASecretKey(sSecretID, sKey, sNewValue); + } + + tsConflicts.SetValue(iter, 3, sNewValue); + } + } + + for (int i = 0; i < treePaths.Length; i++) + { + if (tsConflicts.GetIter(out iter, treePaths[i])) + { + tsConflicts.Remove(ref iter); + } + } + + // refresh the store + //ClearConflicts(); + m_objMiCasa.AggregateStore(); + } + else + { + CommonGUI.DisplayMessage(MessageType.Error, "Select the values you want to import"); + } + } + + private void ClearConflicts() + { + // enumerate thru conflicts, clearing each one + if (m_ss != null) + { + if (m_scConflicts != null) + { + StringEnumerator sEnum = m_scConflicts.GetEnumerator(); + while (sEnum.MoveNext()) + { + string sSecretID = (string)sEnum.Current; + if (sSecretID.StartsWith("SS_CredSet")) + { + sSecretID = sSecretID.Substring(11); + } + m_ss.removeSecret(0, SecretStore.SSCS_CONFLICT_KEYCHAIN, null, sSecretID, Secret.SS_CREDSET); + } + } + } + + tsConflicts.Clear(); + } } } diff --git a/CASA/gui/Makefile.am b/CASA/gui/Makefile.am index 63858ad2..ce245833 100644 --- a/CASA/gui/Makefile.am +++ b/CASA/gui/Makefile.am @@ -66,6 +66,7 @@ CSFILES =$(srcdir)/AssemblyInfo.cs \ $(srcdir)/ExportSecrets.cs \ $(srcdir)/FileChooser.cs \ $(srcdir)/ImportSecrets.cs \ + $(srcdir)/FindAndReplace.cs \ $(srcdir)/Firefox.cs \ $(srcdir)/GnomeKeyring.cs \ $(srcdir)/KdeWallet.cs \ diff --git a/CASA/gui/MiCasa.cs b/CASA/gui/MiCasa.cs index a4656cc1..a445a7f3 100644 --- a/CASA/gui/MiCasa.cs +++ b/CASA/gui/MiCasa.cs @@ -132,7 +132,7 @@ public class MiCasa : Store /// SecretID TreeStore 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); @@ -985,8 +985,14 @@ 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(); + } ///####################################################################### // DELETE SECRET diff --git a/CASA/gui/StoreDataInterface.cs b/CASA/gui/StoreDataInterface.cs index d44327eb..8d620a10 100644 --- a/CASA/gui/StoreDataInterface.cs +++ b/CASA/gui/StoreDataInterface.cs @@ -987,9 +987,7 @@ namespace Novell.CASA.GUI { //Console.WriteLine("EXECUTING OPERATION_ADD_SECRET:Adding"+ccfSecretPath);//FIXME:Remove this line ad.SetSecret(lastChild,operation,storeIDentifier); //and set it } - }//STORE_KDEWALLET - - + }//STORE_KDEWALLET } else if( Common.OPERATION_ADD_KEY == operation ) { @@ -1015,7 +1013,66 @@ namespace Novell.CASA.GUI { } return( Common.STATUS_SUCCESS ); - } + } + + public static bool ModifyCASASecretKey(string SecretID, string keyID, string sValue) + { + return ModifySecretKey(Common.STORE_MICASA, "Default", SecretID, keyID, sValue); + } + + private static bool ModifySecretKey(int StoreID, string keyChainID, string SecretID, string keyID, string sValue) + { + string ccfSecretPath = "//CCF/miCASA/Keychain[@ID='" + keyChainID + "']/Secret[@ID='" + SecretID + "']/Key[@ID='" + keyID + "']"; + + //For Modify operation get to the Node in the tree which needs to be modified + XmlNode root = ccfDoc.DocumentElement; + XmlNodeList keylist = root.SelectNodes(ccfSecretPath); + foreach ( XmlNode key in keylist ) + { + key.ChildNodes[0].InnerText = sValue; + ad.SetSecret(key.ParentNode, Common.OPERATION_MODIFY_KEY, StoreID); + } + + return true; + } + + + // TODO: Make this store independant + public static bool AddCASASecretKey(string SecretID, string keyID, string sValue) + { + XmlElement newKeyElement; + string ccfKeyChainPath = "//CCF/miCASA/Keychain[@ID='Default']/Secret[@ID='" + SecretID + "']"; + string ccfSecretPath = ""; + + //Create the Key element + newKeyElement = ccfDoc.CreateElement(CCFXML_ELEMENT_KEY); + newKeyElement.SetAttribute(CCFXML_ATTRIBUTE_ID, keyID); + XmlElement newValue = ccfDoc.CreateElement(CCFXML_ELEMENT_VALUE); + newValue.InnerText = sValue; + newKeyElement.AppendChild(newValue); + + XmlNode root = ccfDoc.DocumentElement; + XmlNodeList keyNodeList = root.SelectNodes(ccfKeyChainPath); + XmlNode keyNode = keyNodeList.Item(0); + XmlNode lastChild = keyNode.LastChild; + keyNode.InsertBefore(newKeyElement, lastChild); + try + { + int errcode = ad.SetSecret(keyNode, Common.OPERATION_ADD_KEY, Common.STORE_MICASA); + if (errcode == Common.STATUS_SUCCESS) + { + return true; + } + else + { + return false; + } + } + catch (Exception) + { + return false; + } + } ///####################################################################### diff --git a/CASA/gui/images/casa.glade b/CASA/gui/images/casa.glade index 4b892d13..41fe4082 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 @@ -270,7 +270,7 @@ - + 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 @@ -361,6 +361,34 @@ + + + True + + + + + + True + _Find and Replace + True + + + + + + True + gtk-find-and-replace + 1 + 0.5 + 0.5 + 0 + 0 + + + + + True @@ -376,7 +404,7 @@ - + True gtk-delete 1 @@ -410,7 +438,7 @@ True - + True gtk-execute 1 @@ -432,7 +460,7 @@ - + True gtk-execute 1 @@ -453,7 +481,7 @@ - + True gtk-execute 1 @@ -474,7 +502,7 @@ - + True gtk-execute 1 @@ -495,7 +523,7 @@ - + True gtk-execute 1 @@ -520,7 +548,7 @@ - + True gtk-revert-to-saved 1 @@ -547,7 +575,7 @@ - + True gtk-preferences 1 @@ -575,7 +603,7 @@ - + True gtk-properties 1 @@ -609,7 +637,7 @@ - + True gtk-add 1 @@ -630,7 +658,7 @@ - + True gtk-remove 1 @@ -696,7 +724,7 @@ - + True gtk-help 1 @@ -723,7 +751,7 @@ - + True gtk-dialog-info 1 @@ -13811,7 +13839,7 @@ to encrypt this file True gtk-help True - GTK_RELIEF_NORMAL + GTK_RELIEF_NONE True -11 @@ -13939,7 +13967,7 @@ to encrypt this file True gtk-help True - GTK_RELIEF_NORMAL + GTK_RELIEF_NONE True -11 @@ -15084,4 +15112,818 @@ secret for the selected store. + + True + CASA - Find and replace + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER_ALWAYS + True + 450 + 600 + True + False + CASAicons.ico + 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_NONE + True + -11 + + + + + + True + False + True + True + gtk-apply + True + GTK_RELIEF_NORMAL + True + -10 + + + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + gtk-revert-to-saved + True + GTK_RELIEF_NORMAL + True + -5 + + + + + + True + False + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -4 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + False + 0 + + + + True + gtk-find-and-replace + 5 + 0.5 + 0.5 + 0 + 0 + + + 4 + True + True + + + + + + True + False + 0 + + + + True + <b>Find values and replace them</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 4 + False + False + + + + + + True + Enter the value to find, and click Find +Enter the new value. +Select row(s) to replace, and click Replace Selected + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 6 + False + False + + + + + 0 + True + True + + + + + 0 + False + True + + + + + + 6 + True + 0 + 0.5 + GTK_SHADOW_IN + + + + True + False + 0 + + + + True + False + 0 + + + + True + Find value with: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 25 + False + False + + + + + 0 + False + False + + + + + + True + False + 0 + + + + True + False + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + * + False + + + 6 + True + True + + + + + + True + True + Find + True + GTK_RELIEF_NORMAL + True + + + 7 + False + False + + + + + 0 + False + True + + + + + + True + False + 0 + + + + True + Replace with: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 25 + False + False + + + + + 0 + False + False + + + + + + True + False + 0 + + + + True + False + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + * + False + + + 6 + True + True + + + + + + True + True + Replace Selected + True + GTK_RELIEF_NORMAL + True + + + 7 + False + False + + + + + 0 + False + True + + + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + False + False + False + + + + + 8 + True + True + + + + + + True + True + Show Values in clear text. + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + + True + CASA - Resolve conflicts + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER_ALWAYS + True + 450 + 600 + True + False + CASAicons.ico + 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_NONE + True + -11 + + + + + + True + True + True + _Import Selected Rows + True + GTK_RELIEF_NORMAL + True + 0 + + + + + + True + True + True + I_gnore + True + GTK_RELIEF_NORMAL + True + -4 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + False + 0 + + + + True + gtk-justify-fill + 3 + 0.5 + 0.5 + 0 + 0 + + + 4 + True + True + + + + + + True + False + 0 + + + + True + These Secrets from the import conflict with current +values. You can overwrite current values with imported +values by selecting them and clicking import below. + +All other conflicts will be ignored. + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 4 + False + False + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 6 + False + False + + + + + 0 + True + True + + + + + 0 + False + True + + + + + + 6 + True + 0 + 0.5 + GTK_SHADOW_IN + + + + True + False + 0 + + + + True + False + 0 + + + + True + False + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + 0 + False + True + + + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + False + False + False + + + + + 8 + True + True + + + + + + True + True + Show Values in clear text. + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + diff --git a/CASA/micasad/common/Constants.cs b/CASA/micasad/common/Constants.cs index ded99b6d..e5d1e4d9 100644 --- a/CASA/micasad/common/Constants.cs +++ b/CASA/micasad/common/Constants.cs @@ -83,7 +83,9 @@ namespace sscs.constants internal static string SSCS_LOCAL_KEY_CHAIN_ID = "SSCS_LOCAL_KEY_CHAIN_ID"; internal static string SSCS_HIDDEN_LOCAL_KEYCHAIN_ID = "SSCS_HIDDEN_LOCAL_KEYCHAIN_ID"; internal static string SSCS_REMOTE_KEYCHAIN_ID = "SSCS_REMOTE_KEYCHAIN_ID"; - internal static string SSCS_LOCAL_REMOTE_KEYCHAIN_ID = "SSCS_LOCAL_REMOTE_KEYCHAIN_ID"; + internal static string SSCS_LOCAL_REMOTE_KEYCHAIN_ID = "SSCS_LOCAL_REMOTE_KEYCHAIN_ID"; + + internal static string SSCS_CONFLICT_KEYCHAIN = "SSCS_CONFLICT_KEYCHAIN_ID"; //TBD , Need to look at Novell standard for the desktop internal static string SSCS_WIN_ENGINELOG = "c:\\CSSS.log"; diff --git a/CASA/micasad/lss/LocalStorage.cs b/CASA/micasad/lss/LocalStorage.cs index 2da94ddf..9543d545 100644 --- a/CASA/micasad/lss/LocalStorage.cs +++ b/CASA/micasad/lss/LocalStorage.cs @@ -361,152 +361,177 @@ namespace sscs.lss return true; } - internal static void AddXMLSecretsToStore(SecretStore userStore, XmlDocument doc) - { - string xpath = ""; - xpath = "//" + XmlConsts.miCASANode; - XmlNode miCASANode = doc.SelectSingleNode(xpath); - if(miCASANode != null) - { - xpath = "descendant::" + XmlConsts.keyChainNode; - XmlNodeList keyChainNodeList = miCASANode.SelectNodes(xpath); - foreach(XmlNode node in keyChainNodeList) - { - XmlAttributeCollection attrColl = node.Attributes; - string keyChainId = (attrColl[XmlConsts.idAttr]).Value + "\0"; - KeyChain keyChain = null; - - if( userStore.CheckIfKeyChainExists(keyChainId) == false ) - { - keyChain = new KeyChain(keyChainId); - userStore.AddKeyChain(keyChain); - - - } - else - { - keyChain = userStore.GetKeyChain(keyChainId); - - // set the created time if possible - XmlNode timeNode = node.SelectSingleNode("descendant::" + XmlConsts.timeNode); - if (timeNode != null) - { - XmlAttributeCollection timeAttribCol = timeNode.Attributes; - if (timeAttribCol != null) - { - XmlNode createdTimeNode = timeAttribCol.GetNamedItem(XmlConsts.createdTimeNode); - if (createdTimeNode != null) - { - //Console.WriteLine("KeyChain create time:" + new DateTime(long.Parse(createdTimeNode.Value))); - } - else - { - //Console.WriteLine("Create time not found"); - } - XmlNode modifiedTimeNode = timeAttribCol.GetNamedItem(XmlConsts.modifiedTimeNode); - if (modifiedTimeNode != null) - { - //Console.WriteLine("KeyChain mod time:" + new DateTime(long.Parse(modifiedTimeNode.Value))); - } - } - } - } - - xpath = "descendant::" + XmlConsts.secretNode; - XmlNodeList secretNodeList = node.SelectNodes(xpath); - foreach(XmlNode secretNode in secretNodeList) - { - attrColl = secretNode.Attributes; - string secretId = (attrColl[XmlConsts.idAttr]).Value + "\0"; - xpath = "descendant::" + XmlConsts.valueNode; - Secret secret = new Secret(secretId); - - - // get time stamps for this secret - XmlNode timeNode = secretNode.SelectSingleNode("descendant::" + XmlConsts.timeNode); - if (timeNode != null) - { - //Console.WriteLine("Secret: " + secretId); - XmlAttributeCollection timeAttribCol = timeNode.Attributes; - if (timeAttribCol != null) - { - XmlNode createdTimeNode = timeAttribCol.GetNamedItem(XmlConsts.createdTimeNode); - if (createdTimeNode != null) - { - //Console.WriteLine("Secret create time:" + new DateTime(long.Parse(createdTimeNode.Value))); - } - else - { - //Console.WriteLine("Create time not found"); - } - - XmlNode modifiedTimeNode = timeAttribCol.GetNamedItem(XmlConsts.modifiedTimeNode); - if (modifiedTimeNode != null) - { - //Console.WriteLine("Secret mod time:" + new DateTime(long.Parse(modifiedTimeNode.Value))); - } - else - { - //Console.WriteLine("mod time not found"); - } - } - } - - - if( keyChain.CheckIfSecretExists(secretId) == false) - { - keyChain.AddSecret(secret); - XmlNode secretValNode = (secretNode.SelectSingleNode(xpath)); - xpath = "descendant::" + XmlConsts.keyNode; - - XmlNodeList keyNodeList = secretValNode.SelectNodes(xpath); - - secret = keyChain.GetSecret(secretId); - foreach(XmlNode keyNode in keyNodeList) - { - attrColl = keyNode.Attributes; - string key; - try - { - key = (attrColl[XmlConsts.idAttr]).Value; - } - catch (Exception) - { - // LinkedKey node, continue - continue; - } - xpath = "descendant::" + XmlConsts.keyValueNode; - XmlNode keyValNode = keyNode.SelectSingleNode(xpath); - string keyValue = keyValNode.InnerText; - secret.SetKeyValue(key,keyValue); - - // add linked keys - xpath = "descendant::" + XmlConsts.linkedKeyNode; - XmlNodeList linkNodeList = keyNode.SelectNodes(xpath); - foreach(XmlNode linkNode in linkNodeList) - { - // get TargetSecretID - xpath = "descendant::" + XmlConsts.linkedTargetSecretNode; - XmlNode targetSecretNode = linkNode.SelectSingleNode(xpath); - string sSecretID = targetSecretNode.InnerText + "\0"; - - // get TargetSecretKey - xpath = "descendant::" + XmlConsts.linkedTargetKeyNode; - XmlNode targetKeyNode = linkNode.SelectSingleNode(xpath); - string sKeyID = targetKeyNode.InnerText; - - LinkedKeyInfo lki = new LinkedKeyInfo(sSecretID, sKeyID, true); - KeyValue kv = secret.GetKeyValue(key); - kv.AddLink(lki); - } - - } - }//if ends - } - - }//end of traversing keyChainNodeList - } - } + internal static void AddXMLSecretsToStore(SecretStore userStore, XmlDocument doc) + { + // get the conflict keychain + KeyChain kcConflict; + if (!userStore.CheckIfKeyChainExists(ConstStrings.SSCS_CONFLICT_KEYCHAIN + '\0')) + { + kcConflict = new KeyChain(ConstStrings.SSCS_CONFLICT_KEYCHAIN + '\0'); + userStore.AddKeyChain(kcConflict); + } + else + { + kcConflict = userStore.GetKeyChain(ConstStrings.SSCS_CONFLICT_KEYCHAIN + '\0'); + } + + string xpath = ""; + xpath = "//" + XmlConsts.miCASANode; + XmlNode miCASANode = doc.SelectSingleNode(xpath); + if (miCASANode != null) + { + xpath = "descendant::" + XmlConsts.keyChainNode; + XmlNodeList keyChainNodeList = miCASANode.SelectNodes(xpath); + foreach (XmlNode node in keyChainNodeList) + { + XmlAttributeCollection attrColl = node.Attributes; + string keyChainId = (attrColl[XmlConsts.idAttr]).Value + "\0"; + KeyChain keyChain = null; + + if (userStore.CheckIfKeyChainExists(keyChainId) == false) + { + keyChain = new KeyChain(keyChainId); + userStore.AddKeyChain(keyChain); + } + else + { + keyChain = userStore.GetKeyChain(keyChainId); + + // set the created time if possible + XmlNode timeNode = node.SelectSingleNode("descendant::" + XmlConsts.timeNode); + if (timeNode != null) + { + XmlAttributeCollection timeAttribCol = timeNode.Attributes; + if (timeAttribCol != null) + { + XmlNode createdTimeNode = timeAttribCol.GetNamedItem(XmlConsts.createdTimeNode); + if (createdTimeNode != null) + { + //Console.WriteLine("KeyChain create time:" + new DateTime(long.Parse(createdTimeNode.Value))); + } + else + { + //Console.WriteLine("Create time not found"); + } + XmlNode modifiedTimeNode = timeAttribCol.GetNamedItem(XmlConsts.modifiedTimeNode); + if (modifiedTimeNode != null) + { + //Console.WriteLine("KeyChain mod time:" + new DateTime(long.Parse(modifiedTimeNode.Value))); + } + } + } + } + + xpath = "descendant::" + XmlConsts.secretNode; + XmlNodeList secretNodeList = node.SelectNodes(xpath); + foreach (XmlNode secretNode in secretNodeList) + { + attrColl = secretNode.Attributes; + string secretId = (attrColl[XmlConsts.idAttr]).Value + "\0"; + xpath = "descendant::" + XmlConsts.valueNode; + Secret secret = new Secret(secretId); + + + // get time stamps for this secret + XmlNode timeNode = secretNode.SelectSingleNode("descendant::" + XmlConsts.timeNode); + if (timeNode != null) + { + //Console.WriteLine("Secret: " + secretId); + XmlAttributeCollection timeAttribCol = timeNode.Attributes; + if (timeAttribCol != null) + { + XmlNode createdTimeNode = timeAttribCol.GetNamedItem(XmlConsts.createdTimeNode); + if (createdTimeNode != null) + { + //Console.WriteLine("Secret create time:" + new DateTime(long.Parse(createdTimeNode.Value))); + } + else + { + //Console.WriteLine("Create time not found"); + } + + XmlNode modifiedTimeNode = timeAttribCol.GetNamedItem(XmlConsts.modifiedTimeNode); + if (modifiedTimeNode != null) + { + //Console.WriteLine("Secret mod time:" + new DateTime(long.Parse(modifiedTimeNode.Value))); + } + else + { + //Console.WriteLine("mod time not found"); + } + } + } + + + //if (keyChain.CheckIfSecretExists(secretId) == false) + { + //keyChain.AddSecret(secret); + XmlNode secretValNode = (secretNode.SelectSingleNode(xpath)); + xpath = "descendant::" + XmlConsts.keyNode; + + XmlNodeList keyNodeList = secretValNode.SelectNodes(xpath); + + //secret = keyChain.GetSecret(secretId); + foreach (XmlNode keyNode in keyNodeList) + { + attrColl = keyNode.Attributes; + string key; + try + { + key = (attrColl[XmlConsts.idAttr]).Value; + } + catch (Exception) + { + // LinkedKey node, continue + continue; + } + xpath = "descendant::" + XmlConsts.keyValueNode; + XmlNode keyValNode = keyNode.SelectSingleNode(xpath); + string keyValue = keyValNode.InnerText; + secret.SetKeyValue(key, keyValue); + + // add linked keys + xpath = "descendant::" + XmlConsts.linkedKeyNode; + XmlNodeList linkNodeList = keyNode.SelectNodes(xpath); + foreach (XmlNode linkNode in linkNodeList) + { + // get TargetSecretID + xpath = "descendant::" + XmlConsts.linkedTargetSecretNode; + XmlNode targetSecretNode = linkNode.SelectSingleNode(xpath); + string sSecretID = targetSecretNode.InnerText + "\0"; + + // get TargetSecretKey + xpath = "descendant::" + XmlConsts.linkedTargetKeyNode; + XmlNode targetKeyNode = linkNode.SelectSingleNode(xpath); + string sKeyID = targetKeyNode.InnerText; + + LinkedKeyInfo lki = new LinkedKeyInfo(sSecretID, sKeyID, true); + KeyValue kv = secret.GetKeyValue(key); + kv.AddLink(lki); + } + + } + }//if ends + + // if SecretID already exists, add to the conflict keychain + if (keyChain.CheckIfSecretExists(secretId) == false) + { + keyChain.AddSecret(secret); + } + else + { + if (kcConflict.CheckIfSecretExists(secretId)) + { + kcConflict.RemoveSecret(secretId); + } + kcConflict.AddSecret(secret); + } + + } + + }//end of traversing keyChainNodeList + } + } private void PersistStoreDelayThreadFn() { diff --git a/CASA/micasad/verbs/ReadSecret.cs b/CASA/micasad/verbs/ReadSecret.cs index 9c610b44..88dc08d7 100644 --- a/CASA/micasad/verbs/ReadSecret.cs +++ b/CASA/micasad/verbs/ReadSecret.cs @@ -105,6 +105,7 @@ namespace sscs.verbs byte[] secretIdArr = new byte[secretIdLen]; Array.Copy(inBuf,(10+keyChainIdLen+4),secretIdArr,0,secretIdLen); secretId = Encoding.UTF8.GetString(secretIdArr); + // Message Format decipher - End try @@ -118,21 +119,26 @@ namespace sscs.verbs //CSSSLogger.ExpLog(e.ToString()); } - SecretStore ssStore; + SecretStore ssStore; + CSSSLogger.DbgLog("Reading Secret ID: " + secretId); if (extId == 1) { -#if W32 +#if W32 + CSSSLogger.DbgLog("LUID ExtID found"); WinUserIdentifier test = (WinUserIdentifier)userId; // NOTE: ONLY ALLOW THE SWITCH IF THE CALLER IS "SYSTEM" if ((test.GetUIDLow() == 999) && (test.GetUIDHigh() == 0)) { + // WINDOWS LUID // System Services, like DLU create fake UIDs, store credentials and then want to read that data. luidLow = BitConverter.ToInt32(inBuf, 18 + ((int)keyChainIdLen)+((int)secretIdLen) + 8); luidHigh = BitConverter.ToInt32(inBuf, 18 + ((int)keyChainIdLen)+((int)secretIdLen) + 12); tempUserId = new WinUserIdentifier(luidLow, luidHigh); - SecretStore ss = SessionManager.CreateUserSession(tempUserId); + SecretStore ss = SessionManager.CreateUserSession(tempUserId); + + CSSSLogger.DbgLog("Switching LUID to [" + luidHigh.ToString() + "][" + luidLow.ToString() + "]"); } #endif } diff --git a/CASA/micasad/verbs/WriteKey.cs b/CASA/micasad/verbs/WriteKey.cs index a18d0df4..344fd457 100644 --- a/CASA/micasad/verbs/WriteKey.cs +++ b/CASA/micasad/verbs/WriteKey.cs @@ -118,7 +118,9 @@ namespace sscs.verbs valLen = BitConverter.ToUInt32(inBuf,(18+(int)keyChainIdLen+(int)secretIdLen+(int)keyLen)); val = new byte[valLen]; Array.Copy(inBuf,(22+keyChainIdLen+secretIdLen+keyLen),val,0,valLen); - valStr = Encoding.UTF8.GetString(val); + valStr = Encoding.UTF8.GetString(val); + + CSSSLogger.DbgLog("Writing Secret:Key [" + secretId + ":" + key + "]"); try { @@ -133,7 +135,8 @@ namespace sscs.verbs if (extId == 1) { -#if W32 +#if W32 + CSSSLogger.DbgLog("LUID ExtID found"); // WINDOWS LUID // This is how the Login Capture module on windows, running as System, sets the Desktop Credential. @@ -142,7 +145,10 @@ namespace sscs.verbs luidLow = BitConverter.ToInt32(inBuf, 26 + ((int)keyChainIdLen)+((int)secretIdLen) +((int)keyLen) + (int)valLen + 8); luidHigh = BitConverter.ToInt32(inBuf, 26 + ((int)keyChainIdLen)+((int)secretIdLen) +((int)keyLen) + (int)valLen + 12); tempUserId = new WinUserIdentifier(luidLow, luidHigh); - SecretStore ss = SessionManager.CreateUserSession(tempUserId); + SecretStore ss = SessionManager.CreateUserSession(tempUserId); + + CSSSLogger.DbgLog("Switching LUID to [" + luidHigh.ToString() + "][" + luidLow.ToString() + "]"); + try { ss.AddKeyChain(new KeyChain("SSCS_SESSION_KEY_CHAIN_ID\0"));