service(NodeJWTService): fix usage of deprecated parameters

This commit is contained in:
Matthew Penner 2021-01-06 08:54:50 -07:00
parent 935f99ab91
commit ae6b8cba19
6 changed files with 21 additions and 17 deletions

View File

@ -128,7 +128,7 @@ class DownloadBackupController extends ClientApiController
protected function getLocalBackupUrl(Backup $backup, Server $server, User $user)
{
$token = $this->jwtService
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)->toDateTimeImmutable())
->setClaims([
'backup_uuid' => $backup->uuid,
'server_uuid' => $server->uuid,

View File

@ -114,7 +114,7 @@ class FileController extends ClientApiController
public function download(GetFileContentsRequest $request, Server $server)
{
$token = $this->jwtService
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)->toDateTimeImmutable())
->setClaims([
'file_path' => rawurldecode($request->get('file')),
'server_uuid' => $server->uuid,

View File

@ -58,7 +58,7 @@ class FileUploadController extends ClientApiController
protected function getUploadUrl(Server $server, User $user)
{
$token = $this->jwtService
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)->toDateTimeImmutable())
->setClaims([
'server_uuid' => $server->uuid,
])

View File

@ -73,7 +73,7 @@ class WebsocketController extends ClientApiController
}
$token = $this->jwtService
->setExpiresAt(CarbonImmutable::now()->addMinutes(10))
->setExpiresAt(CarbonImmutable::now()->addMinutes(10)->toDateTimeImmutable())
->setClaims([
'user_id' => $request->user()->id,
'server_uuid' => $server->uuid,
@ -85,7 +85,7 @@ class WebsocketController extends ClientApiController
return new JsonResponse([
'data' => [
'token' => $token->__toString(),
'token' => $token->toString(),
'socket' => $socket . sprintf('/api/servers/%s/ws', $server->uuid),
],
]);

View File

@ -2,7 +2,7 @@
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Cake\Chronos\Chronos;
use Carbon\CarbonImmutable;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@ -114,7 +114,7 @@ class ServerTransferController extends Controller
// that node to communicate with the old node during the process to initiate the
// actual file transfer.
$token = $this->jwtService
->setExpiresAt(Chronos::now()->addMinutes(15))
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)->toDateTimeImmutable())
->setSubject($server->uuid)
->handle($server->node, $server->uuid, 'sha256');

View File

@ -2,7 +2,7 @@
namespace Pterodactyl\Services\Nodes;
use DateTimeInterface;
use DateTimeImmutable;
use Lcobucci\JWT\Builder;
use Carbon\CarbonImmutable;
use Illuminate\Support\Str;
@ -18,7 +18,7 @@ class NodeJWTService
private $claims = [];
/**
* @var int|null
* @var \DateTimeImmutable|null
*/
private $expiresAt;
@ -41,12 +41,12 @@ class NodeJWTService
}
/**
* @param \DateTimeInterface $date
* @param \DateTimeImmutable $date
* @return $this
*/
public function setExpiresAt(DateTimeInterface $date)
public function setExpiresAt(DateTimeImmutable $date)
{
$this->expiresAt = $date->getTimestamp();
$this->expiresAt = $date;
return $this;
}
@ -74,18 +74,22 @@ class NodeJWTService
{
$signer = new Sha256;
$identifier = hash($algo, $identifiedBy);
$builder = (new Builder)->issuedBy(config('app.url'))
->permittedFor($node->getConnectionAddress())
->identifiedBy(hash($algo, $identifiedBy), true)
->issuedAt(CarbonImmutable::now()->getTimestamp())
->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5)->getTimestamp());
->identifiedBy($identifier)
->withHeader('jti', $identifier)
->issuedAt(CarbonImmutable::now()->toDateTimeImmutable())
->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5)->toDateTimeImmutable());
if ($this->expiresAt) {
$builder = $builder->expiresAt($this->expiresAt);
}
if (!empty($this->subject)) {
$builder = $builder->relatedTo($this->subject, true);
if (! empty($this->subject)) {
$builder = $builder->relatedTo($this->subject)
->withHeader('sub', $this->subject);
}
foreach ($this->claims as $key => $value) {