Bug 235467. Mark binary keys as binary types when persisting data.
This commit is contained in:
		| @@ -1436,6 +1436,8 @@ public class MiCasa : Store | |||||||
|                 Secret secret = ss.GetSecret(entrySecretID.Text); |                 Secret secret = ss.GetSecret(entrySecretID.Text); | ||||||
|                 value = secret.GetKeyValue(selected); |                 value = secret.GetKeyValue(selected); | ||||||
|                  |                  | ||||||
|  |                  | ||||||
|  |  | ||||||
|                 // strip of header data |                 // strip of header data | ||||||
|                 byte[] baValue = System.Text.Encoding.ASCII.GetBytes(value); |                 byte[] baValue = System.Text.Encoding.ASCII.GetBytes(value); | ||||||
|                 byte[] baTarget = new byte[baValue.Length - 16]; |                 byte[] baTarget = new byte[baValue.Length - 16]; | ||||||
| @@ -1458,8 +1460,19 @@ public class MiCasa : Store | |||||||
|                 Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogDecode", null); |                 Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogDecode", null); | ||||||
|                 gxmlTemp.Autoconnect(this); |                 gxmlTemp.Autoconnect(this); | ||||||
|  |  | ||||||
|                 // display values                 |                 // display decoded value                 | ||||||
|                 textviewClear.Buffer.Text = value; |                 //textviewClear.Buffer.Text = value; | ||||||
|  |                 char[] array = value.ToCharArray(); | ||||||
|  |  | ||||||
|  |                 try | ||||||
|  |                 { | ||||||
|  |                     byte[] bytes = Convert.FromBase64CharArray(array, 0, array.Length); | ||||||
|  |                     textviewClear.Buffer.Text = System.Text.Encoding.ASCII.GetString(bytes); | ||||||
|  |                 } | ||||||
|  |                 catch (Exception e) | ||||||
|  |                 { | ||||||
|  |                     textviewClear.Buffer.Text = e.ToString(); | ||||||
|  |                 } | ||||||
|                           |                           | ||||||
|                 // hook up button handlers |                 // hook up button handlers | ||||||
|                 bttnDecode.Clicked += new EventHandler(bttnDecode_Clicked); |                 bttnDecode.Clicked += new EventHandler(bttnDecode_Clicked); | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								CASA/micasad/cache/KeyValue.cs
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								CASA/micasad/cache/KeyValue.cs
									
									
									
									
										vendored
									
									
								
							| @@ -194,6 +194,7 @@ namespace sscs.cache | |||||||
|         {             |         {             | ||||||
|             byte[] baValueClear = DecyptValueAsBytes();             |             byte[] baValueClear = DecyptValueAsBytes();             | ||||||
|             return Encoding.Default.GetString(baValueClear);                                     |             return Encoding.Default.GetString(baValueClear);                                     | ||||||
|  |             //return Encoding.Default.GetString(baValueClear);                                     | ||||||
|         } |         } | ||||||
| 				 | 				 | ||||||
| 		private byte[] DecyptValueAsBytes() | 		private byte[] DecyptValueAsBytes() | ||||||
| @@ -217,6 +218,11 @@ namespace sscs.cache | |||||||
| 			return m_iValueType; | 			return m_iValueType; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  |         internal void SetValueType(int iValueType) | ||||||
|  |         { | ||||||
|  |             m_iValueType = iValueType; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         public string ToXML() |         public string ToXML() | ||||||
|         { |         { | ||||||
|             StringBuilder sb = new StringBuilder(); |             StringBuilder sb = new StringBuilder(); | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								CASA/micasad/cache/Secret.cs
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								CASA/micasad/cache/Secret.cs
									
									
									
									
										vendored
									
									
								
							| @@ -169,10 +169,10 @@ namespace sscs.cache | |||||||
|  |  | ||||||
|                     sb.Append(kv.Key); |                     sb.Append(kv.Key); | ||||||
|                     sb.Append("="); |                     sb.Append("="); | ||||||
| 					if (kv.GetValueType() ==(KeyValue.VALUE_TYPE_BINARY)) | 					//if (kv.GetValueType() ==(KeyValue.VALUE_TYPE_BINARY)) | ||||||
| 						sb.Append("BINARY - Do not change"); | 					//	sb.Append("BINARY - Do not change"); | ||||||
| 					else | 					//else | ||||||
| 						sb.Append(kv.GetValue()); | 					    sb.Append(kv.GetValue()); | ||||||
|                     sb.Append('\n'); |                     sb.Append('\n'); | ||||||
|                 } |                 } | ||||||
|                 //sb.Append('\0');     |                 //sb.Append('\0');     | ||||||
|   | |||||||
| @@ -156,6 +156,7 @@ namespace sscs.constants | |||||||
|         internal static string versionAttr = "version"; |         internal static string versionAttr = "version"; | ||||||
|         internal static string keyChainNode = "KeyChain"; |         internal static string keyChainNode = "KeyChain"; | ||||||
|         internal static string idAttr       = "id"; |         internal static string idAttr       = "id"; | ||||||
|  |         internal static string binaryAttr   = "binary"; | ||||||
|         internal static string secretNode   = "Secret"; |         internal static string secretNode   = "Secret"; | ||||||
|         internal static string valueNode    = "Value"; |         internal static string valueNode    = "Value"; | ||||||
|         internal static string timeNode     = "Time"; |         internal static string timeNode     = "Time"; | ||||||
|   | |||||||
| @@ -478,20 +478,40 @@ namespace sscs.lss | |||||||
|                             { |                             { | ||||||
|                                 attrColl = keyNode.Attributes; |                                 attrColl = keyNode.Attributes; | ||||||
|                                 string key; |                                 string key; | ||||||
|  |                                 string sIsBinary = ""; | ||||||
|                                 try |                                 try | ||||||
|                                 { |                                 { | ||||||
|                                     key = (attrColl[XmlConsts.idAttr]).Value; |                                     key = (attrColl[XmlConsts.idAttr]).Value; | ||||||
|  |                                      | ||||||
|                                 } |                                 } | ||||||
|                                 catch (Exception) |                                 catch (Exception) | ||||||
|                                 { |                                 { | ||||||
|                                     // LinkedKey node, continue |                                     // LinkedKey node, continue | ||||||
|                                     continue; |                                     continue; | ||||||
|                                 } |                                 } | ||||||
|  |  | ||||||
|  |                                 // get binary attribute, if set | ||||||
|  |                                 try | ||||||
|  |                                 { | ||||||
|  |                                     sIsBinary = attrColl.GetNamedItem(XmlConsts.binaryAttr).Value; | ||||||
|  |                                 } | ||||||
|  |                                 catch  | ||||||
|  |                                 { | ||||||
|  |                                     sIsBinary = "false"; | ||||||
|  |                                 }  | ||||||
|  |  | ||||||
|                                 xpath = "descendant::" + XmlConsts.keyValueNode; |                                 xpath = "descendant::" + XmlConsts.keyValueNode; | ||||||
|                                 XmlNode keyValNode = keyNode.SelectSingleNode(xpath); |                                 XmlNode keyValNode = keyNode.SelectSingleNode(xpath); | ||||||
|                                 string keyValue = keyValNode.InnerText; |                                 string keyValue = keyValNode.InnerText; | ||||||
|                                 secret.SetKeyValue(key, keyValue, false); |                                 secret.SetKeyValue(key, keyValue, false); | ||||||
|                                  |                                  | ||||||
|  |                                 // set binary type if set | ||||||
|  |                                 if ((sIsBinary != null) && (sIsBinary.Equals("true"))) | ||||||
|  |                                 { | ||||||
|  |                                     KeyValue kv = secret.GetKeyValue(key); | ||||||
|  |                                     kv.SetValueType(KeyValue.VALUE_TYPE_BINARY); | ||||||
|  |                                 } | ||||||
|  |  | ||||||
|                                 // get time attributes on this key/value  |                                 // get time attributes on this key/value  | ||||||
|                                 XmlNode timeNodeKey = keyNode.SelectSingleNode("descendant::" + XmlConsts.timeNode); |                                 XmlNode timeNodeKey = keyNode.SelectSingleNode("descendant::" + XmlConsts.timeNode); | ||||||
|                                 if (timeNodeKey != null) |                                 if (timeNodeKey != null) | ||||||
| @@ -766,9 +786,16 @@ namespace sscs.lss | |||||||
|                         while (etor.MoveNext()) |                         while (etor.MoveNext()) | ||||||
|                         { |                         { | ||||||
|                             string sKey = (string)etor.Key; |                             string sKey = (string)etor.Key; | ||||||
|                             string value = secret.GetKeyValue(sKey).GetValue(); |                             KeyValue kv = secret.GetKeyValue(sKey); | ||||||
|  |  | ||||||
|  |                             string value = kv.GetValue(); | ||||||
|                             writer.WriteStartElement(XmlConsts.keyNode); |                             writer.WriteStartElement(XmlConsts.keyNode); | ||||||
|                             writer.WriteAttributeString(XmlConsts.idAttr, sKey); |                             writer.WriteAttributeString(XmlConsts.idAttr, sKey); | ||||||
|  |                             if (kv.GetValueType() == KeyValue.VALUE_TYPE_BINARY) | ||||||
|  |                             { | ||||||
|  |                                 writer.WriteAttributeString(XmlConsts.binaryAttr, "true"); | ||||||
|  |                             } | ||||||
|  |                                                          | ||||||
|                             writer.WriteStartElement(XmlConsts.keyValueNode); |                             writer.WriteStartElement(XmlConsts.keyValueNode); | ||||||
|  |  | ||||||
|                             if (bSaveValues) |                             if (bSaveValues) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user