using System; using System.Collections; using System.Text; using System.Threading; using sscs.verbs; using sscs.cache; using sscs.common; using sscs.constants; namespace sscs.verbs { /* * This class is implementation of OpenSecretStore call. * There will be one instance existing for every call made by the client. */ internal class OpenSecretStore : SSVerb { ushort msgId = 0; uint inMsgLen = 0; uint outMsgLen = 0; uint ssVersion = 0; uint ssNameLen = 0; private string ssName; //Name of SecretStore to open private byte[] inBuf; private byte[] outBuf; int retCode = 0; /* * This method sets the class member with the byte array received. */ public void SetMessageContent(byte[] ipcBytes) { CSSSLogger.ExecutionTrace(this); inBuf = ipcBytes; } /* * This method does the actual implementation of OpenSecretStore * */ public byte[] ProcessRequest(UserIdentifier userId) { /* If an exception occurs in message format decoding, * it is handled by AppHandler */ CSSSLogger.ExecutionTrace(this); msgId = BitConverter.ToUInt16(inBuf,0); inMsgLen = BitConverter.ToUInt32(inBuf,2); if( inMsgLen != inBuf.Length ) throw new FormatException(" MsgLen sent does not match the length of the message received."); ssVersion = BitConverter.ToUInt32(inBuf,6); ssNameLen = BitConverter.ToUInt32(inBuf,10); byte[] tempArr = new byte[ssNameLen]; Array.Copy(inBuf,14,tempArr,0,ssNameLen); ssName = Encoding.UTF8.GetString(tempArr); try { SecretStore ss = SessionManager.CreateUserSession(userId); if( null == ss ) { CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " SecretStore instance is null"); retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR; } else { CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " + - Created a new Session entry"); } } catch(Exception e) { CSSSLogger.ExpLog(e.ToString()); retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR; } try { msgId = 1; outMsgLen = 14; outBuf = new byte[14]; byte[] t = new byte[10]; t = BitConverter.GetBytes((ushort)msgId); Array.Copy(t,0,outBuf,0,2); t = BitConverter.GetBytes((uint)outMsgLen); Array.Copy(t,0,outBuf,2,4); t = BitConverter.GetBytes((uint)ssVersion); Array.Copy(t,0,outBuf,6,4); t = BitConverter.GetBytes(retCode); Array.Copy(t,0,outBuf,10,4); } catch(Exception e) { CSSSLogger.ExpLog(e.ToString()); throw new FormatException("Unable to form the response " + e.ToString()); } return outBuf; } /* * Gives the name of operation performed. Will be used in case * of error. */ public string GetVerbName() { CSSSLogger.ExecutionTrace(this); return this.ToString(); } } }