From 7d3b0a21821eb1be394efb9cf78dc84f21614357 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 20 Apr 2021 16:01:45 -0500 Subject: [PATCH] X509: tweaks to mapOutExtensions --- phpseclib/File/X509.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index 88dd1a80..2e1620c1 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -670,7 +670,7 @@ class X509 */ private function mapOutExtensions(&$root, $path) { - $extensions = &$this->subArray($root, $path, true); + $extensions = &$this->subArray($root, $path, !empty($this->extensionValues)); foreach ($this->extensionValues as $id => $data) { extract($data); @@ -679,16 +679,15 @@ class X509 'extnValue' => $value, 'critical' => $critical ]; - if (!$replace) { - $extensions[] = $newext; - continue; - } - foreach ($extensions as $key => $value) { - if ($value['extnId'] == $id) { - $extensions[$key] = $newext; - break; - } + if ($replace) { + foreach ($extensions as $key => $value) { + if ($value['extnId'] == $id) { + $extensions[$key] = $newext; + continue 2; + } + } } + $extensions[] = $newext; } if (is_array($extensions)) {