From 227792602930704cd0b17eb93e0b3e58f58f6b52 Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Wed, 1 Feb 2006 15:57:13 +0000 Subject: [PATCH] Reverse order on close calls on filestream and cryptstream. Change lazy write of cache to 15 seconds from 30 seconds. --- c_micasad/lss/CASACrypto.cs | 70 ++++++++++++++++++++--------------- c_micasad/lss/LocalStorage.cs | 2 +- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/c_micasad/lss/CASACrypto.cs b/c_micasad/lss/CASACrypto.cs index 76308d83..2ce1de4d 100644 --- a/c_micasad/lss/CASACrypto.cs +++ b/c_micasad/lss/CASACrypto.cs @@ -92,11 +92,11 @@ namespace sscs.crypto CSSSLogger.ExpLog(e.ToString()); CSSSLogger.DbgLog("Unable to store the generated key"); bRet = false; - } + } + if (csEncrypt != null) + csEncrypt.Close(); if( fsEncrypt != null ) fsEncrypt.Close(); - if( csEncrypt != null ) - csEncrypt.Close(); return bRet; } @@ -137,9 +137,9 @@ namespace sscs.crypto { if(storedHash[i] != newHash[i]) { - CSSSLogger.DbgLog("Hash doesnot match"); - fsDecrypt.Close(); + CSSSLogger.DbgLog("Hash doesnot match"); csDecrypt.Close(); + fsDecrypt.Close(); return null; } } @@ -149,12 +149,16 @@ namespace sscs.crypto CSSSLogger.ExpLog(e.ToString()); CSSSLogger.DbgLog("Unable to get the stored key"); baSavedKey = null; - } + } + + + if (csDecrypt != null) + csDecrypt.Close(); + if ( fsDecrypt != null ) fsDecrypt.Close(); - if( csDecrypt != null ) - csDecrypt.Close(); + return baSavedKey; } @@ -198,11 +202,11 @@ namespace sscs.crypto { CSSSLogger.ExpLog(e.ToString()); CSSSLogger.DbgLog("Encrypting and storing to file failed."); - } + } + if (csEncrypt != null) + csEncrypt.Close(); if( fsEncrypt != null ) fsEncrypt.Close(); - if( csEncrypt != null ) - csEncrypt.Close(); } internal static byte[] ReadFileAndDecryptData(byte[] key, @@ -246,29 +250,29 @@ namespace sscs.crypto { if(storedHash[i] != newHash[i]) { - CSSSLogger.DbgLog("Hash doesnot match"); - fsDecrypt.Close(); + CSSSLogger.DbgLog("Hash doesnot match"); csDecrypt.Close(); + fsDecrypt.Close(); return null; } - } - - fsDecrypt.Close(); + } + csDecrypt.Close(); + fsDecrypt.Close(); return tmpEncrypt; } catch(Exception e) { Console.WriteLine(e.ToString()); + } + if (csDecrypt != null) + { + csDecrypt.Close(); } if( fsDecrypt != null ) { fsDecrypt.Close(); - } - if( csDecrypt != null ) - { - csDecrypt.Close(); - } + } return null; } @@ -394,22 +398,23 @@ namespace sscs.crypto //Write all data to the crypto stream and flush it. csEncrypt.Write(baMasterPasscode, 0, baMasterPasscode.Length); - csEncrypt.FlushFinalBlock(); - fsEncrypt.Close(); + csEncrypt.FlushFinalBlock(); csEncrypt.Close(); + fsEncrypt.Close(); } catch(Exception e) { CSSSLogger.ExpLog(e.ToString()); + } + if (csEncrypt != null) + { + csEncrypt.Close(); } if( fsEncrypt != null ) { fsEncrypt.Close(); } - if( csEncrypt != null ) - { - csEncrypt.Close(); - } + } public static byte[] DecryptMasterPasscodeUsingString(string passwd, @@ -443,10 +448,15 @@ namespace sscs.crypto CSSSLogger.DbgLog("Unable to decrypt master passode"); baSavedMasterPasscode = null; } - if( fsDecrypt != null ) - fsDecrypt.Close(); - if( csDecrypt != null ) + + + if (csDecrypt != null) csDecrypt.Close(); + + if ( fsDecrypt != null ) + fsDecrypt.Close(); + + return baSavedMasterPasscode; } diff --git a/c_micasad/lss/LocalStorage.cs b/c_micasad/lss/LocalStorage.cs index b163a824..56815376 100644 --- a/c_micasad/lss/LocalStorage.cs +++ b/c_micasad/lss/LocalStorage.cs @@ -286,7 +286,7 @@ namespace sscs.lss private void PersistStoreDelayThreadFn() { - Thread.Sleep(30000); + Thread.Sleep(15000); PersistStore(); persistThread = null; }