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) protected function getLocalBackupUrl(Backup $backup, Server $server, User $user)
{ {
$token = $this->jwtService $token = $this->jwtService
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)) ->setExpiresAt(CarbonImmutable::now()->addMinutes(15)->toDateTimeImmutable())
->setClaims([ ->setClaims([
'backup_uuid' => $backup->uuid, 'backup_uuid' => $backup->uuid,
'server_uuid' => $server->uuid, 'server_uuid' => $server->uuid,

View File

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

View File

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

View File

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

View File

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

View File

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