示例#1
0
        ///<summary>All incoming data filters through here.</summary>
        public void HandleData(MemBlock data, ISender return_path, object state)
        {
            if (!_active)
            {
                if (_closed == 0)
                {
                    UpdateSH(null, null);
                }
                return;
            }

            SecurityDataMessage sdm = new SecurityDataMessage(data);

            if (sdm.SPI != _spi)
            {
                throw new Exception("Invalid SPI!");
            }

            try {
                // try to decrypt the data
                lock (_sync) {
                    _current_sh.DecryptAndVerify(sdm);
                }
            } catch {
                // Maybe this is just a late arriving packet, if it is, we'll just ignore it
                if (sdm.Epoch == _last_epoch)
                {
                    return;
                    // bad packet, let's throw it away!
                }
                else
                {
                    throw;
                }
            }

            // Hand it to our subscriber
            if (_sub != null)
            {
                _sub.Handle(sdm.Data, this);
            }
            _incoming = true;
            _running  = true;
        }
示例#2
0
        public void TDES()
        {
            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
            SymmetricAlgorithm        sa   = new TripleDESCryptoServiceProvider();
            SecurityHandler           sh   = new SecurityHandler(sa, sa, sha1, sha1, 0);

            byte[] data = new byte[1024];
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            rng.GetBytes(data);
            SecurityDataMessage sdm = new SecurityDataMessage();

            sdm.SPI  = 5;
            sdm.Data = MemBlock.Reference(data);
            sh.SignAndEncrypt(sdm);
            SecurityDataMessage sdm_d = new SecurityDataMessage(sdm.Packet);

            sh.DecryptAndVerify(sdm_d);
            Assert.AreEqual(sdm.Data, sdm.Data, "SecurityHandler");
        }