From d100d3d36f05366b5e42b2477fdff8ed0635dd99 Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Mon, 31 Oct 2005 20:21:32 +0000 Subject: [PATCH] Improve persistence experience for the user --- c_micasad/cache/SecretStore.cs | 54 +++++++++++++++++++------- c_micasad/lib/common/WrappedObject.cs | 2 +- c_micasad/lss/LocalStorage.cs | 7 +++- c_micasad/verbs/ObjectSerialization.cs | 3 +- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/c_micasad/cache/SecretStore.cs b/c_micasad/cache/SecretStore.cs index da1d06ce..e1b76480 100644 --- a/c_micasad/cache/SecretStore.cs +++ b/c_micasad/cache/SecretStore.cs @@ -149,9 +149,16 @@ namespace sscs.cache CSSSLogger.DbgLog("StartPersistenceByDesktopPasswd - Started"); return true; } + if(!File.Exists(GetPasscodeByDesktopFilePath())) - { + { + if (File.Exists(GetPasscodeByMasterPasswdFilePath())) + { + // wait for the user to start the Persistence by entering MP + return false; + } + //Else passcode needs to be generated. baPasscode = CASACrypto.GenerateMasterPasscodeUsingString( desktopPasswd, @@ -164,19 +171,12 @@ namespace sscs.cache if(!File.Exists(GetKeyFilePath())) { - RijndaelManaged myRijndael = new RijndaelManaged(); - byte[] key; - byte[] IV = new byte[16]; - //Create a new key and initialization vector. - myRijndael.GenerateKey(); - key = myRijndael.Key; - CASACrypto.StoreKeySetUsingMasterPasscode(key,IV, - baPasscode, - GetKeyFilePath()); + GenerateAndStoreEncryptionKey(baPasscode); + lss = new LocalStorage(this,baPasscode); + bIsStorePersistent = true; + return true; } - lss = new LocalStorage(this,baPasscode); - bIsStorePersistent = true; - return true; + } baPasscode = CASACrypto.GetMasterPasscodeUsingDesktopPasswd(desktopPasswd, GetPasscodeByDesktopFilePath()); if(baPasscode != null) @@ -209,6 +209,29 @@ namespace sscs.cache return false; } + internal bool GenerateAndStoreEncryptionKey(byte[] baPasscode) + { + RijndaelManaged myRijndael = new RijndaelManaged(); + byte[] key; + byte[] IV = new byte[16]; + //Create a new key and initialization vector. + try + { + myRijndael.GenerateKey(); + key = myRijndael.Key; + + CASACrypto.StoreKeySetUsingMasterPasscode(key,IV, + baPasscode, + GetKeyFilePath()); + } + catch (Exception e) + { + return false; + } + return true; + } + + internal bool SetMasterPassword(string mPasswdFromIDK) { try @@ -288,6 +311,11 @@ namespace sscs.cache baPasscode = CASACrypto.GenerateMasterPasscodeUsingString(mPasswd,GetPasscodeByMasterPasswdFilePath(),GetValidationFilePath(), user.UserIdentifier); if(baPasscode != null) { + if(!File.Exists(GetKeyFilePath())) + { + GenerateAndStoreEncryptionKey(baPasscode); + } + CASACrypto.EncryptAndStoreMasterPasscodeUsingString(baPasscode,mPasswd,GetPasscodeByMasterPasswdFilePath()); if( bIsStorePersistent == false ) { diff --git a/c_micasad/lib/common/WrappedObject.cs b/c_micasad/lib/common/WrappedObject.cs index 0a6b24d3..5d1060b3 100644 --- a/c_micasad/lib/common/WrappedObject.cs +++ b/c_micasad/lib/common/WrappedObject.cs @@ -39,7 +39,7 @@ namespace Novell.CASA.MiCasa.Common if (sSecretID != null) { if (sSecretID.StartsWith("SS_CredSet")) - m_SecretID = "SS_CredSet:" + EscapeReservedChars(sSecretID.Substring(12)) + '\0'; + m_SecretID = "SS_CredSet:" + EscapeReservedChars(sSecretID.Substring(11)) + '\0'; else m_SecretID = "SS_CredSet:" + EscapeReservedChars(sSecretID) + '\0'; } diff --git a/c_micasad/lss/LocalStorage.cs b/c_micasad/lss/LocalStorage.cs index 694fd4a3..7a4920e0 100644 --- a/c_micasad/lss/LocalStorage.cs +++ b/c_micasad/lss/LocalStorage.cs @@ -116,7 +116,12 @@ namespace sscs.lss if (File.Exists(fileName+".tmp")) File.Delete(fileName+".tmp"); - byte[] baPasscode = CASACrypto.GetMasterPasscode(userStore.GetDesktopPasswd(),userStore.GetPasscodeByDesktopFilePath()); + byte[] baPasscode = null; + if (null != m_baGeneratedKey) + baPasscode = m_baGeneratedKey; + else + baPasscode = CASACrypto.GetMasterPasscode(userStore.GetDesktopPasswd(),userStore.GetPasscodeByDesktopFilePath()); + if( null == baPasscode ) return null; diff --git a/c_micasad/verbs/ObjectSerialization.cs b/c_micasad/verbs/ObjectSerialization.cs index adca384e..15da1b2a 100644 --- a/c_micasad/verbs/ObjectSerialization.cs +++ b/c_micasad/verbs/ObjectSerialization.cs @@ -25,7 +25,6 @@ namespace sscs.verbs private ushort msgId = 0; private uint inMsgLen = 0; - private byte[] inBuf; private byte[] outBuf; @@ -657,7 +656,7 @@ namespace sscs.verbs private WrappedObject DoPing(WrappedObject wo) { - Console.WriteLine("MICASAD received Ping from Client"); + //Console.WriteLine("MICASAD received Ping from Client"); wo.SetError(IPCRetCodes.SSCS_REPLY_SUCCESS, null); Ping ping = (Ping)wo.GetObject();