Skip to content

Commit

Permalink
Updated SetaPDF-Signer dependency
Browse files Browse the repository at this point in the history
Implemented #1 "Use PadesProxyTrait"
  • Loading branch information
MaximilianKresse committed Mar 16, 2023
1 parent f770e38 commit e430c12
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 120 deletions.
19 changes: 1 addition & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ USB Token) to digital sign PDF documents in pure PHP.

## Requirements

This modules requires the [PKCS11](https://github.com/gamringer/php-pkcs11) PHP
This module requires the [PKCS11](https://github.com/gamringer/php-pkcs11) PHP
extension to be installed.

You also need to provide the path to the PKCS11 module of your device.
Expand Down Expand Up @@ -34,23 +34,6 @@ and execute `composer update`. You need to define the `repository` to evaluate t
[SetaPDF-Signer](https://www.setasign.com/signer) component
(see [here](https://getcomposer.org/doc/faqs/why-can%27t-composer-load-repositories-recursively.md) for more details).

### Trial version

By default, this packages depends on a licensed version of [SetaPDF-Signer](https://www.setasign.com/signer)
component. If you want to use it with a trial version please use following in your composer.json:

{
"require": {
"setasign/setapdf-signer-addon-pkcs11": "dev-trial"
},
"repositories": [
{
"type": "composer",
"url": "https://www.setasign.com/downloads/"
}
]
}

## Usage

All classes in this package are located in the namespace `setasign\SetaPDF\Signer\Module\Pkcs11`.
Expand Down
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.38.3.1671"
"setasign/setapdf-signer": "^2.40"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

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

102 changes: 9 additions & 93 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
use SetaPDF_Signer_Asn1_Element as Asn1Element;
use SetaPDF_Signer_Asn1_Oid as Asn1Oid;
use SetaPDF_Signer_Digest as Digest;
use SetaPDF_Signer_Signature_Module_PadesProxyTrait;

class Module implements
\SetaPDF_Signer_Signature_Module_ModuleInterface,
\SetaPDF_Signer_Signature_DictionaryInterface,
\SetaPDF_Signer_Signature_DocumentInterface
{
protected \SetaPDF_Signer_Signature_Module_Pades $padesModule;
use SetaPDF_Signer_Signature_Module_PadesProxyTrait;

protected \Pkcs11\Key $privateKey;

Expand All @@ -31,8 +32,6 @@ class Module implements
*/
public function __construct(\Pkcs11\Key $privateKey = null)
{
$this->padesModule = new \SetaPDF_Signer_Signature_Module_Pades();

if ($privateKey !== null) {
$this->setPrivateKey($privateKey);
}
Expand Down Expand Up @@ -82,29 +81,6 @@ public function setPrivateKey(\Pkcs11\Key $privateKey): void
$this->privateKey = $privateKey;
}

/**
* Set the signing certificate.
*
* @param string|\SetaPDF_Signer_X509_Certificate $certificate PEM encoded certificate, path to the PEM encoded
* certificate or a certificate instance.
* @throws \InvalidArgumentException
* @throws \SetaPDF_Signer_Asn1_Exception
*/
public function setCertificate($certificate): void
{
$this->padesModule->setCertificate($certificate);
}

/**
* Get the certificate value.
*
* @return string|\SetaPDF_Signer_X509_Certificate
*/
public function getCertificate()
{
return $this->padesModule->getCertificate();
}

/**
* Set the digest algorithm to use when signing.
*
Expand All @@ -113,7 +89,7 @@ public function getCertificate()
*/
public function setDigest(string $digest): void
{
$this->padesModule->setDigest($digest);
$this->_getPadesModule()->setDigest($digest);
}

/**
Expand All @@ -123,68 +99,7 @@ public function setDigest(string $digest): void
*/
public function getDigest(): string
{
return $this->padesModule->getDigest();
}

/**
* Add additional certificates which are placed into the CMS structure.
*
* @param array|\SetaPDF_Signer_X509_Collection $extraCertificates PEM encoded certificates or pathes to PEM encoded
* certificates.
* @throws \SetaPDF_Signer_Asn1_Exception
*/
public function setExtraCertificates($extraCertificates): void
{
$this->padesModule->setExtraCertificates($extraCertificates);
}

/**
* Adds an OCSP response which will be embedded in the CMS structure.
*
* @param string|\SetaPDF_Signer_Ocsp_Response $ocspResponse DER encoded OCSP response or OCSP response instance.
* @throws \SetaPDF_Signer_Exception
*/
public function addOcspResponse($ocspResponse): void
{
$this->padesModule->addOcspResponse($ocspResponse);
}

/**
* Adds an CRL which will be embedded in the CMS structure.
*
* @param string|\SetaPDF_Signer_X509_Crl $crl
*/
public function addCrl($crl): void
{
$this->padesModule->addCrl($crl);
}

/**
* @inheritDoc
* @throws \SetaPDF_Signer_Exception
*/
public function updateSignatureDictionary(\SetaPDF_Core_Type_Dictionary $dictionary): void
{
$this->padesModule->updateSignatureDictionary($dictionary);
}

/**
* @inheritDoc
*/
public function updateDocument(\SetaPDF_Core_Document $document): void
{
$this->padesModule->updateDocument($document);
}

/**
* Get the complete Cryptographic Message Syntax structure.
*
* @return Asn1Element
* @throws \SetaPDF_Signer_Exception
*/
public function getCms(): Asn1Element
{
return $this->padesModule->getCms();
return $this->_getPadesModule()->getDigest();
}

/**
Expand Down Expand Up @@ -218,8 +133,9 @@ public function getPssPadding(): bool
*/
public function createSignature(\SetaPDF_Core_Reader_FilePath $tmpPath): string
{
$hashData = $this->padesModule->getDataToSign($tmpPath);
$digest = $this->padesModule->getDigest();
$module = $this->_getPadesModule();
$hashData = $module->getDataToSign($tmpPath);
$digest = $module->getDigest();

if ($this->keyType === \Pkcs11\CKK_RSA) {
if ($this->getPssPadding()) {
Expand All @@ -244,7 +160,7 @@ public function createSignature(\SetaPDF_Core_Reader_FilePath $tmpPath): string
}

/** @var Asn1Element $cms */
$cms = $this->padesModule->getCms();
$cms = $module->getCms();

$signatureAlgorithmIdentifier = Asn1Element::findByPath('1/0/4/0/4', $cms);
$signatureAlgorithmIdentifier->getChild(0)->setValue(
Expand Down Expand Up @@ -357,7 +273,7 @@ public function createSignature(\SetaPDF_Core_Reader_FilePath $tmpPath): string
);
}

$this->padesModule->setSignatureValue($signatureValue);
$module->setSignatureValue($signatureValue);

return (string) $this->getCms();
}
Expand Down

0 comments on commit e430c12

Please sign in to comment.