using System; using System.Collections; using System.Text; using System.Threading; using sscs.verbs; using sscs.common; using sscs.cache; using sscs.constants; namespace sscs.verbs { /* * This class is implementation of RemoveSecret call. * There will be one instance existing for every call made by the client. */ internal class RemoveSecret : SSVerb { private ushort msgId = 0; private uint inMsgLen = 0; private uint outMsgLen = 0; private uint keyChainIdLen = 0; private uint secretIdLen = 0; private int retCode = 0; private string keyChainId; private string secretId; private byte[] inBuf; private byte[] outBuf; /* * 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 RemoveSecret * */ public byte[] ProcessRequest(UserIdentifier userId) { CSSSLogger.ExecutionTrace(this); /* If an exception occurs in message format decoding, * it is handled by AppHandler */ // Message Format decipher - Start 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."); keyChainIdLen = BitConverter.ToUInt32(inBuf,6); byte[] keyChainIdArr = new byte[keyChainIdLen]; Array.Copy(inBuf,10,keyChainIdArr,0,keyChainIdLen); keyChainId = Encoding.UTF8.GetString(keyChainIdArr); secretIdLen = BitConverter.ToUInt32(inBuf, (10 + (int)keyChainIdLen)); byte[] secretIdArr = new byte[secretIdLen]; Array.Copy(inBuf,(10+keyChainIdLen+4),secretIdArr,0,secretIdLen); secretId = Encoding.UTF8.GetString(secretIdArr); // Message Format decipher - End try { SecretStore ssStore = SessionManager.GetUserSecretStore(userId); if( ssStore.CheckIfKeyChainExists(keyChainId) ) { KeyChain keyChain = ssStore.GetKeyChain(keyChainId); if( keyChain.CheckIfSecretExists(secretId) == false) { retCode = IPCRetCodes.SSCS_E_SECRETID_DOES_NOT_EXIST; } else { // TODO: get the secret and remove linked keys keyChain.RemoveSecret(secretId); } } else { retCode = IPCRetCodes.SSCS_E_KEYCHAIN_DOES_NOT_EXIST; } } catch(UserNotInSessionException) { CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable to get user's secretstore" ); retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR; } catch(Exception) { CSSSLogger.DbgLog( "In " + CSSSLogger.GetExecutionPath(this) + " - Secret ID not present" + secretId); retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR; } // Construct a Reply try { msgId = 10; outMsgLen = 10; outBuf = new byte[outMsgLen]; 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(retCode); Array.Copy(t,0,outBuf,6,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(); } } }