Skip to content

Commit 158c735

Browse files
loadKey should check return value for openssl_get_privatekey (#249)
The function openssl_get_privatekey may return false, for example if the passphrase is incorrect. In the other 2 branches of the switch statement, this is checked and an exception thrown, but it was not checked in the private key branch. This commit adds a check. This makes it easier to detect problems with invalid keys or pass phrases. Without this change, you are likely to get a confusing exception later on when it tries to use the key.
1 parent ebeaef1 commit 158c735

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/XMLSecurityKey.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ public function loadKey($key, $isFile=false, $isCert = false)
384384

385385
case 'private':
386386
$this->key = openssl_get_privatekey($this->key, $this->passphrase);
387+
if ($this->key === false) {
388+
throw new Exception('Unable to extract private key (invalid key or passphrase): ' . openssl_error_string());
389+
}
387390
break;
388391

389392
case'symmetric':

0 commit comments

Comments
 (0)