コード例 #1
0
        /**
         * Provides access to the collections inside the store, and creates them if they do not already exist.
         */
        public static bool openCollections(JSONStoreCollection[] collections, JSONStoreProvisionOptions options)
        {
            // if the collection dictionary is not already created, then create one
            if (globalJSONStoreCollectionAccessors == null)
            {
                globalJSONStoreCollectionAccessors = new Dictionary <string, JSONStoreCollection>();
            }

            // cannot open a collection during a transaction, throw exception
            if (transactionInProgress)
            {
                //JSONStoreLoggerError(@"Error: JSON_STORE_TRANSACTION_FAILURE_DURING_INIT, code: %d", rc);
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_TRANSACTION_FAILURE_DURING_INIT);
            }

            // if a password is passed in, then we need to take steps to secure the database
            if (!String.IsNullOrEmpty(options.collectionPassword))
            {
                // create a new security manager for the given username
                JSONStoreSecurityManager security = JSONStoreSecurityManager.sharedManager();

                // check if the key is already store, if so, we do nothing more here
                if (!security.isKeyStored(options.username))
                {
                    // create and store the key
                    bool storeDPKworked = storeDataProtectionKey(options.username, options.localKeyGen ? "" : options.secureRandom, options.collectionPassword, security);

                    if (!storeDPKworked)
                    {
                        //JSONStoreLoggerError(@"Error: JSON_STORE_STORE_DATA_PROTECTION_KEY_FAILURE, code: %d, username: %@, salt length: %d, dpkClear length: %d, cbkClear length: %d, securityMgr username: %@", rc, options.username, salt != nil ? [salt length] : 0, options.secureRandom != nil ? [options.secureRandom length] : 0, options.password != nil ? [options.password length] : 0, secMgr != nil ? secMgr.username : @"nil");
                        throw new JSONStoreException(JSONStoreConstants.JSON_STORE_STORE_DATA_PROTECTION_KEY_FAILURE);
                    }
                }
            }

            // loop through each collection and attempt to open
            foreach (JSONStoreCollection collection in collections)
            {
                int rc = provisionCollection(collection.collectionName, collection.searchFields, collection.additionalSearchFields,
                                             options.username, options.collectionPassword, collection.dropFirst);

                // determine if collection is new or was reopened
                if (rc == JSONStoreConstants.JSON_STORE_RC_OK || rc == JSONStoreConstants.JSON_STORE_PROVISION_TABLE_EXISTS)
                {
                    collection.wasReopened = rc > 0 ? true : false;

                    // store the collection in the accessor
                    if (!globalJSONStoreCollectionAccessors.ContainsKey(collection.collectionName))
                    {
                        globalJSONStoreCollectionAccessors.Add(collection.collectionName, collection);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
 public static JSONStoreSecurityManager sharedManager()
 {
     if (sharedManagerSingleton == null)
     {
         sharedManagerSingleton = new JSONStoreSecurityManager();
     }
     return(sharedManagerSingleton);
 }
コード例 #3
0
        private static bool storeDataProtectionKey(string username, string secureRandom, string password, JSONStoreSecurityManager securityMgr)
        {
            bool worked = false;

            // generate a random salt
            IBuffer salt = JSONStoreSecurityManager.generateRandom(JSONStoreConstants.JSON_STORE_DEFAULT_SALT_SIZE);

            worked = securityMgr.storeDPK(username, password, secureRandom, salt, false);

            if (worked && JSONStoreConstants.JSON_STORE_DEFAULT_USER.Equals(username))
            {
                //updateSecurityVersion();
            }

            return(worked);
        }