Skip to content

Commit 88ab77b

Browse files
committed
Add own sha signer for backwards compatibility
1 parent 5cfd265 commit 88ab77b

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace ShinyDeploy\Core\Crypto;
4+
5+
use Lcobucci\JWT\Signer\Hmac;
6+
7+
class Sha256Signer extends Hmac
8+
{
9+
public function algorithmId(): string
10+
{
11+
return 'HS256';
12+
}
13+
14+
public function algorithm(): string
15+
{
16+
return 'sha256';
17+
}
18+
19+
public function minimumBitsLengthForKey(): int
20+
{
21+
return 64;
22+
}
23+
}

src/ShinyDeploy/Domain/Database/Auth.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
use Defuse\Crypto\Key;
66
use Exception;
77
use Lcobucci\JWT\Configuration;
8-
use Lcobucci\JWT\Signer\Hmac\Sha256;
98
use Lcobucci\JWT\Signer\Key\InMemory;
109
use Lcobucci\JWT\Validation\Constraint\IdentifiedBy;
1110
use Lcobucci\JWT\Validation\Constraint\IssuedBy;
1211
use ShinyDeploy\Core\Crypto\KeyCrypto;
1312
use ShinyDeploy\Core\Crypto\PasswordCrypto;
13+
use ShinyDeploy\Core\Crypto\Sha256Signer;
1414
use ShinyDeploy\Exceptions\AuthException;
1515
use ShinyDeploy\Exceptions\CryptographyException;
1616
use ShinyDeploy\Exceptions\DatabaseException;
@@ -29,7 +29,7 @@ class Auth extends DatabaseDomain
2929
public function generateToken(string $username, string $userEncryptionKey, string $clientId): string
3030
{
3131
try {
32-
$signer = new Sha256();
32+
$signer = new Sha256Signer();
3333
$key = InMemory::plainText($this->config->get('auth.secret'));
3434
$config = Configuration::forSymmetricSigner($signer, $key);
3535
$now = new \DateTimeImmutable();
@@ -62,7 +62,7 @@ public function generateToken(string $username, string $userEncryptionKey, strin
6262
public function validateToken(string $token, string $clientId): bool
6363
{
6464
try {
65-
$signer = new Sha256();
65+
$signer = new Sha256Signer();
6666
$key = InMemory::plainText($this->config->get('auth.secret'));
6767
$config = Configuration::forSymmetricSigner($signer, $key);
6868
$parsedToken = $config->parser()->parse($token);
@@ -223,7 +223,7 @@ public function getEncryptionKeyFromToken(string $token): string
223223
}
224224

225225
try {
226-
$signer = new Sha256();
226+
$signer = new Sha256Signer();
227227
$key = InMemory::plainText($this->config->get('auth.secret'));
228228
$config = Configuration::forSymmetricSigner($signer, $key);
229229
$parsedToken = $config->parser()->parse($token);

0 commit comments

Comments
 (0)