Beispiel #1
0
        ///<summary>
        ///
        /// Metodo para enviar a nova mensagem através do botao de enviar
        ///
        ///</summary>
        private void novoEnviarClick(object sender, EventArgs e)
        {
            try
            {
                string destinatarios = novoPara.Text;
                if (!destinatarios.EndsWith(SEPARADOR))
                {
                    destinatarios += SEPARADOR;
                }

                preMensagem msg          = new preMensagem(usuario, destinatarios, novoAssunto.Text, novoTexto.Text, novoCripto.Checked, novoAssina.Checked, CriptoFiles, PlainFiles);
                string      caminhoChave = "";

                if (novoAssina.Checked)
                {
                    gerenciaChave gerenciaChaveForm = new gerenciaChave();
                    gerenciaChaveForm.ShowDialog();
                    caminhoChave = gerenciaChaveForm.getCaminho();
                }

                if (novoPara.Text == null || novoPara.Text == "")
                {
                    MessageBox.Show(MSG_SEM_DESTINATARIO, MSG_INFO, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    List <string> destinatariosInexistentes = gerenciaServlet.criaMensagem(msg, caminhoChave);
                    //bool ret = gerenciaServlet.criaMensagem(msg,caminhoChave);

                    if (destinatariosInexistentes.Count == 0)
                    {
                        MessageBox.Show(MSG_ENVIO_OK, MSG_INFO, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (destinatariosInexistentes.Count > 1)
                    {
                        string nomesInexistentes = "";
                        foreach (string s in destinatariosInexistentes)
                        {
                            nomesInexistentes += s + ", ";
                        }
                        nomesInexistentes = nomesInexistentes.Remove(nomesInexistentes.LastIndexOf(", "), 2);

                        MessageBox.Show(MSG_ENVIO_OK_DESTINATARIOS_INEXISTENTES + nomesInexistentes, MSG_INFO, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }//else MessageBox.Show(MSG_ENVIO_FAIL, MSG_ERRO, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    gerenciaServlet.excluiArquivos();
                    this.Close();
                }
            }
            catch (excecao except)
            {
                MessageBox.Show(except.Message, MSG_ERRO, MessageBoxButtons.OK, MessageBoxIcon.Error);
                novoPara.Clear();
            }
        }
Beispiel #2
0
        ///<summary>
        ///
        /// Método para buscar a mensagem do usuario
        ///
        ///</summary>
        public static preMensagem buscaMensagem(int id, string caminhoChavePrivada)
        {
            string      xml = WService.buscaMensagem(id);
            mensagem    msg = serial.Deserializar(xml, typeof(mensagem)) as mensagem;
            preMensagem pmsg;

            HashSet <string> cripto = new HashSet <string>();
            HashSet <string> plain  = new HashSet <string>();

            foreach (anexo a in msg.anexos)
            {
                if (a.getCripto())
                {
                    cripto.Add(a.getNome());
                }
                else
                {
                    plain.Add(a.getNome());
                }
            }

            if (msg.getCriptografar())
            {
                string conteudoCifrado = simetrica.convertToString(msg.getTexto());
                string conteudo        = simetrica.decifraMensagem(conteudoCifrado, caminhoChavePrivada);
                msg.setTexto(conteudo);
            }

            if (msg.getAssinar())
            {
                string conteudoChave = WService.retornaChavePublica(msg.getDe());
                string caminhoChave  = CAMINHO_TEMP + msg.getDe() + EXTENSAO;
                manipulaArquivo.criaArquivoTexto(caminhoChave, conteudoChave);
                bool textoOk = assimetrica.verificaAssinatura(caminhoChave, msg.getAssinatura(), msg.getTexto());

                if (textoOk)
                {
                    pmsg = new preMensagem(msg.getDe(), msg.getPara(), msg.getAssunto(), msg.getTexto(), msg.getCriptografar(), msg.getAssinar(), cripto, plain);
                    return(pmsg);
                }
                else
                {
                    throw new excecao(MSG_ERRO_ABRIR);
                }
            }

            pmsg = new preMensagem(msg.getDe(), msg.getPara(), msg.getAssunto(), msg.getTexto(), msg.getCriptografar(), msg.getAssinar(), cripto, plain);
            return(pmsg);
        }
Beispiel #3
0
        ///<summary>
        ///
        /// Metodo construtor para inicializar os componentes do formulario
        /// atraves de uma premensagem e um indicador do tipo de mensagem nova
        ///
        ///</summary>
        public novaMensagem(preMensagem msg, int flag, int idmensagem)
        {
            control        = flag;
            usuario        = msg.getPara();
            controleAnexos = 0;
            InitializeComponent();
            novoAssunto.Text = RE + msg.getAssunto();
            novoTexto.Text   = Environment.NewLine + Environment.NewLine + Environment.NewLine + TRACEJADO + Environment.NewLine + DE + msg.getDe() + EMAIL + Environment.NewLine + PARA + msg.getPara() + EMAIL + Environment.NewLine + ASSUNTO + msg.getAssunto() + Environment.NewLine + Environment.NewLine + msg.getTexto();

            if (flag == 1)
            {
                string caminhoChave = "";

                if (msg.getArquivoCripto().Count > 0)
                {
                    foreach (string s in msg.getArquivoCripto())
                    {
                        string nome = gerenciaServlet.recuperaNomeOriginalArquivo(s);
                        nomeAnexos.Text = nome + "; " + nomeAnexos.Text;
                        CriptoFiles.Add(caminho + s);
                    }

                    gerenciaChave gerenciaChaveForm = new gerenciaChave();
                    gerenciaChaveForm.ShowDialog();
                    caminhoChave = gerenciaChaveForm.getCaminho();
                }

                if (msg.getArquivoPlain().Count > 0)
                {
                    foreach (string s in msg.getArquivoPlain())
                    {
                        nomeAnexos.Text = s + "; " + nomeAnexos.Text;
                        PlainFiles.Add(caminho + s);
                    }
                }

                if (CriptoFiles.Count > 0 || PlainFiles.Count > 0)
                {
                    controleAnexos = 1;
                }

                gerenciaServlet.anexoEncaminhar(idmensagem, caminhoChave);
            }
            else
            {
                novoPara.Text = msg.getDe() + EMAIL;
            }
        }
Beispiel #4
0
        public abrirMensagem(int id)
        {
            idmensagem = id;
            InitializeComponent();

            string caminhoChave = "";

            if (gerenciaServlet.verificaMensagemCriptografada(id))
            {
                MessageBox.Show(MSG_CRIPTO, MSG_ATENCAO, MessageBoxButtons.OK, MessageBoxIcon.Information);
                gerenciaChave gerenciaChaveForm = new gerenciaChave();
                gerenciaChaveForm.ShowDialog();

                caminhoChave = gerenciaChaveForm.getCaminho();
            }

            msg = gerenciaServlet.buscaMensagem(id, caminhoChave);

            abreDe.Text      = msg.getDe();
            abreAssunto.Text = msg.getAssunto();
            abreTexto.Text   = msg.getTexto();

            foreach (string s in msg.getArquivoCripto())
            {
                abreAnexos.Text = s + "; " + abreAnexos.Text;
            }
            foreach (string s in msg.getArquivoPlain())
            {
                abreAnexos.Text = s + "; " + abreAnexos.Text;
            }

            if (msg.getAssunto().Equals(MSG_ERRO_ASSUNTO))
            {
                abreResponder.Visible  = false;
                abreEncaminhar.Visible = false;
            }
        }
Beispiel #5
0
        ///<summary>
        ///
        /// Método que cria mensagem a ser enviada a partir da pre-mensagem passada retornando
        /// verdadeiro caso o envio seja feito com sucesso.
        ///
        /// Retorna excecao.
        ///
        ///</summary>
        public static List <string> criaMensagem(preMensagem msg, string caminhoChave)
        {
            try
            {
                string        destinatarios            = msg.getPara() + msg.getDe() + EMAIL;
                string[]      para                     = manipulaString.retornaLoginsContatos(destinatarios);
                string        de                       = msg.getDe();
                string        assunto                  = msg.getAssunto();
                string        body                     = "";
                string        assinatura               = "";
                bool          cripto                   = msg.getCriptografar();
                bool          sign                     = msg.getAssinar();
                List <anexo>  arquivosPlain            = new List <anexo>();
                List <anexo>  arquivosCripto           = new List <anexo>();
                List <string> destinatarioInexistentes = new List <string>();

                // trazendo os arquivos que nao serao criptografados para a lista
                foreach (string s in msg.getArquivoPlain())
                {
                    bool  cript = false;
                    anexo next  = retornaConteudoAnexo(s, cript, "");
                    arquivosPlain.Add(next);
                }

                // criando a mensagem para enviar a cada destinatario
                foreach (string destinatario in para)
                {
                    if (WService.verificaUsuario(destinatario))
                    {
                        body = msg.getTexto();
                        arquivosCripto.Clear();

                        foreach (string s in msg.getArquivoCripto())
                        {
                            string nome  = s;
                            bool   cript = true;
                            if (s.Contains(EXTENSAO_SAC))
                            {
                                nome = manipulaString.recuperaNomeOriginalArquivo(s);
                            }
                            anexo next = retornaConteudoAnexo(nome, cript, destinatario);
                            arquivosCripto.Add(next);
                        }

                        foreach (anexo ap in arquivosPlain)
                        {
                            arquivosCripto.Add(ap);
                        }

                        if (sign)
                        {
                            assinatura = assimetrica.assinaTexto(caminhoChave, body);
                        }

                        if (cripto)
                        {
                            string chaveCertificada = WService.retornaChavePublica(destinatario);
                            string caminhoChaveCert = CAMINHO_TEMP + destinatario + EXTENSAO;
                            manipulaArquivo.criaArquivoTexto(caminhoChaveCert, chaveCertificada);

                            body = simetrica.cifraMensagem(body, caminhoChaveCert);
                            body = simetrica.convertToHexa(body);
                        }

                        mensagem mensagem = new mensagem(de, destinatario, assunto, body, assinatura, cripto, sign, arquivosCripto, msg.getPara());
                        string   xml      = serial.serializarObjeto(mensagem);
                        WService.enviaMensagem(xml);
                        excluiArquivos();
                    }
                    else
                    {
                        destinatarioInexistentes.Add(destinatario);
                    }
                }
                return(destinatarioInexistentes);
            }
            catch (excecao except)
            {
                throw except;
            }
        }