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 diff --git a/src/KeyHelper.php b/src/KeyHelper.php index c25658b..54b63db 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); + } + + $parsedCertificates = $this->parseCertificates($key->getKeyValue(), $type->getInputFormat(), $type->getPassphrase(), $key); + $convertedCertificates = $this->convertCertificates($parsedCertificates, $type->getOutputFormat(), $key); + return $this->parseCertificates($convertedCertificates, $type->getOutputFormat(), $type->getPassphrase(), $key); } /**