Esempio n. 1
0
        public void Validar(bool salvando = true)
        {
            empresa.CertificadoInstalado         = ckbCertificadoInstalado.Checked && ckbTemCertificadoInstalado.Checked;
            empresa.CertificadoArquivo           = ckbTemCertificadoInstalado.Checked ? txtArquivoCertificado.Text : "";
            empresa.CertificadoSenha             = ckbTemCertificadoInstalado.Checked ? txtSenhaCertificado.Text : "";
            empresa.Certificado                  = (ckbTemCertificadoInstalado.Checked ? (this.oMeuCert == null ? empresa.Certificado : oMeuCert.Subject.ToString()) : "");
            empresa.CertificadoDigitalThumbPrint = (ckbTemCertificadoInstalado.Checked ? (this.oMeuCert == null ? empresa.CertificadoDigitalThumbPrint : oMeuCert.Thumbprint) : "");
            empresa.CertificadoPIN               = ckbTemCertificadoInstalado.Checked ? txtPinCertificado.Text : "";
            empresa.UsaCertificado               = ckbTemCertificadoInstalado.Checked;
            if (ckbTemCertificadoInstalado.Checked)
            {
                if (!String.IsNullOrEmpty(empresa.CertificadoPIN))
                {
                    CertificadoDigital oCertificado = new CertificadoDigital();
                    CertProviders      providerInfo = new CertProviders();
                    providerInfo = oCertificado.GetInfoProvider(cboProviders.SelectedItem.ToString());
                    empresa.ProviderCertificado     = providerInfo.NameKey;
                    empresa.ProviderTypeCertificado = providerInfo.Type;

                    if (salvando)
                    {
                        ValidarCertificadoA3(true);
                    }
                }
                if (cboProviders.SelectedItem != null)
                {
                }
            }
        }
Esempio n. 2
0
        private void ValidarCertificadoA3(bool salvando)
        {
            if (String.IsNullOrEmpty(empresa.CertificadoPIN))
            {
                throw new Exception("Informe o PIN do certificado");
            }

            if (cboProviders.SelectedItem.ToString() == "")
            {
                throw new Exception("Informe o provedor do certificado");
            }

            Wait.Show("Validando provider...");
            try
            {
                CertificadoProviders certificadoProviders = new CertificadoProviders(empresa.X509Certificado,
                                                                                     empresa.PastaXmlEnvio,
                                                                                     Empresas.FindEmpresaByThread(),
                                                                                     empresa.CertificadoPIN);
                CertProviders xCertProviders = new CertProviders();
                xCertProviders.NameKey = cboProviders.SelectedItem.ToString();
                xCertProviders.Type    = certificadoProviders.GetProviderType(xCertProviders.NameKey);

                if (certificadoProviders.TestarProvider(xCertProviders))
                {
                    Wait.Close();
                    if (!salvando)
                    {
                        MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm,
                                                            "Provider válido, XML assinado com sucesso.",
                                                            provError,
                                                            MessageBoxButtons.OK);
                    }
                }

                else
                {
                    Wait.Close();
                    MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm,
                                                        "Provider inválido, não foi possível assinar um XML com este provider.",
                                                        provError,
                                                        MessageBoxButtons.OK);

                    if (salvando)
                    {
                        throw new Exception("Não foi possível salvar a configuração.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Wait.Close();
            }
        }
Esempio n. 3
0
        private void ValidarCertificadoA3(bool salvando)
        {
            if (String.IsNullOrEmpty(empresa.CertificadoPIN))
            {
                throw new Exception("Informe o PIN do certificado");
            }

            Wait.Show("Validando PIN...");
            try
            {
                if (Empresas.FindConfEmpresaIndex(empresa.CNPJ, empresa.Servico) == -1)
                {
                    Empresas.Configuracoes.Add(empresa);
                }

                CertificadoProviders certificadoProviders = new CertificadoProviders(empresa.X509Certificado,
                                                                                     empresa.PastaXmlEnvio,
                                                                                     Empresas.FindConfEmpresaIndex(empresa.CNPJ, empresa.Servico),
                                                                                     empresa.CertificadoPIN);
                CertProviders xCertProviders = new CertProviders();

                if (certificadoProviders.TestarProvider(xCertProviders))
                {
                    Wait.Close();
                    if (!salvando)
                    {
                        MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm,
                                                            "Configuração do PIN validada, XML assinado com sucesso.",
                                                            provError,
                                                            MessageBoxButtons.OK);
                    }
                }

                else
                {
                    Wait.Close();
                    MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm,
                                                        "PIN inválido, não foi possível assinar um XML com esta chave.",
                                                        provError,
                                                        MessageBoxButtons.OK);

                    if (salvando)
                    {
                        throw new Exception("Não foi possível salvar a configuração.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Wait.Close();
            }
        }
Esempio n. 4
0
        private void ValidarCertificadoA3(bool salvando)
        {
            Wait.Show("Validando provider...");

            CertificadoProviders certificadoProviders = new CertificadoProviders(empresa.X509Certificado,
                                                                                 empresa.PastaXmlEnvio,
                                                                                 Empresas.FindEmpresaByThread(),
                                                                                 empresa.CertificadoPIN);
            CertProviders xCertProviders = new CertProviders();

            xCertProviders.NameKey = cboProviders.SelectedItem.ToString();
            xCertProviders.Type    = certificadoProviders.GetProviderType(xCertProviders.NameKey);

            if (certificadoProviders.TestarProvider(xCertProviders))
            {
                Wait.Close();
                if (!salvando)
                {
                    MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm,
                                                        "Provider Válido, XML assinado com sucesso.",
                                                        "Validação do Provider - Resultado:",
                                                        MessageBoxButtons.OK);
                }
            }

            else
            {
                Wait.Close();
                MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm,
                                                    "Provider Inválido, não foi possível assinar um XML com este provider.",
                                                    "Validação do Provider - Resultado:",
                                                    MessageBoxButtons.OK);

                if (salvando)
                {
                    throw new Exception("Não foi possível salvar a configuração.");
                }
            }
        }