Security Audit - Remove assumption of username.
This commit is contained in:
parent
174b0eb88c
commit
8b6a60e9ab
27
CASA/micasad/cache/SecretStore.cs
vendored
27
CASA/micasad/cache/SecretStore.cs
vendored
@ -884,6 +884,11 @@ namespace sscs.cache
|
||||
return user.GetUserHomeDir();
|
||||
}
|
||||
|
||||
internal string GetUserName()
|
||||
{
|
||||
return user.GetUserName();
|
||||
}
|
||||
|
||||
internal string GetPersistenceDirectory()
|
||||
{
|
||||
if (m_persistenceDirectory != null)
|
||||
@ -897,7 +902,7 @@ namespace sscs.cache
|
||||
{
|
||||
// the user might have set a different one
|
||||
// load the policy file and check.
|
||||
UIPol uiPolicy = (UIPol)ICASAPol.GetPolicy(CASAPolType.UI_POL, GetUserHomeDirectory());
|
||||
UIPol uiPolicy = (UIPol)ICASAPol.GetPolicy(CASAPolType.UI_POL, GetUserHomeDirectory(), GetUserName());
|
||||
if (uiPolicy != null)
|
||||
{
|
||||
string sDir = uiPolicy.GetConfigSetting(ConstStrings.CONFIG_PERSISTENT_DIRECTORY);
|
||||
@ -1025,6 +1030,26 @@ namespace sscs.cache
|
||||
return persistDir + ConstStrings.MICASA_SERVER_VALIDATION_FILE;
|
||||
}
|
||||
|
||||
internal string GetSecretsForExport(string sEncryptionString)
|
||||
{
|
||||
byte[] baIV = null;
|
||||
byte[] baSecrets = GetSecrets(sEncryptionString, ref baIV);
|
||||
|
||||
if ((baIV != null) && (baSecrets != null))
|
||||
{
|
||||
byte[] baCombined = new byte[baIV.Length + baSecrets.Length];
|
||||
baIV.CopyTo(baCombined, 0);
|
||||
baSecrets.CopyTo(baCombined, baIV.Length);
|
||||
|
||||
string sB64 = Convert.ToBase64String(baCombined);
|
||||
return sB64;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Convert.ToBase64String(baSecrets);
|
||||
}
|
||||
}
|
||||
|
||||
internal byte[] GetSecrets(string sEncryptionString, ref byte[] baIV)
|
||||
{
|
||||
if (lss != null)
|
||||
|
@ -609,7 +609,7 @@ namespace sscs.lss
|
||||
string sPeristSecrets = null;
|
||||
|
||||
// is policy set to persist secrets
|
||||
UIPol uiPolicy = (UIPol)ICASAPol.GetPolicy(CASAPolType.UI_POL, userStore.GetUserHomeDirectory());
|
||||
UIPol uiPolicy = (UIPol)ICASAPol.GetPolicy(CASAPolType.UI_POL, userStore.GetUserHomeDirectory(), userStore.GetUserName());
|
||||
if (uiPolicy != null)
|
||||
{
|
||||
sPeristSecrets = uiPolicy.GetConfigSetting(ConstStrings.CONFIG_PERSIST_SECRETS);
|
||||
@ -739,7 +739,7 @@ namespace sscs.lss
|
||||
// TODO: Does Policy allow persisting this secret.
|
||||
if (policy == null)
|
||||
{
|
||||
policy = (PersistencePol)ICASAPol.GetPolicy(CASAPolType.PERSISTENCE_POL, userStore.GetUserHomeDirectory());
|
||||
policy = (PersistencePol)ICASAPol.GetPolicy(CASAPolType.PERSISTENCE_POL, userStore.GetUserHomeDirectory(), userStore.GetUserName());
|
||||
}
|
||||
|
||||
bool bSaveValues = true;
|
||||
|
@ -277,10 +277,11 @@ namespace sscs.verbs
|
||||
cpd.SetErrorMessage("Directory not allowed");
|
||||
return wo;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// copy all .miCASA* files to new location
|
||||
// copy all .miCASA* files to new location
|
||||
string[] files = Directory.GetFiles(sOldDir, ".miCASA*");
|
||||
if (files != null)
|
||||
{
|
||||
@ -393,7 +394,6 @@ namespace sscs.verbs
|
||||
|
||||
private WrappedObject DoExportSecrets(SecretStore ssStore, WrappedObject wo, UserIdentifier userId)
|
||||
{
|
||||
byte[] baIV = null;
|
||||
ExportXMLSecrets secrets = (ExportXMLSecrets)wo.GetObject();
|
||||
|
||||
// validate masterpassword
|
||||
@ -411,21 +411,16 @@ namespace sscs.verbs
|
||||
string sEncrpyptionPassphrase = secrets.GetPassphrase();
|
||||
|
||||
// get all secrets
|
||||
byte[] baSecrets = ssStore.GetSecrets(sEncrpyptionPassphrase, ref baIV);
|
||||
string sFilePath = secrets.GetFilePath();
|
||||
//byte[] baSecrets = ssStore.GetSecrets(sEncrpyptionPassphrase, ref baIV);
|
||||
string baSecrets = ssStore.GetSecretsForExport(sEncrpyptionPassphrase);
|
||||
|
||||
string sFilePath = secrets.GetFilePath();
|
||||
if (sFilePath != null)
|
||||
{
|
||||
// write em out
|
||||
FileStream fs = new FileStream(sFilePath, FileMode.Create);
|
||||
|
||||
// if a IV was set, write it out.
|
||||
if (baIV != null)
|
||||
{
|
||||
fs.Write(baIV, 0, 16);
|
||||
}
|
||||
|
||||
// write the secrets now
|
||||
fs.Write(baSecrets, 0, baSecrets.Length);
|
||||
//fs.Write(baSecrets, 0, baSecrets.Length);
|
||||
fs.Flush();
|
||||
fs.Close();
|
||||
|
||||
@ -437,7 +432,7 @@ namespace sscs.verbs
|
||||
}
|
||||
else
|
||||
{
|
||||
wo.SetObject(ssStore.GetSecrets(sEncrpyptionPassphrase, ref baIV));
|
||||
wo.SetObject(baSecrets);
|
||||
}
|
||||
|
||||
wo.SetError(constants.RetCodes.SUCCESS, "");
|
||||
|
@ -36,10 +36,10 @@ public class ICASAPol
|
||||
|
||||
static string GetPolicyFilePath()
|
||||
{
|
||||
return GetPolicyFilePath(null);
|
||||
return GetPolicyFilePath(null, null);
|
||||
}
|
||||
|
||||
static string GetPolicyFilePath(string sUserHomeDir)
|
||||
static string GetPolicyFilePath(string sUserHomeDir, string sUserName)
|
||||
{
|
||||
|
||||
try
|
||||
@ -65,13 +65,16 @@ public class ICASAPol
|
||||
}
|
||||
|
||||
// get users name
|
||||
string sUsername = homeDir.Substring(homeDir.LastIndexOf("/") + 1);
|
||||
if (sUserName == null)
|
||||
{
|
||||
sUserName = System.Environment.GetEnvironmentVariable("USER");
|
||||
}
|
||||
|
||||
if (sUsername != null)
|
||||
if (sUserName != null)
|
||||
{
|
||||
// check for existing files
|
||||
string sOldLocation = homeDir + XmlConsts.policyFileName;
|
||||
string sNewLocation = "/home/.casa/" + sUsername + XmlConsts.policyFileName;
|
||||
string sNewLocation = "/home/.casa/" + sUserName + XmlConsts.policyFileName;
|
||||
|
||||
// move file if needed
|
||||
if ((!File.Exists(sNewLocation)) && (File.Exists(sOldLocation)))
|
||||
@ -421,18 +424,18 @@ public class ICASAPol
|
||||
|
||||
static public CASAPol GetPolicy(CASAPolType policyType)
|
||||
{
|
||||
return GetPolicy(policyType, null);
|
||||
return GetPolicy(policyType, null, null);
|
||||
}
|
||||
|
||||
static public CASAPol GetPolicy(CASAPolType policyType, string sDir)
|
||||
static public CASAPol GetPolicy(CASAPolType policyType, string sDir, string sUserName)
|
||||
{
|
||||
CASAPol pol = null;
|
||||
try
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
if(!File.Exists(GetPolicyFilePath(sDir)))
|
||||
if(!File.Exists(GetPolicyFilePath(sDir, sUserName)))
|
||||
return null;
|
||||
doc.Load(GetPolicyFilePath(sDir));
|
||||
doc.Load(GetPolicyFilePath(sDir, sUserName));
|
||||
switch(policyType)
|
||||
{
|
||||
case CASAPolType.AGGREGATION_POL:
|
||||
|
Loading…
Reference in New Issue
Block a user