mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-23 05:29:52 +05:30
Better error checking when saving a temporary key to ensure file was written successfully and the server is the exclusive mode
This commit is contained in:
parent
2f8de3d230
commit
63530443fe
@ -74,7 +74,8 @@ class CryptKey
|
|||||||
*/
|
*/
|
||||||
private function saveKeyToFile($key)
|
private function saveKeyToFile($key)
|
||||||
{
|
{
|
||||||
$keyPath = sys_get_temp_dir() . '/' . sha1($key) . '.key';
|
$tmpDir = sys_get_temp_dir();
|
||||||
|
$keyPath = $tmpDir . '/' . sha1($key) . '.key';
|
||||||
|
|
||||||
if (!file_exists($keyPath) && !touch($keyPath)) {
|
if (!file_exists($keyPath) && !touch($keyPath)) {
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
@ -82,7 +83,17 @@ class CryptKey
|
|||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents($keyPath, $key);
|
if (file_put_contents($keyPath, $key) === false) {
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
throw new \RuntimeException('Unable to write key file to temporary directory "%s"', $tmpDir);
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chmod($keyPath, 0600) === false) {
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
throw new \RuntimeException('The key file "%s" file mode could not be changed with chmod to 600', $keyPath);
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
}
|
||||||
|
|
||||||
return 'file://' . $keyPath;
|
return 'file://' . $keyPath;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user