Skip to content

Commit 9ff4df3

Browse files
authored
Merge pull request #20 from Setasign/development
Development
2 parents 6d972c8 + 41d2591 commit 9ff4df3

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vendor
22
.idea
33
composer.phar
4-
.DS_Store
4+
.DS_Store
5+
local-tests/*.pdf

src/FpdiProtection.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,22 @@ public function __construct($orientation = 'P', $unit = 'mm', $size = 'A4', $use
218218
return;
219219
}
220220

221-
if (OPENSSL_VERSION_NUMBER >= 0x30000000 && PHP_VERSION_ID < 80100) {
222-
throw new \RuntimeException(
223-
'OpenSSL 3 is not supported with PHP versions < 8.1.0. ' .
224-
'You\'re using PHP ' . PHP_VERSION . ' with ' . OPENSSL_VERSION_TEXT . '. ' .
225-
'Please fix your PHP installation or set $useArcfourFallback to true to use a slower fallback implementation.'
226-
);
227-
}
228-
229-
if (!(function_exists('openssl_encrypt') && in_array('rc4-40', openssl_get_cipher_methods(), true))) {
221+
if (!function_exists('openssl_encrypt') || !in_array('rc4-40', openssl_get_cipher_methods(), true)) {
230222
throw new \RuntimeException(
231223
'OpenSSL with RC4 supported is required if $useArcfourFallback is false. ' .
232224
'If using OpenSSL 3 make sure that legacy providers are loaded ' .
233225
'(see https://wiki.openssl.org/index.php/OpenSSL_3.0#Providers).'
234226
);
235227
}
236228

229+
if (OPENSSL_VERSION_NUMBER >= 0x30000000 && PHP_VERSION_ID < 80100) {
230+
throw new \RuntimeException(
231+
'OpenSSL 3 is not supported with PHP versions < 8.1.0. ' .
232+
'You\'re using PHP ' . PHP_VERSION . ' with ' . OPENSSL_VERSION_TEXT . '. ' .
233+
'Please fix your PHP installation or set $useArcfourFallback to true to ' .
234+
'use a slower fallback implementation.'
235+
);
236+
}
237237
}
238238

239239
/**

tests/functional/FpdiProtectionTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,31 @@ public function testLinks()
345345

346346
$this->assertEquals($linkTarget, $uri);
347347
}
348+
349+
public function testWithArcfourFallback()
350+
{
351+
$linkTarget = 'https://setasign.com';
352+
$pdf = new FpdiProtection('P', 'mm', 'A4', true);
353+
$pdf->setProtection([], 'user', 'owner', 3);
354+
$pdf->AddPage();
355+
$pdf->SetFont('Helvetica', '', 12);
356+
$pdf->Cell(0, 10, 'Test', 0, 0, '', false, $linkTarget);
357+
358+
$encryptionKey = $this->getEncryptionKey($pdf);
359+
360+
$pdfString = $pdf->Output('S');
361+
362+
// let's extract the object manually and parse it into a object structre
363+
preg_match('~5 0 obj(.*?)endobj~s', $pdfString, $match);
364+
$parser = new PdfParser(StreamReader::createByString($match[1]));
365+
$value = $parser->readValue();
366+
367+
$uri = PdfString::unescape($value->value['A']->value['URI']->value);
368+
369+
$uri = openssl_decrypt(
370+
$uri, 'RC4-40', $this->calcKey($encryptionKey, 5, 3), OPENSSL_RAW_DATA
371+
);
372+
373+
$this->assertEquals($linkTarget, $uri);
374+
}
348375
}

0 commit comments

Comments
 (0)