2006-01-19 00:34:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2006-01-31 23:01:47 +01:00
|
|
|
* Copyright (C) 2005-2006 Novell, Inc. Inc. All Rights Reserved.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-01-31 23:01:47 +01:00
|
|
|
* Library Lesser General Public License for more details.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-01-31 23:01:47 +01:00
|
|
|
* License along with this library; if not, Novell, Inc.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* To contact Novell about this file by physical or electronic mail,
|
|
|
|
* you may find current contact information at www.novell.com.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|