Exemple #1
0
        public string sendLoginQuery(string[] login)
        {
            //var client = new ServiceReference1.Service1Client();

            EndpointAddress epServ  = new EndpointAddress("net.tcp://localhost:8020/Server/services/server");
            NetTcpBinding   binding = new NetTcpBinding();

            model.MsgStruct msg     = new model.MsgStruct();
            model.MsgStruct msgBack = new model.MsgStruct();



            try
            {
                ChannelFactory <servC.I_Server> channelFactory = new ChannelFactory <servC.I_Server>(binding, epServ);
                servC.I_Server _clientProxy = channelFactory.CreateChannel();

                msg.info          = "Demande de login";
                msg.data          = (object[])login;
                msg.operationName = "auth";
                login[2]          = tokenApp;
                msg.tokenApp      = tokenApp;
                //msgBack = _clientProxy.server(msg);
                Task <string> result = sendMsgToServer(_clientProxy, msg);

                return(result.Result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return("error");
            }
        }
Exemple #2
0
 async Task <string> sendMsgToServer(servC.I_Server client, model.MsgStruct msg)
 {
     model.MsgStruct msgBack = new model.MsgStruct();
     msgBack   = client.server(msg);
     tokenUser = msgBack.tokenUser;
     return(msgBack.info);
 }
Exemple #3
0
        public model.MsgStruct validateAuthentification(model.MsgStruct message)
        {
            model.MsgStruct returnMsg = new model.MsgStruct();
            //EndpointAddress epSql = new EndpointAddress("http://localhost:8010/Server/services/sql_access");

            User[] users;
            string tokenUser = "";
            string login     = message.data[0].ToString();
            string password  = message.data[1].ToString();

            //check password & login en BDD
            try
            {
                //sqlAccess.ISqlAccess proxySql= ChannelFactory<sqlAccess.ISqlAccess>.CreateChannel(new BasicHttpBinding(), epSql);
                sqlAccess.SqlAccess proxySql = new SqlAccess();

                Console.WriteLine("calling CAM");
                users = proxySql.getUserBy2ParametersValue("login", login, "password", password);
                Console.WriteLine("CAM call finished");

                if (users.Length > 0)
                {
                    Console.WriteLine("authentification cool");
                    //generation tokenUser
                    tokenUser                  = "******";
                    returnMsg.info             = "successful authentification";
                    returnMsg.tokenUser        = tokenUser;
                    returnMsg.operationVersion = "1.0";
                    returnMsg.data             = new object[2] {
                        (object)true, (object)tokenUser
                    };
                }
                else // wrong login / password
                {
                    Console.WriteLine("login ou mdp non trouvze");
                    returnMsg.info             = "unsuccessful authentification - wrong login and or problem";
                    returnMsg.operationName    = "auth_return";
                    returnMsg.operationVersion = "1.0";
                    returnMsg.data             = new object[2] {
                        (object)false, (object)""
                    };
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //return message SQM ACASSE
                returnMsg.statutOp         = false;
                returnMsg.info             = "unsuccessful authentification - Database service access error";
                returnMsg.operationName    = "return";
                returnMsg.operationVersion = "1.0";
                returnMsg.data             = new object[2] {
                    (object)false, (object)"Database access error"
                };
            }

            //renvoie au CAM
            return(returnMsg);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            EndpointAddress epServ  = new EndpointAddress("net.tcp://*****:*****@viacesi.fr", (object)"tomb", (object)"?h:XPjO9b)z3Ox7" };
                 * returnMsg = _clientProxy.server(msg);
                 * Console.WriteLine("Server call finished");
                 * Console.WriteLine(returnMsg.info);
                 *
                 * //decryption
                 * Console.WriteLine("calling server");
                 * msg.info = "auth_request";
                 * msg.tokenApp = "?h:XPjO9b)z3Ox7";
                 * msg.tokenUser = null;
                 * msg.appVersion = "1.0";
                 * msg.operationVersion = "1.0";
                 * msg.operationName = "decrypt";
                 * msg.data = new object[] { (object)"*****@*****.**", (object)"?h:XPjO9b)z3Ox7", (object)"file1.txt|sdgshktsh", (object)"file2.txt|dsqg", (object)"file2.txt|gsg"  };
                 * returnMsg = _clientProxy.server(msg);
                 * Console.WriteLine("Server call finished");
                 * Console.WriteLine(returnMsg.info);*/

                //notification
                Console.WriteLine("calling server");
                msg.info             = "notif_request";
                msg.tokenApp         = "?h:XPjO9b)z3Ox7";
                msg.tokenUser        = "******";
                msg.appVersion       = "1.0";
                msg.operationVersion = "1.0";
                msg.operationName    = "notif";
                msg.data             = new object[] { (object)"true", (object)"textfile.txt|fichier décrypté", (object)"AADC", (object)80 };
                returnMsg            = _clientProxy.server(msg);
                Console.WriteLine("Server call finished");
                Console.WriteLine(returnMsg.info);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.Read();
        }
Exemple #5
0
        public model.MsgStruct server(model.MsgStruct message)
        {
            //EndpointAddress epCAM = new EndpointAddress("http://localhost:8010/Server/services/workflow_controller");
            model.MsgStruct returnMsg = new model.MsgStruct();

            string operationName = message.operationName;
            string tokenApp      = message.tokenApp;

            //verif tokenApp
            if (tokenApp == "?h:XPjO9b)z3Ox7")
            {
                try
                {
                    //workflowController.I_WorkflowController proxyWorkflowController = ChannelFactory<workflowController.I_WorkflowController>.CreateChannel(new BasicHttpBinding(), epCAM);
                    workflowController.WorkflowController proxyWorkflowController = new WorkflowController();
                    Console.WriteLine("calling CAM");
                    returnMsg = proxyWorkflowController.workflowControl(message);
                    Console.WriteLine("CAM call finished");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    //return message error CAM
                    returnMsg.info             = "unsuccessful authentification - CAM access error";
                    returnMsg.operationName    = "return";
                    returnMsg.operationVersion = "1.0";
                    returnMsg.data             = new object[2] {
                        (object)false, (object)"CAM access error"
                    };
                }
            }
            else
            {
                //on renvoit un message informant le client que son token app n'est ps valide
                returnMsg.info          = "invalid tokenApp";
                returnMsg.operationName = "return";
                returnMsg.data          = new object[2] {
                    (object)false, (object)"unknow appVersion"
                };
            }
            returnMsg.statutOp   = false;
            returnMsg.tokenApp   = "R]f^l(sj9.*HX+u";
            returnMsg.appVersion = "1.0";

            return(returnMsg);
        }
Exemple #6
0
        public string sendFilesQuery(String[] filesList)
        {
            model.MsgStruct msg = new model.MsgStruct();

            EndpointAddress epServ  = new EndpointAddress("net.tcp://localhost:8020/Server/services/server");
            NetTcpBinding   binding = new NetTcpBinding();

            model.MsgStruct msgBack = new model.MsgStruct();

            try
            {
                ChannelFactory <servC.I_Server> channelFactory = new ChannelFactory <servC.I_Server>(binding, epServ);
                servC.I_Server _clientProxy = channelFactory.CreateChannel();

                msg.info = "Sending files for decryption";
                List <object> data = new List <object>();
                data.Add((object)"'Z|1li:GZ3VW<^3");
                data.Add((object)tokenApp);
                foreach (object file in filesList)
                {
                    data.Add((object)file);
                }
                msg.data          = data.ToArray();
                msg.operationName = "decrypt";
                msg.tokenApp      = tokenApp;
                //msg.tokenUser = tokenUser;
                msg.tokenUser = "******";
                //msgBack = _clientProxy.server(msg);
                Task <string> result = sendMsgToServer(_clientProxy, msg);
                return(result.Result);
                //return (bool)msgBack.data[0];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return("error com");
            }
        }
Exemple #7
0
        public model.MsgStruct workflowControl(model.MsgStruct message)
        {
            //EndpointAddress epAuth = new EndpointAddress("http://localhost:8010/Server/services/auth");
            //EndpointAddress epDecrypt = new EndpointAddress("http://localhost:8010/Server/services/decrypt");

            model.MsgStruct returnMsg = new model.MsgStruct();

            //Analyse la version de l'app et appelle le controlleur de workflow adéquate en fontion de l'opération

            string operationName = message.operationName;
            string appVersion    = message.appVersion;

            //LOG BDD
            dataPersistence.log entryLog = new dataPersistence.log();
            entryLog.type = "msgRequest";
            sqlAccess.SqlAccess sql = new sqlAccess.SqlAccess();
            //string tempLog = "";
            switch (operationName)
            {
            case "auth":
                entryLog.data = "Authentification with login : "******"decrypt":
                string filesnames = "";
                for (int i = 2; i < message.data.Length; i++)
                {
                    string   tempFilename;
                    string[] splitedFile = ((string)message.data[i]).Split(new char[] { '|' }, 2);
                    tempFilename = splitedFile[0];
                    if (i != message.data.Length - 1)
                    {
                        filesnames = String.Concat(filesnames, tempFilename, ", ");
                    }
                }
                entryLog.data = "Decryption - files : " + filesnames;
                break;

            case "default":
                entryLog.data = "Unknown operation";
                break;
            }
            entryLog.date = DateTime.Now;


            sql.createLog(entryLog);



            //analyse opp_name
            switch (operationName)
            {
            case "auth":
                //analyse app_version
                switch (appVersion)
                {
                case "1.0":         //Appelle du controlleur de workflow d'authentification
                    //authentificationWorkflow.I_Authentification authentificationWorkflow = ChannelFactory<authentificationWorkflow.I_Authentification>.CreateChannel(new BasicHttpBinding(), epAuth);
                    authentificationWorkflow.Authentification authentificationWorkflow = new Authentification();
                    Console.WriteLine("calling Auth CW");
                    returnMsg = authentificationWorkflow.validateAuthentification(message);
                    Console.WriteLine("Auth CW call finished");
                    break;

                default:         //retourne message indiquant que le type d'appversion est inconnu
                    returnMsg.info = "unsuccessful authentification - unknow appVersion";
                    returnMsg.data = new object[2] {
                        (object)false, (object)"unknow appVersion"
                    };
                    break;
                }
                returnMsg.operationName = "auth_return";
                break;

            case "decrypt":
                //analyse app_version
                switch (appVersion)
                {
                case "1.0":         //Appelle du controlleur de workflow de decryption
                    //decryptionWorkflow.IDecryption decryptionWorkflow = ChannelFactory<decryptionWorkflow.IDecryption>.CreateChannel(new BasicHttpBinding(), epDecrypt);
                    decryptionWorkflow.Decryption decryptionWorkflow = new decryptionWorkflow.Decryption();
                    Console.WriteLine("calling Decrypt CW");
                    returnMsg = decryptionWorkflow.decrypt(message);
                    Console.WriteLine("Decrypt CW call finished");
                    break;

                default:         //retourne message indiquant que le type d'appversion est inconnu
                    returnMsg.info = "unsuccessful authentification - unknow appVersion";
                    returnMsg.data = new object[2] {
                        (object)false, (object)"unknow appVersion"
                    };
                    break;
                }
                returnMsg.tokenUser     = message.tokenUser;
                returnMsg.operationName = "decrypt_return";
                break;

            case "notif":
                //analyse app_version
                switch (appVersion)
                {
                case "1.0":         //Appelle du controlleur de workflow d'de notification
                    decryptionWorkflow.Decryption     decryptionWorkflow   = new decryptionWorkflow.Decryption();
                    notificationWorkflow.Notification notificationWorkflow = new notificationWorkflow.Notification();
                    Console.WriteLine("calling notif CW");
                    notificationWorkflow.notify(message);
                    Console.WriteLine("Notif CW call finished");
                    break;

                default:         //retourne message indiquant que le type d'appversion est inconnu
                    returnMsg.info = "unsuccessful notification - unknow appVersion";
                    returnMsg.data = new object[2] {
                        (object)false, (object)"unknow appVersion"
                    };
                    break;
                }
                returnMsg.tokenUser     = message.tokenUser;
                returnMsg.operationName = "notif_return";
                break;

            default:
                //retourne mesage comme quoi le type d'operation est inconnu
                returnMsg.info          = "unsuccessful request - unknow operationName";
                returnMsg.operationName = "return";
                returnMsg.data          = new object[2] {
                    (object)false, (object)"unknow operationName"
                };
                break;
            }

            //LOG BDD
            dataPersistence.log returnLog = new dataPersistence.log();
            returnLog.type = "msgReturn";
            returnLog.data = returnMsg.info;
            returnLog.date = DateTime.Now;

            sql.createLog(returnLog);
            return(returnMsg);
        }
Exemple #8
0
        public model.MsgStruct decrypt(model.MsgStruct message)
        {
            model.MsgStruct returnMsg = new model.MsgStruct();
            //EndpointAddress epDecrypt = new EndpointAddress("http://localhost:8010/Server/services/decrypt_file");
            List <model.File> files = new List <model.File>();

            decryptionBusiness.DecryptFile decryptbizz = new decryptionBusiness.DecryptFile();


            string tokenApp   = message.tokenApp;
            string tokenUser  = message.tokenUser;
            int    fileNumber = message.data.Length - 2;

            if (tokenUser != "'Z|1li:GZ3VW<^3")
            {
                returnMsg.statutOp         = false;
                returnMsg.info             = "invalid tokenUser";
                returnMsg.operationName    = "decrypt_return";
                returnMsg.tokenApp         = "?h:XPjO9b)z3Ox7";
                returnMsg.tokenUser        = "******";
                returnMsg.appVersion       = "1.0";
                returnMsg.operationVersion = "1.0";
                return(returnMsg);
            }

            for (int i = 2; i < message.data.Length; i++)
            {
                model.File tempFile = new model.File();

                string[] splitedFile = ((string)message.data[i]).Split(new char[] { '|' }, 2);

                tempFile.name = splitedFile[0];
                tempFile.data = splitedFile[1];
                files.Add(tempFile);
            }

            //thread
            //decryptionBusiness.IDecryptFile decryptionBusiness= ChannelFactory<decryptionBusiness.IDecryptFile>.CreateChannel(new BasicHttpBinding(), epDecrypt);
            //decryptionBusiness.DecryptFile decryptionBusiness = new DecryptFile();

            foreach (model.File file in files.ToArray())
            {
                //decryptionWorkflow.
                //DecryptFile decrypt = new DecryptFile();
                //decrypt.SetFileAndKey(file, "cesi");
                //decrypt.decryptFile(file);
                DecryptFile businessDecrypter = new DecryptFile();
                businessDecrypter.SetFileAndKey(file);
                Thread InstanceCaller = new Thread(new ThreadStart(businessDecrypter.decryptThread));
                InstanceCaller.Start();

                //Task.Run(() => callDecryptFile(file, decryptbizz));

                //decryptionBusiness.SetFileAndKey(file, "cesi");
                //decryptionBusiness.decryptFile(file, "CESI");
                //Thread InstanceCaller = new Thread(new ThreadStart(decryptionBusiness.decryptFile));
            }



            returnMsg.statutOp         = false;
            returnMsg.info             = "successful decryption";
            returnMsg.operationName    = "decrypt_return";
            returnMsg.tokenApp         = "MiddlewareToken";
            returnMsg.tokenUser        = "******";
            returnMsg.appVersion       = "1.0";
            returnMsg.operationVersion = "1.0";
            returnMsg.data             = new object[] { (object)true, (object)"", (object)"", (object)"" };

            return(returnMsg);
            //return null;
        }