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

@ -110,13 +110,15 @@ namespace Novell.CASA.MiCasa.Communication
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;
// buffer for data
MemoryStream ms = new MemoryStream();
while (totalBytes < (msgLen - 6)) while (totalBytes < (msgLen - 6))
{ {
bytesAvailable = mSocket.Available; bytesAvailable = mSocket.Available;
@ -126,13 +128,15 @@ namespace Novell.CASA.MiCasa.Communication
} }
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);

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;
} }