Skip to content

Commit

Permalink
Added Module::setReAuthenticationCallback() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSlabon committed Apr 17, 2024
1 parent e430c12 commit 0b84815
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"php": ">=7.4",
"setasign/setapdf-signer": "^2.40"
"setasign/setapdf-signer": "^2.44"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class Module implements

protected bool $pssPadding = false;

/**
* @var callable
*/
protected $reAuthenticationCallback;

/**
* @param \Pkcs11\Key|null $privateKey
*/
Expand Down Expand Up @@ -126,6 +131,11 @@ public function getPssPadding(): bool
return $this->pssPadding;
}

public function setReAuthenticationCallback(?callable $reAuthenticationCallback): void
{
$this->reAuthenticationCallback = $reAuthenticationCallback;
}

/**
* @param \SetaPDF_Core_Reader_FilePath $tmpPath
* @return string
Expand Down Expand Up @@ -249,7 +259,13 @@ public function createSignature(\SetaPDF_Core_Reader_FilePath $tmpPath): string
throw new Exception('Unsupported key type.');
}

$signatureValue = $this->privateKey->sign($mechanism, $hashData);
$signatureContext = $this->privateKey->initializeSignature($mechanism);
if (\is_callable($this->reAuthenticationCallback)) {
\call_user_func($this->reAuthenticationCallback);
}

$signatureContext->update($hashData);
$signatureValue = $signatureContext->finalize();

if ($this->keyType === \Pkcs11\CKK_EC) {
$len = \strlen($signatureValue);
Expand Down

0 comments on commit 0b84815

Please sign in to comment.