From ff361f742b4ee8e753b75617db8e6c5081fe6a68 Mon Sep 17 00:00:00 2001 From: Esteban De La Fuente Rubio Date: Wed, 3 Jul 2019 13:59:31 -0400 Subject: [PATCH] =?UTF-8?q?Se=20activa=20verificaci=C3=B3n=20firma=20seg?= =?UTF-8?q?=C3=BAn=20cambio=20propuesto=20en=20https://github.com/LibreDTE?= =?UTF-8?q?/libredte-lib/issues/18?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Sii/Dte.php | 20 +++++++++++--------- lib/Sii/EnvioDte.php | 17 ++++++++++------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/Sii/Dte.php b/lib/Sii/Dte.php index 234f6a7a..1356cd58 100644 --- a/lib/Sii/Dte.php +++ b/lib/Sii/Dte.php @@ -1768,19 +1768,21 @@ private function round($valor, $moneda = false, $decimal = 4) * - RUT del emisor (si se pasó uno para comparar) * - RUT del receptor (si se pasó uno para comparar) * @return Código del estado de la validación - * @warning No se está validando la firma * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) - * @version 2015-09-08 + * @version 2019-07-03 */ public function getEstadoValidacion(array $datos = null) { - /*if (!$this->checkFirma()) - return 1;*/ + if (!$this->checkFirma()) { + return 1; + } if (is_array($datos)) { - if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) + if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) { return 2; - if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) + } + if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) { return 3; + } } return 0; } @@ -1790,12 +1792,13 @@ public function getEstadoValidacion(array $datos = null) * @return =true si la firma del DTE es válida, =null si no se pudo determinar * @warning No se está verificando el valor del DigestValue del documento (sólo la firma de ese DigestValue) * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) - * @version 2015-09-08 + * @version 2019-07-03 */ public function checkFirma() { - if (!$this->xml) + if (!$this->xml) { return null; + } // obtener firma $Signature = $this->xml->documentElement->getElementsByTagName('Signature')->item(0); // preparar documento a validar @@ -1803,7 +1806,6 @@ public function checkFirma() $Documento = new \sasco\LibreDTE\XML(); $Documento->loadXML($D->C14N()); $Documento->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); - $Documento->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); $SignedInfo = new \sasco\LibreDTE\XML(); $SignedInfo->loadXML($Signature->getElementsByTagName('SignedInfo')->item(0)->C14N()); $SignedInfo->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); diff --git a/lib/Sii/EnvioDte.php b/lib/Sii/EnvioDte.php index 3f6241cb..121a3ff1 100644 --- a/lib/Sii/EnvioDte.php +++ b/lib/Sii/EnvioDte.php @@ -396,18 +396,20 @@ public function esBoleta() * Método que determina el estado de validación sobre el envío * @param datos Arreglo con datos para hacer las validaciones * @return Código del estado de la validación - * @warning No se está validando la firma del EnvioDTE * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) - * @version 2015-09-07 + * @version 2019-07-03 */ public function getEstadoValidacion(array $datos = null) { - if (!$this->schemaValidate()) + if (!$this->schemaValidate()) { return 1; - /*if (!$this->checkFirma()) - return 2;*/ - if ($datos and $this->getReceptor()!=$datos['RutReceptor']) + } + if (!$this->checkFirma()) { + return 2; + } + if ($datos and $this->getReceptor()!=$datos['RutReceptor']) { return 3; + } return 0; } @@ -419,8 +421,9 @@ public function getEstadoValidacion(array $datos = null) */ public function checkFirma() { - if (!$this->xml) + if (!$this->xml) { return null; + } // listado de firmas del XML $Signatures = $this->xml->documentElement->getElementsByTagName('Signature'); // verificar firma de SetDTE