1919 */
2020class 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