Change Persist Thread to a 30 Second delayed, run once on changes.

This commit is contained in:
Jim Norman 2005-10-27 19:24:13 +00:00
parent bb67a93ec8
commit 2483c16c08
7 changed files with 55 additions and 16 deletions

View File

@ -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.
*/

View File

@ -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)
{

View File

@ -300,7 +300,7 @@
/>
<File
RelPath = "init\ProjectInstaller.cs"
SubType = "Code"
SubType = "Component"
BuildAction = "Compile"
/>
<File
@ -310,7 +310,7 @@
/>
<File
RelPath = "init\WinSecretStoreClientService.cs"
SubType = "Code"
SubType = "Component"
BuildAction = "Compile"
/>
<File

View File

@ -208,7 +208,9 @@ namespace sscs.verbs
{
KeyChain kc = ssStore.GetKeyChain(sKeyChainID);
kc.RemoveAllSecrets();
ssStore.UpdatePersistentStore();
}
return wo;
}
@ -243,7 +245,8 @@ namespace sscs.verbs
{
secret = keyChain.GetSecret(secretID);
secret.RemoveKeyValue(keyID);
wo.SetError(constants.RetCodes.SUCCESS, null);
wo.SetError(constants.RetCodes.SUCCESS, null);
ssStore.UpdatePersistentStore();
}
}
catch (Exception e)
@ -348,6 +351,7 @@ namespace sscs.verbs
ChangeLinkedKeys(keyChain, secret, keyID, sValue);
wo.SetError(constants.RetCodes.SUCCESS, null);
ssStore.UpdatePersistentStore();
}
else
wo.SetError(constants.RetCodes.FAILURE, null);
@ -392,6 +396,7 @@ namespace sscs.verbs
// now call the traget to change it's linked ones
ChangeLinkedKeys(keyChain, targetSecret, key, valStr);
}
}
}
@ -613,6 +618,7 @@ namespace sscs.verbs
Secret targetSecret = keyChain.GetSecret(lki.GetLinkedSecretID());
KeyValue targetkv = targetSecret.GetKeyValue(lki.GetLinkedKeyID());
targetkv.RemoveLink(secretID+":"+keyID);
ssStore.UpdatePersistentStore();
return wo;
}
@ -638,6 +644,7 @@ namespace sscs.verbs
Secret target = keyChain.GetSecret(lki.GetLinkedSecretID());
KeyValue targetkv = target.GetKeyValue(lki.GetLinkedKeyID());
targetkv.AddLink(new LinkedKeyInfo(secretID, keyID));
ssStore.UpdatePersistentStore();
}
catch (Exception e)
{

View File

@ -87,6 +87,7 @@ namespace sscs.verbs
{
// TODO: get the secret and remove linked keys
keyChain.RemoveSecret(secretId);
ssStore.UpdatePersistentStore();
}
}
else

View File

@ -187,6 +187,7 @@ namespace sscs.verbs
// Now change all values for linked keys
ChangeLinkedKeys(keyChain, secret, key, valStr);
ssStore.UpdatePersistentStore();
}
else

View File

@ -172,6 +172,7 @@ namespace sscs.verbs
}
}
ssStore.StartPersistenceByDesktopPasswd(passwd);
ssStore.UpdatePersistentStore();
}
}
else