@@ -33,10 +33,21 @@ class Module implements ModuleInterface, DictionaryInterface, DocumentInterface
3333 protected $ certificateId ;
3434
3535 /**
36+ * A Time based One Time Pin (TOTP) generated by a compatible app such as Google Authenticator, Microsoft
37+ * Authenticator etc.
38+ *
3639 * @var null|string
3740 */
3841 protected $ otp ;
3942
43+ /**
44+ * The Signing Activation Data (SAD) token obtained in an earlier authorise request.
45+ *
46+ * @see Client::authorize()
47+ * @var null|string
48+ */
49+ protected $ sad ;
50+
4051 /**
4152 * @var string
4253 */
@@ -75,11 +86,30 @@ public function setSigningAlgorithm(string $algorithm)
7586 $ this ->_getPadesModule ()->setDigest ($ hashingAlgorithm );
7687 }
7788
89+ /**
90+ * Set a Time based One Time Pin (TOTP) generated by a compatible app such as Google Authenticator, Microsoft
91+ * Authenticator etc.
92+ *
93+ * @param string $otp
94+ * @return void
95+ */
7896 public function setOtp (string $ otp ): void
7997 {
8098 $ this ->otp = $ otp ;
8199 }
82100
101+ /**
102+ * Set a Signing Activation Data (SAD) token obtained in an earlier authorise request.
103+ *
104+ * @see Client::authorize()
105+ * @param string $sad
106+ * @return void
107+ */
108+ public function setSad (string $ sad ): void
109+ {
110+ $ this ->sad = $ sad ;
111+ }
112+
83113 public function getCertificate ()
84114 {
85115 $ padesModule = $ this ->_getPadesModule ();
@@ -92,10 +122,6 @@ public function getCertificate()
92122
93123 public function createSignature (SetaPDF_Core_Reader_FilePath $ tmpPath )
94124 {
95- if ($ this ->otp === null ) {
96- throw new \BadMethodCallException ('Missing otp! ' );
97- }
98-
99125 // ensure certificate
100126 $ certificate = $ this ->getCertificate ();
101127 if ($ certificate === null ) {
@@ -107,12 +133,30 @@ public function createSignature(SetaPDF_Core_Reader_FilePath $tmpPath)
107133 $ padesDigest = $ padesModule ->getDigest ();
108134
109135 $ hashData = hash ($ padesDigest , $ padesModule ->getDataToSign ($ tmpPath ), true );
110- $ signatureValue = $ this ->client ->signWithOtp (
111- $ this ->certificateId ,
112- $ this ->signingAlgorithm ,
113- $ hashData ,
114- $ this ->otp
115- );
136+
137+ if ($ this ->sad !== null && $ this ->otp !== null ) {
138+ throw new \BadMethodCallException ('SAD and OTP given! You must only use one. ' );
139+ }
140+
141+ if ($ this ->sad !== null ) {
142+ // Sign using SAD
143+ $ signatureValue = $ this ->client ->signWithSad (
144+ $ this ->certificateId ,
145+ $ this ->signingAlgorithm ,
146+ $ hashData ,
147+ $ this ->sad
148+ );
149+ } elseif ($ this ->otp !== null ) {
150+ // Sign using OTP
151+ $ signatureValue = $ this ->client ->signWithOtp (
152+ $ this ->certificateId ,
153+ $ this ->signingAlgorithm ,
154+ $ hashData ,
155+ $ this ->otp
156+ );
157+ } else {
158+ throw new \BadMethodCallException ('Missing SAD/OTP! Please use setOtp() OR setSad() before. ' );
159+ }
116160
117161 if (\in_array ($ this ->signingAlgorithm , ['ES256 ' , 'ES384 ' , 'ES512 ' ], true )) {
118162 // THIS NEEDS TO BE USED TO FIX EC SIGNATURES
0 commit comments