mirror of
https://github.com/LibreSign/libresign.git
synced 2025-12-17 21:12:16 +01:00
chore: update dependencies and handler
Update composer.json and Pkcs12Handler changes from refactoring. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
This commit is contained in:
parent
4d23cd91aa
commit
9274075bf8
2 changed files with 24 additions and 21 deletions
|
|
@ -53,7 +53,9 @@
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"OCP\\": "vendor/nextcloud/ocp/OCP"
|
"OCP\\": "vendor/nextcloud/ocp/OCP",
|
||||||
|
"OCA\\Libresign\\Tests\\Unit\\": "tests/php/Unit/",
|
||||||
|
"OCA\\Libresign\\Tests\\Fixtures\\": "tests/php/fixtures/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
|
|
||||||
|
|
@ -52,32 +52,23 @@ class Pkcs12Handler extends SignEngineHandler {
|
||||||
private function getSignatures($resource): iterable {
|
private function getSignatures($resource): iterable {
|
||||||
rewind($resource);
|
rewind($resource);
|
||||||
$content = stream_get_contents($resource);
|
$content = stream_get_contents($resource);
|
||||||
preg_match_all(
|
|
||||||
'/ByteRange\s*\[\s*(?<offset1>\d+)\s+(?<length1>\d+)\s+(?<offset2>\d+)\s+(?<length2>\d+)\s*\]/',
|
preg_match_all('/\/Contents\s*<([0-9a-fA-F]+)>/', $content, $contents, PREG_OFFSET_CAPTURE);
|
||||||
$content,
|
|
||||||
$bytes
|
if (empty($contents[1])) {
|
||||||
);
|
|
||||||
if (empty($bytes['offset1']) || empty($bytes['length1']) || empty($bytes['offset2']) || empty($bytes['length2'])) {
|
|
||||||
throw new LibresignException($this->l10n->t('Unsigned file.'));
|
throw new LibresignException($this->l10n->t('Unsigned file.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 0; $i < count($bytes['offset1']); $i++) {
|
$seenHexSignatures = [];
|
||||||
$offset1 = (int)$bytes['offset1'][$i];
|
foreach ($contents[1] as $match) {
|
||||||
$length1 = (int)$bytes['length1'][$i];
|
$signatureHex = $match[0];
|
||||||
$offset2 = (int)$bytes['offset2'][$i];
|
|
||||||
|
|
||||||
$signatureStart = $offset1 + $length1 + 1;
|
if (isset($seenHexSignatures[$signatureHex])) {
|
||||||
$signatureLength = $offset2 - $signatureStart - 1;
|
|
||||||
|
|
||||||
rewind($resource);
|
|
||||||
|
|
||||||
$signature = stream_get_contents($resource, $signatureLength, $signatureStart);
|
|
||||||
if ($signature === false) {
|
|
||||||
yield null;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$seenHexSignatures[$signatureHex] = true;
|
||||||
|
|
||||||
$decodedSignature = @hex2bin($signature);
|
$decodedSignature = @hex2bin($signatureHex);
|
||||||
if ($decodedSignature === false) {
|
if ($decodedSignature === false) {
|
||||||
yield null;
|
yield null;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -102,7 +93,17 @@ class Pkcs12Handler extends SignEngineHandler {
|
||||||
$certificates = [];
|
$certificates = [];
|
||||||
|
|
||||||
foreach ($this->getSignatures($resource) as $signature) {
|
foreach ($this->getSignatures($resource) as $signature) {
|
||||||
$certificates[] = $this->processSignature($resource, $signature);
|
if (!$signature) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->processSignature($resource, $signature);
|
||||||
|
|
||||||
|
if (empty($result['chain'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$certificates[] = $result;
|
||||||
}
|
}
|
||||||
return $certificates;
|
return $certificates;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue