diff --git a/c_micasad/cache/KeyValue.cs b/c_micasad/cache/KeyValue.cs index 276363a2..e7bfd380 100644 --- a/c_micasad/cache/KeyValue.cs +++ b/c_micasad/cache/KeyValue.cs @@ -8,6 +8,11 @@ namespace sscs.cache { public class KeyValue { + public static int VALUE_TYPE_STRING = 0; + public static int VALUE_TYPE_BINARY = 1; + + private int m_iValueType = VALUE_TYPE_STRING; + private string m_key; public string Key { @@ -27,6 +32,12 @@ namespace sscs.cache return (DecryptValue()); } + public byte[] GetValueAsBytes() + { + return (DecyptValueAsBytes()); + } + + // this sets string values public void SetValue(string sValue) { @@ -42,6 +53,14 @@ namespace sscs.cache } } + // this sets binary values + public void SetValue(byte[] baValue) + { + m_iValueType = VALUE_TYPE_BINARY; + m_value = EncryptValue(baValue); + m_modified = DateTime.Now; + } + /* public string Value { @@ -119,17 +138,36 @@ namespace sscs.cache m_value = EncryptValue(sValue); } + public KeyValue(string sKey, byte[] baValue) + { + // NOTE: Order is important, do not change + m_created = m_modified = DateTime.Now; + m_key = sKey; + m_value = EncryptValue(baValue); + m_iValueType = VALUE_TYPE_BINARY; + } + private byte[] EncryptValue(string sValue) { byte[] baValueClear = Encoding.Default.GetBytes(sValue); - return (XORValue(baValueClear)); + return EncryptValue(baValueClear); } + private byte[] EncryptValue(byte[] baValueClear) + { + return (XORValue(baValueClear)); + } + private string DecryptValue() { - byte[] baValueClear = XORValue(m_value); + byte[] baValueClear = DecyptValueAsBytes(); return Encoding.Default.GetString(baValueClear); } + + private byte[] DecyptValueAsBytes() + { + return XORValue(m_value); + } private byte[] XORValue(byte[] baInput) { @@ -145,6 +183,11 @@ namespace sscs.cache return baOutput; } + public int GetValueType() + { + return m_iValueType; + } + public string ToXML() { StringBuilder sb = new StringBuilder(); diff --git a/c_micasad/cache/Secret.cs b/c_micasad/cache/Secret.cs index 7256914b..7051702b 100644 --- a/c_micasad/cache/Secret.cs +++ b/c_micasad/cache/Secret.cs @@ -146,7 +146,10 @@ namespace sscs.cache sb.Append(kv.Key); sb.Append("="); - sb.Append(kv.GetValue()); + if (kv.GetValueType() ==(KeyValue.VALUE_TYPE_BINARY)) + sb.Append("BINARY - Do not change"); + else + sb.Append(kv.GetValue()); sb.Append('\n'); } //sb.Append('\0'); @@ -169,6 +172,7 @@ namespace sscs.cache { return secretID; } + public void SetKeyValue(string key, string value) { KeyValue kv; @@ -185,6 +189,22 @@ namespace sscs.cache this.ModifiedTime = DateTime.Now; } + public void SetKeyValue(string key, byte[] baValue) + { + KeyValue kv; + if (htKeyValues.Contains(key)) + { + kv = (KeyValue)htKeyValues[key]; + kv.SetValue(baValue); + } + else + { + kv = new KeyValue(key, baValue); + htKeyValues.Add(key, kv); + } + this.ModifiedTime = DateTime.Now; + } + public KeyValue GetKeyValue(string key) { this.AccessedTime = DateTime.Now; diff --git a/c_micasad/common/RequestParser.cs b/c_micasad/common/RequestParser.cs index db723151..eab80874 100644 --- a/c_micasad/common/RequestParser.cs +++ b/c_micasad/common/RequestParser.cs @@ -59,6 +59,8 @@ namespace sscs.common msgIdMap.Add(18,"sscs.verbs.SetMasterPassword"); msgIdMap.Add(19,"sscs.verbs.IsSecretPersistent"); msgIdMap.Add(20,"sscs.verbs.ObjectSerialization"); + msgIdMap.Add(21,"sscs.verbs.WriteBinaryKey"); + msgIdMap.Add(22,"sscs.verbs.ReadBinaryKey"); } diff --git a/c_micasad/objs.lux b/c_micasad/objs.lux index 9fb01d08..876813ee 100644 --- a/c_micasad/objs.lux +++ b/c_micasad/objs.lux @@ -37,9 +37,11 @@ OBJS=\ verbs/RemoveSecret \ verbs/EnumerateKeyChainIds \ verbs/EnumerateSecretIds \ - verbs/SetMasterPassword \ + verbs/SetMasterPassword \ verbs/WriteKey \ verbs/ReadKey \ + verbs/WriteBinaryKey \ + verbs/ReadBinaryKey \ verbs/IsSecretPersistent \ verbs/ObjectSerialization \ test/cache/TestSecret \ diff --git a/c_micasad/src.lux b/c_micasad/src.lux index 5181a698..bafad361 100644 --- a/c_micasad/src.lux +++ b/c_micasad/src.lux @@ -40,6 +40,8 @@ SRC=\ verbs/SetMasterPassword.cs \ verbs/WriteKey.cs \ verbs/ReadKey.cs \ + verbs/WriteBinaryKey.cs \ + verbs/ReadBinaryKey.cs \ verbs/IsSecretPersistent.cs \ verbs/ObjectSerialization.cs \ test/cache/TestSecret.cs \