Skip to content

Commit f6a8c92

Browse files
committed
Version 2.7.3
Fix v2.7.2
2 parents e3b7c34 + 0e30fe3 commit f6a8c92

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

docs/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
- Remove `trigger_error` on `\CfdiUtils\Elements\Cfdi33\Comprobante::getCfdiRelacionados` when called with arguments.
1414

1515

16+
## Version 2.7.3 2018-12-05
17+
18+
- Fix previous release since it did not publish the changes made on 2.7.2.
19+
20+
21+
## Version 2.7.2 2018-12-05
22+
23+
- Add method `CfdiUtils\Certificado\Certificado::getCertificateName(): string` to obtain the certificate
24+
name as returned by `openssl_x509_parse`.
25+
26+
1627
## Version 2.7.1 2018-12-04
1728

1829
- Fix wrong use of `escapeshellcmd` replacing with `escapeshellarg`

docs/componentes/certificado.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ En este último caso es convertido internamente a formato PEM y luego interpreta
88
Una vez cargado el certificado permite obtener los siguientes datos utilizando *getters* (como `getRfc()`):
99

1010
- RFC
11-
- Nombre
11+
- Nombre amigable
12+
- Nombre del certificado
1213
- Número de serie
1314
- Válido desde y hasta
1415
- Llave pública

src/CfdiUtils/Certificado/Certificado.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ class Certificado
66
/** @var string */
77
private $rfc;
88

9+
/** @var string */
10+
private $certificateName;
11+
912
/** @var string */
1013
private $name;
1114

@@ -54,14 +57,17 @@ public function __construct(string $filename)
5457
if (! is_array($data)) {
5558
throw new \RuntimeException("Cannot parse the certificate file $filename");
5659
}
60+
if (! isset($data['subject'])) {
61+
$data['subject'] = [];
62+
}
5763

5864
// get the public key
5965
$pubKey = $this->obtainPubKeyFromContents($contents);
6066

6167
// set all the values
62-
$this->rfc = (string) strstr($data['subject']['x500UniqueIdentifier'] . ' ', ' ', true);
63-
$this->rfc = (string) strstr($data['subject']['x500UniqueIdentifier'] . ' ', ' ', true);
64-
$this->name = $data['subject']['name'];
68+
$this->certificateName = strval($data['name'] ?? '');
69+
$this->rfc = (string) strstr(($data['subject']['x500UniqueIdentifier'] ?? '') . ' ', ' ', true);
70+
$this->name = strval($data['subject']['name'] ?? '');
6571
$serial = new SerialNumber('');
6672
if (isset($data['serialNumberHex'])) {
6773
$serial->loadHexadecimal($data['serialNumberHex']);
@@ -71,8 +77,8 @@ public function __construct(string $filename)
7177
throw new \RuntimeException("Cannot get serialNumberHex or serialNumber from certificate file $filename");
7278
}
7379
$this->serial = $serial->asAscii();
74-
$this->validFrom = $data['validFrom_time_t'];
75-
$this->validTo = $data['validTo_time_t'];
80+
$this->validFrom = $data['validFrom_time_t'] ?? 0;
81+
$this->validTo = $data['validTo_time_t'] ?? 0;
7682
$this->pubkey = $pubKey;
7783
$this->pemContents = $contents;
7884
$this->filename = $filename;
@@ -117,6 +123,11 @@ public function getRfc(): string
117123
return $this->rfc;
118124
}
119125

126+
public function getCertificateName(): string
127+
{
128+
return $this->certificateName;
129+
}
130+
120131
/**
121132
* Name (Razón Social) set when certificate was created
122133
* @return string

tests/CfdiUtilsTests/Certificado/CertificadoTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public function testConstructWithValidExample()
2828
$certificado = new Certificado($cerfile);
2929

3030
$this->assertEquals($cerfile, $certificado->getFilename());
31+
$certificateName = implode('', [
32+
'/CN=ACCEM SERVICIOS EMPRESARIALES SC',
33+
'/name=ACCEM SERVICIOS EMPRESARIALES SC',
34+
'/O=ACCEM SERVICIOS EMPRESARIALES SC',
35+
'/x500UniqueIdentifier=AAA010101AAA / HEGT7610034S2',
36+
'/serialNumber= / HEGT761003MDFRNN09',
37+
'/OU=CSD01_AAA010101AAA',
38+
]);
39+
$this->assertEquals($certificateName, $certificado->getCertificateName());
3140
$this->assertEquals('ACCEM SERVICIOS EMPRESARIALES SC', $certificado->getName());
3241
$this->assertEquals('AAA010101AAA', $certificado->getRfc());
3342
$this->assertEquals('30001000000300023708', $certificado->getSerial());

0 commit comments

Comments
 (0)