diff --git a/.gitignore b/.gitignore index 2992304..b478b4f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ composer.phar /vendor/ +/.idea/ auth.json # Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index ef7f707..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -/deployment.xml -/webServers.xml -# Datasource local storage ignored files -/../../../../:\Sandbox\SetaPDF-Signer-Addon-CSC\.idea/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/SetaPDF-Signer-Addon-CSC.iml b/.idea/SetaPDF-Signer-Addon-CSC.iml deleted file mode 100644 index 5120627..0000000 --- a/.idea/SetaPDF-Signer-Addon-CSC.iml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/dictionaries b/.idea/dictionaries deleted file mode 100644 index b88e931..0000000 --- a/.idea/dictionaries +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 5a42bf2..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 1f7d1ab..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 622b97b..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index f40f94c..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index 6c685e7..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/composer.json b/composer.json index 34fa6f6..5962c1d 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "ext-json": "*", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", - "setasign/setapdf-signer": "^2.36" + "setasign/setapdf-signer": "^2.40" }, "require-dev": { "guzzlehttp/guzzle": "^6.5", diff --git a/composer.lock b/composer.lock index 6b3ba88..aa8773a 100644 --- a/composer.lock +++ b/composer.lock @@ -168,10 +168,10 @@ }, { "name": "setasign/setapdf-core", - "version": "2.36.0.1597", + "version": "2.41.0.1834", "dist": { "type": "zip", - "url": "https://www.setasign.com/downloads/2854243/SetaPDF-Core_2.36.0.1597-without-demos.zip" + "url": "https://www.setasign.com/downloads/4304267/SetaPDF-Core_2.41.0.1834-without-demos.zip" }, "type": "library", "autoload": { @@ -185,17 +185,17 @@ "support": { "email": "support@setasign.com" }, - "time": "2020-12-22T00:00:00+00:00" + "time": "2023-02-21T00:00:00+00:00" }, { "name": "setasign/setapdf-signer", - "version": "2.36.0.1597", + "version": "2.41.0.1834", "dist": { "type": "zip", - "url": "https://www.setasign.com/downloads/2854244/SetaPDF-Signer_2.36.0.1597-without-core.zip" + "url": "https://www.setasign.com/downloads/4304289/SetaPDF-Signer_2.41.0.1834-without-core.zip" }, "require": { - "setasign/setapdf-core": "2.36.0.1597" + "setasign/setapdf-core": "2.41.0.1834" }, "type": "library", "autoload": { @@ -209,7 +209,7 @@ "support": { "email": "support@setasign.com" }, - "time": "2020-12-22T00:00:00+00:00" + "time": "2023-02-21T00:00:00+00:00" } ], "packages-dev": [ @@ -330,16 +330,16 @@ }, { "name": "guzzlehttp/promises", - "version": "1.5.1", + "version": "1.5.2", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da" + "reference": "b94b2807d85443f9719887892882d0329d1e2598" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da", - "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da", + "url": "https://api.github.com/repos/guzzle/promises/zipball/b94b2807d85443f9719887892882d0329d1e2598", + "reference": "b94b2807d85443f9719887892882d0329d1e2598", "shasum": "" }, "require": { @@ -394,7 +394,7 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/1.5.1" + "source": "https://github.com/guzzle/promises/tree/1.5.2" }, "funding": [ { @@ -410,7 +410,7 @@ "type": "tidelift" } ], - "time": "2021-10-22T20:56:57+00:00" + "time": "2022-08-28T14:55:35+00:00" }, { "name": "guzzlehttp/psr7", @@ -524,28 +524,28 @@ }, { "name": "http-interop/http-factory-guzzle", - "version": "1.0.0", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/http-interop/http-factory-guzzle.git", - "reference": "34861658efb9899a6618cef03de46e2a52c80fc0" + "reference": "6e1efa1e020bf1c47cf0f13654e8ef9efb1463b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/http-interop/http-factory-guzzle/zipball/34861658efb9899a6618cef03de46e2a52c80fc0", - "reference": "34861658efb9899a6618cef03de46e2a52c80fc0", + "url": "https://api.github.com/repos/http-interop/http-factory-guzzle/zipball/6e1efa1e020bf1c47cf0f13654e8ef9efb1463b3", + "reference": "6e1efa1e020bf1c47cf0f13654e8ef9efb1463b3", "shasum": "" }, "require": { - "guzzlehttp/psr7": "^1.4.2", + "guzzlehttp/psr7": "^1.4.2||^2.0", "psr/http-factory": "^1.0" }, "provide": { "psr/http-factory-implementation": "^1.0" }, "require-dev": { - "http-interop/http-factory-tests": "^0.5", - "phpunit/phpunit": "^6.5" + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5" }, "type": "library", "autoload": { @@ -572,22 +572,22 @@ ], "support": { "issues": "https://github.com/http-interop/http-factory-guzzle/issues", - "source": "https://github.com/http-interop/http-factory-guzzle/tree/master" + "source": "https://github.com/http-interop/http-factory-guzzle/tree/1.1.1" }, - "time": "2018-07-31T19:32:56+00:00" + "time": "2021-07-23T15:14:50+00:00" }, { "name": "league/oauth2-client", - "version": "2.6.0", + "version": "2.6.1", "source": { "type": "git", "url": "https://github.com/thephpleague/oauth2-client.git", - "reference": "badb01e62383430706433191b82506b6df24ad98" + "reference": "2334c249907190c132364f5dae0287ab8666aa19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/badb01e62383430706433191b82506b6df24ad98", - "reference": "badb01e62383430706433191b82506b6df24ad98", + "url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/2334c249907190c132364f5dae0287ab8666aa19", + "reference": "2334c249907190c132364f5dae0287ab8666aa19", "shasum": "" }, "require": { @@ -596,9 +596,9 @@ "php": "^5.6 || ^7.0 || ^8.0" }, "require-dev": { - "mockery/mockery": "^1.3", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpunit/phpunit": "^5.7 || ^6.0 || ^9.3", + "mockery/mockery": "^1.3.5", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpunit/phpunit": "^5.7 || ^6.0 || ^9.5", "squizlabs/php_codesniffer": "^2.3 || ^3.0" }, "type": "library", @@ -642,9 +642,9 @@ ], "support": { "issues": "https://github.com/thephpleague/oauth2-client/issues", - "source": "https://github.com/thephpleague/oauth2-client/tree/2.6.0" + "source": "https://github.com/thephpleague/oauth2-client/tree/2.6.1" }, - "time": "2020-10-28T02:03:40+00:00" + "time": "2021-12-22T16:42:49+00:00" }, { "name": "mjelamanov/psr18-guzzle", @@ -752,16 +752,16 @@ }, { "name": "phpseclib/phpseclib", - "version": "2.0.31", + "version": "2.0.42", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "233a920cb38636a43b18d428f9a8db1f0a1a08f4" + "reference": "665d289f59e646a259ebf13f29be7f6f54cab24b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/233a920cb38636a43b18d428f9a8db1f0a1a08f4", - "reference": "233a920cb38636a43b18d428f9a8db1f0a1a08f4", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/665d289f59e646a259ebf13f29be7f6f54cab24b", + "reference": "665d289f59e646a259ebf13f29be7f6f54cab24b", "shasum": "" }, "require": { @@ -776,7 +776,8 @@ "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.", "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.", "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.", - "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations." + "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations.", + "ext-xml": "Install the XML extension to load XML formatted public keys." }, "type": "library", "autoload": { @@ -841,7 +842,7 @@ ], "support": { "issues": "https://github.com/phpseclib/phpseclib/issues", - "source": "https://github.com/phpseclib/phpseclib/tree/2.0.31" + "source": "https://github.com/phpseclib/phpseclib/tree/2.0.42" }, "funding": [ { @@ -857,7 +858,7 @@ "type": "tidelift" } ], - "time": "2021-04-06T13:56:45+00:00" + "time": "2023-03-06T12:45:53+00:00" }, { "name": "ralouphie/getallheaders", @@ -905,16 +906,16 @@ }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.26.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "59a8d271f00dd0e4c2e518104cc7963f655a1aa8" + "reference": "639084e360537a19f9ee352433b84ce831f3d2da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/59a8d271f00dd0e4c2e518104cc7963f655a1aa8", - "reference": "59a8d271f00dd0e4c2e518104cc7963f655a1aa8", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/639084e360537a19f9ee352433b84ce831f3d2da", + "reference": "639084e360537a19f9ee352433b84ce831f3d2da", "shasum": "" }, "require": { @@ -928,7 +929,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -972,7 +973,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.27.0" }, "funding": [ { @@ -988,20 +989,20 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.26.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "219aa369ceff116e673852dce47c3a41794c14bd" + "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/219aa369ceff116e673852dce47c3a41794c14bd", - "reference": "219aa369ceff116e673852dce47c3a41794c14bd", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/19bd1e4fcd5b91116f14d8533c57831ed00571b6", + "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6", "shasum": "" }, "require": { @@ -1013,7 +1014,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -1056,7 +1057,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.27.0" }, "funding": [ { @@ -1072,20 +1073,20 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "symfony/polyfill-php72", - "version": "v1.26.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "bf44a9fd41feaac72b074de600314a93e2ae78e2" + "reference": "869329b1e9894268a8a61dabb69153029b7a8c97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/bf44a9fd41feaac72b074de600314a93e2ae78e2", - "reference": "bf44a9fd41feaac72b074de600314a93e2ae78e2", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/869329b1e9894268a8a61dabb69153029b7a8c97", + "reference": "869329b1e9894268a8a61dabb69153029b7a8c97", "shasum": "" }, "require": { @@ -1094,7 +1095,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -1132,7 +1133,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php72/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-php72/tree/v1.27.0" }, "funding": [ { @@ -1148,7 +1149,7 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-11-03T14:55:06+00:00" } ], "aliases": [], @@ -1161,5 +1162,5 @@ "ext-json": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/Module.php b/src/Module.php index e4fdcad..97be30e 100644 --- a/src/Module.php +++ b/src/Module.php @@ -11,16 +11,13 @@ use InvalidArgumentException; use SetaPDF_Core_Reader_FilePath; -use SetaPDF_Core_Type_Dictionary; -use SetaPDF_Core_Document as Document; use SetaPDF_Signer_Asn1_Element as Asn1Element; use SetaPDF_Signer_Digest as Digest; -use SetaPDF_Signer_Asn1_Oid as Asn1Oid; -use SetaPDF_Signer_Exception; use SetaPDF_Signer_Signature_DictionaryInterface; use SetaPDF_Signer_Signature_DocumentInterface; use SetaPDF_Signer_Signature_Module_ModuleInterface; use SetaPDF_Signer_Signature_Module_Pades; +use SetaPDF_Signer_Signature_Module_PadesProxyTrait; /** * Class Module @@ -32,6 +29,8 @@ class Module implements SetaPDF_Signer_Signature_DictionaryInterface, SetaPDF_Signer_Signature_DocumentInterface { + use SetaPDF_Signer_Signature_Module_PadesProxyTrait; + public static function findHashAndSignAlgorithm(string $signatureAlgorithmOid): array { $found = false; @@ -190,11 +189,6 @@ public static function fixEccSignatures(string $signatureValue): string */ protected $client; - /** - * @var SetaPDF_Signer_Signature_Module_Pades Internal pades module. - */ - protected $padesModule; - /** * @var string|null */ @@ -237,7 +231,6 @@ public function __construct( ) { $this->accessToken = $accessToken; $this->client = $client; - $this->padesModule = new SetaPDF_Signer_Signature_Module_Pades(); } public function setCredentialId(string $credentialId): void @@ -255,30 +248,13 @@ public function setPin(string $pin): void $this->pin = $pin; } - /** - * @param $certificate - * @throws \SetaPDF_Signer_Asn1_Exception - */ - public function setCertificate($certificate) - { - $this->padesModule->setCertificate($certificate); - } - - /** - * @return \SetaPDF_Signer_X509_Certificate|string - */ - public function getCertificate() - { - return $this->padesModule->getCertificate(); - } - /** * @param string $signatureAlgorithmOid */ public function setSignatureAlgorithmOid(string $signatureAlgorithmOid) { ['hashAlgorithm' => $hashAlgorithm, 'signAlgorithm' => $signAlgorithm] = self::findHashAndSignAlgorithm($signatureAlgorithmOid); - $this->padesModule->setDigest($hashAlgorithm); + $this->_getPadesModule()->setDigest($hashAlgorithm); $this->signAlgorithm = $signAlgorithm; $this->signatureAlgorithmOid = $signatureAlgorithmOid; } @@ -291,66 +267,6 @@ public function getSignatureAlgorithmOid(): ?string return $this->signatureAlgorithmOid; } - /** - * 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) - { - $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) - { - $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) - { - $this->padesModule->addCrl($crl); - } - - /** - * @inheritDoc - */ - public function updateSignatureDictionary(SetaPDF_Core_Type_Dictionary $dictionary) - { - $this->padesModule->updateSignatureDictionary($dictionary); - } - - /** - * @inheritDoc - */ - public function updateDocument(Document $document) - { - $this->padesModule->updateDocument($document); - } - - /** - * Get the complete Cryptographic Message Syntax structure. - * - * @return Asn1Element - * @throws SetaPDF_Signer_Exception - */ - public function getCms() - { - return $this->padesModule->getCms(); - } - /** * @inheritDoc */ @@ -366,15 +282,16 @@ public function createSignature(SetaPDF_Core_Reader_FilePath $tmpPath) throw new \BadMethodCallException('Missing signature algorithm!'); } + $module = $this->_getPadesModule(); // get the hash data from the module - $padesDigest = $this->padesModule->getDigest(); + $padesDigest = $module->getDigest(); $signatureAlgorithmParameters = null; if ($this->signAlgorithm === Digest::RSA_PSS_ALGORITHM) { - $signatureAlgorithmParameters = self::updateCmsForPssPadding($this->padesModule); + $signatureAlgorithmParameters = self::updateCmsForPssPadding($module); } - $hashData = \base64_encode(hash($padesDigest, $this->padesModule->getDataToSign($tmpPath), true)); + $hashData = \base64_encode(hash($padesDigest, $module->getDataToSign($tmpPath), true)); $SAD = $this->client->credentialsAuthorize( $this->accessToken, @@ -400,8 +317,8 @@ public function createSignature(SetaPDF_Core_Reader_FilePath $tmpPath) } // pass it to the module - $this->padesModule->setSignatureValue($signatureValue); + $module->setSignatureValue($signatureValue); - return (string) $this->padesModule->getCms(); + return (string) $module->getCms(); } }