Skip to content

Commit

Permalink
Se activa verificación firma según cambio propuesto en #18
Browse files Browse the repository at this point in the history
  • Loading branch information
estebandelaf committed Jul 3, 2019
1 parent 42b255a commit ff361f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
20 changes: 11 additions & 9 deletions lib/Sii/Dte.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -1790,20 +1792,20 @@ 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
$D = $this->xml->documentElement->getElementsByTagName('Documento')->item(0);
$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');
Expand Down
17 changes: 10 additions & 7 deletions lib/Sii/EnvioDte.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand Down

0 comments on commit ff361f7

Please sign in to comment.