public string GetPubKey(Principal prin)
 {
     if (logger != null) logger.Log("GetPubKey request for " + prin.ToString());
     // TODO(trinabh): return should be signed
     if (keytable.ContainsKey(prin.ToString()))
     {
         return keytable[prin.ToString()];
     }
     else
     {
         return null;
     }
 }
 public bool RegisterPubKey(Principal prin, string key)
 {
     if (logger != null) logger.Log("RegisterPubKey request for " + prin.ToString());
     if (keytable.ContainsKey(prin.ToString()))
     {
         return false;
     }
     else
     {
         keytable[prin.ToString()] = key;
     }
     return true;
 }
        public bool UpdateReaderKey(Principal caller, FQStreamID stream, ACLEntry entry)
        {
            if (logger != null) logger.Log("UpdateReaderKey request from caller " + caller.ToString() + " for stream "
                + stream.ToString() + " and principal " + entry.readerName.ToString()
                + " key version " + entry.keyVersion);
            
            // Authentication is not required for unlisted streams
            /*
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
            string callerpubkey = GetPubKey(caller);
            if (callerpubkey == null)
                return false;
            RSA.FromXmlString(callerpubkey);

            Byte[] data = { };
            data = data.Concat(this.GetBytes(caller.HomeId)).ToArray();
            data = data.Concat(this.GetBytes(caller.AppId)).ToArray();
            data = data.Concat(this.GetBytes(stream.HomeId)).ToArray();
            data = data.Concat(this.GetBytes(stream.AppId)).ToArray();
            data = data.Concat(this.GetBytes(stream.StreamId)).ToArray();
            data = data.Concat(this.GetBytes(entry.readerName.HomeId)).ToArray();
            data = data.Concat(this.GetBytes(entry.readerName.AppId)).ToArray();
            data = data.Concat(entry.encKey).ToArray();
            data = data.Concat(entry.IV).ToArray();
            data = data.Concat(this.GetBytes("" + entry.keyVersion)).ToArray();

            if (RSA.VerifyData(data, new SHA256CryptoServiceProvider(), caller.Auth) == false)
            {
                if (logger != null) logger.Log("Verification of request failed");
                return false;
            }
            //
            */

            if (caller.HomeId == stream.HomeId && caller.AppId == stream.AppId)
            {
                if (!mdtable.ContainsKey(stream.ToString()))
                    mdtable[stream.ToString()] = new StreamInfo(stream);
                mdtable[stream.ToString()].UpdateReader(entry);
                return true;
            }
            else
            {
                return false;
            }
        }
 public ACLEntry GetReader(Principal prin)
 {
     if (readers.ContainsKey(prin.ToString()))
     {
         return readers[prin.ToString()];
     }
     return null;
 }
 public StreamInfo(FQStreamID sname)
 {
     stream = sname;
     owner = new Principal(sname.HomeId, sname.AppId);
     accounts = new Dictionary<int, AccountInfo>();
     readers = new Dictionary<string, ACLEntry>();
     latest_keyversion = 0;
 }
 public ACLEntry(Principal rName, byte[] key, byte[] iv, uint kversion)
 {
     _readerName = rName;
     _encKey = key;
     _IV = iv;
     _keyVersion = kversion;
 }
 public ACLEntry GetReaderKey(FQStreamID stream, Principal p)
 {
     if (logger != null) logger.Log("GetReaderKey from caller " + p.ToString() + " for stream "
         + stream.ToString());
     // TODO(trinabh): Return should be signed
     if (mdtable.ContainsKey(stream.ToString()))
     {
         return mdtable[stream.ToString()].GetReader(p);
     }
     return null;
 }