Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions lib/internal/Magento/Framework/Jwt/JwkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ private function createPrivateRsa(string $key, ?string $pass, string $use, strin
{
$resource = openssl_get_privatekey($key, (string)$pass);
$keyData = openssl_pkey_get_details($resource)['rsa'];
$this->freeResource($resource);

$keysMap = [
'n' => 'n',
'e' => 'e',
Expand Down Expand Up @@ -821,7 +821,7 @@ private function createPublicRsa(string $key, string $use, string $algorithm, ?s
{
$resource = openssl_get_publickey($key);
$keyData = openssl_pkey_get_details($resource)['rsa'];
$this->freeResource($resource);

$keysMap = [
'n' => 'n',
'e' => 'e'
Expand Down Expand Up @@ -857,7 +857,7 @@ private function createPrivateEc(
): Jwk {
$resource = openssl_get_privatekey($key, (string)$pass);
$keyData = openssl_pkey_get_details($resource)['ec'];
$this->freeResource($resource);

if (!array_key_exists($keyData['curve_oid'], self::EC_CURVE_MAP)) {
throw new \RuntimeException('Unsupported EC curve');
}
Expand Down Expand Up @@ -895,7 +895,7 @@ private function createPublicEc(
): Jwk {
$resource = openssl_get_publickey($key);
$keyData = openssl_pkey_get_details($resource)['ec'];
$this->freeResource($resource);

if (!array_key_exists($keyData['curve_oid'], self::EC_CURVE_MAP)) {
throw new \RuntimeException('Unsupported EC curve');
}
Expand Down Expand Up @@ -950,15 +950,4 @@ private static function base64Decode(string $encoded): string
return $value;
}

/**
* @param mixed $resource
*
* @return void
*/
private function freeResource($resource): void
{
if (\is_resource($resource) && (version_compare(PHP_VERSION, '8.0') < 0)) {
openssl_free_key($resource);
}
}
}