Skip to content

Commit

Permalink
Añadida corrección de atributos OID al firmar
Browse files Browse the repository at this point in the history
- Actualizada clase FacturaeSigner

> Related to #143
  • Loading branch information
josemmo committed Nov 12, 2023
1 parent 5772ef8 commit 96c5b83
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Common/FacturaeSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ final class FacturaeSigner {
const SIGN_POLICY_NAME = 'Política de Firma FacturaE v3.1';
const SIGN_POLICY_URL = 'http://www.facturae.es/politica_de_firma_formato_facturae/politica_de_firma_formato_facturae_v3_1.pdf';
const SIGN_POLICY_DIGEST = 'Ohixl6upD6av8N7pEvDABhEL6hM=';
const ALLOWED_OID_TYPES = [
// Mandatory fields in https://datatracker.ietf.org/doc/html/rfc4514#section-3
'CN' => 'CN',
'L' => 'L',
'ST' => 'ST',
'O' => 'O',
'OU' => 'OU',
'C' => 'C',
'STREET' => 'STREET',
'DC' => 'DC',
'UID' => 'UID',

// Other fields with well-known names
'GN' => 'GN',
'SN' => 'SN',

// Other fields with compatibility issues
'organizationIdentifier' => 'OID.2.5.4.97',
'serialNumber' => 'OID.2.5.4.5',
'title' => 'OID.2.5.4.12',
];

use KeyPairReaderTrait;

Expand Down Expand Up @@ -155,12 +176,16 @@ public function sign($xml) {
$certData = openssl_x509_parse($this->publicChain[0]);
$certIssuer = [];
foreach ($certData['issuer'] as $item=>$rawValues) {
if (!isset(self::ALLOWED_OID_TYPES[$item])) {
continue;
}
$item = self::ALLOWED_OID_TYPES[$item];
$values = is_array($rawValues) ? $rawValues : [$rawValues];
foreach ($values as $value) {
$certIssuer[] = "$item=$value";
}
}
$certIssuer = implode(',', array_reverse($certIssuer));
$certIssuer = implode(', ', array_reverse($certIssuer));
$xadesSignedProperties = '<xades:SignedProperties Id="'. $this->signatureSignedPropertiesId . '">' .
'<xades:SignedSignatureProperties>' .
'<xades:SigningTime>' . date('c', $signingTime) . '</xades:SigningTime>' .
Expand Down

0 comments on commit 96c5b83

Please sign in to comment.