Bug 135386: Linking secrets with colon in the name - FIXED

This commit is contained in:
Jim Norman 2006-02-17 21:05:10 +00:00
parent 95e66ba8b8
commit d7bf9b40a5
7 changed files with 113 additions and 42 deletions

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Fri Feb 17 14:01:12 MST 2006 - jnorman@novell.com
- Bug 135386: Linking secrets with colon in the name - FIXED
------------------------------------------------------------------- -------------------------------------------------------------------
Fri Feb 17 21:31:10 IST 2006 - smanojna@novell.com Fri Feb 17 21:31:10 IST 2006 - smanojna@novell.com

View File

@ -1018,7 +1018,7 @@ public class MiCasa : Store
while (ienum.MoveNext()) while (ienum.MoveNext())
{ {
LinkedKeyInfo lki = (LinkedKeyInfo) ienum.Value; LinkedKeyInfo lki = (LinkedKeyInfo) ienum.Value;
tsLinkedKeys.AppendValues(lki.GetLinkedSecretID(), lki.GetLinkedKeyID()); tsLinkedKeys.AppendValues(lki.GetLinkedSecretID(true), lki.GetLinkedKeyID());
} }
} }
} }
@ -1071,7 +1071,7 @@ public class MiCasa : Store
//tsLinkedKeys.AppendValues(selectedSecret, selectedKey); //tsLinkedKeys.AppendValues(selectedSecret, selectedKey);
// add a null terminator to the secretid // add a null terminator to the secretid
selectedSecret = selectedSecret + '\0'; //selectedSecret = selectedSecret + '\0';
LinkedKeyInfo lki = new LinkedKeyInfo(selectedSecret, selectedKey); LinkedKeyInfo lki = new LinkedKeyInfo(selectedSecret, selectedKey);
MiCasaRequestReply.Send(MiCasaRequestReply.VERB_SET_LINKED_KEY, null, labelLinkSecretID.Text, labelLinkKeyID.Text, lki); MiCasaRequestReply.Send(MiCasaRequestReply.VERB_SET_LINKED_KEY, null, labelLinkSecretID.Text, labelLinkKeyID.Text, lki);
@ -1093,7 +1093,7 @@ public class MiCasa : Store
{ {
selectedSecret = (string) model.GetValue(iter,0); selectedSecret = (string) model.GetValue(iter,0);
// add NULL // add NULL
selectedSecret = selectedSecret + '\0'; selectedSecret = selectedSecret;
selectedKey = (string) model.GetValue(iter,1); selectedKey = (string) model.GetValue(iter,1);
LinkedKeyInfo lki = new LinkedKeyInfo(selectedSecret, selectedKey); LinkedKeyInfo lki = new LinkedKeyInfo(selectedSecret, selectedKey);

View File

@ -38,14 +38,35 @@ namespace Novell.CASA.MiCasa.Common
public LinkedKeyInfo(string sDestSecretID, string sDestKey) public LinkedKeyInfo(string sDestSecretID, string sDestKey)
{ {
if (sDestSecretID.StartsWith("SS_CredSet")) if (sDestSecretID != null)
m_sDestSecretID = sDestSecretID; {
else if (sDestSecretID.StartsWith("SS_CredSet"))
m_sDestSecretID = "SS_CredSet:" + sDestSecretID + '\0'; sDestSecretID = "SS_CredSet:" + Utils.EscapeReservedChars(sDestSecretID.Substring(11)) + '\0';
else
sDestSecretID = "SS_CredSet:" + Utils.EscapeReservedChars(sDestSecretID) + '\0';
}
m_sDestSecretID = sDestSecretID;
m_sDestKeyID = sDestKey; m_sDestKeyID = sDestKey;
} }
public LinkedKeyInfo(string sDestSecretID, string sDestKey, bool bAlreadyEscaped)
{
if (!bAlreadyEscaped)
{
if (sDestSecretID != null)
{
if (sDestSecretID.StartsWith("SS_CredSet"))
sDestSecretID = "SS_CredSet:" + Utils.EscapeReservedChars(sDestSecretID.Substring(11)) + '\0';
else
sDestSecretID = "SS_CredSet:" + Utils.EscapeReservedChars(sDestSecretID) + '\0';
}
}
m_sDestSecretID = sDestSecretID;
m_sDestKeyID = sDestKey;
}
public string GetLinkID() public string GetLinkID()
{ {
return m_sDestSecretID + ":" + m_sDestKeyID; return m_sDestSecretID + ":" + m_sDestKeyID;
@ -56,6 +77,19 @@ namespace Novell.CASA.MiCasa.Common
return m_sDestSecretID; return m_sDestSecretID;
} }
public string GetLinkedSecretID(bool bUnescape)
{
if (bUnescape)
{
if (m_sDestSecretID.StartsWith("SS_CredSet"))
return ("SS_CredSet:" + Utils.UnescapeString(m_sDestSecretID.Substring(11)));
else
return Utils.UnescapeString(m_sDestSecretID);
}
return m_sDestSecretID;
}
public string GetLinkedKeyID() public string GetLinkedKeyID()
{ {
return m_sDestKeyID; return m_sDestKeyID;

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Novell.CASA.MiCasa.Common
{
class Utils
{
public static string EscapeReservedChars(string origString)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < origString.Length; i++)
{
switch (origString[i])
{
case ':':
{
sb.Append("\\");
break;
}
case '\\':
{
sb.Append("\\");
break;
}
case '=':
{
sb.Append("\\");
break;
}
}
sb.Append(origString[i]);
}
return sb.ToString();
}
public static string UnescapeString(string sOrig)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < sOrig.Length; i++)
{
if (sOrig[i].Equals('\\'))
{
if (i + 1 < sOrig.Length)
{
if (sOrig[i + 1].Equals(':')
|| sOrig[i + 1].Equals('\\')
|| sOrig[i + 1].Equals('='))
{
i++;
}
}
}
sb.Append(sOrig[i]);
}
return sb.ToString();
}
}
}

View File

@ -61,13 +61,13 @@ namespace Novell.CASA.MiCasa.Common
if (sSecretID != null) if (sSecretID != null)
{ {
if (sSecretID.StartsWith("SS_CredSet")) if (sSecretID.StartsWith("SS_CredSet"))
m_SecretID = "SS_CredSet:" + EscapeReservedChars(sSecretID.Substring(11)) + '\0'; m_SecretID = "SS_CredSet:" + Utils.EscapeReservedChars(sSecretID.Substring(11)) + '\0';
else else
m_SecretID = "SS_CredSet:" + EscapeReservedChars(sSecretID) + '\0'; m_SecretID = "SS_CredSet:" + Utils.EscapeReservedChars(sSecretID) + '\0';
} }
if (sKeyID != null) if (sKeyID != null)
m_KeyID = EscapeReservedChars(sKeyID); // + '\0'; m_KeyID = Utils.EscapeReservedChars(sKeyID); // + '\0';
// serialize the object // serialize the object
m_object = theObject; m_object = theObject;
@ -118,34 +118,5 @@ namespace Novell.CASA.MiCasa.Common
{ {
return m_errorMsg; return m_errorMsg;
} }
private string EscapeReservedChars(string origString)
{
StringBuilder sb = new StringBuilder();
for (int i=0; i<origString.Length; i++)
{
switch (origString[i])
{
case ':' :
{
sb.Append("\\");
break;
}
case '\\' :
{
sb.Append("\\");
break;
}
case '=' :
{
sb.Append("\\");
break;
}
}
sb.Append(origString[i]);
}
return sb.ToString();
}
} }
} }

View File

@ -265,7 +265,7 @@ namespace sscs.lss
XmlNode targetKeyNode = linkNode.SelectSingleNode(xpath); XmlNode targetKeyNode = linkNode.SelectSingleNode(xpath);
string sKeyID = targetKeyNode.InnerText; string sKeyID = targetKeyNode.InnerText;
LinkedKeyInfo lki = new LinkedKeyInfo(sSecretID, sKeyID); LinkedKeyInfo lki = new LinkedKeyInfo(sSecretID, sKeyID, true);
KeyValue kv = secret.GetKeyValue(key); KeyValue kv = secret.GetKeyValue(key);
kv.AddLink(lki); kv.AddLink(lki);
} }

View File

@ -730,12 +730,12 @@ namespace sscs.verbs
{ {
Secret target = keyChain.GetSecret(lki.GetLinkedSecretID()); Secret target = keyChain.GetSecret(lki.GetLinkedSecretID());
KeyValue targetkv = target.GetKeyValue(lki.GetLinkedKeyID()); KeyValue targetkv = target.GetKeyValue(lki.GetLinkedKeyID());
targetkv.AddLink(new LinkedKeyInfo(secretID, keyID)); targetkv.AddLink(new LinkedKeyInfo(secretID, keyID, true));
ssStore.UpdatePersistentStore(); ssStore.UpdatePersistentStore();
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine("Reverse Link error: " + e.ToString()); //Console.WriteLine("Reverse Link error: " + e.ToString());
wo.SetError(constants.RetCodes.FAILURE, "Reverse Link: " + e.ToString()); wo.SetError(constants.RetCodes.FAILURE, "Reverse Link: " + e.ToString());
} }