Skip to content

Commit 3d27508

Browse files
committed
Update to SetaPDF-Signer Component 2.4.0.817
- Integrated SetaPDF_Signer_Signature_DictionaryInterface and SetaPDF_Signer_Signature_DocumentInterface interfaces in module class. - Module adds correct SubFilter and Filter for PAdES conforming signatures now. - Module adds correct extensions entry for PAdES conforming signatures now. - Updated method signature ot Module::createSignature(). - Removed setup of temporary path for temporary writer instance from all examples.
1 parent 888b1e9 commit 3d27508

File tree

9 files changed

+52
-30
lines changed

9 files changed

+52
-30
lines changed

examples/_tmp/dummy.txt

Whitespace-only changes.

examples/demo-batch-on-demand.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@
4949
'passphrase' => $passphrase
5050
);
5151

52-
// let's prepare the temporary file writer
53-
SetaPDF_Core_Writer_TempFile::setTempDir(realpath('_tmp/'));
54-
5552
// create a re-usable array of filenames (in/out)
5653
$files = array(
5754
array(

examples/demo-batch-ts.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// require the autoload class from Composer
1313
require_once('../vendor/autoload.php');
1414

15-
if (file_exists('credentials.php')) {
15+
if (file_exists('credentials-ts.php')) {
1616
// The vars are defined in this file for privacy reason.
17-
require('credentials.php');
17+
require('credentials-ts.php');
1818
} else {
1919
// path to your certificate and private key
2020
$cert = realpath('mycertandkey.crt');
@@ -36,9 +36,6 @@
3636
'passphrase' => $passphrase
3737
);
3838

39-
// let's prepare the temporary file writer
40-
SetaPDF_Core_Writer_TempFile::setTempDir(realpath('_tmp/'));
41-
4239
// create a re-usable array of filenames (in/out)
4340
$files = array(
4441
array(

examples/demo-batch.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
'passphrase' => $passphrase
3737
);
3838

39-
// let's prepare the temporary file writer
40-
SetaPDF_Core_Writer_TempFile::setTempDir(realpath('_tmp/'));
41-
4239
// create a re-usable array of filenames (in/out)
4340
$files = array(
4441
array(

examples/demo-on-demand.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
// let's get the document
5555
$document = SetaPDF_Core_Document::loadByFilename('files/tektown/Laboratory-Report.pdf', $writer);
5656

57-
// let's prepare the temporary file writer
58-
SetaPDF_Core_Writer_TempFile::setTempDir(realpath('_tmp/'));
59-
6057
// now let's create a signer instance
6158
$signer = new SetaPDF_Signer($document);
6259
$signer->setAllowSignatureContentLengthChange(false);

examples/demo-ts-ltv.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// require the autoload class from Composer
1414
require_once('../vendor/autoload.php');
1515

16-
if (file_exists('credentials.php')) {
16+
if (file_exists('credentials-ts.php')) {
1717
// The vars are defined in this file for privacy reason.
18-
require('credentials.php');
18+
require('credentials-ts.php');
1919
} else {
2020
// path to your certificate and private key
2121
$cert = realpath('mycertandkey.crt');
@@ -40,9 +40,6 @@
4040
// the signature field name
4141
$signatureFieldName = 'Signature';
4242

43-
// let's prepare the temporary file writer
44-
SetaPDF_Core_Writer_TempFile::setTempDir(realpath('_tmp/'));
45-
4643
// create a HTTP writer
4744
$writer = new SetaPDF_Core_Writer_Http('Swisscom-Ts-Ltv.pdf');
4845
$tempWriter = new SetaPDF_Core_Writer_TempFile();

examples/demo-ts.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// require the autoload class from Composer
1313
require_once('../vendor/autoload.php');
1414

15-
if (file_exists('credentials.php')) {
15+
if (file_exists('credentials-ts.php')) {
1616
// The vars are defined in this file for privacy reason.
17-
require('credentials.php');
17+
require('credentials-ts.php');
1818
} else {
1919
// path to your certificate and private key
2020
$cert = realpath('mycertandkey.crt');
@@ -41,9 +41,6 @@
4141
// let's get the document
4242
$document = SetaPDF_Core_Document::loadByFilename('files/tektown/Laboratory-Report.pdf', $writer);
4343

44-
// let's prepare the temporary file writer
45-
SetaPDF_Core_Writer_TempFile::setTempDir(realpath('_tmp/'));
46-
4744
// now let's create a signer instance
4845
$signer = new SetaPDF_Signer($document);
4946
$signer->setAllowSignatureContentLengthChange(false);

examples/demo.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
// let's get the document
4242
$document = SetaPDF_Core_Document::loadByFilename('files/camtown/Laboratory-Report.pdf', $writer);
4343

44-
// let's prepare the temporary file writer
45-
SetaPDF_Core_Writer_TempFile::setTempDir(realpath('_tmp/'));
46-
4744
// now let's create a signer instance
4845
$signer = new SetaPDF_Signer($document);
4946
$signer->setAllowSignatureContentLengthChange(false);

src/SetaPDF/Signer/SwisscomAIS/Module.php

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
*/
2020
class SetaPDF_Signer_SwisscomAIS_Module extends SetaPDF_Signer_SwisscomAIS_AbstractModule implements
2121
SetaPDF_Signer_Signature_Module_ModuleInterface,
22-
SetaPDF_Signer_Timestamp_Module_ModuleInterface
22+
SetaPDF_Signer_Timestamp_Module_ModuleInterface,
23+
SetaPDF_Signer_Signature_DictionaryInterface,
24+
SetaPDF_Signer_Signature_DocumentInterface
2325
{
2426
/**
2527
* The last signature/timestamp result.
@@ -28,14 +30,55 @@ class SetaPDF_Signer_SwisscomAIS_Module extends SetaPDF_Signer_SwisscomAIS_Abstr
2830
*/
2931
protected $_signature;
3032

33+
/**
34+
* Updates the signature dictionary.
35+
*
36+
* PAdES requires special Filter and SubFilter entries in the signature dictionary.
37+
*
38+
* @param SetaPDF_Core_Type_Dictionary $dictionary
39+
* @throws SetaPDF_Signer_Exception
40+
*/
41+
public function updateSignatureDictionary(SetaPDF_Core_Type_Dictionary $dictionary)
42+
{
43+
// break if the instance is used as a time stamp module
44+
if ($dictionary->getValue('Type')->getValue() == 'DocTimeStamp') {
45+
return;
46+
}
47+
48+
/* do some checks:
49+
* - entry with the key M in the Signature Dictionary
50+
*/
51+
if (!$dictionary->offsetExists('M')) {
52+
throw new SetaPDF_Signer_Exception(
53+
'The key M (the time of signing) shall be present in the signature dictionary to conform with PAdES.'
54+
);
55+
}
56+
57+
$dictionary['SubFilter'] = new SetaPDF_Core_Type_Name('ETSI.CAdES.detached', true);
58+
$dictionary['Filter'] = new SetaPDF_Core_Type_Name('Adobe.PPKLite', true);
59+
}
60+
61+
/**
62+
* Updates the document instance.
63+
*
64+
* @param SetaPDF_Core_Document $document
65+
* @see ETSI TS 102 778-3 V1.2.1 - 4.7 Extensions Dictionary
66+
* @see ETSI EN 319 142-1 V1.1.0 - 5.6 Extension dictionary
67+
*/
68+
public function updateDocument(SetaPDF_Core_Document $document)
69+
{
70+
$extensions = $document->getCatalog()->getExtensions();
71+
$extensions->setExtension('ESIC', '1.7', 2);
72+
}
73+
3174
/**
3275
* Implementation of the createSignautre() method.
3376
*
34-
* @param SetaPDF_Core_Reader_FilePath|string $tmpPath
77+
* @param SetaPDF_Core_Reader_FilePath $tmpPath
3578
* @return mixed
3679
* @throws SetaPDF_Signer_Exception
3780
*/
38-
public function createSignature($tmpPath)
81+
public function createSignature(SetaPDF_Core_Reader_FilePath $tmpPath)
3982
{
4083
if (!file_exists($tmpPath) || !is_readable($tmpPath)) {
4184
throw new InvalidArgumentException('Signature template file cannot be read.');

0 commit comments

Comments
 (0)