Exemplo n.º 1
0
        /// <summary>
        /// WriteToCache method implementation
        /// </summary>
        private static void WriteToCache(SIDsParametersRecord config)
        {
            if (config.ADFSDelegateServiceAdministrationAllowed)
            {
                StoreDelegatedGroupStatus(config.ADFSAdministrationGroupName);
            }
            else
            {
                StoreDelegatedGroupStatus(null);
            }
            DataContractSerializer serializer = new DataContractSerializer(typeof(SIDsParametersRecord));
            MemoryStream           stm        = new MemoryStream();

            using (StreamReader reader = new StreamReader(stm))
            {
                serializer.WriteObject(stm, config);
                stm.Position = 0;
                byte[] byt = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    byt = aes.Encrypt(stm.ToArray());
                }
                using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Create, FileAccess.ReadWrite))
                {
                    fs.Write(byt, 0, byt.Length);
                    fs.Close();
                }
                return;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// LoadFromCache method implementation
        /// </summary>
        private static SIDsParametersRecord LoadFromCache()
        {
            SIDsParametersRecord config = null;

            if (!File.Exists(SystemUtilities.SystemCacheFile))
            {
                return(null);
            }
            DataContractSerializer serializer = new DataContractSerializer(typeof(SIDsParametersRecord));

            using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Open, FileAccess.Read))
            {
                byte[] bytes = new byte[fs.Length];
                int    n     = fs.Read(bytes, 0, (int)fs.Length);
                fs.Close();

                byte[] byt = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    byt = aes.Decrypt(bytes);
                }
                using (MemoryStream ms = new MemoryStream(byt))
                {
                    using (StreamReader reader = new StreamReader(ms))
                    {
                        config = (SIDsParametersRecord)serializer.ReadObject(ms);
                    }
                }
            }
            return(config);
        }
Exemplo n.º 3
0
            /// <summary>
            /// WriteMessage method override
            /// </summary>
            public override void WriteMessage(Message message, Stream stream)
            {
                byte[] cryptedBytes = new byte[stream.Length];
                stream.Read(cryptedBytes, 0, (int)stream.Length);
                byte[] unencryptedBytes = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    unencryptedBytes = aes.Decrypt(cryptedBytes);
                }
                MemoryStream stm = new MemoryStream(unencryptedBytes);

                innerEncoder.WriteMessage(message, stm);
                stream.Flush();
            }
Exemplo n.º 4
0
            /// <summary>
            /// ReadMessage method override
            /// </summary>
            public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
            {
                byte[] unencryptedBytes = new byte[stream.Length];
                stream.Read(unencryptedBytes, 0, (int)stream.Length);

                byte[] cryptedBytes = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    cryptedBytes = aes.Encrypt(unencryptedBytes);
                }

                MemoryStream stm = new MemoryStream(cryptedBytes);

                return(innerEncoder.ReadMessage(stm, maxSizeOfHeaders));
            }
Exemplo n.º 5
0
            /// <summary>
            /// EncryptBuffer method implementation (compress)
            /// </summary>
            private ArraySegment <byte> EncryptBuffer(ArraySegment <byte> buffer, BufferManager bufferManager, int messageOffset)
            {
                byte[] unencryptedBytes = new byte[buffer.Count];
                Array.Copy(buffer.Array, buffer.Offset, unencryptedBytes, 0, unencryptedBytes.Length);

                byte[] cryptedBytes = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    cryptedBytes = aes.Encrypt(unencryptedBytes);
                }

                int totalLength = messageOffset + cryptedBytes.Length;

                byte[] bufferManagerBuffer = bufferManager.TakeBuffer(totalLength);
                Array.Clear(bufferManagerBuffer, 0, bufferManagerBuffer.Length);
                Array.Copy(cryptedBytes, 0, bufferManagerBuffer, messageOffset, cryptedBytes.Length);

                bufferManager.ReturnBuffer(buffer.Array);
                ArraySegment <byte> byteArray = new ArraySegment <byte>(bufferManagerBuffer, messageOffset, cryptedBytes.Length);

                return(byteArray);
            }
Exemplo n.º 6
0
        /// <summary>
        /// WriteToCache method implementation
        /// </summary>
        private static void WriteToCache(SIDsParametersRecord config)
        {
            XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(SIDsParametersRecord));
            MemoryStream        stm           = new MemoryStream();

            using (StreamReader reader = new StreamReader(stm))
            {
                xmlserializer.Serialize(stm, config);
                stm.Position = 0;
                byte[] byt = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    byt = aes.Encrypt(stm.ToArray());
                }
                using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Create, FileAccess.ReadWrite))
                {
                    fs.Write(byt, 0, byt.Length);
                    fs.Close();
                }
                return;
            }
        }
 /// <summary>
 /// WriteConfigurationToCache method implementation
 /// </summary>
 internal void WriteConfigurationToCache(byte[] config)
 {
     try
     {
         using (FileStream fs = new FileStream(CFGUtilities.ConfigCacheFile, FileMode.Create, FileAccess.ReadWrite))
         {
             fs.Write(config, 0, config.Length);
             fs.Close();
         }
         if (SIDs.Loaded)
         {
             XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(SIDsParametersRecord));
             MemoryStream        stm           = new MemoryStream();
             byte[] bytes = null;
             using (StreamReader reader = new StreamReader(stm))
             {
                 xmlserializer.Serialize(stm, SIDs.GetSIDs());
                 stm.Position = 0;
                 using (AESSystemEncryption aes = new AESSystemEncryption())
                 {
                     bytes = aes.Encrypt(stm.ToArray());
                 }
             }
             using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Create, FileAccess.ReadWrite))
             {
                 fs.Write(bytes, 0, bytes.Length);
                 fs.Close();
             }
         }
     }
     catch (Exception e)
     {
         _log.WriteEntry(string.Format("Error on WebAdminService Service WriteConfigurationToCache method : {0}.", e.Message), EventLogEntryType.Error, 2010);
         throw e;
     }
 }