Merge pull request #821 from davgothic/toggle-key-permissions-check

Add toggle to disable key permissions check for 5.1.*
This commit is contained in:
Andrew Millington 2017-11-29 21:47:00 +00:00 committed by GitHub
commit a1a6cb7b4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,8 +29,9 @@ class CryptKey
/** /**
* @param string $keyPath * @param string $keyPath
* @param null|string $passPhrase * @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)) { if (preg_match(self::RSA_KEY_PATTERN, $keyPath)) {
$keyPath = $this->saveKeyToFile($keyPath); $keyPath = $this->saveKeyToFile($keyPath);
@ -44,20 +45,16 @@ class CryptKey
throw new \LogicException(sprintf('Key path "%s" does not exist or is not readable', $keyPath)); throw new \LogicException(sprintf('Key path "%s" does not exist or is not readable', $keyPath));
} }
// Verify the permissions of the key if ($keyPermissionsCheck === true) {
$keyPathPerms = decoct(fileperms($keyPath) & 0777); // Verify the permissions of the key
if ($keyPathPerms !== '600') { $keyPathPerms = decoct(fileperms($keyPath) & 0777);
// Attempt to correct the permissions if (in_array($keyPathPerms, ['600', '660'], true) === false) {
if (chmod($keyPath, 0600) === false) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
trigger_error( trigger_error(sprintf(
sprintf( 'Key file "%s" permissions are not correct, should be 600 or 660 instead of %s',
'Key file "%s" permissions are not correct, should be 600 instead of %s, unable to automatically resolve the issue', $keyPath,
$keyPath, $keyPathPerms
$keyPathPerms ), E_USER_NOTICE);
),
E_USER_NOTICE
);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
} }