Skip to content

Commit 71de8e5

Browse files
committedSep 13, 2022
Cambiado digest de firma a SHA-512
- Actualizado SignableTrait.php - Actualizado XmlTools.php
1 parent 232f88f commit 71de8e5

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed
 

‎src/Common/XmlTools.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ public function getCertDigest($publicKey, $pretty=false) {
120120

121121

122122
/**
123-
* Get signature in SHA-1
123+
* Get signature in SHA-512
124124
* @param string $payload Data to sign
125125
* @param string $privateKey Private Key
126126
* @param boolean $pretty Pretty Base64 response
127127
* @return string Base64 Signature
128128
*/
129129
public function getSignature($payload, $privateKey, $pretty=true) {
130-
openssl_sign($payload, $signature, $privateKey);
130+
openssl_sign($payload, $signature, $privateKey, OPENSSL_ALGO_SHA512);
131131
return $this->toBase64($signature, $pretty);
132132
}
133133

‎src/FacturaeTraits/SignableTrait.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected function injectSignature($xml) {
179179
$sInfo = '<ds:SignedInfo Id="Signature-SignedInfo' . $this->signedInfoID . '">' . "\n" .
180180
'<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315">' .
181181
'</ds:CanonicalizationMethod>' . "\n" .
182-
'<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1">' .
182+
'<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha512">' .
183183
'</ds:SignatureMethod>' . "\n" .
184184
'<ds:Reference Id="SignedPropertiesID' . $this->signedPropertiesID . '" ' .
185185
'Type="http://uri.etsi.org/01903#SignedProperties" ' .
@@ -248,11 +248,10 @@ private function injectTimestamp($signedXml) {
248248
$payload = '<ds:SignatureValue' . $payload . '</ds:SignatureValue>';
249249
$payload = $tools->injectNamespaces($payload, $this->getNamespaces());
250250

251-
// Create TimeStampQuery in ASN1 using SHA-1
252-
$tsq = "302c0201013021300906052b0e03021a05000414";
253-
$tsq .= hash('sha1', $payload);
254-
$tsq .= "0201000101ff";
255-
$tsq = hex2bin($tsq);
251+
// Create TimeStampQuery in ASN1 using SHA-512
252+
$tsq = "\x30\x59\x02\x01\x01\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03\x05\x00\x04\x40";
253+
$tsq .= hash('sha512', $payload, true);
254+
$tsq .= "\x01\x01\xff";
256255

257256
// Await TimeStampRequest
258257
$chOpts = array(
@@ -280,7 +279,7 @@ private function injectTimestamp($signedXml) {
280279

281280
// Validate TimeStampRequest
282281
$responseCode = substr($tsr, 6, 3);
283-
if ($responseCode !== "\02\01\00") { // Bytes for INTEGER 0 in ASN1
282+
if ($responseCode !== "\x02\x01\x00") { // Bytes for INTEGER 0 in ASN1
284283
throw new \Exception('Invalid TSR response code');
285284
}
286285

0 commit comments

Comments
 (0)