-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix certificate testing, and allowing RSA certs as well as pkcs12 #72
Changes from all commits
e235368
37a7cb2
9bc4e80
1dab170
60f842f
2cd53b4
d86a28c
03106e6
b6dc947
963382c
da8190a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the returned array is empty, you will get a warning here - because value is not set. Might be wise to handle that gracefully |
||
|
||
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. returned result
|
||
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()]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will you fix the formatting?