Import/Export changes

This commit is contained in:
Jim Norman 2006-08-22 16:45:08 +00:00
parent 3e261ca152
commit f7ce95ae97
5 changed files with 91 additions and 23 deletions

View File

@ -111,7 +111,12 @@ 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); ExportXMLSecrets exportSecrets = new ExportXMLSecrets(sMasterPWD, sEncryptString, sFileName);
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); byte[] theSecrets = (byte[])Novell.CASA.MiCasa.Communication.MiCasaRequestReply.Send(MiCasaRequestReply.VERB_EXPORT_SECRETS, null, null, null, exportSecrets);
// write em out. // write em out.
@ -121,6 +126,7 @@ namespace Novell.CASA.GUI
fs.Write(theSecrets, 0, theSecrets.Length); fs.Write(theSecrets, 0, theSecrets.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);

View File

@ -13,6 +13,7 @@ namespace Novell.CASA.GUI
{ {
Config m_config = null; Config m_config = null;
public MiCasa m_objMiCasa = null; public MiCasa m_objMiCasa = null;
string sFile = null;
byte[] buffer = null; byte[] buffer = null;
[Glade.Widget] [Glade.Widget]
@ -32,8 +33,7 @@ namespace Novell.CASA.GUI
{ {
String sHintDir = m_config.GetConfigSetting(CommonGUI.HINT_DIR, null);; String sHintDir = m_config.GetConfigSetting(CommonGUI.HINT_DIR, null);;
String sHintFilename = m_config.GetConfigSetting(CommonGUI.HINT_FILENAME, null); String sHintFilename = m_config.GetConfigSetting(CommonGUI.HINT_FILENAME, null);
string sFile = null;
FileChooser fc = new FileChooser(FileChooser.ACTION_OPEN); FileChooser fc = new FileChooser(FileChooser.ACTION_OPEN);
sFile = fc.GetFile(sHintDir, sHintFilename); sFile = fc.GetFile(sHintDir, sHintFilename);
@ -71,7 +71,7 @@ namespace Novell.CASA.GUI
// check for clear text secrets // check for clear text secrets
if (data.StartsWith("<?xml")) if (data.StartsWith("<?xml"))
{ {
ImportXMLSecrets addSecrets = new ImportXMLSecrets(null, buffer); ImportXMLSecrets addSecrets = new ImportXMLSecrets(null, null, sFile);
MiCasaRequestReply.Send(MiCasaRequestReply.VERB_ADD_XML_SECRETS, null, null, null, addSecrets); MiCasaRequestReply.Send(MiCasaRequestReply.VERB_ADD_XML_SECRETS, null, null, null, addSecrets);
CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Import complete"); CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Import complete");
} }
@ -134,7 +134,7 @@ namespace Novell.CASA.GUI
{ {
if (entryMasterPassword != null) if (entryMasterPassword != null)
{ {
ImportXMLSecrets addSecrets = new ImportXMLSecrets(entryMasterPassword.Text, buffer); ImportXMLSecrets addSecrets = new ImportXMLSecrets(entryMasterPassword.Text, null, sFile);
addSecrets = (ImportXMLSecrets)MiCasaRequestReply.Send(MiCasaRequestReply.VERB_ADD_XML_SECRETS, null, null, null, addSecrets); addSecrets = (ImportXMLSecrets)MiCasaRequestReply.Send(MiCasaRequestReply.VERB_ADD_XML_SECRETS, null, null, null, addSecrets);
if (dialogImport != null) if (dialogImport != null)

View File

@ -11,14 +11,21 @@ namespace Novell.CASA.MiCasa.Common
{ {
private string m_sMasterPassword = null; private string m_sMasterPassword = null;
private string m_sPassphrase = null; private string m_sPassphrase = null;
private string m_sFilePath = null;
public ExportXMLSecrets(string sMasterPassword, string sPassphrase) public ExportXMLSecrets(string sMasterPassword, string sPassphrase, string sFilePath)
{ {
m_sMasterPassword = sMasterPassword; m_sMasterPassword = sMasterPassword;
if (sPassphrase != null) if (sPassphrase != null)
{ {
m_sPassphrase = sPassphrase; m_sPassphrase = sPassphrase;
} }
if (sFilePath != null)
{
m_sFilePath = sFilePath;
}
} }
public string GetMasterPassword() public string GetMasterPassword()
@ -30,5 +37,10 @@ namespace Novell.CASA.MiCasa.Common
{ {
return m_sPassphrase; return m_sPassphrase;
} }
public string GetFilePath()
{
return m_sFilePath;
}
} }
} }

View File

@ -12,11 +12,16 @@ namespace Novell.CASA.MiCasa.Common
private string m_MasterPassword = null; private string m_MasterPassword = null;
private byte[] m_XmlSecrets = null; private byte[] m_XmlSecrets = null;
private string m_sStatus = ""; private string m_sStatus = "";
private string m_sFilePath = null;
public ImportXMLSecrets(string sMasterPassword, byte[] XmlSecrets) public ImportXMLSecrets(string sMasterPassword, byte[] XmlSecrets, string sFilePath)
{ {
m_MasterPassword = sMasterPassword; m_MasterPassword = sMasterPassword;
m_XmlSecrets = XmlSecrets; m_XmlSecrets = XmlSecrets;
if (sFilePath != null)
{
m_sFilePath = sFilePath;
}
} }
public string GetMasterPasssword() public string GetMasterPasssword()
@ -29,6 +34,11 @@ namespace Novell.CASA.MiCasa.Common
return m_XmlSecrets; return m_XmlSecrets;
} }
public string GetFilePath()
{
return m_sFilePath;
}
public void SetStatus(string s) public void SetStatus(string s)
{ {
m_sStatus = s; m_sStatus = s;

View File

@ -248,27 +248,53 @@ namespace sscs.verbs
{ {
ImportXMLSecrets addSecrets = (ImportXMLSecrets)wo.GetObject(); ImportXMLSecrets addSecrets = (ImportXMLSecrets)wo.GetObject();
string sMasterPassword = addSecrets.GetMasterPasssword(); string sMasterPassword = addSecrets.GetMasterPasssword();
byte[] baXMLSecrets = addSecrets.GetXmlSecrets();
try string sFilePath = addSecrets.GetFilePath();
byte[] baXMLSecrets = null;
try
{ {
if (sMasterPassword != null) if (File.Exists(sFilePath))
{ {
// decrypt secrets if possible
ssStore.MergeXMLSecrets(baXMLSecrets, sMasterPassword); // let's read it
FileStream fs = new FileStream(sFilePath, FileMode.Open);
baXMLSecrets = new byte[fs.Length];
int iBytes = fs.Read(baXMLSecrets, 0, (int)fs.Length);
fs.Flush();
fs.Close();
} }
else }
{
// do the merge now.
ssStore.MergeXMLSecrets(baXMLSecrets);
}
addSecrets.SetStatus("Success");
wo.SetError(constants.RetCodes.SUCCESS, "");
}
catch (Exception e) catch (Exception e)
{ {
addSecrets.SetStatus(e.ToString());
wo.SetError(constants.RetCodes.FAILURE, e.ToString()); wo.SetError(constants.RetCodes.FAILURE, e.ToString());
return wo;
}
//byte[] baXMLSecrets = addSecrets.GetXmlSecrets();
if (baXMLSecrets != null)
{
try
{
if (sMasterPassword != null)
{
// decrypt secrets if possible
ssStore.MergeXMLSecrets(baXMLSecrets, sMasterPassword);
}
else
{
// do the merge now.
ssStore.MergeXMLSecrets(baXMLSecrets);
}
addSecrets.SetStatus("Success");
wo.SetError(constants.RetCodes.SUCCESS, "");
}
catch (Exception e)
{
addSecrets.SetStatus(e.ToString());
wo.SetError(constants.RetCodes.FAILURE, e.ToString());
}
} }
return wo; return wo;
@ -293,7 +319,21 @@ namespace sscs.verbs
string sEncrpyptionPassphrase = secrets.GetPassphrase(); string sEncrpyptionPassphrase = secrets.GetPassphrase();
// get all secrets // get all secrets
wo.SetObject(ssStore.GetSecrets(sEncrpyptionPassphrase)); byte[] baSecrets = ssStore.GetSecrets(sEncrpyptionPassphrase);
string sFilePath = secrets.GetFilePath();
if (sFilePath != null)
{
// write em out
FileStream fs = new FileStream(sFilePath, FileMode.Create);
fs.Write(baSecrets, 0, baSecrets.Length);
fs.Flush();
fs.Close();
}
else
{
wo.SetObject(ssStore.GetSecrets(sEncrpyptionPassphrase));
}
wo.SetError(constants.RetCodes.SUCCESS, ""); wo.SetError(constants.RetCodes.SUCCESS, "");
return wo; return wo;