Example #1
0
        public string getUpdates(string token, string url)
        {
            string status = "";
            string json   = JSON.getContractUpdate(token);
            string key    = Cryptography.randomString(32);
            string iv     = Cryptography.randomString(32);

            string encryptedContent = Cryptography.encryptRJ256(json, key, iv);
            string sendData         = encryptedContent + key + iv;

            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("CTT", sendData);

            string webResponse = HttpComm.httpPostData(data, url);

            if (webResponse.Length <= 6)
            {
                status = HttpComm.treatHttpError(webResponse, "UCT");
            }
            else
            {
                if (this.lastModified != this.lastModifiedWeb)
                {
                    status = this.updateContractData(webResponse);
                }
                else
                {
                    status = "OK";
                }
            }
            return(status);
        }
Example #2
0
        public string getConfigs(string token)
        {
            string status = "OK";
            string json   = JSON.getConfigUpdate(token);
            string key    = Cryptography.randomString(32);
            string iv     = Cryptography.randomString(32);

            string encryptedContent = Cryptography.encryptRJ256(json, key, iv);
            string sendData         = encryptedContent + key + iv;

            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("CTT", sendData);

            string webResponse = HttpComm.httpPostData(data, this.consultGateway);

            if (webResponse.Length <= 6)
            {
                status = HttpComm.treatHttpError(webResponse, "CCF");
            }
            else
            {
                string encryptedData = "";
                string decodeKey     = webResponse.Substring(0, 32);
                string decodeIv      = webResponse.Substring(webResponse.Length - 32);

                int keyIndex = webResponse.IndexOf(decodeKey);
                encryptedData = webResponse.Remove(keyIndex, decodeKey.Length);

                int ivIndex = encryptedData.IndexOf(decodeIv);
                encryptedData = encryptedData.Remove(ivIndex, decodeIv.Length);

                string configData = Cryptography.decryptRJ256(encryptedData, decodeKey, decodeIv);
                Config c          = new Config();
                c = JSON.decodeConfig(configData);

                if (c.lastModified > this.lastModified)
                {
                    this.consultGateway = c.consultGateway;
                    this.threadSleep    = c.threadSleep;
                    this.lastModified   = c.lastModified;

                    try
                    {
                        this.saveConfigs();
                    }
                    catch (Exception e)
                    {
                        status = "Impossível salvar as configurações";
                    }
                }
            }
            return(status);
        }
Example #3
0
        public static string newFileUploaded(string token, string key, string file, string url)
        {
            string status = "OK";

            file = file.Replace("\\", "#");
            string[] filePath = file.Split('#');

            string json       = JSON.encodeFileUploadLog("NUF", token, key, filePath[filePath.Length - 1]);
            string encryptKey = Cryptography.randomString(32);
            string encryptIv  = Cryptography.randomString(32);

            string encryptedContent = Cryptography.encryptRJ256(json, encryptKey, encryptIv);
            string sendData         = encryptedContent + encryptKey + encryptIv;

            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("CTT", sendData);

            string webResponse = HttpComm.httpPostData(data, url);

            if (webResponse.Length <= 6)
            {
                status = HttpComm.treatHttpError(webResponse, "NUF");
            }
            else
            {
                string encryptedData = "";
                string decodeKey     = webResponse.Substring(0, 32);
                string decodeIv      = webResponse.Substring(webResponse.Length - 32);

                int keyIndex = webResponse.IndexOf(decodeKey);
                encryptedData = webResponse.Remove(keyIndex, decodeKey.Length);

                int ivIndex = encryptedData.IndexOf(decodeIv);
                encryptedData = encryptedData.Remove(ivIndex, decodeIv.Length);

                string logData = Cryptography.decryptRJ256(encryptedData, decodeKey, decodeIv);
                status = JSON.decodeUploadLog(logData);
            }

            return(status);
        }
Example #4
0
        private void proccessLogin()
        {
            this.configs = new Config();

            this.updateDialogLabel("Carregando configurações");

            string status = this.configs.loadConfigs();

            if (status.Equals("OK"))
            {
                this.httpFunc = "LGN";

                if (loginErrorLabel.InvokeRequired)
                {
                    loginErrorLabel.Invoke(new MethodInvoker(delegate { loginErrorLabel.Text = "Autenticando usuário"; }));
                }

                string user = username.Text;
                string pass = password.Text;

                byte[] keyBytes  = Encoding.UTF8.GetBytes(this.hashKey);
                byte[] passBytes = Encoding.UTF8.GetBytes(pass);

                var    md5             = new HMACMD5(keyBytes);
                byte[] hashedBytesPass = md5.ComputeHash(passBytes);
                string md5Pass         = BitConverter.ToString(hashedBytesPass).Replace("-", "").ToLower();

                Dictionary <string, string> fields = new Dictionary <string, string>();
                fields.Add("FNC", this.httpFunc);
                fields.Add("USR", user);
                fields.Add("PWD", md5Pass);

                string json = this.generateJson(fields);

                string randomKey = Cryptography.randomString(32);
                string randomIV  = Cryptography.randomString(32);

                string encryptedData = Cryptography.encryptRJ256(json, randomKey, randomIV);
                encryptedData += randomKey;
                encryptedData += randomIV;

                Dictionary <string, string> sendData = new Dictionary <string, string>();
                sendData.Add("CTT", encryptedData);

                string webResponse = HttpComm.httpPostData(sendData, this.configs.consultGateway);

                if (webResponse.Length <= 6)
                {
                    string message = HttpComm.treatHttpError(webResponse, this.httpFunc);
                    this.updateDialogLabel(message);
                }
                else
                {
                    this.performLogin(webResponse);
                }
            }
            else
            {
                this.updateDialogLabel(status);
            }
        }
Example #5
0
        private void sendFilesToBucket()
        {
            string bucket       = this.userData.contract.bucketName;
            string targetFolder = this.configs.targetCloudFolder;
            string key          = targetFolder.Equals(" ") ? "" : targetFolder + "/";

            decimal progress   = 0;
            decimal filesSent  = 0;
            decimal totalFiles = (decimal)files.Count;

            int currentProgress = 0;

            foreach (String file in this.files)
            {
                if (sendFileLabel.InvokeRequired)
                {
                    sendFileLabel.Invoke(new MethodInvoker(delegate { sendFileLabel.Text = "Enviando arquivo " + (filesSent + 1) + " de " + totalFiles; }));
                }

                String[] fileData = file.Split('\\');
                String   fileName = fileData[(fileData.Length - 1)];

                TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.SAEast1));

                try
                {
                    updateSendStatus("Enviando arquivo...");

                    TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest
                    {
                        BucketName   = bucket,
                        FilePath     = file,
                        StorageClass = S3StorageClass.Standard,
                        Key          = key + fileName,
                        CannedACL    = S3CannedACL.Private,
                    };

                    if (this.userData.contract.encryption > 0)
                    {
                        fileTransferUtilityRequest.ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256;
                    }

                    fileTransferUtility.Upload(fileTransferUtilityRequest);

                    updateSendStatus("Gerando log de envio");

                    string status = HttpComm.newFileUploaded(this.userData.token, key, file, this.configs.consultGateway);

                    if (status.Equals("OK"))
                    {
                        updateSendStatus("Arquivo enviado com sucesso");
                    }
                    else
                    {
                        updateSendStatus(status);
                    }

                    filesSent++;
                    progress        = filesSent / totalFiles * 100;
                    currentProgress = Convert.ToInt32(progress);

                    if (sendFileProgress.InvokeRequired)
                    {
                        sendFileProgress.Invoke(new MethodInvoker(delegate { sendFileProgress.Value = currentProgress; }));
                    }
                }
                catch (Exception exception)
                {
                    this.updateDialogLabel("Erro ao enviar o arquivo para nuvem");
                }

                try
                {
                    string[] filePath = file.Split('\\');
                    int      last     = filePath.Length - 1;

                    string from = this.configs.sourceFolder + "\\" + filePath[last];
                    string to   = this.configs.targetLocalFolder + "\\" + filePath[last];

                    File.Move(from, to);
                }
                catch (Exception e)
                {
                    this.updateDialogLabel("Impossível mover o arquivo para a pasta destino");
                }

                if (!keepAlive)
                {
                    break;
                }
            }

            if (sendFileLabel.InvokeRequired)
            {
                sendFileLabel.Invoke(new MethodInvoker(delegate { sendFileLabel.Text = "Envio realizado com sucesso"; }));
            }

            if (button3.InvokeRequired)
            {
                button3.Invoke(new MethodInvoker(delegate { button3.Enabled = true; }));
            }
        }