Skip to content
Snippets Groups Projects
Commit fcbbcaca authored by Roeland Jago Douma's avatar Roeland Jago Douma
Browse files

Also load CA properly in integrity check

parent d751fedf
No related branches found
No related tags found
No related merge requests found
...@@ -299,6 +299,18 @@ class Checker { ...@@ -299,6 +299,18 @@ class Checker {
} }
} }
/**
* Split the certificate file in individual certs
*
* @param string $cert
* @return string[]
*/
private function splitCerts(string $cert): array {
preg_match_all('([\-]{3,}[\S\ ]+?[\-]{3,}[\S\s]+?[\-]{3,}[\S\ ]+?[\-]{3,})', $cert, $matches);
return $matches[0];
}
/** /**
* Verifies the signature for the specified path. * Verifies the signature for the specified path.
* *
...@@ -333,7 +345,11 @@ class Checker { ...@@ -333,7 +345,11 @@ class Checker {
// Check if certificate is signed by Nextcloud Root Authority // Check if certificate is signed by Nextcloud Root Authority
$x509 = new \phpseclib\File\X509(); $x509 = new \phpseclib\File\X509();
$rootCertificatePublicKey = $this->fileAccessHelper->file_get_contents($this->environmentHelper->getServerRoot().'/resources/codesigning/root.crt'); $rootCertificatePublicKey = $this->fileAccessHelper->file_get_contents($this->environmentHelper->getServerRoot().'/resources/codesigning/root.crt');
$x509->loadCA($rootCertificatePublicKey);
$rootCerts = $this->splitCerts($rootCertificatePublicKey);
foreach ($rootCerts as $rootCert) {
$x509->loadCA($rootCert);
}
$x509->loadX509($certificate); $x509->loadX509($certificate);
if (!$x509->validateSignature()) { if (!$x509->validateSignature()) {
throw new InvalidSignatureException('Certificate is not valid.'); throw new InvalidSignatureException('Certificate is not valid.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment