From a50904a68bdc215d4ccc312627d44c736a1bceb5 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 10 Aug 2009 06:41:03 -0700 Subject: More clean up from asset cache legacy. None of these classes are used anymore. --- .../Communications/Cache/AssetServerBase.cs | 246 --------- .../Communications/Cache/CryptoGridAssetClient.cs | 559 --------------------- .../Communications/Cache/FileAssetClient.cs | 121 ----- .../Communications/Cache/GridAssetClient.cs | 140 ------ 4 files changed, 1066 deletions(-) delete mode 100644 OpenSim/Framework/Communications/Cache/AssetServerBase.cs delete mode 100644 OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs delete mode 100644 OpenSim/Framework/Communications/Cache/FileAssetClient.cs delete mode 100644 OpenSim/Framework/Communications/Cache/GridAssetClient.cs (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs deleted file mode 100644 index 4b2a752..0000000 --- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using System.Threading; -using log4net; -using OpenMetaverse; -using OpenSim.Data; -using OpenSim.Framework.AssetLoader.Filesystem; -using OpenSim.Framework.Statistics; - -namespace OpenSim.Framework.Communications.Cache -{ - public abstract class AssetServerBase : IAssetServer - { - private static readonly ILog m_log - = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - protected IAssetReceiver m_receiver; - protected BlockingQueue m_assetRequests = new BlockingQueue(); - protected Thread m_localAssetServerThread; - protected IAssetDataPlugin m_assetProvider; - - #region IPlugin - - /// - /// The methods and properties in this region are needed to implement - /// the IPlugin interface and its local extensions. - /// These can all be overridden as appropriate by a derived class. - /// These methods are only applicable when a class is loaded by the - /// IPlugin mechanism. - /// - /// Note that in the case of AssetServerBase, all initialization is - /// performed by the default constructor, so nothing additional is - /// required here. A derived class may wish to do more. - /// - - public virtual string Name - { - // get { return "OpenSim.Framework.Communications.Cache.AssetServerBase"; } - get { return "AssetServerBase"; } - } - - public virtual string Version - { - get { return "1.0"; } - } - - public virtual void Initialise() - { - m_log.Debug("[ASSET SERVER]: IPlugin null initialization"); - } - - public virtual void Initialise(ConfigSettings settings) - { - m_log.Debug("[ASSET SERVER]: IPlugin null configured initialization(1)"); - m_log.InfoFormat("[ASSET SERVER]: Initializing client [{0}/{1}", Name, Version); - } - - public virtual void Initialise(ConfigSettings settings, string p_url) - { - m_log.Debug("[ASSET SERVER]: IPlugin null configured initialization(2)"); - m_log.InfoFormat("[ASSET SERVER]: Initializing client [{0}/{1}", Name, Version); - } - - public virtual void Initialise(ConfigSettings settings, string p_url, string p_dir, bool p_t) - { - m_log.Debug("[ASSET SERVER]: IPlugin null configured initialization(3)"); - m_log.InfoFormat("[ASSET SERVER]: Initializing client [{0}/{1}", Name, Version); - } - - public virtual void Dispose() - { - m_log.Debug("[ASSET SERVER]: dispose"); - } - - #endregion - - public IAssetDataPlugin AssetProviderPlugin - { - get { return m_assetProvider; } - } - - // Temporarily hardcoded - should be a plugin - protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); - - public virtual void Start() - { - m_log.Debug("[ASSET SERVER]: Starting asset server"); - - m_localAssetServerThread = new Thread(RunRequests); - m_localAssetServerThread.Name = "LocalAssetServerThread"; - m_localAssetServerThread.IsBackground = true; - m_localAssetServerThread.Start(); - ThreadTracker.Add(m_localAssetServerThread); - } - - public virtual void Stop() - { - m_localAssetServerThread.Abort(); - } - - public abstract void StoreAsset(AssetBase asset); - - /// - /// This method must be implemented by a subclass to retrieve the asset named in the - /// AssetRequest. If the asset is not found, null should be returned. - /// - /// - /// - /// - /// Thrown if the request failed for some other reason than that the - /// asset cannot be found. - /// - protected abstract AssetBase GetAsset(AssetRequest req); - - /// - /// Does the asset server have any waiting requests? - /// - /// - /// This does include any request that is currently being handled. This information is not reliable where - /// another thread may be processing requests. - /// - /// - /// True if there are waiting requests. False if there are no waiting requests. - /// - public virtual bool HasWaitingRequests() - { - return m_assetRequests.Count() != 0; - } - - /// - /// Process an asset request. This method will call GetAsset(AssetRequest req) - /// on the subclass. - /// - public virtual void ProcessNextRequest() - { - AssetRequest req = m_assetRequests.Dequeue(); - AssetBase asset; - - try - { - asset = GetAsset(req); - } - catch (Exception e) - { - m_log.ErrorFormat("[ASSET]: Asset request for {0} threw exception {1} - Stack Trace: {2}", req.AssetID, e, e.StackTrace); - - if (StatsManager.SimExtraStats != null) - StatsManager.SimExtraStats.AddAssetServiceRequestFailure(); - - m_receiver.AssetNotFound(req.AssetID, req.IsTexture); - - return; - } - - if (asset != null) - { - //m_log.DebugFormat("[ASSET]: Asset {0} received from asset server", req.AssetID); - - m_receiver.AssetReceived(asset, req.IsTexture); - } - else - { - //m_log.WarnFormat("[ASSET]: Asset {0} not found by asset server", req.AssetID); - - m_receiver.AssetNotFound(req.AssetID, req.IsTexture); - } - } - - public virtual void LoadDefaultAssets(string pAssetSetsXml) - { - m_log.Info("[ASSET SERVER]: Setting up asset database"); - - assetLoader.ForEachDefaultXmlAsset(pAssetSetsXml, StoreAsset); - } - - private void RunRequests() - { - while (true) // Since it's a 'blocking queue' - { - try - { - ProcessNextRequest(); - } - catch (Exception e) - { - m_log.Error("[ASSET SERVER]: " + e.ToString()); - } - } - } - - /// - /// The receiver will be called back with asset data once it comes in. - /// - /// - public void SetReceiver(IAssetReceiver receiver) - { - m_receiver = receiver; - } - - public void RequestAsset(UUID assetID, bool isTexture) - { - AssetRequest req = new AssetRequest(); - req.AssetID = assetID; - req.IsTexture = isTexture; - m_assetRequests.Enqueue(req); - - //m_log.DebugFormat("[ASSET SERVER]: Added {0} to request queue", assetID); - } - - public virtual void UpdateAsset(AssetBase asset) - { - m_assetProvider.UpdateAsset(asset); - } - - public void SetServerInfo(string ServerUrl, string ServerKey) - { - } - } -} diff --git a/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs b/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs deleted file mode 100644 index 4e35f5b..0000000 --- a/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs +++ /dev/null @@ -1,559 +0,0 @@ -/* - * Copyright (c) Contributors, http://www.openmetaverse.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/* - * This file includes content derived from Obviex. - * Copyright (C) 2002 Obviex(TM). All rights reserved. - * http://www.obviex.com/samples/Encryption.aspx - */ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Security.Cryptography; -using System.Text; -using System.Xml.Serialization; -using log4net; -using OpenSim.Framework.Servers.HttpServer; - -namespace OpenSim.Framework.Communications.Cache -{ - public class CryptoGridAssetClient : AssetServerBase - { - - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private string _assetServerUrl; - private bool m_encryptOnUpload; - private RjinKeyfile m_encryptKey; - private readonly Dictionary m_keyfiles = new Dictionary(); - - #region IPlugin - - public override string Name - { - get { return "Crypto"; } - } - - public override string Version - { - get { return "1.0"; } - } - - public override void Initialise(ConfigSettings p_set, string p_url, string p_dir, bool p_t) - { - m_log.Debug("[CRYPTOGRID] Plugin configured initialisation"); - Initialise(p_url, p_dir, p_t); - } - - #endregion - - #region Keyfile Classes - [Serializable] - public class RjinKeyfile - { - public string Secret; - public string AlsoKnownAs; - public int Keysize; - public string IVBytes; - public string Description = "OpenSim Key"; - - private static string SHA1Hash(byte[] bytes) - { - SHA1 sha1 = SHA1CryptoServiceProvider.Create(); - byte[] dataMd5 = sha1.ComputeHash(bytes); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < dataMd5.Length; i++) - sb.AppendFormat("{0:x2}", dataMd5[i]); - return sb.ToString(); - } - - public void GenerateRandom() - { - RNGCryptoServiceProvider Gen = new RNGCryptoServiceProvider(); - - byte[] genSec = new byte[32]; - byte[] genAKA = new byte[32]; - byte[] genIV = new byte[32]; - - Gen.GetBytes(genSec); - Gen.GetBytes(genAKA); - Gen.GetBytes(genIV); - - Secret = SHA1Hash(genSec); - AlsoKnownAs = SHA1Hash(genAKA); - IVBytes = SHA1Hash(genIV).Substring(0, 16); - Keysize = 256; - } - } - #endregion - - #region Rjindael - /// - /// This class uses a symmetric key algorithm (Rijndael/AES) to encrypt and - /// decrypt data. As long as encryption and decryption routines use the same - /// parameters to generate the keys, the keys are guaranteed to be the same. - /// The class uses static functions with duplicate code to make it easier to - /// demonstrate encryption and decryption logic. In a real-life application, - /// this may not be the most efficient way of handling encryption, so - as - /// soon as you feel comfortable with it - you may want to redesign this class. - /// - public class UtilRijndael - { - /// - /// Encrypts specified plaintext using Rijndael symmetric key algorithm - /// and returns a base64-encoded result. - /// - /// - /// Plaintext value to be encrypted. - /// - /// - /// Passphrase from which a pseudo-random password will be derived. The - /// derived password will be used to generate the encryption key. - /// Passphrase can be any string. In this example we assume that this - /// passphrase is an ASCII string. - /// - /// - /// Salt value used along with passphrase to generate password. Salt can - /// be any string. In this example we assume that salt is an ASCII string. - /// - /// - /// Hash algorithm used to generate password. Allowed values are: "MD5" and - /// "SHA1". SHA1 hashes are a bit slower, but more secure than MD5 hashes. - /// - /// - /// Number of iterations used to generate password. One or two iterations - /// should be enough. - /// - /// - /// Initialization vector (or IV). This value is required to encrypt the - /// first block of plaintext data. For RijndaelManaged class IV must be - /// exactly 16 ASCII characters long. - /// - /// - /// Size of encryption key in bits. Allowed values are: 128, 192, and 256. - /// Longer keys are more secure than shorter keys. - /// - /// - /// Encrypted value formatted as a base64-encoded string. - /// - public static byte[] Encrypt(byte[] plainText, - string passPhrase, - string saltValue, - string hashAlgorithm, - int passwordIterations, - string initVector, - int keySize) - { - // Convert strings into byte arrays. - // Let us assume that strings only contain ASCII codes. - // If strings include Unicode characters, use Unicode, UTF7, or UTF8 - // encoding. - byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector); - byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue); - - // Convert our plaintext into a byte array. - // Let us assume that plaintext contains UTF8-encoded characters. - byte[] plainTextBytes = plainText; - - // First, we must create a password, from which the key will be derived. - // This password will be generated from the specified passphrase and - // salt value. The password will be created using the specified hash - // algorithm. Password creation can be done in several iterations. - PasswordDeriveBytes password = new PasswordDeriveBytes( - passPhrase, - saltValueBytes, - hashAlgorithm, - passwordIterations); - - // Use the password to generate pseudo-random bytes for the encryption - // key. Specify the size of the key in bytes (instead - // of bits). - #pragma warning disable 0618 - byte[] keyBytes = password.GetBytes(keySize / 8); - #pragma warning restore 0618 - - // Create uninitialized Rijndael encryption object. - RijndaelManaged symmetricKey = new RijndaelManaged(); - - // It is reasonable to set encryption mode to Cipher Block Chaining - // (CBC). Use default options for other symmetric key parameters. - symmetricKey.Mode = CipherMode.CBC; - - // Generate encryptor from the existing key bytes and initialization - // vector. Key size will be defined based on the number of the key - // bytes. - ICryptoTransform encryptor = symmetricKey.CreateEncryptor( - keyBytes, - initVectorBytes); - - // Define memory stream which will be used to hold encrypted data. - MemoryStream memoryStream = new MemoryStream(); - - // Define cryptographic stream (always use Write mode for encryption). - CryptoStream cryptoStream = new CryptoStream(memoryStream, - encryptor, - CryptoStreamMode.Write); - // Start encrypting. - cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length); - - // Finish encrypting. - cryptoStream.FlushFinalBlock(); - - // Convert our encrypted data from a memory stream into a byte array. - byte[] cipherTextBytes = memoryStream.ToArray(); - - // Close both streams. - memoryStream.Close(); - cryptoStream.Close(); - - // Return encrypted string. - return cipherTextBytes; - } - - /// - /// Decrypts specified ciphertext using Rijndael symmetric key algorithm. - /// - /// - /// Base64-formatted ciphertext value. - /// - /// - /// Passphrase from which a pseudo-random password will be derived. The - /// derived password will be used to generate the encryption key. - /// Passphrase can be any string. In this example we assume that this - /// passphrase is an ASCII string. - /// - /// - /// Salt value used along with passphrase to generate password. Salt can - /// be any string. In this example we assume that salt is an ASCII string. - /// - /// - /// Hash algorithm used to generate password. Allowed values are: "MD5" and - /// "SHA1". SHA1 hashes are a bit slower, but more secure than MD5 hashes. - /// - /// - /// Number of iterations used to generate password. One or two iterations - /// should be enough. - /// - /// - /// Initialization vector (or IV). This value is required to encrypt the - /// first block of plaintext data. For RijndaelManaged class IV must be - /// exactly 16 ASCII characters long. - /// - /// - /// Size of encryption key in bits. Allowed values are: 128, 192, and 256. - /// Longer keys are more secure than shorter keys. - /// - /// - /// Decrypted string value. - /// - /// - /// Most of the logic in this function is similar to the Encrypt - /// logic. In order for decryption to work, all parameters of this function - /// - except cipherText value - must match the corresponding parameters of - /// the Encrypt function which was called to generate the - /// ciphertext. - /// - public static byte[] Decrypt(byte[] cipherText, - string passPhrase, - string saltValue, - string hashAlgorithm, - int passwordIterations, - string initVector, - int keySize) - { - // Convert strings defining encryption key characteristics into byte - // arrays. Let us assume that strings only contain ASCII codes. - // If strings include Unicode characters, use Unicode, UTF7, or UTF8 - // encoding. - byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector); - byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue); - - // Convert our ciphertext into a byte array. - byte[] cipherTextBytes = cipherText; - - // First, we must create a password, from which the key will be - // derived. This password will be generated from the specified - // passphrase and salt value. The password will be created using - // the specified hash algorithm. Password creation can be done in - // several iterations. - PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, - saltValueBytes, - hashAlgorithm, - passwordIterations); - - // Use the password to generate pseudo-random bytes for the encryption - // key. Specify the size of the key in bytes (instead - // of bits). - #pragma warning disable 0618 - byte[] keyBytes = password.GetBytes(keySize / 8); - #pragma warning restore 0618 - - // Create uninitialized Rijndael encryption object. - RijndaelManaged symmetricKey = new RijndaelManaged(); - - // It is reasonable to set encryption mode to Cipher Block Chaining - // (CBC). Use default options for other symmetric key parameters. - symmetricKey.Mode = CipherMode.CBC; - - // Generate decryptor from the existing key bytes and initialization - // vector. Key size will be defined based on the number of the key - // bytes. - ICryptoTransform decryptor = symmetricKey.CreateDecryptor( - keyBytes, - initVectorBytes); - - // Define memory stream which will be used to hold encrypted data. - MemoryStream memoryStream = new MemoryStream(cipherTextBytes); - - // Define cryptographic stream (always use Read mode for encryption). - CryptoStream cryptoStream = new CryptoStream(memoryStream, - decryptor, - CryptoStreamMode.Read); - - // Since at this point we don't know what the size of decrypted data - // will be, allocate the buffer long enough to hold ciphertext; - // plaintext is never longer than ciphertext. - byte[] plainTextBytes = new byte[cipherTextBytes.Length]; - - // Start decrypting. - int decryptedByteCount = cryptoStream.Read(plainTextBytes, - 0, - plainTextBytes.Length); - - // Close both streams. - memoryStream.Close(); - cryptoStream.Close(); - - byte[] plainText = new byte[decryptedByteCount]; - int i; - for (i = 0; i < decryptedByteCount; i++) - plainText[i] = plainTextBytes[i]; - - // Return decrypted string. - return plainText; - } - } - #endregion - - public CryptoGridAssetClient() {} - - public CryptoGridAssetClient(string serverUrl, string keydir, bool decOnly) - { - m_log.Debug("[CRYPTOGRID] Direct constructor"); - Initialise(serverUrl, keydir, decOnly); - } - - public void Initialise(string serverUrl, string keydir, bool decOnly) - { - - m_log.Debug("[CRYPTOGRID] Common constructor"); - - _assetServerUrl = serverUrl; - - string[] keys = Directory.GetFiles(keydir, "*.deckey"); - foreach (string key in keys) - { - XmlSerializer xs = new XmlSerializer(typeof (RjinKeyfile)); - FileStream file = new FileStream(key, FileMode.Open, FileAccess.Read); - - RjinKeyfile rjkey = (RjinKeyfile) xs.Deserialize(file); - - file.Close(); - - m_keyfiles.Add(rjkey.AlsoKnownAs, rjkey); - } - - - keys = Directory.GetFiles(keydir, "*.enckey"); - if (keys.Length == 1) - { - string Ekey = keys[0]; - XmlSerializer Exs = new XmlSerializer(typeof (RjinKeyfile)); - FileStream Efile = new FileStream(Ekey, FileMode.Open, FileAccess.Read); - - RjinKeyfile Erjkey = (RjinKeyfile) Exs.Deserialize(Efile); - - Efile.Close(); - - m_keyfiles.Add(Erjkey.AlsoKnownAs, Erjkey); - - m_encryptKey = Erjkey; - } else - { - if (keys.Length > 1) - throw new Exception( - "You have more than one asset *encryption* key. (You should never have more than one)," + - "If you downloaded this key from someone, rename it to .deckey to convert it to" + - "a decryption-only key."); - - m_log.Warn("No encryption key found, generating a new one for you..."); - RjinKeyfile encKey = new RjinKeyfile(); - encKey.GenerateRandom(); - - m_encryptKey = encKey; - - FileStream encExportFile = new FileStream("mysecretkey_rename_me.enckey",FileMode.CreateNew); - XmlSerializer xs = new XmlSerializer(typeof(RjinKeyfile)); - xs.Serialize(encExportFile, encKey); - encExportFile.Flush(); - encExportFile.Close(); - - m_log.Info( - "Encryption file generated, please rename 'mysecretkey_rename_me.enckey' to something more appropriate (however preserve the file extension)."); - } - - // If Decrypt-Only, dont encrypt on upload - m_encryptOnUpload = !decOnly; - } - - private static void EncryptAssetBase(AssetBase x, RjinKeyfile file) - { - // Make a salt - RNGCryptoServiceProvider RandomGen = new RNGCryptoServiceProvider(); - byte[] rand = new byte[32]; - RandomGen.GetBytes(rand); - - string salt = Convert.ToBase64String(rand); - - x.Data = UtilRijndael.Encrypt(x.Data, file.Secret, salt, "SHA1", 2, file.IVBytes, file.Keysize); - x.Description = String.Format("ENCASS#:~:#{0}#:~:#{1}#:~:#{2}#:~:#{3}", - "OPENSIM_AES_AF1", - file.AlsoKnownAs, - salt, - x.Description); - } - - private bool DecryptAssetBase(AssetBase x) - { - // Check it's encrypted first. - if (!x.Description.Contains("ENCASS")) - return true; - - // ENCASS:ALG:AKA:SALT:Description - // 0 1 2 3 4 - string[] splitchars = new string[1]; - splitchars[0] = "#:~:#"; - - string[] meta = x.Description.Split(splitchars, StringSplitOptions.None); - if (meta.Length < 5) - { - m_log.Warn("[ENCASSETS] Recieved Encrypted Asset, but header is corrupt"); - return false; - } - - // Check if we have a matching key - if (m_keyfiles.ContainsKey(meta[2])) - { - RjinKeyfile deckey = m_keyfiles[meta[2]]; - x.Description = meta[4]; - switch (meta[1]) - { - case "OPENSIM_AES_AF1": - x.Data = UtilRijndael.Decrypt(x.Data, - deckey.Secret, - meta[3], - "SHA1", - 2, - deckey.IVBytes, - deckey.Keysize); - // Decrypted Successfully - return true; - default: - m_log.Warn( - "[ENCASSETS] Recieved Encrypted Asset, but we dont know how to decrypt '" + meta[1] + "'."); - // We dont understand this encryption scheme - return false; - } - } - - m_log.Warn("[ENCASSETS] Recieved Encrypted Asset, but we do not have the decryption key."); - return false; - } - - #region IAssetServer Members - - protected override AssetBase GetAsset(AssetRequest req) - { -#if DEBUG - //m_log.DebugFormat("[GRID ASSET CLIENT]: Querying for {0}", req.AssetID.ToString()); -#endif - - RestClient rc = new RestClient(_assetServerUrl); - rc.AddResourcePath("assets"); - rc.AddResourcePath(req.AssetID.ToString()); - if (req.IsTexture) - rc.AddQueryParameter("texture"); - - rc.RequestMethod = "GET"; - - Stream s = rc.Request(); - - if (s == null) - return null; - - if (s.Length > 0) - { - XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); - - AssetBase encAsset = (AssetBase)xs.Deserialize(s); - - // Try decrypt it - if (DecryptAssetBase(encAsset)) - return encAsset; - } - - return null; - } - - public override void UpdateAsset(AssetBase asset) - { - throw new Exception("The method or operation is not implemented."); - } - - public override void StoreAsset(AssetBase asset) - { - if (m_encryptOnUpload) - EncryptAssetBase(asset, m_encryptKey); - - try - { - string assetUrl = _assetServerUrl + "/assets/"; - - m_log.InfoFormat("[CRYPTO GRID ASSET CLIENT]: Sending store request for asset {0}", asset.FullID); - - RestObjectPoster.BeginPostObject(assetUrl, asset); - } - catch (Exception e) - { - m_log.ErrorFormat("[CRYPTO GRID ASSET CLIENT]: {0}", e); - } - } - - #endregion - } -} diff --git a/OpenSim/Framework/Communications/Cache/FileAssetClient.cs b/OpenSim/Framework/Communications/Cache/FileAssetClient.cs deleted file mode 100644 index 8d03f56..0000000 --- a/OpenSim/Framework/Communications/Cache/FileAssetClient.cs +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System.IO; -using System.Reflection; -using log4net; -using System.Xml.Serialization; - -namespace OpenSim.Framework.Communications.Cache -{ - public class FileAssetClient : AssetServerBase - { - - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - #region IPlugin - - public override string Name - { - get { return "File"; } - } - - public override string Version - { - get { return "1.0"; } - } - - public override void Initialise(ConfigSettings p_set, string p_url) - { - m_log.Debug("[FILEASSET] Plugin configured initialisation"); - Initialise(p_url); - } - - #endregion - - private string m_dir; - private readonly XmlSerializer m_xs = new XmlSerializer(typeof(AssetBase)); - - public FileAssetClient() {} - - public FileAssetClient(string p_url) - { - m_log.Debug("[FILEASSET] Direct constructor"); - Initialise(p_url); - } - - public void Initialise(string dir) - { - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } - m_dir = dir; - } - - public override void StoreAsset(AssetBase asset) - { - byte[] idBytes = asset.FullID.Guid.ToByteArray(); - - string cdir = m_dir + Path.DirectorySeparatorChar + idBytes[0] - + Path.DirectorySeparatorChar + idBytes[1]; - - if (!Directory.Exists(m_dir + Path.DirectorySeparatorChar + idBytes[0])) - Directory.CreateDirectory(m_dir + Path.DirectorySeparatorChar + idBytes[0]); - - if (!Directory.Exists(cdir)) - Directory.CreateDirectory(cdir); - - FileStream x = new FileStream(cdir + Path.DirectorySeparatorChar + asset.FullID + ".xml", FileMode.Create); - m_xs.Serialize(x, asset); - - x.Flush(); - x.Close(); - } - - public override void UpdateAsset(AssetBase asset) - { - StoreAsset(asset); - } - - protected override AssetBase GetAsset(AssetRequest req) - { - byte[] idBytes = req.AssetID.Guid.ToByteArray(); - - string cdir = m_dir + Path.DirectorySeparatorChar + idBytes[0] - + Path.DirectorySeparatorChar + idBytes[1]; - if (File.Exists(cdir + Path.DirectorySeparatorChar + req.AssetID + ".xml")) - { - FileStream x = File.OpenRead(cdir + Path.DirectorySeparatorChar + req.AssetID + ".xml"); - AssetBase ret = (AssetBase) m_xs.Deserialize(x); - x.Close(); - return ret; - } - return null; - } - } -} diff --git a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs deleted file mode 100644 index e070131..0000000 --- a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) Contributors, http://www.openmetaverse.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.IO; -using System.Reflection; -using System.Xml.Serialization; -using log4net; -using OpenSim.Framework.Servers.HttpServer; - -namespace OpenSim.Framework.Communications.Cache -{ - public class GridAssetClient : AssetServerBase - { - #region IPlugin - - public override string Name - { - get { return "Grid"; } - } - - public override string Version - { - get { return "1.0"; } - } - - public override void Initialise(ConfigSettings p_set, string p_url) - { - m_log.Debug("[GRID ASSET CLIENT]: Plugin configured initialisation"); - Initialise(p_url); - } - - #endregion - - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private string _assetServerUrl; - - public GridAssetClient() {} - - public GridAssetClient(string p_url) - { - m_log.Debug("[GRID ASSET CLIENT]: Direct constructor"); - Initialise(p_url); - } - - public void Initialise(string serverUrl) - { - _assetServerUrl = serverUrl; - } - - #region IAssetServer Members - - protected override AssetBase GetAsset(AssetRequest req) - { - #if DEBUG - //m_log.DebugFormat("[GRID ASSET CLIENT]: Querying for {0}", req.AssetID.ToString()); - #endif - - RestClient rc = new RestClient(_assetServerUrl); - rc.AddResourcePath("assets"); - rc.AddResourcePath(req.AssetID.ToString()); - - rc.RequestMethod = "GET"; - - Stream s = rc.Request(); - - if (s == null) - return null; - - if (s.Length > 0) - { - XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); - - return (AssetBase) xs.Deserialize(s); - } - - return null; - } - - public override void UpdateAsset(AssetBase asset) - { - throw new Exception("The method or operation is not implemented."); - } - - public override void StoreAsset(AssetBase asset) - { - try - { - // MemoryStream s = new MemoryStream(); - - // XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); - // xs.Serialize(s, asset); - // RestClient rc = new RestClient(_assetServerUrl); - - string assetUrl = _assetServerUrl + "/assets/"; - - //rc.AddResourcePath("assets"); - - // rc.RequestMethod = "POST"; - // rc.Request(s); - //m_log.InfoFormat("[ASSET]: Stored {0}", rc); - - m_log.InfoFormat("[GRID ASSET CLIENT]: Sending store request for asset {0}", asset.FullID); - - RestObjectPoster.BeginPostObject(assetUrl, asset); - } - catch (Exception e) - { - m_log.ErrorFormat("[GRID ASSET CLIENT]: {0}", e); - } - } - - #endregion - } -} -- cgit v1.1