Esempio n. 1
0
        //The name of the file needs to be consequent with the parameters inside the file

        #region         private bool ControlNombre(DatosFile myFileData)

        private bool ControlNombre(DatosFile myFileData)
        {
            bool blnReturn = false;

            try
            {
                if (myFileData.ProductID == _productID && myFileData.ProductVersion == _productVersion)
                {
                    blnReturn = true;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("BuscarControlar:Controlar.ControlNombre - " + ex);
            }

            return(blnReturn);
        }
Esempio n. 2
0
        //Checks if the evaluation date (Relative) is not expired

        #region         private bool IsInsideTimeRelative(DatosFile myFileData)

        private bool IsInsideTimeRelative(DatosFile myFileData)
        {
            bool blnReturn = false;

            try
            {
                DateTime InitiationDateFromReg;
                //Make a key for the register (using ProductID and VersionID, encrypted and based in the LicenseID
                using (CryptoString myCrypto = new CryptoString())
                {
                    string RegKeyDirectory = myCrypto.Encrypt((myFileData.ProductID + myFileData.ProductVersion), myFileData.LicenseID);
                    string RegKeyValue     = myCrypto.Encrypt(DateTime.Today.ToShortDateString(), myFileData.LicenseID);

                    //If the key exists in the register, retrive his value
                    string strInitiationDateFromReg = ReadFromRegistry(string.Empty, RegKeyDirectory);

                    //If the key not exists in the register, make one with the date of today (also encrypted)
                    if (strInitiationDateFromReg.Length == 0) //Key doesn't exist --> make a new one
                    {
                        WriteToRegistry(string.Empty, RegKeyDirectory, RegKeyValue);
                    }

                    //Compare the value in the register with today
                    strInitiationDateFromReg = ReadFromRegistry(string.Empty, RegKeyDirectory);
                    InitiationDateFromReg    = DateTime.Parse(myCrypto.Decrypt(strInitiationDateFromReg, myFileData.LicenseID));
                }
                // DateTime ExpirationDate = InitiationDateFromReg.AddDays(int.Parse(myFileData.DaysToExpiration));

                if (DateTime.Today <= InitiationDateFromReg)
                {
                    blnReturn = true;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("BuscarControlar:Controlar.IsInsideTimeRelative - " + ex);
            }

            return(blnReturn);
        }
Esempio n. 3
0
        public bool Aceptado()
        {
            bool          blnReturn = false;
            bool          FileFound = false;
            bool          FileCorrectlyDecrypted = false;
            bool          FileNameCorrect        = false;
            bool          LicenseGoodValidated   = false;
            List <string> myMACs       = new List <string>();
            List <string> myIPs        = new List <string>();
            List <string> myDomains    = new List <string>();
            DatosFile     myFileData   = new DatosFile();
            TextReader    myTextReader = null;

            //#region FARM

            //try
            //{
            //    IPHostEntry host = Dns.GetHostEntry("10.64.136.90");
            //    if (!string.IsNullOrEmpty(host.HostName))
            //        return true;
            //    return false;
            //}
            //catch (SocketException ex)
            //{
            //    return false;
            //}

            //#endregion

            try
            {
                //Debug.WriteLine("** Begin Comprobation - " + DateTime.Now.Millisecond);

                //Search for spsproparts.lic file in %windows32% directory
                FileFound = EncontrarFile(ref myTextReader);

                if (FileFound)
                {
                    //Try to decrypt the file, checks that everything is correct and fill the Object with the values
                    FileCorrectlyDecrypted = LeerFile(myTextReader, ref myFileData);

                    if (FileCorrectlyDecrypted)
                    {
                        //Test code
                        //Debug.WriteLine("ProductName - " + myFileData.ProductName);
                        //Debug.WriteLine("ProductID - " + myFileData.ProductID);
                        //Debug.WriteLine("ProductVersion - " + myFileData.ProductVersion);
                        //Debug.WriteLine("LicenseID - " + myFileData.LicenseID);
                        //Debug.WriteLine("RawData - " + myFileData.RawData);
                        //Debug.WriteLine("EngineVersion - " + myFileData.LicenseEngineVersion);
                        //Debug.WriteLine("LicenseDate - " + myFileData.LicenseDate);
                        //Debug.WriteLine("LicenseSort - " + myFileData.LicenseSort);
                        //Debug.WriteLine("EvaluationDate - " + myFileData.DateExpiration);
                        //Debug.WriteLine("EvaluationDays - " + myFileData.DaysToExpiration);
                        //Debug.WriteLine("MAC - " + myFileData.MacAddress);
                        //Debug.WriteLine("IP - " + myFileData.IpAddress);
                        //Debug.WriteLine("Domain - " + myFileData.DomainName);
                        //Debug.WriteLine("ClientName - " + myFileData.ClientName);
                        //Debug.WriteLine("Other - " + myFileData.OtherInformation);

                        //The name of the file need to be consequent with the parameters inside the file
                        FileNameCorrect = ControlNombre(myFileData);

                        if (FileNameCorrect)
                        {
                            //Based in the type license, check if the license is correct
                            switch (myFileData.LicenseSort)
                            {
                            case DatosFile.TypeLicense.EvaluationDate:
                                LicenseGoodValidated = IsInsideTimeAbsolute(myFileData.DateExpiration);
                                break;

                            case DatosFile.TypeLicense.EvaluationDays:
                                LicenseGoodValidated = IsInsideTimeRelative(myFileData);
                                break;

                            case DatosFile.TypeLicense.MAC:
                                myMACs = DireccionesM();
                                LicenseGoodValidated = FoundInList(myMACs, myFileData.MacAddress);
                                break;

                            case DatosFile.TypeLicense.IP:
                                myIPs = DireccionesI();
                                LicenseGoodValidated = FoundInList(myIPs, myFileData.IpAddress);
                                break;

                            case DatosFile.TypeLicense.Domain:
                                myDomains            = Dominios();
                                LicenseGoodValidated = FoundInList(myDomains, myFileData.DomainName.ToUpper());
                                break;

                            case DatosFile.TypeLicense.Host:
                                LicenseGoodValidated = (Dns.GetHostName().ToLower() == myFileData.HostName.ToLower());
                                break;

                            default:
                                LicenseGoodValidated = false;
                                break;
                            }

                            blnReturn = LicenseGoodValidated;
                        }
                    }
                }

                Debug.WriteLine("** End Comprobation - " + DateTime.Now.Millisecond);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("BuscarControlar:Controlar.Aceptado - " + ex);
            }

            return(blnReturn);
        }
Esempio n. 4
0
        //Decript the Licence File

        #region         private bool LeerFile(TextReader myTextReader, ref DatosFile myFileData)

        private bool LeerFile(TextReader myTextReader, ref DatosFile myFileData)
        {
            /* File Schema:
             * File Format: spsproparts_[ProductID]_productVersion].lic
             *
             * spsProParts                          --> Always
             * http://www.spsproparts.net           --> Always
             * ProductName: productAAA              --> Product Name, doesn't have any meaning
             * ProductVersion: 1.0.0.0              --> Needs to be the same as in the name of the lic file (used internally without dots)
             * ProductID: 123456789ABCDEF           --> Needs to be the same as in the name of the lic file
             * LicenseID: 987654321QWERTY           --> IMPORTANT: needed als public key to decrypt the raw data
             * RXpTjTdBl7RP1oQqfqScDlYXQxgAYPg+m    --> Raw data
             *
             * Raw data format:
             * EngineVersion|LicenseDate|TypeLicense|EvaluationDate|EvaluationDays|MAC|IP|Domain|Client|Other
             * 1.0|20071125|mac|||112233445566|||ClientAAA||
             * EngineVersion                        --> The version of this Class. In the future, the class can change
             * LicenseDate                          --> Date of issuance of the License - yyyymmdd
             * TypeLicense                          --> can be: mac - ip - days - date - domain
             * EvaluationDate                       --> If the expiration evaluation periode is absolute - yyyymmdd
             * EvaluationDays                       --> If the expiration evaluation periode is relative - number of days
             * MAC                                  --> MAC Address to check, if TypeLicense is "mac"
             * IP                                   --> IP Address to check, if TypeLicense is "ip"
             * Domain                               --> Domain name to check, if TypeLicense is "domain"
             *  Host
             * Client                               --> Client name and other information
             * Other                                --> Reserved for other information
             * Host
             */

            bool   blnReturn   = false;
            string OneLine     = string.Empty;
            int    LineCounter = 1;

            string[] TempString = new string[2];

            try
            {
                //Read each line of the File, inclusive the raw data (last line), and set it in the object
                while ((OneLine = myTextReader.ReadLine()) != null)
                {
                    //Console.WriteLine(OneLine);

                    switch (LineCounter)
                    {
                    case (1):
                        //Nothing to do --> "spsProParts"
                        break;

                    case (2):
                        //Nothing to do --> "http://www.spsrproparts.net"
                        break;

                    case (3):
                        TempString             = OneLine.Split(':');
                        myFileData.ProductName = TempString[1].Trim();
                        break;

                    case (4):
                        TempString = OneLine.Split(':');
                        myFileData.ProductVersion = TempString[1].Trim().Replace(".", string.Empty);
                        break;

                    case (5):
                        TempString           = OneLine.Split(':');
                        myFileData.ProductID = TempString[1].Trim();
                        break;

                    case (6):
                        TempString           = OneLine.Split(':');
                        myFileData.LicenseID = TempString[1].Trim();
                        break;

                    case (7):
                        myFileData.RawData = OneLine;
                        break;

                    default:
                        break;
                    }
                    LineCounter++;
                }
                myTextReader.Close();

                string RawLine;
                //Read the values of the encrypted last line, and set it in the object
                using (CryptoString myCryptoString = new CryptoString())
                {
                    RawLine = myCryptoString.Decrypt(myFileData.RawData, myFileData.LicenseID);
                    //string RawLine = myCryptoString.Encrypt("1.0|20071125|days||1|11223344556677|||clientAA||", myFileData.LicenseID);
                    //Console.WriteLine(RawLine);
                }
                TempString = RawLine.Split('|');
                myFileData.LicenseEngineVersion = TempString[0].Trim();
                myFileData.LicenseDate          = TempString[1].Trim();
                //Type Licenses can be: mac - ip - days - date - domain
                switch (TempString[2].Trim().ToLower())
                {
                case ("mac"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.MAC;
                    break;

                case ("ip"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.IP;
                    break;

                case ("days"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.EvaluationDays;
                    break;

                case ("date"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.EvaluationDate;
                    break;

                case ("domain"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.Domain;
                    break;

                case ("host"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.Host;
                    break;

                default:
                    break;
                }
                myFileData.DateExpiration   = TempString[3].Trim();
                myFileData.DaysToExpiration = TempString[4].Trim();
                myFileData.MacAddress       = TempString[5].Trim();
                myFileData.IpAddress        = TempString[6].Trim();
                myFileData.DomainName       = TempString[7].Trim();
                myFileData.HostName         = TempString[8].Trim();
                myFileData.ClientName       = TempString[9].Trim();
                myFileData.OtherInformation = TempString[10].Trim();

                blnReturn = true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("BuscarControlar:Controlar.LeerFile - " + ex);
            }

            return(blnReturn);
        }