Example #1
0
        public virtual void TestBlockTokenSecretManager()
        {
            BlockTokenSecretManager masterHandler = new BlockTokenSecretManager(blockKeyUpdateInterval
                                                                                , blockTokenLifetime, 0, "fake-pool", null);
            BlockTokenSecretManager slaveHandler = new BlockTokenSecretManager(blockKeyUpdateInterval
                                                                               , blockTokenLifetime, "fake-pool", null);
            ExportedBlockKeys keys = masterHandler.ExportKeys();

            slaveHandler.AddKeys(keys);
            TokenGenerationAndVerification(masterHandler, slaveHandler);
            // key updating
            masterHandler.UpdateKeys();
            TokenGenerationAndVerification(masterHandler, slaveHandler);
            keys = masterHandler.ExportKeys();
            slaveHandler.AddKeys(keys);
            TokenGenerationAndVerification(masterHandler, slaveHandler);
        }
 /// <summary>Set block keys, only to be used in slave mode</summary>
 /// <exception cref="System.IO.IOException"/>
 public virtual void AddKeys(ExportedBlockKeys exportedKeys)
 {
     lock (this)
     {
         if (isMaster || exportedKeys == null)
         {
             return;
         }
         Log.Info("Setting block keys");
         RemoveExpiredKeys();
         this.currentKey = exportedKeys.GetCurrentKey();
         BlockKey[] receivedKeys = exportedKeys.GetAllKeys();
         for (int i = 0; i < receivedKeys.Length; i++)
         {
             if (receivedKeys[i] == null)
             {
                 continue;
             }
             this.allKeys[receivedKeys[i].GetKeyId()] = receivedKeys[i];
         }
     }
 }
Example #3
0
        public virtual void TestBlockPoolTokenSecretManager()
        {
            BlockPoolTokenSecretManager bpMgr = new BlockPoolTokenSecretManager();

            // Test BlockPoolSecretManager with upto 10 block pools
            for (int i = 0; i < 10; i++)
            {
                string bpid = Sharpen.Extensions.ToString(i);
                BlockTokenSecretManager masterHandler = new BlockTokenSecretManager(blockKeyUpdateInterval
                                                                                    , blockTokenLifetime, 0, "fake-pool", null);
                BlockTokenSecretManager slaveHandler = new BlockTokenSecretManager(blockKeyUpdateInterval
                                                                                   , blockTokenLifetime, "fake-pool", null);
                bpMgr.AddBlockPool(bpid, slaveHandler);
                ExportedBlockKeys keys = masterHandler.ExportKeys();
                bpMgr.AddKeys(bpid, keys);
                TokenGenerationAndVerification(masterHandler, bpMgr.Get(bpid));
                // Test key updating
                masterHandler.UpdateKeys();
                TokenGenerationAndVerification(masterHandler, bpMgr.Get(bpid));
                keys = masterHandler.ExportKeys();
                bpMgr.AddKeys(bpid, keys);
                TokenGenerationAndVerification(masterHandler, bpMgr.Get(bpid));
            }
        }
 /// <summary>
 /// See
 /// <see cref="BlockTokenSecretManager.AddKeys(ExportedBlockKeys)"/>
 /// </summary>
 /// <exception cref="System.IO.IOException"/>
 public virtual void AddKeys(string bpid, ExportedBlockKeys exportedKeys)
 {
     Get(bpid).AddKeys(exportedKeys);
 }