Skip to content

Commit

Permalink
Merge pull request #75 from OS2Forms/inuitviking/removing_my_own_darn…
Browse files Browse the repository at this point in the history
…_mess

Undo all of my previous changes
  • Loading branch information
inuitviking authored Nov 10, 2023
2 parents da8190a + 0b4f9ad commit cfb3c1c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -147,4 +146,4 @@
"zaporylie/composer-drupal-optimizations": true
}
}
}
}
23 changes: 2 additions & 21 deletions modules/os2forms_digital_post/src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand Down
1 change: 1 addition & 0 deletions src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}

$this->messenger()->addStatus($this->t('The configuration options have been saved.'));

}

}

0 comments on commit cfb3c1c

Please sign in to comment.