public SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignatureType AsignatureProceso(string strPPrivada, Encabezado encLMetadata, string pass, string strCertificado)
 {
     SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignatureType result;
     try
     {
         string strPXmlFirmado = "";
         SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignatureType Asig = new SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignatureType();
         Asig.Id            = "Signature";
         Asig.SignedInfo    = new SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignedInfoType();
         Asig.SignedInfo.Id = "Signature-SignedInfo";
         Asig.SignedInfo.CanonicalizationMethod           = new SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.CanonicalizationMethodType();
         Asig.SignedInfo.CanonicalizationMethod.Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n20010315";
         Asig.SignedInfo.SignatureMethod           = new SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignatureMethodType();
         Asig.SignedInfo.SignatureMethod.Algorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
         Asig.SignedInfo.Reference     = new SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.ReferenceType();
         Asig.SignedInfo.Reference.URI = "#Certificate1";
         List <SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.TransformType> T = new List <SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.TransformType>();
         T.Add(new SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.TransformType
         {
             Algorithm = "http://www.w3.org/2000/09/xmldsig#envelopedsignature"
         });
         Asig.SignedInfo.Reference.Transforms             = T.ToArray();
         Asig.SignedInfo.Reference.DigestMethod           = new SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.DigestMethodType();
         Asig.SignedInfo.Reference.DigestMethod.Algorithm = "http://www.w3.org/2000/09/xmldsig#sha1";
         if (File.Exists(strPPrivada + ".pem"))
         {
             strPPrivada += ".pem";
         }
         string ext = Path.GetExtension(strPPrivada);
         AccesoServicios.SignXmlFile(this.ArmarXmlPreFirma(encLMetadata), ref strPXmlFirmado, OpensslKey.DecodePrivateKey(File.ReadAllBytes(strPPrivada), pass, ext));
         string hex = strPXmlFirmado.Substring(strPXmlFirmado.IndexOf("<DigestValue>") + 13, strPXmlFirmado.IndexOf("</DigestValue>") - strPXmlFirmado.IndexOf("<DigestValue>") - 13);
         Asig.SignedInfo.Reference.DigestValue = Convert.FromBase64String(hex);
         Asig.SignatureValue = Convert.FromBase64String(strPXmlFirmado.Substring(strPXmlFirmado.IndexOf("<SignatureValue>") + 16, strPXmlFirmado.IndexOf("</SignatureValue>") - strPXmlFirmado.IndexOf("<SignatureValue>") - 16));
         X509Certificate2 x509 = new X509Certificate2(strCertificado);
         Asig.KeyInfo          = new SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.KeyInfoType();
         Asig.KeyInfo.X509Data = new SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.X509DataType();
         Asig.KeyInfo.X509Data.X509Certificate = File.ReadAllBytes(strCertificado);
         Asig.KeyInfo.Id = "Certificate1";
         result          = Asig;
     }
     catch (Exception exception)
     {
         AccesoServicios.Log.Error("(Asignature) Error al generar la firma de los CFDI's " + exception.ToString());
         result = null;
     }
     return(result);
 }
Esempio n. 2
0
        public string ProcesarRespuestaAceptacionRechazo(string RfcReceptor, string RfcPacEnviaSolicitud, List <Folios> F)
        {
            AccesoServicios ser           = new AccesoServicios();
            IList           uuidsCancelar = new List <string>();

            foreach (Folios f in F)
            {
                uuidsCancelar.Add(f.UUDI.ToUpper());
            }
            List <SolicitudAceptacionRechazoFolios> Folio = new List <SolicitudAceptacionRechazoFolios>();

            foreach (Folios f in F)
            {
                SolicitudAceptacionRechazoFolios x = new SolicitudAceptacionRechazoFolios();
                x.UUID = f.UUDI;
                if (f.Respuesta.ToString() == "Aceptacion")
                {
                    x.Respuesta = TipoAccionPeticionCancelacion.Aceptacion;
                }
                else
                {
                    x.Respuesta = TipoAccionPeticionCancelacion.Rechazo;
                }
                Folio.Add(x);
            }
            string result;

            using (new NtLinkLocalServiceEntities())
            {
                NtLinkEmpresa nle     = new NtLinkEmpresa();
                empresa       empresa = nle.GetByRfc(RfcReceptor);
                string        fecha   = this.FechaHoy();
                SAT.CFDI.Cliente.Procesamiento.Encabezado encLMetadata2 = new SAT.CFDI.Cliente.Procesamiento.Encabezado(RfcReceptor, fecha, uuidsCancelar);
                string path    = Path.Combine(ConfigurationManager.AppSettings["Resources"], RfcReceptor);
                string pathCer = Path.Combine(path, "Certs", "csd.cer");
                string pathKey = Path.Combine(path, "Certs", "csd.key");
                string pass    = empresa.PassKey;
                SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignatureType asignature = ser.AsignatureProceso(pathKey, encLMetadata2, pass, pathCer);
                result = ser.ProcesarRespuestaAceptacionRechazo(RfcReceptor, fecha, RfcPacEnviaSolicitud, Folio, asignature);
            }
            return(result);
        }
        public string ProcesarRespuestaAceptacionRechazo(string RfcReceptor, string fecha, string rfcPac, List <SolicitudAceptacionRechazoFolios> F, SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignatureType asig)
        {
            string result;

            try
            {
                AceptacionRechazoServiceClient CFDI = new AceptacionRechazoServiceClient();
                AcuseAceptacionRechazo         A    = new AcuseAceptacionRechazo();
                HttpRequestMessageProperty     tokenAutenticacion = this.AutenticaServicio();
                using (new OperationContextScope(CFDI.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = tokenAutenticacion;
                    A = CFDI.ProcesarRespuesta(new SolicitudAceptacionRechazo
                    {
                        Fecha = Convert.ToDateTime(fecha),
                        RfcPacEnviaSolicitud = rfcPac,
                        RfcReceptor          = RfcReceptor,
                        Signature            = asig,
                        Folios = F.ToArray()
                    });
                    result = AccesoServicios.GetXMLFromObject(A);
                }
            }
            catch (Exception exception)
            {
                AccesoServicios.Log.Error("(Envio) Error al enviar los CFDI's " + exception.ToString());
                result = null;
            }
            return(result);
        }