Ejemplo n.º 1
0
 public LocalUserStorage(DatabasePath path, UserStorageConfiguration config)
 {
     if (path == null)
         throw new ArgumentNullException ("path");
     if (config == null)
         throw new ArgumentNullException ("config");
     this.path = path;
     Log.WriteLine ("Reading KeyValueStores");
     userNames = config.Users.OpenStorage<string> (path);
     userParents = config.UserParents.OpenStorage<byte[]> (path);
     userCerts = config.UserCerts.OpenStorage<byte[]> (path);
     userKeys = config.UserKeys.OpenStorage<byte[]> (path);
     userSigningCerts = config.UserSigningCerts.OpenStorage<byte[]> (path);
     userSigningKeys = config.UserSigningKeys.OpenStorage<byte[]> (path);
     userRepositories = config.UserRepositores.OpenStorage<byte[][]> (path);
     repositories = config.Repositores.OpenStorage<byte[]> (path);
     meta = config.Meta.OpenStorage<byte[]> (path);
     //permissions = new LevelDBKeyValueStorage<byte[]> (path.CreatePath (config.PermissionsPath));
     genericRepositories = new SortedDictionary<byte[], GenericUserStorageCollection> (ByteSequenceComparer.Shared);
     loggedInUsers = new SortedDictionary<byte[], RSAParameters> (ByteSequenceComparer.Shared);
     Log.WriteLine ("Done");
     var e = userNames.GetEnumerator ();
     while (e.MoveNext ()) {
         var user = e.Current;
         Log.WriteLine ("user: {0}:{1}", user.Key, user.Value);
         genericRepositories.Add (user.Key,
             new GenericUserStorageCollection (path.CreatePath (user.Key.ToHexadecimal ()), null));
     }
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public DatabasePath(DatabasePath parent, string path)
 {
     if (parent == null)
         throw new ArgumentNullException ("parent");
     if (path == null)
         throw new ArgumentNullException ("path");
     this.parent = parent;
     this.path = path;
 }
Ejemplo n.º 4
0
 public SolidKeyValueStorage(DatabasePath path, string name)
 {
     if (name == null)
         throw new ArgumentNullException ("name");
     if (path == null)
         throw new ArgumentNullException ("path");
     this.name = name;
     this.path = path;
     Initialize ();
 }
Ejemplo n.º 5
0
 public GenericUserStorageCollection(DatabasePath path, RSAParameters? rsa)
 {
     if (path == null)
         throw new ArgumentNullException ("path");
     this.path = path;
     stores = new SortedDictionary<string, KeyValueStorage<byte[]>> ();
     eSymmetricKeys = new SqliteKeyValueStorage (path, "SymmetricKeys");
     eMeta = new SqliteKeyValueStorage (path, "Meta");
     eRepositoryConfigurations = new SqliteKeyValueStorage (path, "RepositoryConfigurations");
     if (rsa.HasValue)
         SetRSAParameters (rsa.Value);
 }
Ejemplo n.º 6
0
 public DatabasePath(DatabasePath parent, string path)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     this.parent = parent;
     this.path   = path;
 }
Ejemplo n.º 7
0
 public BPlusKeyValueStorage(DatabasePath path, string name)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     this.name = name;
     this.path = path;
     Initialize();
 }
Ejemplo n.º 8
0
 public GenericUserRepositoryCollection(DatabasePath path, RSAParameters?rsa)
 {
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     this.path                 = path;
     stores                    = new SortedDictionary <string, KeyValueStorage <byte[]> > ();
     eSymmetricKeys            = new BPlusKeyValueStorage(path, "SymmetricKeys");
     eMeta                     = new BPlusKeyValueStorage(path, "Meta");
     eRepositoryConfigurations = new BPlusKeyValueStorage(path, "RepositoryConfigurations");
     if (rsa.HasValue)
     {
         SetRSAParameters(rsa.Value);
     }
 }
Ejemplo n.º 9
0
        //readonly DatabasePath path;

        public UserRepository(DatabasePath path, UserRepositoryConfiguration config)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            Console.WriteLine("Reading KeyValueStores");
            userNames        = config.Users.OpenStorage <string> (path);
            userParents      = config.UserParents.OpenStorage <byte[]> (path);
            userCerts        = config.UserCerts.OpenStorage <byte[]> (path);
            userKeys         = config.UserKeys.OpenStorage <byte[]> (path);
            userSigningCerts = config.UserSigningCerts.OpenStorage <byte[]> (path);
            userSigningKeys  = config.UserSigningKeys.OpenStorage <byte[]> (path);
            userRepositories = config.UserRepositores.OpenStorage <byte[][]> (path);
            repositories     = config.Repositores.OpenStorage <byte[]> (path);
            meta             = config.Meta.OpenStorage <byte[]> (path);
            //permissions = new LevelDBKeyValueStorage<byte[]> (path.CreatePath (config.PermissionsPath));
            genericRepositories = new SortedDictionary <byte[], GenericUserRepositoryCollection> (ByteSequenceComparer.Shared);
            loggedInUsers       = new SortedDictionary <byte[], RSAParameters> (ByteSequenceComparer.Shared);
            Console.WriteLine("Done");
            var e = userNames.GetEnumerator();

            while (e.MoveNext())
            {
                var user = e.Current;
                Console.WriteLine("user: {0}:{1}", user.Key, user.Value);
                genericRepositories.Add(user.Key,
                                        new GenericUserRepositoryCollection(path.CreatePath(user.Key.ToHexadecimal()),
                                                                            DeserializeKey(new MemoryStream(userCerts.Get(user.Key), false)))
                                        );
            }
        }
Ejemplo n.º 10
0
 public KeyValueStorage <T> OpenStorage <T> (DatabasePath path)
 {
     lock (fns)
         return((KeyValueStorage <T>)fns [Type].Invoke(path, Path, typeof(T)));
 }
Ejemplo n.º 11
0
 public LevelDBKeyValueStorage(DatabasePath path)
     : this(path.Path)
 {
 }
Ejemplo n.º 12
0
        public DataContext(Frontend frontend, byte[] id, DatabasePath path)
            : base(frontend)
        {
            Log.WriteLine ("DataContext-{0}..ctor(frontend={1}, id={2}, path={3})", id.ToHexadecimal (), frontend.ToString (), id.ToHexadecimal (), path);
            this.id = id;
            this.path = path;
            KeyValueStorageConfiguration kvscPrecomputedQueries = new KeyValueStorageConfiguration ("PrecomputedQueries", "Sqlite");
            KeyValueStorageConfiguration kvscMeta = new KeyValueStorageConfiguration ("Meta", "Sqlite");
            KeyValueStorageConfiguration kvscTemporary = new KeyValueStorageConfiguration ("Temporary", "Sqlite");
            precomputedQueries = kvscPrecomputedQueries.OpenStorage<byte[]> (path);
            meta = kvscMeta.OpenStorage<byte[]> (path);
            temporary = kvscTemporary.OpenStorage<byte[]> (path);
            try {
                byte[] cid = meta.Get ("ID".SHA256 ());
                if (cid == null) {
                    meta.Put ("ID".SHA256 (), id);
                    meta.Put ("Solid".SHA256 (), new byte[] { 0 });
                } else {
                    if (ByteSequenceComparer.Shared.Compare (cid, id) != 0)
                        throw new InvalidDataException ("Wrong ID");//should i even do this?
                }
            } catch {
                meta.Put ("ID".SHA256 (), id);
                meta.Put ("Solid".SHA256 (), new byte[] { 0 });
            }
            foreach (var t in frontend.GetTables ())
                perTableRows.Add (t, new SortedDictionary<byte[], Row> (ByteSequenceComparer.Shared));
            foreach (var kvp in temporary) {
                byte[] objectID = kvp.Key;
                //BaseDataObject bdo = new BaseDataObject (this.Frontend, objectID);
                System.IO.MemoryStream ms = new MemoryStream (kvp.Value, 16, kvp.Value.Length - 16);
                byte[] GuidBytes = new byte[16];
                System.Buffer.BlockCopy (kvp.Value, 0, GuidBytes, 0, 16);
                BaseDataObjectVersion bdov = BaseDataObjectTypeIdAttribute.GetAttribFor (new Guid (GuidBytes)).Deserialize (this.Frontend, null, ms.ToArray ());
                var row = bdov as Row;
                if (!references.ContainsKey (bdov.ID)) {
                    if (row != null) {
                        perTableRows [row.Table].Add (bdov.ID, row);
                    }
                    objects.Add (bdov.ID, row);
                }
                foreach (var r in bdov.ReplacingIDs) {
                    if (!references.ContainsKey (r)) {
                        references.Add (r, new SortedSet<byte[]> (ByteSequenceComparer.Shared));
                    }
                    references [r].Add (bdov.ID);
                }

            }
            //this.frontendInstanceBase = (FrontendInstance)frontendInstanceBase;
        }