From dabc589afd292d6901618f0db1f05df6bfd97a8a Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Thu, 23 Jan 2025 13:13:43 +0100 Subject: [PATCH 1/3] Convert certificates if necessary --- src/KeyHelper.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/KeyHelper.php b/src/KeyHelper.php index c25658b..6b124a1 100644 --- a/src/KeyHelper.php +++ b/src/KeyHelper.php @@ -38,8 +38,15 @@ public function getCertificates(KeyInterface $key): array { throw $this->createSslRuntimeException(sprintf('Invalid key type: %s', $type::class), $key); } - return $this->parseCertificates($key->getKeyValue(), $type->getInputFormat(), $type->getPassphrase(), $key); + // Check whether conversion is needed. + if ($type->getInputFormat() === $type->getOutputFormat()) { + return $this->parseCertificates($key->getKeyValue(), $type->getInputFormat(), $type->getPassphrase(), $key); + } + + $preConvertedCertificates = $this->parseCertificates($key->getKeyValue(), $type->getInputFormat(), $type->getPassphrase(), $key); + $convertedAndCombinedCertificate = $this->convertCertificates($preConvertedCertificates, $type->getOutputFormat(), $key); + return $this->parseCertificates($convertedAndCombinedCertificate, $type->getOutputFormat(), $type->getPassphrase(), $key); } /** From 2ff78964e80f785a91b940de7bca32ad431692ed Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Thu, 23 Jan 2025 13:16:39 +0100 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5271aeb..160c361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +* [PR-5](https://github.com/OS2web/os2web_key/pull/5) + Convert certificates when necessary. * [PR-4](https://github.com/OS2web/os2web_key/pull/4) - Added HashiCorp Vault key provider + Added HashiCorp Vault key provider. * [PR-2](https://github.com/OS2web/os2web_key/pull/2) - Updated documentation + Updated documentation. * [PR-1](https://github.com/OS2web/os2web_key/pull/1) - Added OS2Web key module + Added OS2Web key module. [Unreleased]: https://github.com/rimi-itk/os2web_key From 620489d292ee7d3af07c2fbf319004e9430c1960 Mon Sep 17 00:00:00 2001 From: Jeppe Kuhlmann Andersen <78410897+jekuaitk@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:17:56 +0100 Subject: [PATCH 3/3] Update src/KeyHelper.php Co-authored-by: Mikkel Ricky --- src/KeyHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/KeyHelper.php b/src/KeyHelper.php index 6b124a1..54b63db 100644 --- a/src/KeyHelper.php +++ b/src/KeyHelper.php @@ -43,10 +43,10 @@ public function getCertificates(KeyInterface $key): array { return $this->parseCertificates($key->getKeyValue(), $type->getInputFormat(), $type->getPassphrase(), $key); } - $preConvertedCertificates = $this->parseCertificates($key->getKeyValue(), $type->getInputFormat(), $type->getPassphrase(), $key); - $convertedAndCombinedCertificate = $this->convertCertificates($preConvertedCertificates, $type->getOutputFormat(), $key); + $parsedCertificates = $this->parseCertificates($key->getKeyValue(), $type->getInputFormat(), $type->getPassphrase(), $key); + $convertedCertificates = $this->convertCertificates($parsedCertificates, $type->getOutputFormat(), $key); - return $this->parseCertificates($convertedAndCombinedCertificate, $type->getOutputFormat(), $type->getPassphrase(), $key); + return $this->parseCertificates($convertedCertificates, $type->getOutputFormat(), $type->getPassphrase(), $key); } /**