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)) {