Skip to content

Commit

Permalink
Merge pull request #821 from davgothic/toggle-key-permissions-check
Browse files Browse the repository at this point in the history
Add toggle to disable key permissions check for 5.1.*
  • Loading branch information
Sephster authored Nov 29, 2017
2 parents 8e5df6d + 696c78d commit a1a6cb7
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/CryptKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class CryptKey
/**
* @param string $keyPath
* @param null|string $passPhrase
* @param bool $keyPermissionsCheck
*/
public function __construct($keyPath, $passPhrase = null)
public function __construct($keyPath, $passPhrase = null, $keyPermissionsCheck = true)
{
if (preg_match(self::RSA_KEY_PATTERN, $keyPath)) {
$keyPath = $this->saveKeyToFile($keyPath);
Expand All @@ -44,20 +45,16 @@ public function __construct($keyPath, $passPhrase = null)
throw new \LogicException(sprintf('Key path "%s" does not exist or is not readable', $keyPath));
}

// Verify the permissions of the key
$keyPathPerms = decoct(fileperms($keyPath) & 0777);
if ($keyPathPerms !== '600') {
// Attempt to correct the permissions
if (chmod($keyPath, 0600) === false) {
if ($keyPermissionsCheck === true) {
// Verify the permissions of the key
$keyPathPerms = decoct(fileperms($keyPath) & 0777);
if (in_array($keyPathPerms, ['600', '660'], true) === false) {
// @codeCoverageIgnoreStart
trigger_error(
sprintf(
'Key file "%s" permissions are not correct, should be 600 instead of %s, unable to automatically resolve the issue',
$keyPath,
$keyPathPerms
),
E_USER_NOTICE
);
trigger_error(sprintf(
'Key file "%s" permissions are not correct, should be 600 or 660 instead of %s',
$keyPath,
$keyPathPerms
), E_USER_NOTICE);
// @codeCoverageIgnoreEnd
}
}
Expand Down

0 comments on commit a1a6cb7

Please sign in to comment.