Beispiel #1
0
        public bool Login(byte[] userID, string password, string pepper)
        {
            if (userStorage.LoggedInUsers.Contains(userID))
            {
                throw new InvalidOperationException(string.Format("User [0x{0}] is already logged in.", userID.ToHexadecimal()));
            }
            bool v = userStorage.Login(userID, password, pepper);

            if (v)
            {
                foreach (var ur in userStorage.GetUserRepositories(userID))
                {
                    byte[] repoInfo = userStorage.GetRawRepositoryInfo(ur);
                    System.Xml.Serialization.XmlSerializer xmls = new System.Xml.Serialization.XmlSerializer(typeof(ChunkRepositoryConfiguration));
                    ChunkRepositoryConfiguration           cri  = (ChunkRepositoryConfiguration)xmls.Deserialize(new MemoryStream(repoInfo, false));
                    DatabasePath dbp = GetRepositoryPath(cri.ID);
                    if (dataStorage.ContainsKey(ur))
                    {
                        foreach (var sk in userStorage.GetUserRepository(ur).SymmetricKeys)
                        {
                            if (!dataStorage [ur].LencryptedData.ContainsKey(sk.Key))
                            {
                                dataStorage [ur].LencryptedData.Add(sk.Key, new AESEncryptingKeyValueStorage(
                                                                        new LevelDBKeyValueStorage(dbp.CreatePath("Encrypted").CreatePath(sk.Key.ToHexadecimal()))
                                                                        , sk.Value));
                            }
                        }
                    }
                    else
                    {
                        SortedDictionary <byte[], KeyValueStorage <byte[]> > EncryptedData = new SortedDictionary <byte[], KeyValueStorage <byte[]> > ();
                        foreach (var sk in userStorage.GetUserRepository(ur).SymmetricKeys)
                        {
                            KeyValueStorageConfiguration ESC = new KeyValueStorageConfiguration();
                            ESC.Type = cri.Data.Type;
                            ESC.Path = sk.Key.ToHexadecimal();
                            EncryptedData.Add(sk.Key, new AESEncryptingKeyValueStorage(
                                                  ESC.OpenStorage <byte[]> (dbp.CreatePath("Encrypted")), sk.Value));
                        }
                        ChunkRepository cr = new ChunkRepository(
                            cri.Data.OpenStorage <byte[]> (dbp),
                            cri.TopLevels.OpenStorage <byte[][]> (dbp),
                            cri.Dependencies.OpenStorage <byte[][]> (dbp),
                            cri.Meta.OpenStorage <byte[]> (dbp),
                            cri.MetaTopLevels.OpenStorage <byte[][]> (dbp),
                            cri.MetaDependencies.OpenStorage <byte[][]> (dbp),
                            cri.Signatures.OpenStorage <byte[][]> (dbp),
                            cri.ChunkSymmetricKeys.OpenStorage <byte[][]> (dbp),
                            cri.Index.OpenStorage <byte[]> (dbp),
                            EncryptedData);
                        dataStorage.Add(cr.ID, cr);
                    }
                    //encryptedStorageManager.Add (ur, new EncryptedStorageManager (cr, userStorage));
                }
            }
            return(v);
        }
Beispiel #2
0
 public override byte[] AddRepositoryForUsers(IEnumerable<byte[]> users)
 {
     RandomNumberGenerator rng = RandomNumberGenerator.Create ();
     byte[] key = new byte[32];
     rng.GetBytes (key);
     ChunkRepositoryConfiguration crc = new ChunkRepositoryConfiguration ();
     crc.ID = key;
     crc.Data = new KeyValueStorageConfiguration ("Data", "Sqlite");
     crc.TopLevels = new KeyValueStorageConfiguration ("TopLevels", "Sqlite");
     crc.Dependencies = new KeyValueStorageConfiguration ("Dependencies", "Sqlite");
     crc.Meta = new KeyValueStorageConfiguration ("Meta", "Sqlite");
     crc.MetaTopLevels = new KeyValueStorageConfiguration ("MetaTopLevels", "Sqlite");
     crc.MetaDependencies = new KeyValueStorageConfiguration ("MetaDependencies", "Sqlite");
     crc.Signatures = new KeyValueStorageConfiguration ("Signatures", "Sqlite");
     crc.ChunkSymmetricKeys = new KeyValueStorageConfiguration ("ChunkSymmetricKeys", "Sqlite");
     crc.Index = new KeyValueStorageConfiguration ("Index", "Sqlite");
     crc.InternalMeta = new KeyValueStorageConfiguration ("InternalMeta", "Sqlite");
     XmlSerializer xmls = new XmlSerializer (typeof(ChunkRepositoryConfiguration));
     MemoryStream ms = new MemoryStream ();
     xmls.Serialize (ms, crc);
     byte[] value = ms.ToArray ();
     repositories.Put (key, value);
     foreach (var user in users)
         AddRepositoryForUser (key, user);
     return key;
 }