Skip to content

Commit d0f8e47

Browse files
committed
Only try as PEM certificate when length is >= 2000
1 parent dc27845 commit d0f8e47

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/CfdiUtils/Certificado/Certificado.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public function __construct(string $filename, OpenSSL $openSSL = null)
9595

9696
private function extractPemCertificate(string $contents): string
9797
{
98+
if (strlen($contents) < 2000) {
99+
return ''; // is too short to be a PEM certificate
100+
}
98101
$openssl = $this->getOpenSSL();
99102
$decoded = @base64_decode($contents, true) ?: '';
100103
if ($contents === base64_encode($decoded)) { // is a one liner certificate
@@ -109,7 +112,8 @@ private function extractPemCertificate(string $contents): string
109112

110113
private function obtainPemCertificate(string $contents): string
111114
{
112-
$extracted = $this->extractPemCertificate($contents);
115+
$openssl = $this->getOpenSSL();
116+
$extracted = $openssl->readPemContents($contents)->certificate();
113117
if ('' === $extracted) { // cannot extract, could be on DER format
114118
$extracted = $this->getOpenSSL()->derCerConvertPhp($contents);
115119
}

0 commit comments

Comments
 (0)