diff --git a/c_micasad/cache/SecretStore.cs b/c_micasad/cache/SecretStore.cs index 5012b00a..da1d06ce 100644 --- a/c_micasad/cache/SecretStore.cs +++ b/c_micasad/cache/SecretStore.cs @@ -501,6 +501,13 @@ namespace sscs.cache return false; } + + internal void UpdatePersistentStore() + { + if (lss != null) + lss.PersistStoreWithDelay(); + } + /* This function would need to do any storage/cleanup required * before removing a user session. */ diff --git a/c_micasad/lss/LocalStorage.cs b/c_micasad/lss/LocalStorage.cs index af43f1e3..9b4ffc43 100644 --- a/c_micasad/lss/LocalStorage.cs +++ b/c_micasad/lss/LocalStorage.cs @@ -48,8 +48,6 @@ namespace sscs.lss m_baGeneratedKey = baMasterPasscode; LoadPersistentStore(); userStore.DumpSecretstore(); - persistThread = new Thread(new ThreadStart(PersistStoreThreadFn)); - persistThread.Start(); } ~LocalStorage() { @@ -68,22 +66,29 @@ namespace sscs.lss m_baGeneratedKey = baMasterPasscode; LoadPersistentStore(); userStore.DumpSecretstore(); - persistThread = new Thread(new ThreadStart(PersistStoreThreadFn)); - persistThread.Start(); } - public void StorePersistentData(string sDataID, byte[] baData) + private void StorePersistentData(string sDataID, byte[] baData) { } - public byte[] RetrievePersistentData(string sDataID) + private byte[] RetrievePersistentData(string sDataID) { return null; } + public void PersistStoreWithDelay() + { + if (persistThread == null) + { + persistThread = new Thread(new ThreadStart(PersistStoreDelayThreadFn)); + persistThread.Start(); + } + } + public bool StopPersistence() { if(persistThread != null) @@ -246,6 +251,13 @@ namespace sscs.lss return true; } + private void PersistStoreDelayThreadFn() + { + Thread.Sleep(30000); + PersistStore(); + persistThread = null; + } + private void PersistStoreThreadFn() { while(true) @@ -264,12 +276,6 @@ namespace sscs.lss // userStore.DumpSecretstore(); try { - string fileName = userStore.GetPersistenceFilePath(); - - if(File.Exists(fileName)) - { - File.Delete(fileName); - } MemoryStream ms1 = new MemoryStream(); XmlTextWriter writer = new XmlTextWriter(ms1,null); @@ -384,8 +390,24 @@ namespace sscs.lss writer.Flush(); writer.Close(); - byte[] key = CASACrypto.GetKeySetFromFile(CASACrypto.GetMasterPasscode(userStore.GetDesktopPasswd(),userStore.GetPasscodeByDesktopFilePath()),userStore.GetKeyFilePath()); + //byte[] key = CASACrypto.GetKeySetFromFile(CASACrypto.GetMasterPasscode(userStore.GetDesktopPasswd(),userStore.GetPasscodeByDesktopFilePath()),userStore.GetKeyFilePath()); + byte[] key = CASACrypto.GetKeySetFromFile(m_baGeneratedKey, userStore.GetKeyFilePath()); + + string fileName = userStore.GetPersistenceFilePath(); + + // rename existing file + if(File.Exists(fileName)) + { + File.Move(fileName, fileName+".tmp"); + } + CASACrypto.EncryptDataAndWriteToFile(ms1.ToArray(),key,fileName); + + //remove temp + if(File.Exists(fileName+".tmp")) + { + File.Delete(fileName+".tmp"); + } } catch(Exception e) { diff --git a/c_micasad/micasad.csproj b/c_micasad/micasad.csproj index a77dd058..e9ddd470 100644 --- a/c_micasad/micasad.csproj +++ b/c_micasad/micasad.csproj @@ -300,7 +300,7 @@ />