Exemple #1
0
        internal static string SendMessageLicense(string xmlMessage, string decryptedsimkey)
        {
            string  responseStr = "";
            Message xmlResponseMessage;

            // get server response
            responseStr = CommunicationManager.SendXmlMessage(xmlMessage, GlobalResources.LicenseAnonymousUrl);

            if (string.IsNullOrEmpty(responseStr))
            {
                return(CommunicationManager.Deny(GlobalResources.ServerFailedMessage));
            }

            if (CommunicationManager.IsDenied(responseStr))
            {
                return(responseStr);
            }

            CryptographyManager objQueryTalkCryptography = new CryptographyManager();

            responseStr        = objQueryTalkCryptography.DecryptSim(responseStr, CryptoContext.ComunicationKey);
            xmlResponseMessage = CommunicationManager.ReadXML(responseStr, decryptedsimkey, true);
            if (!IsValidResponseNoUser(xmlResponseMessage as ResponseMessage))
            {
                return(CommunicationManager.Deny(GlobalResources.ServerFailedMessage));
            }

            return((xmlResponseMessage as ResponseMessage).Response);
        }
        private static string RegisterAnonymousEmail(string xmlMessage, string decryptedsimkey)
        {
            var responseStr = SendXmlMessage(xmlMessage, GlobalResources.RegisterAnonymousEmailUrl);

            if (string.IsNullOrEmpty(responseStr))
            {
                return(Deny(GlobalResources.ServerFailedMessage));
            }

            if (IsDenied(responseStr))
            {
                return(responseStr);
            }

            CryptographyManager objQueryTalkCryptography = new CryptographyManager();

            responseStr = objQueryTalkCryptography.DecryptSim(responseStr, CryptoContext.ComunicationKey);

            var xmlResponseMessage = ReadXML(responseStr, decryptedsimkey, true);

            //Los mensajes de los servicios de licenciamiento se verifica que no se alterara ninguno de los datos originalmente enviados
            //y que hacen unica y universal la comunicación entre el usuario/machine/servidor
            if (!IsValidResponse(xmlResponseMessage as ResponseMessage))
            {
                return(Deny(GlobalResources.ServerFailedMessage));
            }

            return((xmlResponseMessage as ResponseMessage).Response);
        }
        private static string SendMessageLicense(string xmlMessage, string decryptedsimkey, string user, string password)
        {
            string  responseStr = "";
            Message xmlResponseMessage;

            responseStr = SendXmlMessage(xmlMessage, GlobalResources.LicenseUrl);

            if (string.IsNullOrEmpty(responseStr))
            {
                return(Deny(GlobalResources.ServerFailedMessage));
            }

            if (IsDenied(responseStr))
            {
                return(responseStr);
            }

            //Los mensajes de los servicios de licenciamiento se encriptan doblemente en el servidor con el ComunicationKey
            CryptographyManager objQueryTalkCryptography = new CryptographyManager();

            responseStr = objQueryTalkCryptography.DecryptSim(responseStr, CryptoContext.ComunicationKey);

            xmlResponseMessage = ReadXML(responseStr, decryptedsimkey, true);

            //Los mensajes de los servicios de licenciamiento se verifica que no se alterara ninguno de los datos originalmente enviados
            //y que hacen unica y universal la comunicación entre el usuario/machine/servidor
            if (!IsValidResponse(xmlResponseMessage as ResponseMessage, user, password))
            {
                return(Deny(GlobalResources.ServerFailedMessage));
            }

            return((xmlResponseMessage as ResponseMessage).Response);
        }
Exemple #4
0
        private List <string> GetKeyCredentials()
        {
            RegistryKey keyCredential = GetCredentialRoute();

            string credential1 = (string)keyCredential.GetValue(GlobalResources.Key1);
            string credential2 = (string)keyCredential.GetValue(GlobalResources.Key2);
            string credential3 = (string)keyCredential.GetValue(GlobalResources.Key3);

            if (credential1 != null && credential2 != null && credential3 != null)
            {
                CryptographyManager objQueryTalkCryptography = new CryptographyManager();
                //string decryptedsimkey = objQueryTalkCryptography.DecryptAsim(CryptoContext.CryptedSimKey, CryptoContext.RSAPrivateKey);

                string user       = objQueryTalkCryptography.DecryptSim(credential1, CryptoContext.ComunicationKey);
                string password   = objQueryTalkCryptography.DecryptSim(credential2, CryptoContext.ComunicationKey);
                string rememberMe = objQueryTalkCryptography.DecryptSim(credential3, CryptoContext.ComunicationKey);

                List <string> Keys = new List <string>()
                {
                    user, password, rememberMe
                };

                return(Keys);
            }
            else
            {
                return(new List <string> {
                    "", "", ""
                });
            }
        }
Exemple #5
0
        internal void SaveCredencials(string user, string password, bool rememberMe)
        {
            RegistryKey key = GetCredentialRoute();

            CryptographyManager objQueryTalkCryptography = new CryptographyManager();

            //string decryptedsimkey = objQueryTalkCryptography.DecryptAsim(CryptoContext.CryptedSimKey, CryptoContext.RSAPrivateKey);

            key.SetValue(GlobalResources.Key1, objQueryTalkCryptography.EncryptSim(user, CryptoContext.ComunicationKey), RegistryValueKind.String);
            key.SetValue(GlobalResources.Key2, objQueryTalkCryptography.EncryptSim(password, CryptoContext.ComunicationKey), RegistryValueKind.String);
            key.SetValue(GlobalResources.Key3, objQueryTalkCryptography.EncryptSim(rememberMe.ToString(), CryptoContext.ComunicationKey), RegistryValueKind.String);
        }
Exemple #6
0
        // not implemented:
        //internal static void PullMapperResponeAsync(IAsyncResult asyncResult)
        //{
        //    PlayResponeAsync(asyncResult, GlobalResources.MapperPackage + GlobalResources.MapperPackageDefaultExtension);
        //}

        private static void PlayResponeAsync(IAsyncResult asyncResult, string fileName)
        {
            long           total      = 0;
            int            received   = 0;
            HttpWebRequest webRequest = (HttpWebRequest)asyncResult.AsyncState;

            CryptographyManager objQueryTalkCryptography = new CryptographyManager();
            string decryptedsimkey = objQueryTalkCryptography.DecryptAsim(CryptoContext.CryptedSimKey, CryptoContext.RSAPrivateKey);

            try
            {
                using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.EndGetResponse(asyncResult))
                {
                    byte[] buffer = new byte[1024];

                    FileStream fileStream = File.OpenWrite(fileName);
                    using (Stream input = webResponse.GetResponseStream())
                    {
                        total = input.Length;

                        int size = input.Read(buffer, 0, buffer.Length);
                        while (size > 0)
                        {
                            fileStream.Write(buffer, 0, size);
                            received += size;

                            size = input.Read(buffer, 0, buffer.Length);
                        }
                    }

                    fileStream.Flush();
                    fileStream.Close();
                }
            }
            catch (Exception ex)
            {
                Exception ex1 = new Exception(GlobalResources.PullFailedMessage, ex);
            }
        }
        // prepara el mensaje XML criptado
        internal static string PrepareCommand(string communicationID, string command, string user, string password, string email,
                                              out string decryptedSimKey, out CryptographyManager cryptographyManager)
        {
            Message message = new Message();

            message.CommunicationID = communicationID;
            message.Command         = command;
            message.CK           = CryptoContext.ComunicationKey;
            message.User         = user;
            message.Password     = password;
            message.MK           = MachineManager.MachineKey;
            message.ComputerName = MachineManager.ComputerName;
            message.Manufacturer = MachineManager.ComputerManufacturer;
            message.Model        = MachineManager.Model;
            message.Processor    = MachineManager.Procesor;
            message.Email        = email;

            cryptographyManager = new CryptographyManager();
            decryptedSimKey     = cryptographyManager.DecryptAsim(CryptoContext.CryptedSimKey, CryptoContext.RSAPrivateKey);

            return(CreateXmlMessage(message, decryptedSimKey));
        }
        internal static Message ReadXML(string xmlString, Func <string, string> simKeyProvider, bool response)
        {
            Message             message   = response ? new ResponseMessage() : new Message();
            CryptographyManager objCrypto = new CryptographyManager();

            XmlNode     node;
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlString);

            node = doc.DocumentElement.SelectSingleNode("/message/block0/block0value1");
            message.CommunicationID = node.InnerText;

            // get symetric key
            var simKey = simKeyProvider(message.CommunicationID);

            node            = doc.DocumentElement.SelectSingleNode("/message/block1/block1value1");
            message.Command = objCrypto.DecryptSim(node.InnerText, simKey);

            if (message.Command != Commands.VIEWLICENSE)
            {
                node       = doc.DocumentElement.SelectSingleNode("/message/block2/block2value1");
                message.CK = objCrypto.DecryptSim(node.InnerText, simKey);
            }

            node             = doc.DocumentElement.SelectSingleNode("/message/block3/block3value1");
            message.User     = objCrypto.DecryptSim(node.InnerText, simKey);
            node             = doc.DocumentElement.SelectSingleNode("/message/block3/block3value2");
            message.Password = objCrypto.DecryptSim(node.InnerText, simKey);

            //Información necesaria solo para los servicios de licenciamiento
            if (message.Command == Commands.AUTHENTICATE ||
                message.Command == Commands.AUTHENTICATE_ANONYMOUS ||
                message.Command == Commands.REMOVE ||
                message.Command == Commands.REGISTEREMAIL)
            {
                node                 = doc.DocumentElement.SelectSingleNode("/message/block4/block4value1");
                message.MK           = objCrypto.DecryptSim(node.InnerText, simKey);
                node                 = doc.DocumentElement.SelectSingleNode("/message/block4/block4value2");
                message.ComputerName = objCrypto.DecryptSim(node.InnerText, simKey);
                node                 = doc.DocumentElement.SelectSingleNode("/message/block4/block4value3");
                message.Manufacturer = objCrypto.DecryptSim(node.InnerText, simKey);
                node                 = doc.DocumentElement.SelectSingleNode("/message/block4/block4value4");
                message.Model        = objCrypto.DecryptSim(node.InnerText, simKey);
                node                 = doc.DocumentElement.SelectSingleNode("/message/block4/block4value5");
                message.Processor    = objCrypto.DecryptSim(node.InnerText, simKey);
            }

            //Información usada para los responses desde el servidor
            if (response)
            {
                node = doc.DocumentElement.SelectSingleNode("/message/block5/block5value1");
                (message as ResponseMessage).Response = objCrypto.DecryptSim(node.InnerText, simKey);
            }

            if (message.Command == Commands.REGISTEREMAIL)
            {
                node          = doc.DocumentElement.SelectSingleNode("/message/block6/block6value1");
                message.Email = objCrypto.DecryptSim(node.InnerText, simKey);
            }

            return(message);
        }
        internal static string CreateXmlMessage(Message message, string simKey)
        {
            string xmlContent = "";

            CryptographyManager objQueryTalkCryptography = new CryptographyManager();

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;

            StringWriter writer = new StringWriter();

            using (XmlWriter xmlWriter = XmlWriter.Create(writer, settings))
            {
                xmlWriter.WriteStartElement("message");

                //Guid
                xmlWriter.WriteStartElement("block0");
                //GuidText
                xmlWriter.WriteElementString("block0value1", message.CommunicationID);
                xmlWriter.WriteEndElement();

                //Command
                xmlWriter.WriteStartElement("block1");
                //CommandText
                xmlWriter.WriteElementString("block1value1", objQueryTalkCryptography.EncryptSim(message.Command, simKey));
                xmlWriter.WriteEndElement();

                if (message.Command != Commands.VIEWLICENSE)
                {
                    //CK
                    xmlWriter.WriteStartElement("block2");
                    //CKText
                    xmlWriter.WriteElementString("block2value1", objQueryTalkCryptography.EncryptSim(message.CK, simKey));
                    xmlWriter.WriteEndElement();
                }

                //Credentials
                xmlWriter.WriteStartElement("block3");
                //User
                xmlWriter.WriteElementString("block3value1", objQueryTalkCryptography.EncryptSim(message.User, simKey));
                //Password
                xmlWriter.WriteElementString("block3value2", objQueryTalkCryptography.EncryptSim(message.Password, simKey));
                xmlWriter.WriteEndElement();

                //Información necesaria solo para los servicios de licenciamiento
                if (message.Command == Commands.AUTHENTICATE ||
                    message.Command == Commands.AUTHENTICATE_ANONYMOUS ||
                    message.Command == Commands.REMOVE ||
                    message.Command == Commands.REGISTEREMAIL)
                {
                    //ComputerInfo
                    xmlWriter.WriteStartElement("block4");
                    //MK
                    xmlWriter.WriteElementString("block4value1", objQueryTalkCryptography.EncryptSim(message.MK, simKey));
                    //ComputerName
                    xmlWriter.WriteElementString("block4value2", objQueryTalkCryptography.EncryptSim(message.ComputerName, simKey));
                    //Manufacturer
                    xmlWriter.WriteElementString("block4value3", objQueryTalkCryptography.EncryptSim(message.Manufacturer, simKey));
                    //Model
                    xmlWriter.WriteElementString("block4value4", objQueryTalkCryptography.EncryptSim(message.Model, simKey));
                    //Processor
                    xmlWriter.WriteElementString("block4value5", objQueryTalkCryptography.EncryptSim(message.Processor, simKey));
                    xmlWriter.WriteEndElement();
                }

                //Información usada para los responses desde el servidor
                if (message is ResponseMessage)
                {
                    //Response
                    xmlWriter.WriteStartElement("block5");
                    //CommandText
                    xmlWriter.WriteElementString("block5value1", objQueryTalkCryptography.EncryptSim((message as ResponseMessage).Response, simKey));
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteEndDocument();
                }

                if (message.Command == Commands.REGISTEREMAIL)
                {
                    //CK
                    xmlWriter.WriteStartElement("block6");
                    //CKText
                    xmlWriter.WriteElementString("block6value1", objQueryTalkCryptography.EncryptSim(message.Email, simKey));
                    xmlWriter.WriteEndElement();
                }

                writer.Flush();
            }

            xmlContent = writer.ToString();
            return(xmlContent);
        }