From 87082fbdb2e00aa6446495b6070555d12d697c58 Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Wed, 14 Feb 2007 16:00:42 +0000 Subject: [PATCH] Pass ssFlags from NDK to micasad on WriteBinaryKey. Needed by AuthToken. --- CASA/micasacache/sscs_unx_ipc_client.c | 5 ++- CASA/micasad/cache/KeyValue.cs | 19 ++++++++-- CASA/micasad/common/Constants.cs | 10 +++++- CASA/micasad/lss/LocalStorage.cs | 2 +- CASA/micasad/verbs/WriteBinaryKey.cs | 48 +++++++++++++++++--------- 5 files changed, 62 insertions(+), 22 deletions(-) diff --git a/CASA/micasacache/sscs_unx_ipc_client.c b/CASA/micasacache/sscs_unx_ipc_client.c index 3d0d41af..e09dea62 100644 --- a/CASA/micasacache/sscs_unx_ipc_client.c +++ b/CASA/micasacache/sscs_unx_ipc_client.c @@ -3621,7 +3621,8 @@ int ipc_WriteBinaryKey if(epPassword == NULL) epPassword = &myPassword; - msgLen = MSGID_LEN + MSG_LEN + + msgLen = MSGID_LEN + MSG_LEN + + MSG_STRING_LEN + // ssFlags length MSG_STRING_LEN + // KeychainID length keychainIDLen + // Keychain ID MSG_STRING_LEN + // SecretID length @@ -3687,6 +3688,8 @@ int ipc_WriteBinaryKey pReq += MSGID_LEN; memcpy(pReq, &msgLen, MSG_LEN); pReq += MSG_LEN; + memcpy(pReq, &ssFlags, MSG_STRING_LEN); + pReq += MSG_STRING_LEN; memcpy(pReq, &keychainIDLen, MSG_STRING_LEN); pReq += MSG_STRING_LEN; memcpy(pReq,keychainID->keychainID,keychainIDLen ); diff --git a/CASA/micasad/cache/KeyValue.cs b/CASA/micasad/cache/KeyValue.cs index 9476ffc2..55294d64 100644 --- a/CASA/micasad/cache/KeyValue.cs +++ b/CASA/micasad/cache/KeyValue.cs @@ -33,9 +33,22 @@ namespace sscs.cache public static int VALUE_TYPE_STRING = 0; public static int VALUE_TYPE_BINARY = 1; - private int m_iValueType = VALUE_TYPE_STRING; - - private string m_key; + private int m_iValueType = VALUE_TYPE_STRING; + + private bool m_IsPersistent = true; + public bool IsPersistent + { + get + { + return m_IsPersistent; + } + set + { + m_IsPersistent = value; + } + } + + private string m_key; public string Key { get diff --git a/CASA/micasad/common/Constants.cs b/CASA/micasad/common/Constants.cs index 405cb271..11badee3 100644 --- a/CASA/micasad/common/Constants.cs +++ b/CASA/micasad/common/Constants.cs @@ -54,7 +54,15 @@ namespace sscs.constants internal static int SSCS_SECRET_IS_PERSISTENT = -24; internal static int SSCS_SECRET_IS_NOT_PERSISTENT = -25; internal static int SSCS_SECRET_STORE_IS_LOCKED = -26; - } + } + + class SSFLAGS + { + // used internally by WriteBinaryKey + // these are not published in the NDK + internal static int FLAG_PERSIST = 0x10000000; + internal static int FLAG_DO_NOT_PERSIST = 0x20000000; + } internal class ReqMsgId { diff --git a/CASA/micasad/lss/LocalStorage.cs b/CASA/micasad/lss/LocalStorage.cs index 1e845b11..7e5ce842 100644 --- a/CASA/micasad/lss/LocalStorage.cs +++ b/CASA/micasad/lss/LocalStorage.cs @@ -804,7 +804,7 @@ namespace sscs.lss writer.WriteStartElement(XmlConsts.keyValueNode); - if (bSaveValues) + if (kv.IsPersistent && bSaveValues) { if (kv.GetValueType() == KeyValue.VALUE_TYPE_BINARY) { diff --git a/CASA/micasad/verbs/WriteBinaryKey.cs b/CASA/micasad/verbs/WriteBinaryKey.cs index 18bc39a7..16814fdc 100644 --- a/CASA/micasad/verbs/WriteBinaryKey.cs +++ b/CASA/micasad/verbs/WriteBinaryKey.cs @@ -44,6 +44,7 @@ namespace sscs.verbs private ushort msgId = 0; private uint inMsgLen = 0; private uint outMsgLen = 0; + private uint ssFlags = 0; private uint keyChainIdLen = 0; private uint secretIdLen = 0; private uint secretValLen = 0; @@ -91,38 +92,42 @@ namespace sscs.verbs inMsgLen = BitConverter.ToUInt32(inBuf,2); if( inMsgLen != inBuf.Length ) - throw new FormatException(" MsgLen sent does not match the length of the message received."); + throw new FormatException(" MsgLen sent does not match the length of the message received."); + + // get flags + ssFlags = BitConverter.ToUInt32(inBuf, 6); - keyChainIdLen = BitConverter.ToUInt32(inBuf,6); + // get keychain + keyChainIdLen = BitConverter.ToUInt32(inBuf, 10); byte[] keyChainIdArr = new byte[keyChainIdLen]; - Array.Copy(inBuf,10,keyChainIdArr,0,keyChainIdLen); + Array.Copy(inBuf,14,keyChainIdArr,0,keyChainIdLen); keyChainId = Encoding.UTF8.GetString(keyChainIdArr); secretIdLen = BitConverter.ToUInt32(inBuf, - (10 + (int)keyChainIdLen )); + (14 + (int)keyChainIdLen )); byte[] secretIdArr = new byte[secretIdLen]; - Array.Copy(inBuf,(10+keyChainIdLen+4),secretIdArr,0,secretIdLen); + Array.Copy(inBuf,(14+keyChainIdLen+4),secretIdArr,0,secretIdLen); secretId = Encoding.UTF8.GetString(secretIdArr); if (secretId.IndexOf("*") < 0) { - keyLen = BitConverter.ToUInt32(inBuf,(14+(int)keyChainIdLen+(int)secretIdLen)); + keyLen = BitConverter.ToUInt32(inBuf,(18+(int)keyChainIdLen+(int)secretIdLen)); byte[] keyArr = new byte[keyLen]; - Array.Copy(inBuf,(18+keyChainIdLen+secretIdLen),keyArr,0,keyLen); + Array.Copy(inBuf,(22+keyChainIdLen+secretIdLen),keyArr,0,keyLen); key = Encoding.UTF8.GetString(keyArr); - valLen = BitConverter.ToUInt32(inBuf,(18+(int)keyChainIdLen+(int)secretIdLen+(int)keyLen)); + valLen = BitConverter.ToUInt32(inBuf,(22+(int)keyChainIdLen+(int)secretIdLen+(int)keyLen)); val = new byte[valLen]; - Array.Copy(inBuf,(22+keyChainIdLen+secretIdLen+keyLen),val,0,valLen); + Array.Copy(inBuf,(26+keyChainIdLen+secretIdLen+keyLen),val,0,valLen); try { // get extension ID - int extLocation = 26 + ((int)keyChainIdLen) + ((int)secretIdLen) + ((int)keyLen) + ((int)valLen); + int extLocation = 30 + ((int)keyChainIdLen) + ((int)secretIdLen) + ((int)keyLen) + ((int)valLen); extId = BitConverter.ToUInt32(inBuf, extLocation); } catch (Exception) @@ -138,8 +143,8 @@ namespace sscs.verbs // This is how the Login Capture module on windows, running as System, sets the Desktop Credential. // we might be able to change this if/when we abstract the session. // [4 byte extID][4 byte length][4 byte luidLow][4 byte luidHigh] - 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); + luidLow = BitConverter.ToInt32(inBuf, 30 + ((int)keyChainIdLen)+((int)secretIdLen) +((int)keyLen) + (int)valLen + 8); + luidHigh = BitConverter.ToInt32(inBuf, 30 + ((int)keyChainIdLen)+((int)secretIdLen) +((int)keyLen) + (int)valLen + 12); tempUserId = new WinUserIdentifier(luidLow, luidHigh); SecretStore ss = SessionManager.CreateUserSession(tempUserId); try @@ -180,12 +185,23 @@ namespace sscs.verbs (ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME == key) ) { - KeyValue kv = secret.GetKeyValue(ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME); - if( null != kv ) - oldPasswd = kv.GetValue(); + KeyValue kvDesktop = secret.GetKeyValue(ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME); + if (null != kvDesktop) + oldPasswd = kvDesktop.GetValue(); } - secret.SetKeyValue(key,val); + secret.SetKeyValue(key,val); + + KeyValue kv = secret.GetKeyValue(key); + if ((ssFlags & SSFLAGS.FLAG_DO_NOT_PERSIST) == SSFLAGS.FLAG_DO_NOT_PERSIST) + { + kv.IsPersistent = false; + } + else + { + kv.IsPersistent = true; + } + if((ConstStrings.MICASA_DESKTOP_PASSWD == secretId) && (ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME == key)