Skip to content

Commit d751fed

Browse files
committed
phpsec lib can't parse multiple certs in one go
So we have to split it manually and do it ourselves Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 4373afe commit d751fed

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/private/Installer.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ public function updateAppstoreApp($appId, $allowUnstable = false) {
215215
return false;
216216
}
217217

218+
/**
219+
* Split the certificate file in individual certs
220+
*
221+
* @param string $cert
222+
* @return string[]
223+
*/
224+
private function splitCerts(string $cert): array {
225+
preg_match_all('([\-]{3,}[\S\ ]+?[\-]{3,}[\S\s]+?[\-]{3,}[\S\ ]+?[\-]{3,})', $cert, $matches);
226+
227+
return $matches[0];
228+
}
229+
218230
/**
219231
* Downloads an app and puts it into the app directory
220232
*
@@ -231,12 +243,18 @@ public function downloadApp($appId, $allowUnstable = false) {
231243
if ($app['id'] === $appId) {
232244
// Load the certificate
233245
$certificate = new X509();
234-
$certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
246+
$rootCrt = file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt');
247+
$rootCrts = $this->splitCerts($rootCrt);
248+
foreach ($rootCrts as $rootCrt) {
249+
$certificate->loadCA($rootCrt);
250+
}
235251
$loadedCertificate = $certificate->loadX509($app['certificate']);
236252

237253
// Verify if the certificate has been revoked
238254
$crl = new X509();
239-
$crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
255+
foreach ($rootCrts as $rootCrt) {
256+
$crl->loadCA($rootCrt);
257+
}
240258
$crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl'));
241259
if ($crl->validateSignature() !== true) {
242260
throw new \Exception('Could not validate CRL signature');

0 commit comments

Comments
 (0)