Esempio n. 1
0
        private bool CheckUserToken(STC_MSG msg)
        {
            // L'orchestration et la gestion transactionnelle doivent être mise en oeuvre ici.

            /* To handle with database connection
             *          int count = -1;
             *
             *          this.sql = new SQL_Request();
             *          this.msg = this.sql.SelectByUserToken(this.msg);
             *
             *          this.msg.data = new object[2] { this.msg.data[0], (object)"resultat" };
             *          this.msg = this.db.GetRows(this.msg);
             *
             *          count = ((System.Data.DataTable)this.msg.data[0]).Rows.Count;
             *
             *          if (count == 1)
             */
            if (true)
            {
                this.msg.op_info   = "succes";
                this.msg.op_statut = true;
            }
            else
            {
                this.msg.op_info   = "fail";
                this.msg.op_statut = false;
            }

            return(this.msg.op_statut);
        }
        public STC_MSG SelectByLoginPsw(STC_MSG msg)
        {
            this.msg = msg;

            string log = msg.user_login;
            string psw = msg.user_psw;

            using (SqlConnection cnx = new SqlConnection(this.cnx.ConnectionString))
            {
                try
                {
                    cnx.Open();

                    //querie to check if the user's informations match
                    SqlCommand sqlcmd = new SqlCommand("select count(1) from InfoUser where login=@login and pwd = sha1(@pwd)", this.cnx);
                    sqlcmd.Parameters.AddWithValue("@login", log);
                    sqlcmd.Parameters.AddWithValue("@pwd", psw);

                    Console.Write("Response request SQL " + sqlcmd.ExecuteScalar());

                    this.msg.op_statut = Convert.ToInt32(sqlcmd.ExecuteScalar()) == 1;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
            }

            return(this.msg);
        }
        public STC_MSG Exec(STC_MSG msg)
        {
            this.msg = msg;

            // Set auth at false before db auth
            this.msg.op_statut = false;

            this.msg = this.db.SelectByLoginPsw(this.msg);

            if (this.msg.op_statut)
            // if (msg.user_login == "theo" && msg.user_psw =="123")
            {
                this.msg.op_info    = "succes";
                this.msg.op_statut  = true;
                this.msg.user_token = new Guid().ToString();
            }
            else
            {
                this.msg.op_info   = "fail";
                this.msg.op_statut = false;
            }

            this.msg.app_name    = null;
            this.msg.app_token   = null;
            this.msg.app_version = null;
            this.msg.data        = null;
            this.msg.op_name     = null;
            this.msg.user_login  = null;
            this.msg.user_psw    = null;

            return(this.msg);
        }
        public STC_MSG Crack(STC_MSG msg)
        {
            string text = msg.data[1].ToString();

            // Then send those files to the JEE app
            ProjetService req = new ProjetService();

            string[] d = new string[5];

            Parallel.ForEach(keyList, (item) =>
            {
                string key = item;

                byte[] bytes        = Encoding.ASCII.GetBytes(text);
                string[] binaryText = bytes.Select(x => Convert.ToString(x, 2).PadLeft(8, '0')).ToArray();

                byte[] bytesKey    = Encoding.ASCII.GetBytes(key);
                string[] binaryKey = bytesKey.Select(x => Convert.ToString(x, 2).PadLeft(8, '0')).ToArray();

                string txtDecode = "";
                for (int i = 0; i < binaryText.Length; i++)
                {
                    txtDecode += (char)Convert.ToInt16(XOR(binaryText[i], binaryKey[i % 4]), 2);
                }

                // 0 = file name
                d[0] = msg.data[0].ToString();
                // 1 = file content crypted
                d[1] = msg.data[1].ToString();
                // 2 = file content décrypted
                d[2] = txtDecode;
                // 3 = Key
                d[3]     = key;
                msg.data = d;

                // Method to get trust value
                try
                {
                    // 4 = string result of JEE
                    d[4] = req.decodage(GenerateXml(msg));
                }
                catch (Exception e)
                {
                    throw new Exception("Code JEE error " + e);
                }
            });

            msg.data = d;
            return(msg);
        }
        public Database()
        {
            this.msg = new STC_MSG();
            this.cnx = new SqlConnection();

            //information about the remote server
            string server   = "51.210.103.59";
            string port     = "3306";
            string database = "ProjetDev_db";
            string username = "******";
            string password = "******";

            this.cnx.ConnectionString = "Data Source=" + server + "," + port + ";Initial Catalog=" + database + ";User Id=" + username + ";Password="******";";
        }
Esempio n. 6
0
        public STC_MSG DecryptFiles(STC_MSG msg)
        {
            this.msg = msg;

            if (new Auth().CheckRequest(this.msg))
            {
                if (msg.op_name == "decrypter")
                {
                    if (CheckUserToken(this.msg))
                    {
                        // Method used to decrypt files
                        Semaphore _pool = new Semaphore(0, 6);

                        List <string> keyList = new GenKey().GetList();
                        this.msg = new XorCracker(keyList).Crack(msg);

                        /*
                         * Task.Run(() => {
                         *      _pool.WaitOne();
                         *
                         *      this.msg = new XorCracker(keyList).Crack(msg);
                         *
                         *      _pool.Release();
                         * });
                         */
                    }
                    else
                    {
                        this.msg.op_info    = "User token invalid";
                        this.msg.user_token = "";
                    }
                }
                else
                {
                    this.msg.op_info   = "Operation invalid";
                    this.msg.op_statut = false;
                    this.msg.op_name   = "";
                }
            }

            return(msg);
        }
Esempio n. 7
0
        public STC_MSG Login(STC_MSG msg)
        {
            this.msg = msg;

            if (CheckRequest(this.msg))
            {
                if (msg.op_name == "authentifier")
                {
                    this.msg = new CTRL_Auth().Exec(this.msg);
                }
                else
                {
                    this.msg.op_info   = "Operation invalid";
                    this.msg.op_statut = false;
                    this.msg.op_name   = "";
                }
            }

            return(this.msg);
        }
Esempio n. 8
0
 public Decrypt()
 {
     this.msg = new STC_MSG();
 }
        private string GenerateXml(STC_MSG msg)
        {
            XmlDocument doc = new XmlDocument();

            XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");

            doc.AppendChild(docNode);

            XmlNode msgNode = doc.CreateElement("stcMSG");

            doc.AppendChild(msgNode);

            // op_statut
            XmlNode statutNode = doc.CreateElement("op_statut");

            statutNode.AppendChild(doc.CreateTextNode(msg.op_statut.ToString()));
            msgNode.AppendChild(statutNode);

            // op_name
            XmlNode opNameNode = doc.CreateElement("op_name");

            opNameNode.AppendChild(doc.CreateTextNode(msg.op_name.ToString()));
            msgNode.AppendChild(opNameNode);

            //op_info
            XmlNode infoNode = doc.CreateElement("op_info");

            infoNode.AppendChild(doc.CreateTextNode(msg.op_info.ToString()));
            msgNode.AppendChild(infoNode);

            //app_name
            XmlNode appNameNode = doc.CreateElement("app_name");

            appNameNode.AppendChild(doc.CreateTextNode(msg.app_name.ToString()));
            msgNode.AppendChild(appNameNode);

            // app_version
            XmlNode nameNode = doc.CreateElement("app_version");

            nameNode.AppendChild(doc.CreateTextNode(msg.app_version.ToString()));
            msgNode.AppendChild(nameNode);

            // app_token
            XmlNode appTokenNode = doc.CreateElement("app_token");

            appTokenNode.AppendChild(doc.CreateTextNode(msg.app_token.ToString()));
            msgNode.AppendChild(appTokenNode);

            // user_login
            XmlNode loginNode = doc.CreateElement("user_login");

            loginNode.AppendChild(doc.CreateTextNode(msg.user_login.ToString()));
            msgNode.AppendChild(loginNode);

            // user_psw
            XmlNode pwdNode = doc.CreateElement("user_psw");

            pwdNode.AppendChild(doc.CreateTextNode(msg.user_psw.ToString()));
            msgNode.AppendChild(pwdNode);

            // user_token
            XmlNode userTokenNode = doc.CreateElement("user_token");

            userTokenNode.AppendChild(doc.CreateTextNode(msg.user_token.ToString()));
            msgNode.AppendChild(userTokenNode);

            // data
            XmlNode dataNode = doc.CreateElement("data");

            msgNode.AppendChild(dataNode);

            if (msg.data != null)
            {
                // attributs
                XmlNode fileNode = doc.CreateElement("file");

                // Get name prop and value from the object

                XmlNode fileNameAttribute = doc.CreateElement("name");
                fileNameAttribute.AppendChild(doc.CreateTextNode(msg.data[0].ToString()));
                fileNode.AppendChild(fileNameAttribute);

                // Get text prop and value from the object
                XmlNode fileTextAttribute = doc.CreateElement("text");
                fileTextAttribute.AppendChild(doc.CreateTextNode(msg.data[2].ToString()));
                fileNode.AppendChild(fileTextAttribute);

                // Get text prop and value from the object
                XmlNode fileKeyAttribute = doc.CreateElement("key");
                fileKeyAttribute.AppendChild(doc.CreateTextNode(msg.data[3].ToString()));
                fileNode.AppendChild(fileKeyAttribute);

                dataNode.AppendChild(fileNode);
            }

            string xml = doc.InnerXml.ToString();

            return(xml);
        }
Esempio n. 10
0
 public CTRL_Auth()
 {
     this.msg = new STC_MSG();
     this.db  = new Database();
 }
Esempio n. 11
0
        public bool CheckRequest(STC_MSG msg)
        {
            OperationContext              context    = OperationContext.Current;
            MessageProperties             msgProp    = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty remoteProp = msgProp[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            ServiceSecurityContext        ssc        = ServiceSecurityContext.Current;


            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Demande entrente : " + "<" + ssc.WindowsIdentity.Name + ">" + ssc.WindowsIdentity.User);
            Console.WriteLine("Adresse cliente : " + remoteProp.Address);
            Console.WriteLine("Port client : " + remoteProp.Port);
            Console.WriteLine("Détail du message ->");
            Console.WriteLine("Application cliente : " + msg.app_name);
            Console.WriteLine("Application token : " + msg.app_token);
            Console.WriteLine("Application version : " + msg.app_version);
            Console.WriteLine("Opération info : " + msg.op_info);
            Console.WriteLine("Opération nom : " + msg.op_name);
            Console.WriteLine("Opération statut : " + msg.op_statut);
            Console.WriteLine("Utilisteur login : "******"Utilisteur password : "******"Utilisteur token : " + msg.user_token);

            if (msg.data != null)
            {
                int i = msg.data.Length;
                Console.WriteLine("Le message contient {0} donnée(s) spécifique(s)", i + 1);
            }
            else
            {
                Console.WriteLine("Le message ne contient pas de données spécifiques");
            }

            if (msg.app_token == "apptoken")             // App token to change
            {
                if (msg.app_name == "Middleware")        //tmp app_name
                {
                    if (msg.app_version == "2.0")        //tmp app_version
                    {
                        return(true);
                    }
                    else
                    {
                        this.msg.op_info     = "App version invalid";
                        this.msg.op_statut   = false;
                        this.msg.app_version = "";
                    }
                }
                else
                {
                    this.msg.op_info   = "This plateforme doesn't handle this application.";
                    this.msg.op_statut = false;
                    this.msg.app_name  = "";
                }
            }
            else
            {
                this.msg.op_info   = "App token invalid";
                this.msg.op_statut = false;
                this.msg.app_token = "";
            }

            this.msg.data       = null;
            this.msg.op_name    = "";
            this.msg.user_login = "";
            this.msg.user_psw   = "";
            this.msg.user_token = "";

            return(false);
        }
Esempio n. 12
0
 public Auth()
 {
     this.msg = new STC_MSG();
 }