diff --git a/CHANGELOG.md b/CHANGELOG.md index 8de636e2..88e04657 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,6 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#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 diff --git a/composer.json b/composer.json index ed85472b..50d3d8f6 100644 --- a/composer.json +++ b/composer.json @@ -82,9 +82,8 @@ "tecnickcom/tcpdf": "~6", "webmozart/path-util": "^2.3", "wsdltophp/packagebase": "^5.0", - "zaporylie/composer-drupal-optimizations": "^1.2", - "ext-openssl": "*" - }, + "zaporylie/composer-drupal-optimizations": "^1.2" + }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", "drupal/coder": "^8.3", @@ -147,4 +146,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 fc869112..0d968590 100644 --- a/modules/os2forms_digital_post/src/Form/SettingsForm.php +++ b/modules/os2forms_digital_post/src/Form/SettingsForm.php @@ -258,27 +258,8 @@ 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($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')); + $certificateLocator->getCertificates(); + $this->messenger()->addStatus($this->t('Certificate succesfully tested')); } catch (\Throwable $throwable) { $message = $this->t('Error testing certificate: %message', ['%message' => $throwable->getMessage()]); diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php index efb88219..41b2645a 100644 --- a/src/Form/SettingsForm.php +++ b/src/Form/SettingsForm.php @@ -85,6 +85,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } $this->messenger()->addStatus($this->t('The configuration options have been saved.')); + } }