diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf72d67..8de636e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ 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 + ## [3.13.2] 2023-10-19 - Fixing CPR fetch pattern 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 0d968590..fc869112 100644 --- a/modules/os2forms_digital_post/src/Form/SettingsForm.php +++ b/modules/os2forms_digital_post/src/Form/SettingsForm.php @@ -258,8 +258,27 @@ public function submitForm(array &$form, FormStateInterface $formState): void { private function testCertificate(): void { try { $certificateLocator = $this->certificateLocatorHelper->getCertificateLocator(); - $certificateLocator->getCertificates(); - $this->messenger()->addStatus($this->t('Certificate succesfully tested')); + $certificatePath = $this->settings->getCertificate()[CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM]['path']; + + // Check if the certificate has the pkcs12 extension or not. + if (pathinfo($certificatePath, 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()]); 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; + } + } } } }