From e23536848b13a63da300812fde3293d26c8fbb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angutivik=20Casper=20R=C3=BAnur=20Tausen?= Date: Wed, 25 Oct 2023 16:49:34 +0200 Subject: [PATCH 01/10] Fix certificate testing, and allowing RSA certs as well as pkcs12 --- modules/os2forms_digital_post/src/Form/SettingsForm.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/os2forms_digital_post/src/Form/SettingsForm.php b/modules/os2forms_digital_post/src/Form/SettingsForm.php index 0d968590..d3bfb54f 100644 --- a/modules/os2forms_digital_post/src/Form/SettingsForm.php +++ b/modules/os2forms_digital_post/src/Form/SettingsForm.php @@ -258,7 +258,8 @@ public function submitForm(array &$form, FormStateInterface $formState): void { private function testCertificate(): void { try { $certificateLocator = $this->certificateLocatorHelper->getCertificateLocator(); - $certificateLocator->getCertificates(); + $certificate = $this->settings->getCertificate(); + ($certificate[CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM]['path'] != NULL) ? $certificateLocator->getCertificate() : $certificateLocator->getCertificates(); $this->messenger()->addStatus($this->t('Certificate succesfully tested')); } catch (\Throwable $throwable) { From 37a7cb2bf497222e0cb2d2b33f8ff548ddc072e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angutivik=20Casper=20R=C3=BAnur=20Tausen?= Date: Fri, 27 Oct 2023 13:41:22 +0200 Subject: [PATCH 02/10] Certificate testing now properly checks PEM as well as pkcs12 certificates --- composer.json | 7 +++--- .../src/Form/SettingsForm.php | 25 ++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 50d3d8f6..ed85472b 100644 --- a/composer.json +++ b/composer.json @@ -82,8 +82,9 @@ "tecnickcom/tcpdf": "~6", "webmozart/path-util": "^2.3", "wsdltophp/packagebase": "^5.0", - "zaporylie/composer-drupal-optimizations": "^1.2" - }, + "zaporylie/composer-drupal-optimizations": "^1.2", + "ext-openssl": "*" + }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", "drupal/coder": "^8.3", @@ -146,4 +147,4 @@ "zaporylie/composer-drupal-optimizations": true } } -} +} \ No newline at end of file diff --git a/modules/os2forms_digital_post/src/Form/SettingsForm.php b/modules/os2forms_digital_post/src/Form/SettingsForm.php index d3bfb54f..1d666edd 100644 --- a/modules/os2forms_digital_post/src/Form/SettingsForm.php +++ b/modules/os2forms_digital_post/src/Form/SettingsForm.php @@ -258,9 +258,26 @@ public function submitForm(array &$form, FormStateInterface $formState): void { private function testCertificate(): void { try { $certificateLocator = $this->certificateLocatorHelper->getCertificateLocator(); - $certificate = $this->settings->getCertificate(); - ($certificate[CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM]['path'] != NULL) ? $certificateLocator->getCertificate() : $certificateLocator->getCertificates(); - $this->messenger()->addStatus($this->t('Certificate succesfully tested')); + + // Check if the certificate has the pkcs12 extension or not. + if (pathinfo($certificateLocator->getAbsolutePathToCertificate(), PATHINFO_EXTENSION) == 'pkcs12') { + // Check the certificate if it is a valid pkcs12 certificate. + $certificateLocator->getCertificates(); + } + else { + // Get contents of certificate. + $certificateKeyFile = $certificateLocator->getCertificate(); + // Create an array for checking the key with the certificate. + $keyCheckData = [$certificateKeyFile, $certificateLocator->getPassphrase()]; + // Check the private key against the certificate. + $result = openssl_x509_check_private_key($certificateKeyFile, $keyCheckData); + // If the result is not "1", throw an exception. + if ($result != 1) { + throw new \ErrorException('PEM certificate is not valid.'); + } + } + + $this->messenger()->addStatus($this->t('Certificate successfully tested')); } catch (\Throwable $throwable) { $message = $this->t('Error testing certificate: %message', ['%message' => $throwable->getMessage()]); @@ -268,4 +285,4 @@ private function testCertificate(): void { } } -} +} \ No newline at end of file From 9bc4e80d530b8c4f1cdd379e72307b586ecf0aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angutivik=20Casper=20R=C3=BAnur=20Tausen?= Date: Fri, 27 Oct 2023 13:44:15 +0200 Subject: [PATCH 03/10] Updated changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf72d67..95b26b8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ See ["how do I make a good changelog record?"](https://keepachangelog.com/en/1.0 before starting to add changes. Use example [placed in the end of the page](#example-of-change-log-record) ## [Unreleased] +- [#72](https://github.com/OS2Forms/os2forms/pull/72) + Fix certificate testing, also testing for RSA/PEM certs as well as PKCS12. ## [3.13.2] 2023-10-19 @@ -182,4 +184,4 @@ before starting to add changes. Use example [placed in the end of the page](#exa [Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.5.0...HEAD [3.5.0]: https://github.com/OS2Forms/os2forms/compare/3.2.5...3.5.0 [3.2.6]: https://github.com/OS2Forms/os2forms/compare/3.2.5...3.2.6 -[3.2.5]: https://github.com/OS2Forms/os2forms/compare/3.2.4...3.2.5 +[3.2.5]: https://github.com/OS2Forms/os2forms/compare/3.2.4...3.2.5 \ No newline at end of file From 1dab1702eb20d68350ee5b5f7e2db62f12cb2007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angutivik=20Casper=20R=C3=BAnur=20Tausen?= Date: Fri, 27 Oct 2023 13:46:35 +0200 Subject: [PATCH 04/10] Add empty line at end of changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95b26b8d..cbe5927e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -184,4 +184,5 @@ before starting to add changes. Use example [placed in the end of the page](#exa [Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.5.0...HEAD [3.5.0]: https://github.com/OS2Forms/os2forms/compare/3.2.5...3.5.0 [3.2.6]: https://github.com/OS2Forms/os2forms/compare/3.2.5...3.2.6 -[3.2.5]: https://github.com/OS2Forms/os2forms/compare/3.2.4...3.2.5 \ No newline at end of file +[3.2.5]: https://github.com/OS2Forms/os2forms/compare/3.2.4...3.2.5 + From 60f842f33a0844864149c91338593367a7f55ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angutivik=20Casper=20R=C3=BAnur=20Tausen?= Date: Fri, 27 Oct 2023 13:47:19 +0200 Subject: [PATCH 05/10] Added empty line at end of SettingsForm.php --- modules/os2forms_digital_post/src/Form/SettingsForm.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/os2forms_digital_post/src/Form/SettingsForm.php b/modules/os2forms_digital_post/src/Form/SettingsForm.php index 1d666edd..88d342ee 100644 --- a/modules/os2forms_digital_post/src/Form/SettingsForm.php +++ b/modules/os2forms_digital_post/src/Form/SettingsForm.php @@ -285,4 +285,5 @@ private function testCertificate(): void { } } -} \ No newline at end of file +} + From 2cd53b4757f0d8c0fd69949f3b4939df03441fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angutivik=20Casper=20R=C3=BAnur=20Tausen?= Date: Fri, 27 Oct 2023 14:04:40 +0200 Subject: [PATCH 06/10] Fix markdown formatting in changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbe5927e..f403c00b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ See ["how do I make a good changelog record?"](https://keepachangelog.com/en/1.0 before starting to add changes. Use example [placed in the end of the page](#example-of-change-log-record) ## [Unreleased] + - [#72](https://github.com/OS2Forms/os2forms/pull/72) Fix certificate testing, also testing for RSA/PEM certs as well as PKCS12. From d86a28cb67f5df58cfce8ca53aaded749018964c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angutivik=20Casper=20R=C3=BAnur=20Tausen?= Date: Fri, 27 Oct 2023 14:06:20 +0200 Subject: [PATCH 07/10] Fix deprecation error in SettingsForm.php --- modules/os2forms_digital_post/src/Form/SettingsForm.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/os2forms_digital_post/src/Form/SettingsForm.php b/modules/os2forms_digital_post/src/Form/SettingsForm.php index 88d342ee..e66892b3 100644 --- a/modules/os2forms_digital_post/src/Form/SettingsForm.php +++ b/modules/os2forms_digital_post/src/Form/SettingsForm.php @@ -258,9 +258,10 @@ public function submitForm(array &$form, FormStateInterface $formState): void { private function testCertificate(): void { try { $certificateLocator = $this->certificateLocatorHelper->getCertificateLocator(); + $certificatePath = $this->settings->getCertificate()[CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM]['path']; // Check if the certificate has the pkcs12 extension or not. - if (pathinfo($certificateLocator->getAbsolutePathToCertificate(), PATHINFO_EXTENSION) == 'pkcs12') { + if (pathinfo($certificatePath, PATHINFO_EXTENSION) == 'pkcs12') { // Check the certificate if it is a valid pkcs12 certificate. $certificateLocator->getCertificates(); } From 03106e6e7e8854b7b470173722b627675ad227b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angutivik=20Casper=20R=C3=BAnur=20Tausen?= Date: Fri, 27 Oct 2023 14:14:15 +0200 Subject: [PATCH 08/10] Fix markdownlint error --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f403c00b..c03d94f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] - [#72](https://github.com/OS2Forms/os2forms/pull/72) - Fix certificate testing, also testing for RSA/PEM certs as well as PKCS12. + Fix certificate testing, also testing for RSA/PEM certs as well as PKCS12 ## [3.13.2] 2023-10-19 @@ -186,4 +186,3 @@ before starting to add changes. Use example [placed in the end of the page](#exa [3.5.0]: https://github.com/OS2Forms/os2forms/compare/3.2.5...3.5.0 [3.2.6]: https://github.com/OS2Forms/os2forms/compare/3.2.5...3.2.6 [3.2.5]: https://github.com/OS2Forms/os2forms/compare/3.2.4...3.2.5 - From b6dc9476feb7b0349c67b23c93016ecd61a50195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angutivik=20Casper=20R=C3=BAnur=20Tausen?= Date: Fri, 27 Oct 2023 14:14:27 +0200 Subject: [PATCH 09/10] Fix too many empty lines --- modules/os2forms_digital_post/src/Form/SettingsForm.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/os2forms_digital_post/src/Form/SettingsForm.php b/modules/os2forms_digital_post/src/Form/SettingsForm.php index e66892b3..fc869112 100644 --- a/modules/os2forms_digital_post/src/Form/SettingsForm.php +++ b/modules/os2forms_digital_post/src/Form/SettingsForm.php @@ -287,4 +287,3 @@ private function testCertificate(): void { } } - From 963382c5688c8995f7697f97e3a9bcff7687beb2 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Fri, 27 Oct 2023 17:15:53 +0200 Subject: [PATCH 10/10] Handled nested elements in webform inherit --- CHANGELOG.md | 2 ++ .../EngineTasks/MaestroWebformInheritTask.php | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c03d94f7..8de636e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- [#73](https://github.com/OS2Forms/os2forms/pull/73a) + Fix issue with nested elements in webform inherit - [#72](https://github.com/OS2Forms/os2forms/pull/72) Fix certificate testing, also testing for RSA/PEM certs as well as PKCS12 diff --git a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index b04137ce..8bd0040e 100644 --- a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -2,9 +2,11 @@ namespace Drupal\os2forms_forloeb\Plugin\EngineTasks; +use Drupal\Component\Utility\NestedArray; use Drupal\Core\Form\FormStateInterface; use Drupal\maestro\Engine\MaestroEngine; use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask; +use Drupal\webform\Entity\Webform; use Drupal\webform\Entity\WebformSubmission; use Drupal\webform\Utility\WebformArrayHelper; @@ -152,9 +154,18 @@ public static function webformSubmissionFormAlter(array &$form, FormStateInterfa if ('webform_submission' === ($entityIdentifier['entity_type'] ?? NULL)) { $submission = WebformSubmission::load($entityIdentifier['entity_id']); $data = $submission->getData(); - foreach ($data as $key => $value) { - if (isset($form['elements'][$key])) { - $form['elements'][$key]['#default_value'] = $value; + + // The target element may be hidden inside sections or field groups + // on the target form. Therefore, we need to load that form and get + // element information to properly set default element values nested + // inside the form. + if ($targetWebform = Webform::load($form['#webform_id'] ?? NULL)) { + foreach ($data as $key => $value) { + if ($targetElement = $targetWebform->getElement($key)) { + if ($element = &NestedArray::getValue($form['elements'], $targetElement['#webform_parents'])) { + $element['#default_value'] = $value; + } + } } } }