Moving micasa 1.5 trunk to Novell forge.
This commit is contained in:
129
c_micasad/verbs/AddKeyChain.cs
Normal file
129
c_micasad/verbs/AddKeyChain.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
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 AddKeyChain call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class AddKeyChain : SSVerb
|
||||
{
|
||||
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint keyChainFlags = 0;
|
||||
private uint keyChainIdLen = 0;
|
||||
private string keyChainId;
|
||||
private uint outMsgLen = 0;
|
||||
private byte[] inBuf;
|
||||
private byte[] outBuf;
|
||||
private 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 AddKeyChain
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
|
||||
/* If an exception occurs in message format decoding,
|
||||
* it is handled by AppHandler
|
||||
*/
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
|
||||
// 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.");
|
||||
|
||||
keyChainFlags = BitConverter.ToUInt32(inBuf,6);
|
||||
keyChainIdLen = BitConverter.ToUInt32(inBuf,10);
|
||||
byte[] tempArr = new byte[keyChainIdLen];
|
||||
Array.Copy(inBuf,14,tempArr,0,keyChainIdLen);
|
||||
keyChainId = Encoding.UTF8.GetString(tempArr);
|
||||
// Message Format decipher - End
|
||||
|
||||
try
|
||||
{
|
||||
SecretStore ssStore = null;
|
||||
KeyChain keyChain = null;
|
||||
keyChain = new KeyChain(keyChainId);
|
||||
|
||||
ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
if( ssStore.CheckIfKeyChainExists(keyChainId) == false )
|
||||
{
|
||||
ssStore.AddKeyChain(keyChain);
|
||||
}
|
||||
else
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Keychain already present for keychain id " +keyChainId );
|
||||
retCode = IPCRetCodes.SSCS_E_KEYCHAIN_ALREADY_EXISTS;
|
||||
}
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable to get user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 5;
|
||||
outMsgLen = 10;
|
||||
outBuf = new byte[10];
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
117
c_micasad/verbs/CloseSecretStore.cs
Normal file
117
c_micasad/verbs/CloseSecretStore.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
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 CloseSecretStore call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class CloseSecretStore : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private byte[] inBuf;
|
||||
|
||||
private byte[] outBuf;
|
||||
private 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 CloseSecretStore
|
||||
*
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
/* If an exception occurs in message format decoding,
|
||||
* it is handled by AppHandler
|
||||
*/
|
||||
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
// 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.");
|
||||
|
||||
uint ssFlags = BitConverter.ToUInt32(inBuf,6);
|
||||
// Message Format decipher - End
|
||||
|
||||
try
|
||||
{
|
||||
if ((ssFlags & ConstFlags.SSFLAGS_DESTROY_SESSION_F) == ConstFlags.SSFLAGS_DESTROY_SESSION_F)
|
||||
{
|
||||
#if W32
|
||||
SessionManager.RemoveUserSession(userId, true);
|
||||
#else
|
||||
SessionManager.CheckAndDestroySession(userId, true);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
SessionManager.RemoveUserSession(userId, false);
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Exception encountered in removing user session.");
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
|
||||
// Construct a Reply.
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 2;
|
||||
outMsgLen = 10;
|
||||
outBuf = new byte[10];
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
131
c_micasad/verbs/EnumerateKeyChainIds.cs
Normal file
131
c_micasad/verbs/EnumerateKeyChainIds.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
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 EnumerateKeyChainIds call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class EnumerateKeyChainIds : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private int retCode = 0;
|
||||
|
||||
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 EnumerateKeyChainIds
|
||||
*
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
int keyChainIdsLen = 0;
|
||||
StringBuilder keyChainIds = new StringBuilder();
|
||||
/* 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.");
|
||||
|
||||
// Message Format decipher - End
|
||||
try
|
||||
{
|
||||
int index = 0;
|
||||
SecretStore ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
int numKeyChains = ssStore.GetNumKeyChains();
|
||||
IDictionaryEnumerator etor = (IDictionaryEnumerator)ssStore.GetKeyChainEnumerator();
|
||||
while(etor.MoveNext())
|
||||
{
|
||||
index++;
|
||||
keyChainIds.Append((string)etor.Key,0,(((string)(etor.Key)).Length)-1);
|
||||
keyChainIdsLen += ((string)(etor.Key)).Length-1;
|
||||
if( index != numKeyChains )
|
||||
{
|
||||
keyChainIds.Append("*");
|
||||
keyChainIdsLen += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable to get user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
// Construct a Reply.
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 4;
|
||||
outMsgLen = 14 + (uint)keyChainIds.Length;
|
||||
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(keyChainIdsLen);
|
||||
Array.Copy(t,0,outBuf,6,4);
|
||||
|
||||
Encoding.UTF8.GetBytes(keyChainIds.ToString(),0,keyChainIds.Length,outBuf,10);
|
||||
|
||||
t = BitConverter.GetBytes(retCode);
|
||||
Array.Copy(t,0,outBuf,(10+keyChainIds.Length),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()
|
||||
{
|
||||
return this.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
147
c_micasad/verbs/EnumerateSecretIds.cs
Normal file
147
c_micasad/verbs/EnumerateSecretIds.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
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 EnumerateSecretIds call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class EnumerateSecretIds : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private uint keyChainIdLen = 0;
|
||||
private string keyChainId;
|
||||
|
||||
private int retCode = 0;
|
||||
|
||||
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 EnumerateSecretIds
|
||||
*
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
/* If an exception occurs in message format decoding,
|
||||
* it is handled by AppHandler
|
||||
*/
|
||||
|
||||
int secretIdsLen = 0;
|
||||
StringBuilder secretIds = new StringBuilder();
|
||||
// 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);
|
||||
|
||||
// Message Format decipher - End
|
||||
try
|
||||
{
|
||||
SecretStore ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
if( ssStore.CheckIfKeyChainExists(keyChainId) )
|
||||
{
|
||||
KeyChain keyChain = ssStore.GetKeyChain(keyChainId);
|
||||
int numSecrets = keyChain.GetNumSecrets();
|
||||
int index = 0;
|
||||
IDictionaryEnumerator etor = (IDictionaryEnumerator)keyChain.GetAllSecrets();
|
||||
while(etor.MoveNext())
|
||||
{
|
||||
index++;
|
||||
secretIds.Append((string)etor.Key,0,(((string)(etor.Key)).Length)-1);
|
||||
secretIdsLen += ((string)(etor.Key)).Length-1;
|
||||
if( index != numSecrets )
|
||||
{
|
||||
secretIds.Append("*");
|
||||
secretIdsLen += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
//Construct a reply.
|
||||
try
|
||||
{
|
||||
msgId = 7;
|
||||
|
||||
outMsgLen = 14 + (uint)secretIds.Length;
|
||||
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(secretIdsLen);
|
||||
Array.Copy(t,0,outBuf,6,4);
|
||||
|
||||
Encoding.UTF8.GetBytes(secretIds.ToString(),0,secretIds.Length,outBuf,10);
|
||||
|
||||
t = BitConverter.GetBytes(retCode);
|
||||
Array.Copy(t,0,outBuf,(10+secretIds.Length),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();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
c_micasad/verbs/GetSecretStoreInfo.cs
Normal file
120
c_micasad/verbs/GetSecretStoreInfo.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
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 GetSecretStoreInfo call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class GetSecretStoreInfo : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private uint numKeyChains = 0;
|
||||
private byte[] inBuf;
|
||||
private byte[] outBuf;
|
||||
private 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 GetSecretStoreInfo
|
||||
*
|
||||
*/
|
||||
|
||||
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.");
|
||||
|
||||
// Message Format decipher - End
|
||||
|
||||
try
|
||||
{
|
||||
SecretStore ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
numKeyChains = (uint) ssStore.GetNumKeyChains();
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable to get user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
|
||||
// Construct Response
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 11;
|
||||
outMsgLen = 14;
|
||||
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(numKeyChains);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
34
c_micasad/verbs/ISSVerb.cs
Normal file
34
c_micasad/verbs/ISSVerb.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using sscs.verbs;
|
||||
using sscs.common;
|
||||
|
||||
|
||||
namespace sscs.verbs
|
||||
{
|
||||
|
||||
/*
|
||||
* Defines the interfaces to be implemenetd by all Secret Store Verbs.
|
||||
*/
|
||||
interface SSVerb
|
||||
{
|
||||
/* Takes in the raw bytes and sets them for a Verb,
|
||||
* so that the verb will execute in the bytes given.
|
||||
* TBD: In case we are able to send the byte[] through constructor,
|
||||
* we can avoid this interface.
|
||||
*/
|
||||
|
||||
void SetMessageContent(byte[] rawbytes);
|
||||
|
||||
/* Takes in the SecretStore Reeference and returns the correct SSVerb
|
||||
*/
|
||||
byte[] ProcessRequest(UserIdentifier userId);
|
||||
|
||||
//Gives the name of operation performed.Can be used in case of error.
|
||||
string GetVerbName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
156
c_micasad/verbs/IsSecretPersistent.cs
Normal file
156
c_micasad/verbs/IsSecretPersistent.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
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 IsSecretPersistent call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
class IsSecretPersistent : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private uint keyChainIdLen = 0;
|
||||
private uint secretIdLen = 0;
|
||||
private int ssFlags = 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 IsSecretPersistent
|
||||
*
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
// Message Format decipher - Start
|
||||
msgId = BitConverter.ToUInt16(inBuf,0);
|
||||
inMsgLen = BitConverter.ToUInt32(inBuf,2);
|
||||
ssFlags = BitConverter.ToInt32(inBuf,6);
|
||||
if( inMsgLen != inBuf.Length )
|
||||
throw new FormatException(" MsgLen sent does not match the length of the message received.");
|
||||
if(ssFlags == 0)
|
||||
{
|
||||
keyChainIdLen = BitConverter.ToUInt32(inBuf,10);
|
||||
byte[] keyChainIdArr = new byte[keyChainIdLen];
|
||||
Array.Copy(inBuf,14,keyChainIdArr,0,keyChainIdLen);
|
||||
keyChainId = Encoding.UTF8.GetString(keyChainIdArr);
|
||||
|
||||
secretIdLen = BitConverter.ToUInt32(inBuf,
|
||||
(14 + (int)keyChainIdLen ));
|
||||
|
||||
byte[] secretIdArr = new byte[secretIdLen];
|
||||
Array.Copy(inBuf,(14+keyChainIdLen+4),secretIdArr,0,secretIdLen);
|
||||
secretId = Encoding.UTF8.GetString(secretIdArr);
|
||||
|
||||
}
|
||||
try
|
||||
{
|
||||
KeyChain keyChain = null;
|
||||
SecretStore ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
if(ssFlags != 0)
|
||||
{
|
||||
if(ssStore.IsStorePersistent())
|
||||
retCode = IPCRetCodes.SSCS_STORE_IS_PERSISTENT;
|
||||
else
|
||||
retCode = IPCRetCodes.SSCS_STORE_IS_NOT_PERSISTENT;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ssStore.CheckIfKeyChainExists(keyChainId) )
|
||||
{
|
||||
keyChain = ssStore.GetKeyChain(keyChainId);
|
||||
if( keyChain.CheckIfSecretExists(secretId) == false)
|
||||
{
|
||||
if(ssStore.IsStorePersistent())
|
||||
retCode = IPCRetCodes.SSCS_SECRET_IS_PERSISTENT;
|
||||
else
|
||||
retCode = IPCRetCodes.SSCS_SECRET_IS_NOT_PERSISTENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
retCode = IPCRetCodes.SSCS_E_SECRETID_DOES_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
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 e )
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 19;
|
||||
outMsgLen = 10;
|
||||
outBuf = new byte[10];
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
772
c_micasad/verbs/ObjectSerialization.cs
Normal file
772
c_micasad/verbs/ObjectSerialization.cs
Normal file
@@ -0,0 +1,772 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using sscs.verbs;
|
||||
using sscs.cache;
|
||||
using sscs.common;
|
||||
using sscs.constants;
|
||||
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
|
||||
using Novell.CASA.MiCasa.Common;
|
||||
using Novell.CASA.MiCasa.Communication;
|
||||
|
||||
namespace sscs.verbs
|
||||
{
|
||||
|
||||
/*
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class ObjectSerialization : SSVerb
|
||||
{
|
||||
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
|
||||
|
||||
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 ReadSecret
|
||||
*
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
//Console.WriteLine("Serialization verb: msgId is " + msgId + " inMsgLen = " + inMsgLen + "inBuf.Length is " + inBuf.Length);
|
||||
|
||||
// if( inMsgLen != inBuf.Length )
|
||||
// Console.WriteLine("inMsgLen != inBuf.Length");
|
||||
// throw new FormatException(" MsgLen sent does not match the length of the message received.");
|
||||
|
||||
// deserialize the data
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
MemoryStream ms = new MemoryStream(inBuf, 6, (int)inMsgLen - 6);
|
||||
// MemoryStream ms = new MemoryStream(inBuf, 6, (int)inMsgLen);
|
||||
|
||||
WrappedObject request;
|
||||
WrappedObject reply;
|
||||
try
|
||||
{
|
||||
request = (WrappedObject)formatter.Deserialize(ms);
|
||||
reply = ProcessMessage(request, userId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
reply = new WrappedObject(-1, null);
|
||||
}
|
||||
|
||||
// Serialize the WrappedObject and send the reply
|
||||
ms = new MemoryStream();
|
||||
formatter.Serialize(ms, reply);
|
||||
|
||||
int msLen = (int)ms.Length;
|
||||
outBuf = new byte[4+msLen];
|
||||
byte[] t = new byte[10];
|
||||
|
||||
t = BitConverter.GetBytes(ms.Length);
|
||||
Array.Copy(t,0,outBuf,0,4);
|
||||
Array.Copy(ms.GetBuffer(), 0, outBuf, 4, msLen);
|
||||
SessionManager.RemoveUserSession(userId, false);
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
|
||||
internal WrappedObject ProcessMessage(WrappedObject wo, UserIdentifier userId)
|
||||
{
|
||||
|
||||
//Console.WriteLine("ObjectSerialization Called");
|
||||
SecretStore ssStore = SessionManager.CreateUserSession(userId);
|
||||
|
||||
try
|
||||
{
|
||||
int action = wo.GetAction();
|
||||
switch (action)
|
||||
{
|
||||
case MiCasaRequestReply.VERB_PING_MICASAD:
|
||||
{
|
||||
return DoPing(wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_SET_LINKED_KEY:
|
||||
{
|
||||
return DoSetLinkedKey(ssStore, wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_REMOVE_LINKED_KEY:
|
||||
{
|
||||
return DoRemoveLinkedKey(ssStore, wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_GET_LINKED_KEYS:
|
||||
{
|
||||
return DoGetLinkedKeys(ssStore, wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_CREATE_TEST_SECRETS:
|
||||
{
|
||||
return DoCreateTestSecrets(ssStore, wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_REMOVE_TEST_SECRETS:
|
||||
{
|
||||
return DoRemoveTestSecrets(ssStore, wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_DUMP_LINKED_KEYS:
|
||||
{
|
||||
return DoDumpLinkedKeys(ssStore, wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_WRITE_KEY:
|
||||
{
|
||||
return DoWriteKey(ssStore, wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_LOCK_STORE:
|
||||
{
|
||||
ssStore.LockStore();
|
||||
return wo;
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_UNLOCK_STORE:
|
||||
{
|
||||
return DoUnlockStore(ssStore, wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_REMOVE_ALL_SECRETS:
|
||||
{
|
||||
// stop persistence
|
||||
ssStore.StopPersistence();
|
||||
|
||||
// remove secrets
|
||||
return DoRemoveAllSecrets(ssStore, wo);
|
||||
}
|
||||
|
||||
case MiCasaRequestReply.VERB_GET_STORE_STATUS:
|
||||
{
|
||||
wo.SetObject(ssStore.GetSecretStoreState());
|
||||
return wo;
|
||||
}
|
||||
case MiCasaRequestReply.VERB_REMOVE_KEY:
|
||||
{
|
||||
return DoRemoveKey(ssStore, wo);
|
||||
}
|
||||
case MiCasaRequestReply.VERB_READ_KEY:
|
||||
{
|
||||
return DoReadKey(ssStore, wo);
|
||||
}
|
||||
case MiCasaRequestReply.VERB_GET_KEY_LIST:
|
||||
{
|
||||
return DoGetKeyList(ssStore, wo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE, "Verb Not Supported");
|
||||
return wo;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE, e.ToString());
|
||||
}
|
||||
|
||||
|
||||
return wo;
|
||||
}
|
||||
|
||||
|
||||
private WrappedObject DoRemoveAllSecrets(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
string sKeyChainID = wo.GetKeychainID();
|
||||
if (sKeyChainID != null)
|
||||
{
|
||||
KeyChain kc = ssStore.GetKeyChain(sKeyChainID);
|
||||
kc.RemoveAllSecrets();
|
||||
}
|
||||
return wo;
|
||||
}
|
||||
|
||||
private WrappedObject DoUnlockStore(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
try
|
||||
{
|
||||
ssStore.UnlockStore("Desktop", "Master");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE, e.ToString());
|
||||
}
|
||||
return wo;
|
||||
}
|
||||
private WrappedObject DoRemoveKey(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
try
|
||||
{
|
||||
string keychainID = wo.GetKeychainID();
|
||||
string secretID = wo.GetSecretID();
|
||||
string keyID = wo.GetKeyID();
|
||||
|
||||
KeyChain keyChain = ssStore.GetKeyChain(keychainID);
|
||||
Secret secret = null;
|
||||
if( keyChain.CheckIfSecretExists(secretID) == false)
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE,"Secret does not exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
secret = keyChain.GetSecret(secretID);
|
||||
secret.RemoveKeyValue(keyID);
|
||||
wo.SetError(constants.RetCodes.SUCCESS, null);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE, e.ToString());
|
||||
}
|
||||
|
||||
return wo;
|
||||
}
|
||||
private WrappedObject DoReadKey(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
try
|
||||
{
|
||||
string keychainID = wo.GetKeychainID();
|
||||
string secretID = wo.GetSecretID();
|
||||
string keyID = wo.GetKeyID();
|
||||
|
||||
|
||||
// string sValue = (String)wo.GetObject();
|
||||
|
||||
KeyChain keyChain = ssStore.GetKeyChain(keychainID);
|
||||
Secret secret = null;
|
||||
if( keyChain.CheckIfSecretExists(secretID) == false)
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE,"Secret does not exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
secret = keyChain.GetSecret(secretID);
|
||||
KeyValue kv = secret.GetKeyValue(keyID);
|
||||
string value = kv.GetValue();
|
||||
wo.SetObject(value);
|
||||
wo.SetError(constants.RetCodes.SUCCESS, null);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE, e.ToString());
|
||||
}
|
||||
|
||||
return wo;
|
||||
}
|
||||
private WrappedObject DoGetKeyList(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
try
|
||||
{
|
||||
string keychainID = wo.GetKeychainID();
|
||||
string secretID = wo.GetSecretID();
|
||||
|
||||
|
||||
|
||||
KeyChain keyChain = ssStore.GetKeyChain(keychainID);
|
||||
Secret secret = null;
|
||||
if( keyChain.CheckIfSecretExists(secretID) == false)
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE,"Secret does not exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
secret = keyChain.GetSecret(secretID);
|
||||
if( null != secret )
|
||||
{
|
||||
ArrayList keyList = secret.GetKeyList();
|
||||
wo.SetObject(keyList);
|
||||
wo.SetError(constants.RetCodes.SUCCESS, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE, e.ToString());
|
||||
}
|
||||
|
||||
return wo;
|
||||
}
|
||||
|
||||
private WrappedObject DoWriteKey(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
try
|
||||
{
|
||||
string keychainID = wo.GetKeychainID();
|
||||
string secretID = wo.GetSecretID();
|
||||
string keyID = wo.GetKeyID();
|
||||
string sValue = (String)wo.GetObject();
|
||||
|
||||
KeyChain keyChain = ssStore.GetKeyChain(keychainID);
|
||||
Secret secret;
|
||||
if( keyChain.CheckIfSecretExists(secretID) == false)
|
||||
{
|
||||
secret = new Secret(secretID);
|
||||
keyChain.AddSecret(secret);
|
||||
}
|
||||
else
|
||||
{
|
||||
secret = keyChain.GetSecret(secretID);
|
||||
}
|
||||
secret.SetKeyValue(keyID, sValue);
|
||||
|
||||
ChangeLinkedKeys(keyChain, secret, keyID, sValue);
|
||||
wo.SetError(constants.RetCodes.SUCCESS, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wo.SetError(constants.RetCodes.FAILURE, e.ToString());
|
||||
}
|
||||
|
||||
return wo;
|
||||
|
||||
}
|
||||
|
||||
private void ChangeLinkedKeys(KeyChain keyChain, Secret secret, string key, string valStr)
|
||||
{
|
||||
Hashtable htLinkedkeys = secret.GetLinkedKeys(key);
|
||||
if (htLinkedkeys != null)
|
||||
{
|
||||
// enumerate the hashtable, getting each secret/key and change it's value
|
||||
ICollection coll = htLinkedkeys.Values;
|
||||
IDictionaryEnumerator ienum = (IDictionaryEnumerator)coll.GetEnumerator();
|
||||
|
||||
LinkedKeyInfo linkedInfo; // = (LinkedKeyInfo)ienum.Current;
|
||||
|
||||
while (ienum.MoveNext())
|
||||
{
|
||||
linkedInfo = (LinkedKeyInfo)ienum.Value;
|
||||
|
||||
// Get the target Secret
|
||||
Secret targetSecret = keyChain.GetSecret(linkedInfo.GetLinkedSecretID());
|
||||
if (targetSecret != null)
|
||||
{
|
||||
// get target key value
|
||||
string targetkv = targetSecret.GetKeyValue(linkedInfo.GetLinkedKeyID()).GetValue();
|
||||
|
||||
// if a change is required in the target, then call this method recursively using the TargetSecret
|
||||
if (!targetkv.Equals(valStr))
|
||||
{
|
||||
// NOTE: ORDER IS IMPORTANT
|
||||
// first change this one
|
||||
targetSecret.SetKeyValue(linkedInfo.GetLinkedKeyID(), valStr);
|
||||
|
||||
// now call the traget to change it's linked ones
|
||||
ChangeLinkedKeys(keyChain, targetSecret, key, valStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private WrappedObject DoDumpLinkedKeys(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
// create 2 secrets
|
||||
string keychainID = wo.GetKeychainID();
|
||||
KeyChain keyChain;
|
||||
|
||||
|
||||
Console.WriteLine("\r\n*********Dumping Linked Keys");
|
||||
try
|
||||
{
|
||||
keyChain = ssStore.GetKeyChain(keychainID);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
keyChain = new KeyChain(keychainID);
|
||||
ssStore.AddKeyChain(keyChain);
|
||||
}
|
||||
|
||||
// enumerate all secrets
|
||||
IDictionaryEnumerator ienum = (IDictionaryEnumerator)keyChain.GetAllSecrets();
|
||||
ienum.Reset();
|
||||
while (ienum.MoveNext())
|
||||
{
|
||||
string secretID = (string)ienum.Key;
|
||||
Secret secret = keyChain.GetSecret(secretID);
|
||||
IDictionaryEnumerator idenum = secret.GetKeyValueEnumerator();
|
||||
idenum.Reset();
|
||||
while (idenum.MoveNext())
|
||||
{
|
||||
KeyValue kv = (KeyValue)idenum.Value;
|
||||
Hashtable htLKI = kv.GetLinkedKeys();
|
||||
|
||||
if (htLKI != null)
|
||||
{
|
||||
Console.WriteLine(secret.GetKey() + ":" + kv.Key + " is Linked to");
|
||||
IDictionaryEnumerator htienum = (IDictionaryEnumerator)htLKI.GetEnumerator();
|
||||
htienum.Reset();
|
||||
while (htienum.MoveNext())
|
||||
{
|
||||
LinkedKeyInfo lki = (LinkedKeyInfo) htienum.Value;
|
||||
Console.WriteLine(" " + lki.GetLinkID());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return wo;
|
||||
|
||||
}
|
||||
|
||||
|
||||
string GW = "SS_CredSet:TestGroupwise\0";
|
||||
string IFOLDER = "SS_CredSet:TestiFolder\0";
|
||||
string GWIM = "SS_CredSet:TestGWIM\0";
|
||||
|
||||
private WrappedObject DoRemoveTestSecrets(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
|
||||
string keychainID = wo.GetKeychainID();
|
||||
KeyChain keyChain;
|
||||
|
||||
try
|
||||
{
|
||||
keyChain = ssStore.GetKeyChain(keychainID);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return wo;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
keyChain.RemoveSecret(GW);
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
|
||||
try
|
||||
{
|
||||
keyChain.RemoveSecret(GWIM);
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
|
||||
try
|
||||
{
|
||||
keyChain.RemoveSecret(IFOLDER);
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
|
||||
return wo;
|
||||
|
||||
}
|
||||
|
||||
private WrappedObject DoCreateTestSecrets(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
// create 2 secrets
|
||||
string keychainID = wo.GetKeychainID();
|
||||
KeyChain keyChain;
|
||||
|
||||
try
|
||||
{
|
||||
keyChain = ssStore.GetKeyChain(keychainID);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
keyChain = new KeyChain(keychainID);
|
||||
ssStore.AddKeyChain(keyChain);
|
||||
}
|
||||
|
||||
Secret secret1 = new Secret(GW);
|
||||
secret1.SetKeyValue("CN", "User1");
|
||||
secret1.SetKeyValue("Password", "GWPass");
|
||||
try
|
||||
{
|
||||
keyChain.AddSecret(secret1);
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
|
||||
Secret secret2 = new Secret(IFOLDER);
|
||||
secret2.SetKeyValue("CN", "User2");
|
||||
secret2.SetKeyValue("Password", "IfolderPass");
|
||||
secret2.SetKeyValue("EmployeeID", "123456");
|
||||
try
|
||||
{
|
||||
keyChain.AddSecret(secret2);
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
|
||||
Secret secret3 = new Secret(GWIM);
|
||||
secret3.SetKeyValue("CN", "User3");
|
||||
secret3.SetKeyValue("Password", "GwimPass");
|
||||
try
|
||||
{
|
||||
keyChain.AddSecret(secret3);
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
|
||||
try
|
||||
{
|
||||
// link password fields
|
||||
KeyValue kv = secret1.GetKeyValue("Password");
|
||||
KeyValue kv2 = secret2.GetKeyValue("Password");
|
||||
KeyValue kv3 = secret3.GetKeyValue("Password");
|
||||
|
||||
kv.AddLink(new LinkedKeyInfo(IFOLDER, "Password"));
|
||||
kv2.AddLink(new LinkedKeyInfo(GW, "Password"));
|
||||
|
||||
kv2.AddLink(new LinkedKeyInfo(GWIM, "Password"));
|
||||
kv3.AddLink(new LinkedKeyInfo(IFOLDER, "Password"));
|
||||
|
||||
kv3.AddLink(new LinkedKeyInfo(GW, "Password"));
|
||||
kv.AddLink(new LinkedKeyInfo(GWIM, "Password"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
|
||||
DoDumpLinkedKeys(ssStore, wo);
|
||||
|
||||
return wo;
|
||||
}
|
||||
|
||||
|
||||
private WrappedObject DoGetLinkedKeys(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
string keychainID = wo.GetKeychainID();
|
||||
string secretID = wo.GetSecretID();
|
||||
string keyID = wo.GetKeyID();
|
||||
|
||||
KeyChain keyChain = ssStore.GetKeyChain(keychainID);
|
||||
Secret secret = keyChain.GetSecret(secretID);
|
||||
KeyValue kv = secret.GetKeyValue(keyID);
|
||||
|
||||
wo.SetObject(kv.GetLinkedKeys());
|
||||
wo.SetError(constants.RetCodes.SUCCESS, null);
|
||||
return wo;
|
||||
}
|
||||
|
||||
private WrappedObject DoRemoveLinkedKey(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
|
||||
string keychainID = wo.GetKeychainID();
|
||||
string secretID = wo.GetSecretID();
|
||||
string keyID = wo.GetKeyID();
|
||||
|
||||
KeyChain keyChain = ssStore.GetKeyChain(keychainID);
|
||||
Secret secret = keyChain.GetSecret(secretID);
|
||||
KeyValue kv = secret.GetKeyValue(keyID);
|
||||
|
||||
LinkedKeyInfo lki = (LinkedKeyInfo)wo.GetObject();
|
||||
kv.RemoveLink(lki.GetLinkID());
|
||||
|
||||
// remove reverse link as well
|
||||
Secret targetSecret = keyChain.GetSecret(lki.GetLinkedSecretID());
|
||||
KeyValue targetkv = targetSecret.GetKeyValue(lki.GetLinkedKeyID());
|
||||
targetkv.RemoveLink(secretID+":"+keyID);
|
||||
|
||||
return wo;
|
||||
}
|
||||
|
||||
|
||||
private WrappedObject DoSetLinkedKey(SecretStore ssStore, WrappedObject wo)
|
||||
{
|
||||
|
||||
string keychainID = wo.GetKeychainID();
|
||||
string secretID = wo.GetSecretID();
|
||||
string keyID = wo.GetKeyID();
|
||||
|
||||
KeyChain keyChain = ssStore.GetKeyChain(keychainID);
|
||||
Secret secret = keyChain.GetSecret(secretID);
|
||||
KeyValue kv = secret.GetKeyValue(keyID);
|
||||
|
||||
LinkedKeyInfo lki = (LinkedKeyInfo)wo.GetObject();
|
||||
kv.AddLink(lki);
|
||||
|
||||
// add reverse link
|
||||
try
|
||||
{
|
||||
Secret target = keyChain.GetSecret(lki.GetLinkedSecretID());
|
||||
KeyValue targetkv = target.GetKeyValue(lki.GetLinkedKeyID());
|
||||
targetkv.AddLink(new LinkedKeyInfo(secretID, keyID));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Reverse Link error: " + e.ToString());
|
||||
wo.SetError(constants.RetCodes.FAILURE, "Reverse Link: " + e.ToString());
|
||||
}
|
||||
|
||||
return wo;
|
||||
}
|
||||
|
||||
private WrappedObject DoPing(WrappedObject wo)
|
||||
{
|
||||
Console.WriteLine("MICASAD received Ping from Client");
|
||||
wo.SetError(IPCRetCodes.SSCS_REPLY_SUCCESS, null);
|
||||
|
||||
Ping ping = (Ping)wo.GetObject();
|
||||
ping.servermessage = "MICASAD echos client message: <" + ping.clientmessage + ">";
|
||||
return wo;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
internal WrappedObject ProcessMessage(WrappedObject wo, UserIdentifier userId)
|
||||
{
|
||||
|
||||
Console.WriteLine("ObjectSerialization Called");
|
||||
SecretStore ssStore = SessionManager.CreateUserSession(userId);
|
||||
Secret secret;
|
||||
|
||||
try
|
||||
{
|
||||
keyChainId = wo.GetKeychainID();
|
||||
secretId = wo.GetSecretID();
|
||||
keyId = wo.GetKeyID();
|
||||
|
||||
int action = wo.GetAction();
|
||||
|
||||
if (action == WrappedObject.VERB_PING_MICASAD)
|
||||
{
|
||||
Console.WriteLine("MICASAD received Ping from Client");
|
||||
wo.SetError(IPCRetCodes.SSCS_REPLY_SUCCESS, null);
|
||||
|
||||
Ping ping = (Ping)wo.GetObject();
|
||||
ping.servermessage = "MICASAD echos client message: <" + ping.clientmessage + ">";
|
||||
return wo;
|
||||
}
|
||||
|
||||
else if (action <= WrappedObject.VERB_REMOVE_LINKED_KEY)
|
||||
{
|
||||
|
||||
wo.SetError(IPCRetCodes.SSCS_REPLY_SUCCESS, null);
|
||||
if (action == WrappedObject.VERB_GET_STORE)
|
||||
{
|
||||
wo.SetObject(ssStore);
|
||||
return wo;
|
||||
}
|
||||
|
||||
// look up Keychain
|
||||
KeyChain keyChain = new KeyChain(keyChainId);
|
||||
|
||||
// temporary
|
||||
try
|
||||
{
|
||||
if (true)
|
||||
ssStore.AddKeyChain(keyChain);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if( ssStore.CheckIfKeyChainExists(keyChainId) )
|
||||
{
|
||||
keyChain = ssStore.GetKeyChain(keyChainId);
|
||||
if (action == WrappedObject.VERB_GET_KEYCHAIN)
|
||||
{
|
||||
wo.SetObject(keyChain);
|
||||
return wo;
|
||||
}
|
||||
|
||||
if((action == WrappedObject.VERB_GET_SECRET) && (keyChain.CheckIfSecretExists(secretId) == false))
|
||||
{
|
||||
wo.SetError(IPCRetCodes.SSCS_E_SECRETID_DOES_NOT_EXIST, null);
|
||||
return wo;
|
||||
}
|
||||
else
|
||||
{
|
||||
secret = keyChain.GetSecret(secretId);
|
||||
|
||||
if (action == WrappedObject.VERB_GET_SECRET)
|
||||
{
|
||||
wo.SetObject(secret);
|
||||
return wo;
|
||||
}
|
||||
else if ((action == WrappedObject.VERB_SET_SECRET) && (null != wo.GetObject()))
|
||||
{
|
||||
keyChain.AddSecret((Secret)wo.GetObject());
|
||||
}
|
||||
|
||||
else if (action == WrappedObject.VERB_SET_LINKED_KEY)
|
||||
{
|
||||
KeyValue kv = secret.GetKeyValue(keyId);
|
||||
LinkedKeyInfo lki = (LinkedKeyInfo)wo.GetObject();
|
||||
kv.AddLink(lki);
|
||||
|
||||
// add reverse link
|
||||
try
|
||||
{
|
||||
Secret target = keyChain.GetSecret(lki.GetLinkedSecretID());
|
||||
KeyValue targetkv = target.GetKeyValue(lki.GetLinkedKeyID());
|
||||
targetkv.AddLink(new LinkedKeyInfo(secretId, keyId));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Reverse Link error: " + e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
wo.SetError(IPCRetCodes.SSCS_E_KEYCHAIN_DOES_NOT_EXIST, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
wo.SetError(IPCRetCodes.SSCS_E_SYSTEM_ERROR, "Action not supported");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
String error = e.ToString();
|
||||
Console.WriteLine(error);
|
||||
wo = new WrappedObject(constants.RetCodes.FAILURE, error);
|
||||
}
|
||||
return wo;
|
||||
}
|
||||
*/
|
||||
public string GetVerbName()
|
||||
{
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
return this.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
127
c_micasad/verbs/OpenSecretStore.cs
Normal file
127
c_micasad/verbs/OpenSecretStore.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
181
c_micasad/verbs/ReadKey.cs
Normal file
181
c_micasad/verbs/ReadKey.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
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 ReadKey call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class ReadKey : 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 uint keyLen;
|
||||
private string key;
|
||||
private uint valLen;
|
||||
private byte[] val;
|
||||
|
||||
//private byte[] secretVal;
|
||||
|
||||
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 ReadKey
|
||||
*
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
|
||||
Secret secret = null;
|
||||
|
||||
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
|
||||
|
||||
keyLen = BitConverter.ToUInt32(inBuf,(14+(int)keyChainIdLen+(int)secretIdLen));
|
||||
|
||||
byte[] keyArr = new byte[keyLen];
|
||||
Array.Copy(inBuf,(18+(int)keyChainIdLen+(int)secretIdLen),keyArr,0,keyLen);
|
||||
key = Encoding.UTF8.GetString(keyArr);
|
||||
|
||||
try
|
||||
{
|
||||
KeyChain keyChain = null;
|
||||
// Secret secret = null;
|
||||
SecretStore ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
if (!ssStore.IsStoreLocked())
|
||||
{
|
||||
if( ssStore.CheckIfKeyChainExists(keyChainId) )
|
||||
{
|
||||
keyChain = ssStore.GetKeyChain(keyChainId);
|
||||
if( keyChain.CheckIfSecretExists(secretId) == false)
|
||||
{
|
||||
retCode = IPCRetCodes.SSCS_E_SECRETID_DOES_NOT_EXIST;
|
||||
}
|
||||
else
|
||||
{
|
||||
secret = keyChain.GetSecret(secretId);
|
||||
string valStr = secret.GetKeyValue(key).GetValue();
|
||||
val = Encoding.UTF8.GetBytes(valStr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retCode = IPCRetCodes.SSCS_E_KEYCHAIN_DOES_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
else
|
||||
retCode = IPCRetCodes.SSCS_E_SECRETID_DOES_NOT_EXIST;
|
||||
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 16;
|
||||
if( 0 == retCode )
|
||||
{
|
||||
valLen = (uint)val.Length;
|
||||
outMsgLen = 14 + valLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
outMsgLen = 14; //2+4+4+4
|
||||
}
|
||||
|
||||
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(valLen);
|
||||
Array.Copy(t,0,outBuf,6,4);
|
||||
|
||||
if( 0 == retCode )
|
||||
Array.Copy(val,0,outBuf,10,valLen);
|
||||
|
||||
t = BitConverter.GetBytes(retCode);
|
||||
Array.Copy(t,0,outBuf,10+valLen,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
175
c_micasad/verbs/ReadSecret.cs
Normal file
175
c_micasad/verbs/ReadSecret.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
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 ReadSecret call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class ReadSecret : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private uint keyChainIdLen = 0;
|
||||
private uint secretIdLen = 0;
|
||||
private uint secretValLen = 0;
|
||||
private int retCode = 0;
|
||||
private string keyChainId;
|
||||
private string secretId;
|
||||
//private byte[] secretVal;
|
||||
|
||||
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 ReadSecret
|
||||
*
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
|
||||
Secret secret = null;
|
||||
|
||||
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
|
||||
{
|
||||
KeyChain keyChain = null;
|
||||
// Secret secret = null;
|
||||
SecretStore ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
|
||||
if (!ssStore.IsStoreLocked())
|
||||
{
|
||||
if( ssStore.CheckIfKeyChainExists(keyChainId) )
|
||||
{
|
||||
keyChain = ssStore.GetKeyChain(keyChainId);
|
||||
if( keyChain.CheckIfSecretExists(secretId) == false)
|
||||
{
|
||||
retCode = IPCRetCodes.SSCS_E_SECRETID_DOES_NOT_EXIST;
|
||||
}
|
||||
else
|
||||
{
|
||||
secret = keyChain.GetSecret(secretId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retCode = IPCRetCodes.SSCS_E_KEYCHAIN_DOES_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
else
|
||||
retCode = IPCRetCodes.SSCS_E_SECRETID_DOES_NOT_EXIST;
|
||||
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 8;
|
||||
uint secretValLen = 0;
|
||||
byte[] baSecretValue = new byte[0];
|
||||
|
||||
if( 0 == retCode )
|
||||
{
|
||||
baSecretValue = secret.GetValue(secretId);
|
||||
secretValLen = (uint)baSecretValue.Length;
|
||||
outMsgLen = 14 + secretValLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
outMsgLen = 14; //2+4+4+4
|
||||
}
|
||||
|
||||
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(secretValLen);
|
||||
Array.Copy(t,0,outBuf,6,4);
|
||||
|
||||
if( 0 == retCode )
|
||||
Array.Copy(baSecretValue,0,outBuf,10,secretValLen);
|
||||
|
||||
t = BitConverter.GetBytes(retCode);
|
||||
Array.Copy(t,0,outBuf,10+secretValLen,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
128
c_micasad/verbs/RemoveKeyChain.cs
Normal file
128
c_micasad/verbs/RemoveKeyChain.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using sscs.verbs;
|
||||
using sscs.common;
|
||||
using sscs.constants;
|
||||
using sscs.cache;
|
||||
namespace sscs.verbs
|
||||
{
|
||||
|
||||
/*
|
||||
* This class is implementation of RemoveKeyChain call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class RemoveKeyChain : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private uint keyChainIdLen = 0;
|
||||
private string keyChainId;
|
||||
private int retCode = 0;
|
||||
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 RemoveKeyChain
|
||||
*
|
||||
*/
|
||||
|
||||
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);
|
||||
// Message Format decipher - End
|
||||
|
||||
try
|
||||
{
|
||||
SecretStore ssStore = null;
|
||||
ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
|
||||
if( ssStore.CheckIfKeyChainExists(keyChainId) )
|
||||
{
|
||||
ssStore.RemoveKeyChain(keyChainId);
|
||||
}
|
||||
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 e)
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 6;
|
||||
outMsgLen = 10;
|
||||
outBuf = new byte[10];
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
147
c_micasad/verbs/RemoveSecret.cs
Normal file
147
c_micasad/verbs/RemoveSecret.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
109
c_micasad/verbs/RemoveSecretStore.cs
Normal file
109
c_micasad/verbs/RemoveSecretStore.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
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 RemoveSecretStore call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class RemoveSecretStore : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private byte[] inBuf;
|
||||
|
||||
private byte[] outBuf;
|
||||
private int retCode = 0;
|
||||
|
||||
/*
|
||||
* This method sets the class member with the byte array received.
|
||||
*/
|
||||
|
||||
public void SetMessageContent(byte[] ipcBytes)
|
||||
{
|
||||
inBuf = ipcBytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* This method does the actual implementation of RemoveSecretStore
|
||||
*
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
|
||||
/* If an exception occurs in message format decoding,
|
||||
* it is handled by AppHandler
|
||||
*/
|
||||
|
||||
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.");
|
||||
|
||||
try
|
||||
{
|
||||
SessionManager.RemoveUserSession(userId, true);
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable to get user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 3;
|
||||
outMsgLen = 10;
|
||||
outBuf = new byte[10];
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
119
c_micasad/verbs/SetMasterPasscode.cs
Normal file
119
c_micasad/verbs/SetMasterPasscode.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
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 SetMasterPasscode call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class SetMasterPasscode : SSVerb
|
||||
{
|
||||
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint passcodeLen = 0;
|
||||
private string passcode;
|
||||
private uint passcodeType = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private byte[] inBuf;
|
||||
private byte[] outBuf;
|
||||
private 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 SetMasterPasscode
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
/* If an exception occurs in message format decoding,
|
||||
* it is handled by AppHandler
|
||||
*/
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
|
||||
// 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.");
|
||||
passcodeType = BitConverter.ToUInt32(inBuf,6);
|
||||
passcodeLen = BitConverter.ToUInt32(inBuf,10);
|
||||
byte[] tempArr = new byte[passcodeLen];
|
||||
Array.Copy(inBuf,14,tempArr,0,passcodeLen);
|
||||
passcode = Encoding.UTF8.GetString(tempArr);
|
||||
// Message Format decipher - End
|
||||
|
||||
try
|
||||
{
|
||||
SecretStore ssStore = null;
|
||||
ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
if(ssStore.SetMasterPasscode(passcode))
|
||||
retCode = IPCRetCodes.SSCS_REPLY_SUCCESS;
|
||||
else
|
||||
retCode = IPCRetCodes.SSCS_E_SETTING_PASSCODE_FAILED;
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable to get user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 15;
|
||||
outMsgLen = 10;
|
||||
outBuf = new byte[10];
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
119
c_micasad/verbs/SetMasterPassword.cs
Normal file
119
c_micasad/verbs/SetMasterPassword.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
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 SetMasterPassword call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
internal class SetMasterPassword : SSVerb
|
||||
{
|
||||
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint passwdLen = 0;
|
||||
private string passwd;
|
||||
private uint passwdType = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private byte[] inBuf;
|
||||
private byte[] outBuf;
|
||||
private 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 SetMasterPassword
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
/* If an exception occurs in message format decoding,
|
||||
* it is handled by AppHandler
|
||||
*/
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
|
||||
// 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.");
|
||||
passwdType = BitConverter.ToUInt32(inBuf,6);
|
||||
passwdLen = BitConverter.ToUInt32(inBuf,10);
|
||||
byte[] tempArr = new byte[passwdLen];
|
||||
Array.Copy(inBuf,14,tempArr,0,passwdLen);
|
||||
passwd = Encoding.UTF8.GetString(tempArr);
|
||||
// Message Format decipher - End
|
||||
|
||||
try
|
||||
{
|
||||
SecretStore ssStore = null;
|
||||
ssStore = SessionManager.GetUserSecretStore(userId);
|
||||
if(ssStore.SetMasterPassword(passwd))
|
||||
retCode = IPCRetCodes.SSCS_REPLY_SUCCESS;
|
||||
else
|
||||
retCode = IPCRetCodes.SSCS_E_SETTING_PASSCODE_FAILED;
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable to get user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 15;
|
||||
outMsgLen = 10;
|
||||
outBuf = new byte[10];
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
285
c_micasad/verbs/WriteKey.cs
Normal file
285
c_micasad/verbs/WriteKey.cs
Normal file
@@ -0,0 +1,285 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using sscs.verbs;
|
||||
using sscs.common;
|
||||
using sscs.cache;
|
||||
using sscs.constants;
|
||||
|
||||
using Novell.CASA.MiCasa.Common;
|
||||
|
||||
namespace sscs.verbs
|
||||
{
|
||||
|
||||
/*
|
||||
* This class is implementation of WriteKey call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
class WriteKey : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private uint keyChainIdLen = 0;
|
||||
private uint secretIdLen = 0;
|
||||
private uint secretValLen = 0;
|
||||
private int retCode = 0;
|
||||
private string keyChainId;
|
||||
private string secretId;
|
||||
|
||||
private uint keyLen;
|
||||
private string key;
|
||||
private uint valLen;
|
||||
private byte[] val;
|
||||
private string valStr;
|
||||
|
||||
private byte[] inBuf;
|
||||
private byte[] outBuf;
|
||||
|
||||
// extension operations
|
||||
private uint extId = 0;
|
||||
#if W32
|
||||
private int luidLow = 0;
|
||||
private int luidHigh = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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 WriteKey
|
||||
*
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
UserIdentifier tempUserId = userId;
|
||||
// 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);
|
||||
|
||||
|
||||
keyLen = BitConverter.ToUInt32(inBuf,(14+(int)keyChainIdLen+(int)secretIdLen));
|
||||
byte[] keyArr = new byte[keyLen];
|
||||
Array.Copy(inBuf,(18+keyChainIdLen+secretIdLen),keyArr,0,keyLen);
|
||||
key = Encoding.UTF8.GetString(keyArr);
|
||||
|
||||
|
||||
valLen = BitConverter.ToUInt32(inBuf,(18+(int)keyChainIdLen+(int)secretIdLen+(int)keyLen));
|
||||
val = new byte[valLen];
|
||||
Array.Copy(inBuf,(22+keyChainIdLen+secretIdLen+keyLen),val,0,valLen);
|
||||
valStr = Encoding.UTF8.GetString(val);
|
||||
|
||||
try
|
||||
{
|
||||
// get extension ID
|
||||
int extLocation = 26 + ((int)keyChainIdLen) + ((int)secretIdLen) + ((int)keyLen) + ((int)valLen);
|
||||
extId = BitConverter.ToUInt32(inBuf, extLocation);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//CSSSLogger.ExpLog(e.ToString());
|
||||
}
|
||||
|
||||
if (extId == 1)
|
||||
{
|
||||
#if W32
|
||||
|
||||
// WINDOWS LUID
|
||||
// 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);
|
||||
tempUserId = new WinUserIdentifier(luidLow, luidHigh);
|
||||
SecretStore ss = SessionManager.CreateUserSession(tempUserId);
|
||||
try
|
||||
{
|
||||
ss.AddKeyChain(new KeyChain("SSCS_SESSION_KEY_CHAIN_ID\0"));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
KeyChain keyChain = null;
|
||||
SecretStore ssStore = SessionManager.GetUserSecretStore(tempUserId);
|
||||
if (!ssStore.IsStoreLocked())
|
||||
{
|
||||
if( ssStore.CheckIfKeyChainExists(keyChainId) )
|
||||
{
|
||||
keyChain = ssStore.GetKeyChain(keyChainId);
|
||||
Secret secret = null;
|
||||
|
||||
// add this secret if it doesn't already exist
|
||||
if( keyChain.CheckIfSecretExists(secretId) == false)
|
||||
{
|
||||
secret = new Secret(secretId);
|
||||
keyChain.AddSecret(secret);
|
||||
}
|
||||
else
|
||||
{
|
||||
secret = keyChain.GetSecret(secretId);
|
||||
}
|
||||
string oldPasswd = null;
|
||||
if((ConstStrings.MICASA_DESKTOP_PASSWD == secretId) &&
|
||||
(ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME == key)
|
||||
)
|
||||
{
|
||||
KeyValue kv = secret.GetKeyValue(ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME);
|
||||
if( null != kv )
|
||||
oldPasswd = kv.GetValue();
|
||||
}
|
||||
secret.SetKeyValue(key,valStr);
|
||||
|
||||
if((ConstStrings.MICASA_DESKTOP_PASSWD == secretId) &&
|
||||
(ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME == key)
|
||||
)
|
||||
{
|
||||
string passwd = secret.GetKeyValue(ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME).GetValue();
|
||||
|
||||
if( ( oldPasswd != null ) && ( passwd != null ) )
|
||||
{
|
||||
if( oldPasswd != passwd )
|
||||
{
|
||||
byte[] baPasscode = ssStore.GetPasscodeFromOldDesktopPasswd(oldPasswd);
|
||||
if( null != baPasscode )
|
||||
{
|
||||
ssStore.RewriteDesktopPasswdFile(baPasscode, passwd);
|
||||
}
|
||||
}
|
||||
}
|
||||
ssStore.StartPersistenceByDesktopPasswd(passwd);
|
||||
}
|
||||
|
||||
// Now change all values for linked keys
|
||||
ChangeLinkedKeys(keyChain, secret, key, valStr);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
retCode = IPCRetCodes.SSCS_E_KEYCHAIN_DOES_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable to get user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e )
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 9;
|
||||
outMsgLen = 10;
|
||||
outBuf = new byte[10];
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
private void ChangeLinkedKeys(KeyChain keyChain, Secret secret, string key, string valStr)
|
||||
{
|
||||
Hashtable htLinkedkeys = secret.GetLinkedKeys(key);
|
||||
if (htLinkedkeys != null)
|
||||
{
|
||||
// enumerate the hashtable, getting each secret/key and change it's value
|
||||
ICollection coll = htLinkedkeys.Values;
|
||||
IDictionaryEnumerator ienum = (IDictionaryEnumerator)coll.GetEnumerator();
|
||||
|
||||
LinkedKeyInfo linkedInfo; // = (LinkedKeyInfo)ienum.Current;
|
||||
|
||||
while (ienum.MoveNext())
|
||||
{
|
||||
linkedInfo = (LinkedKeyInfo)ienum.Value;
|
||||
|
||||
// Get the target Secret
|
||||
Secret targetSecret = keyChain.GetSecret(linkedInfo.GetLinkedSecretID());
|
||||
if (targetSecret != null)
|
||||
{
|
||||
// get target key value
|
||||
string targetkv = targetSecret.GetKeyValue(linkedInfo.GetLinkedKeyID()).GetValue();
|
||||
|
||||
// if a change is required in the target, then call this method recursively using the TargetSecret
|
||||
if (!targetkv.Equals(valStr))
|
||||
{
|
||||
// NOTE: ORDER IS IMPORTANT
|
||||
// first change this one
|
||||
targetSecret.SetKeyValue(linkedInfo.GetLinkedKeyID(), valStr);
|
||||
|
||||
// now call the traget to change it's linked ones
|
||||
ChangeLinkedKeys(keyChain, targetSecret, key, valStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Gives the name of operation performed. Will be used in case
|
||||
* of error.
|
||||
*/
|
||||
public string GetVerbName()
|
||||
{
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
return this.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
230
c_micasad/verbs/WriteSecret.cs
Normal file
230
c_micasad/verbs/WriteSecret.cs
Normal file
@@ -0,0 +1,230 @@
|
||||
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 WriteSecret call.
|
||||
* There will be one instance existing for every call made by the client.
|
||||
*/
|
||||
|
||||
class WriteSecret : SSVerb
|
||||
{
|
||||
private ushort msgId = 0;
|
||||
private uint inMsgLen = 0;
|
||||
private uint outMsgLen = 0;
|
||||
private uint keyChainIdLen = 0;
|
||||
private uint secretIdLen = 0;
|
||||
private uint secretValLen = 0;
|
||||
private int retCode = 0;
|
||||
private string keyChainId;
|
||||
private string secretId;
|
||||
private byte[] secretVal;
|
||||
|
||||
private byte[] inBuf;
|
||||
private byte[] outBuf;
|
||||
|
||||
// extension operations
|
||||
private uint extId = 0;
|
||||
#if W32
|
||||
private int luidLow = 0;
|
||||
private int luidHigh = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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 WriteSecret
|
||||
*
|
||||
*/
|
||||
|
||||
public byte[] ProcessRequest(UserIdentifier userId)
|
||||
{
|
||||
UserIdentifier tempUserId = userId;
|
||||
CSSSLogger.ExecutionTrace(this);
|
||||
// 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);
|
||||
|
||||
secretValLen = BitConverter.ToUInt32(inBuf,
|
||||
(14 + ((int)keyChainIdLen)+((int)secretIdLen)));
|
||||
//secretVal = new byte[secretValLen];
|
||||
string secretValStr = Encoding.UTF8.GetString(inBuf,
|
||||
(18 + ((int)keyChainIdLen)+((int)secretIdLen)),
|
||||
(int)secretValLen
|
||||
);
|
||||
secretVal = Encoding.UTF8.GetBytes(secretValStr);
|
||||
|
||||
try
|
||||
{
|
||||
// get extension ID
|
||||
int extLocation = 22 + ((int)keyChainIdLen) + ((int)secretIdLen) + ((int)secretValLen);
|
||||
extId = BitConverter.ToUInt32(inBuf, extLocation);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//CSSSLogger.ExpLog(e.ToString());
|
||||
}
|
||||
|
||||
if (extId == 1)
|
||||
{
|
||||
#if W32
|
||||
// WINDOWS LUID
|
||||
// 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, 22 + ((int)keyChainIdLen)+((int)secretIdLen) +(int)secretValLen + 8);
|
||||
luidHigh = BitConverter.ToInt32(inBuf, 22 + ((int)keyChainIdLen)+((int)secretIdLen) +(int)secretValLen + 12);
|
||||
tempUserId = new WinUserIdentifier(luidLow, luidHigh);
|
||||
SecretStore ss = SessionManager.CreateUserSession(tempUserId);
|
||||
try
|
||||
{
|
||||
ss.AddKeyChain(new KeyChain("SSCS_SESSION_KEY_CHAIN_ID\0"));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string passwd = null;
|
||||
KeyChain keyChain = null;
|
||||
SecretStore ssStore = SessionManager.GetUserSecretStore(tempUserId);
|
||||
if (!ssStore.IsStoreLocked())
|
||||
{
|
||||
if( ssStore.CheckIfKeyChainExists(keyChainId) )
|
||||
{
|
||||
keyChain = ssStore.GetKeyChain(keyChainId);
|
||||
Secret secret = new Secret(secretId,secretVal);
|
||||
if( keyChain.CheckIfSecretExists(secretId) == false)
|
||||
{
|
||||
keyChain.AddSecret(secret);
|
||||
if(ConstStrings.MICASA_DESKTOP_PASSWD == secretId)
|
||||
{
|
||||
// Secret sec = keyChain.GetSecret(secretId);
|
||||
|
||||
KeyValue kv = secret.GetKeyValue(ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME);
|
||||
if( null != kv )
|
||||
passwd = kv.GetValue();
|
||||
if( null != passwd )
|
||||
{
|
||||
ssStore.StartPersistenceByDesktopPasswd(passwd);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Secret masterSecret = keyChain.GetSecret(secretId);
|
||||
string oldPasswd = masterSecret.GetKeyValue(ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME).GetValue();
|
||||
masterSecret.MergeSecret(secret);
|
||||
//keyChain.RemoveSecret(secretId);
|
||||
keyChain.AddSecret(secret);
|
||||
|
||||
KeyValue kv = secret.GetKeyValue(ConstStrings.MICASA_DESKTOP_PASSWD_KEYNAME);
|
||||
if( null != kv )
|
||||
passwd = kv.GetValue();
|
||||
if( ( oldPasswd != null ) && ( passwd != null ) )
|
||||
{
|
||||
if( oldPasswd != passwd )
|
||||
{
|
||||
byte[] baPasscode = ssStore.GetPasscodeFromOldDesktopPasswd( oldPasswd );
|
||||
if( null != baPasscode )
|
||||
{
|
||||
ssStore.RewriteDesktopPasswdFile(baPasscode, passwd);
|
||||
}
|
||||
}
|
||||
}
|
||||
ssStore.StartPersistenceByDesktopPasswd(passwd);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retCode = IPCRetCodes.SSCS_E_KEYCHAIN_DOES_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
catch(UserNotInSessionException)
|
||||
{
|
||||
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Unable to get user's secretstore" );
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
catch(Exception e )
|
||||
{
|
||||
CSSSLogger.ExpLog(e.ToString());
|
||||
retCode = IPCRetCodes.SSCS_E_SYSTEM_ERROR;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
msgId = 9;
|
||||
outMsgLen = 10;
|
||||
outBuf = new byte[10];
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user