Skip to content

Commit 4cf9e9b

Browse files
committed
keys rotated
1 parent 57232a0 commit 4cf9e9b

File tree

6 files changed

+108
-6
lines changed

6 files changed

+108
-6
lines changed

config/verify.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
return [
1212
'validation' => [
13-
ValidateSupporter::class => '882f8890242f77ee8dd8b84c6511c82e32858c12',
14-
ValidatePro::class => '676b945ac8649a099ced12bfbab87b11c5c0daad',
13+
ValidateSupporter::class => 'ef1a42701af6dc36e052556a0ee1c762394f9428',
14+
ValidatePro::class => '482b48f1a026684b6c1754e45ca180ffc52483ff',
1515
ValidateSignature::class => '5a8a855d4b59c44c298daa66801c79f2aba20492',
1616
Verify::class => 'e5a8ebb4878c0fd3387ec0cb2f28d9caa463e5bb',
1717
VerifySupporterStatus::class => '6358c45ed0414c1e2697e0881238659fa6221bed',
1818
VerifyProStatus::class => '212e6ada794587ee8e2b81cf76e243d134a7e823',
19-
VerifyServiceProvider::class => '927a8f3c811fc82cb8a0ac2667c06e7d292c3633',
19+
VerifyServiceProvider::class => '923b63b15d25e69b95ed1d5ec1c82ba57f1a7d74',
2020
],
2121
];

generate-key.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* Generate a cryptographically secure key in the format:
5+
* XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
6+
*
7+
* Each segment contains 5 uppercase alphanumeric characters (A-Z, 0-9)
8+
*/
9+
function generateSecureKey(): string
10+
{
11+
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
12+
$segments = [];
13+
14+
// Generate 5 segments
15+
for ($i = 0; $i < 5; $i++) {
16+
$segment = '';
17+
18+
// Generate 5 characters per segment
19+
for ($j = 0; $j < 5; $j++) {
20+
$randomIndex = random_int(0, strlen($characters) - 1);
21+
$segment .= $characters[$randomIndex];
22+
}
23+
24+
$segments[] = $segment;
25+
}
26+
27+
return implode('-', $segments);
28+
}
29+
30+
// Generate and display the key
31+
$key = generateSecureKey();
32+
$hash = password_hash($key, PASSWORD_BCRYPT);
33+
34+
echo "Generated key: " . $key . PHP_EOL;
35+
echo "Bcrypt hash: " . $hash . PHP_EOL;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace LycheeVerify\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use LycheeVerify\Contract\Status;
7+
use LycheeVerify\Validators\ValidatePro;
8+
use LycheeVerify\Validators\ValidateSupporter;
9+
10+
use function Safe\json_encode;
11+
12+
class CheckKeyCommand extends Command
13+
{
14+
/**
15+
* The name and signature of the console command.
16+
*
17+
* @var string
18+
*/
19+
protected $signature = 'verify:check-key {key : The license key to check}';
20+
21+
/**
22+
* The console command description.
23+
*
24+
* @var string
25+
*/
26+
protected $description = 'Check the sponsorship level for a given license key';
27+
28+
/**
29+
* Execute the console command.
30+
*/
31+
public function handle(): int
32+
{
33+
$key = $this->argument('key');
34+
35+
$validateSupporter = new ValidateSupporter();
36+
$validatePro = new ValidatePro();
37+
38+
// We use a dummy verifiable string for checking
39+
$verifiable = json_encode(['url' => '', 'email' => '']);
40+
41+
// Check Pro edition first (highest tier)
42+
if ($validatePro->validate($verifiable, $key)) {
43+
$this->info('Key: ' . $key);
44+
$this->info('Sponsorship Level: ' . Status::PRO_EDITION->value . ' (Pro Edition)');
45+
return Command::SUCCESS;
46+
}
47+
48+
// Check Supporter edition
49+
if ($validateSupporter->validate($verifiable, $key)) {
50+
$this->info('Key: ' . $key);
51+
$this->info('Sponsorship Level: ' . Status::SUPPORTER_EDITION->value . ' (Supporter Edition)');
52+
return Command::SUCCESS;
53+
}
54+
55+
// Key doesn't match any known tier
56+
$this->warn('Key: ' . $key);
57+
$this->warn('Sponsorship Level: ' . Status::FREE_EDITION->value . ' (No valid sponsorship found)');
58+
59+
return Command::FAILURE;
60+
}
61+
}

src/Validators/ValidatePro.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ValidatePro implements ValidatorInterface
1515

1616
public function __construct(#[\SensitiveParameter] ?string $hash = null)
1717
{
18-
$this->hash = $hash ?? '$2y$10$Bo9bqC34tQr.hEJ1qZZNBO.dkJRoEiLeZpXxlsYaSlaKi/dRyCyea';
18+
$this->hash = $hash ?? '$2y$12$HCan1i4raFBRltqPSy2imeDAIf7UQxSQTJpA3Jv0cJ/fplNc4mEta';
1919
}
2020

2121
/**

src/Validators/ValidateSupporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ValidateSupporter implements ValidatorInterface
1515

1616
public function __construct(#[\SensitiveParameter] ?string $hash = null)
1717
{
18-
$this->hash = $hash ?? '$2y$10$Bo9bqC34tQr.hEJ1qZZNBO.dkJRoEiLeZpXxlsYaSlaKi/dRyCyea';
18+
$this->hash = $hash ?? '$2y$12$x58lfmOIxyKh3kzZyWJibuDPnDXO7er6xmDqoUZ3PNrFJHF9DaHpC';
1919
}
2020

2121
/**

src/VerifyServiceProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace LycheeVerify;
44

55
use Illuminate\Support\ServiceProvider;
6+
use LycheeVerify\Console\Commands\CheckKeyCommand;
67

78
class VerifyServiceProvider extends ServiceProvider
89
{
@@ -17,7 +18,7 @@ class VerifyServiceProvider extends ServiceProvider
1718
*/
1819
public function register()
1920
{
20-
$this->mergeConfigFrom(static::CONFIG, 'verify');
21+
$this->mergeConfigFrom(self::CONFIG, 'verify');
2122

2223
$this->app->bind('verify', function () {
2324
return new \LycheeVerify\Verify(); // Replace with your actual instantiation logic.
@@ -26,5 +27,10 @@ public function register()
2627

2728
public function boot(): void
2829
{
30+
if ($this->app->runningInConsole()) {
31+
$this->commands([
32+
CheckKeyCommand::class,
33+
]);
34+
}
2935
}
3036
}

0 commit comments

Comments
 (0)