Security Audit - Marshal export file to CASAManager for saving.

This commit is contained in:
Jim Norman 2006-12-20 10:22:27 +00:00
parent 98c12387a6
commit 43009ada4f
4 changed files with 198 additions and 207 deletions

View File

@ -108,7 +108,6 @@ namespace Novell.CASA.GUI
#endif #endif
//Store off this location for next export //Store off this location for next export
int iLastSlash = sFileName.LastIndexOf("/"); int iLastSlash = sFileName.LastIndexOf("/");
if (Common.IS_WINDOWS) if (Common.IS_WINDOWS)
iLastSlash = sFileName.LastIndexOf("\\"); iLastSlash = sFileName.LastIndexOf("\\");
@ -125,25 +124,28 @@ namespace Novell.CASA.GUI
m_config.WriteConfig(); m_config.WriteConfig();
// call our daemon to get the users secrets // call our daemon to get the users secrets
ExportXMLSecrets exportSecrets = new ExportXMLSecrets(sMasterPWD, sEncryptString, sFileName); ExportXMLSecrets exportSecrets = new ExportXMLSecrets(sMasterPWD, sEncryptString, null);
byte[] baSecrets = (byte[])Novell.CASA.MiCasa.Communication.MiCasaRequestReply.Send(MiCasaRequestReply.VERB_EXPORT_SECRETS, null, null, null, exportSecrets);
object obj = Novell.CASA.MiCasa.Communication.MiCasaRequestReply.Send(MiCasaRequestReply.VERB_EXPORT_SECRETS, null, null, null, exportSecrets);
/*
byte[] theSecrets = (byte[])Novell.CASA.MiCasa.Communication.MiCasaRequestReply.Send(MiCasaRequestReply.VERB_EXPORT_SECRETS, null, null, null, exportSecrets);
// write em out.
if (baSecrets != null)
{
try
{
FileStream fs = new FileStream(sFileName, FileMode.Create); FileStream fs = new FileStream(sFileName, FileMode.Create);
fs.Write(theSecrets, 0, theSecrets.Length); fs.Write(baSecrets, 0, baSecrets.Length);
fs.Flush(); fs.Flush();
fs.Close(); fs.Close();
*/
CommonGUI.DisplayMessage(MessageType.Info, "Secrets saved to: \r\n" + sFileName); CommonGUI.DisplayMessage(MessageType.Info, "Secrets saved to: \r\n" + sFileName);
}
catch
{
CommonGUI.DisplayMessage(MessageType.Error, "Failed to save secrets");
}
}
else
{
CommonGUI.DisplayMessage(MessageType.Error, "No Secrets found");
}
} }
} }
else else

View File

@ -1030,7 +1030,7 @@ namespace sscs.cache
return persistDir + ConstStrings.MICASA_SERVER_VALIDATION_FILE; return persistDir + ConstStrings.MICASA_SERVER_VALIDATION_FILE;
} }
internal string GetSecretsForExport(string sEncryptionString) internal byte[] GetSecretsForExport(string sEncryptionString)
{ {
byte[] baIV = null; byte[] baIV = null;
byte[] baSecrets = GetSecrets(sEncryptionString, ref baIV); byte[] baSecrets = GetSecrets(sEncryptionString, ref baIV);
@ -1040,13 +1040,11 @@ namespace sscs.cache
byte[] baCombined = new byte[baIV.Length + baSecrets.Length]; byte[] baCombined = new byte[baIV.Length + baSecrets.Length];
baIV.CopyTo(baCombined, 0); baIV.CopyTo(baCombined, 0);
baSecrets.CopyTo(baCombined, baIV.Length); baSecrets.CopyTo(baCombined, baIV.Length);
return baCombined;
string sB64 = Convert.ToBase64String(baCombined);
return sB64;
} }
else else
{ {
return Convert.ToBase64String(baSecrets); return baSecrets;
} }
} }

View File

@ -45,9 +45,9 @@ namespace Novell.CASA.MiCasa.Communication
public void Open() public void Open()
{ {
mSocket = new Socket( AddressFamily.Unix, mSocket = new Socket(AddressFamily.Unix,
SocketType.Stream, SocketType.Stream,
ProtocolType.IP ); ProtocolType.IP);
if (mSocket == null) if (mSocket == null)
{ {
@ -96,55 +96,59 @@ namespace Novell.CASA.MiCasa.Communication
byte[] msgIdBytes = new byte[2]; byte[] msgIdBytes = new byte[2];
bytesRecvd = mSocket.Receive(msgIdBytes); bytesRecvd = mSocket.Receive(msgIdBytes);
if( 0 == bytesRecvd ) if (0 == bytesRecvd)
{ {
return null; return null;
} }
byte[] msgLenBytes = new byte[4]; byte[] msgLenBytes = new byte[4];
bytesRecvd = mSocket.Receive(msgLenBytes); bytesRecvd = mSocket.Receive(msgLenBytes);
if( 0 == bytesRecvd ) if (0 == bytesRecvd)
{ {
return null; return null;
} }
uint msgLen = BitConverter.ToUInt32(msgLenBytes,0); uint msgLen = BitConverter.ToUInt32(msgLenBytes, 0);
if( msgLen > 6 ) if (msgLen > 6)
{ {
System.Text.Encoding encoding = System.Text.Encoding.ASCII;
byte[] buf = null; byte[] buf = null;
int bytesAvailable; int bytesAvailable;
int totalBytes = 0; int totalBytes = 0;
int msgLencount = 0; int msgLencount = 0;
string bufstring = null; string bufstring = null;
byte[] temp = null;
while(totalBytes<(msgLen-6)) // buffer for data
MemoryStream ms = new MemoryStream();
while (totalBytes < (msgLen - 6))
{ {
bytesAvailable = mSocket.Available; bytesAvailable = mSocket.Available;
if( 0 == bytesAvailable) if (0 == bytesAvailable)
{ {
break; break;
} }
buf = new byte[bytesAvailable]; buf = new byte[bytesAvailable];
bytesRecvd = mSocket.Receive (buf); bytesRecvd = mSocket.Receive(buf);
bufstring = bufstring + encoding.GetString(buf); //keep buffering in a string ms.Write(buf, 0, bytesRecvd);
totalBytes = totalBytes + bytesAvailable; totalBytes = totalBytes + bytesAvailable;
} }
if(totalBytes==0) if (totalBytes == 0)
return null; return null;
byte[] finalbuf = encoding.GetBytes(bufstring);//finally, convert the string to a byte array of size 'totalBytes' byte[] finalbuf = ms.ToArray();
int returnBufferLen = msgIdBytes.Length+msgLenBytes.Length+totalBytes;
int returnBufferLen = msgIdBytes.Length + msgLenBytes.Length + totalBytes;
returnBuffer = new byte[returnBufferLen]; returnBuffer = new byte[returnBufferLen];
Array.Copy(msgIdBytes,returnBuffer,2); Array.Copy(msgIdBytes, returnBuffer, 2);
Array.Copy(msgLenBytes,0,returnBuffer,2,4); Array.Copy(msgLenBytes, 0, returnBuffer, 2, 4);
Array.Copy(finalbuf,0,returnBuffer,6,finalbuf.Length); Array.Copy(finalbuf, 0, returnBuffer, 6, finalbuf.Length);
return returnBuffer; return returnBuffer;
} }
else else
{ {
returnBuffer = new byte[6]; returnBuffer = new byte[6];
Array.Copy(msgIdBytes,returnBuffer,2); Array.Copy(msgIdBytes, returnBuffer, 2);
Array.Copy(msgLenBytes,0,returnBuffer,2,4); Array.Copy(msgLenBytes, 0, returnBuffer, 2, 4);
return returnBuffer; return returnBuffer;
} }
} }

View File

@ -411,31 +411,18 @@ namespace sscs.verbs
string sEncrpyptionPassphrase = secrets.GetPassphrase(); string sEncrpyptionPassphrase = secrets.GetPassphrase();
// get all secrets // get all secrets
//byte[] baSecrets = ssStore.GetSecrets(sEncrpyptionPassphrase, ref baIV); byte[] baSecrets = ssStore.GetSecretsForExport(sEncrpyptionPassphrase);
string baSecrets = ssStore.GetSecretsForExport(sEncrpyptionPassphrase);
string sFilePath = secrets.GetFilePath(); if (baSecrets != null)
if (sFilePath != null)
{ {
// write em out wo.SetObject(baSecrets);
FileStream fs = new FileStream(sFilePath, FileMode.Create); wo.SetError(constants.RetCodes.SUCCESS, "");
// write the secrets now
//fs.Write(baSecrets, 0, baSecrets.Length);
fs.Flush();
fs.Close();
#if LINUX
// change file ownership to the user
Mono.Unix.Native.Syscall.chown(sFilePath, (uint)userId.GetUID(), (uint)userId.GetUID());
#endif
} }
else else
{ {
wo.SetObject(baSecrets); wo.SetError(constants.RetCodes.FAILURE, "No Secrets for Export");
} }
wo.SetError(constants.RetCodes.SUCCESS, "");
return wo; return wo;
} }