Added license management module

This commit is contained in:
2026-05-25 22:45:23 +02:00
parent 93b7be7e2c
commit df24d48038
16 changed files with 861 additions and 9 deletions
@@ -0,0 +1,55 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class GenerateLicenseKeysCommand extends Command
{
protected $signature = 'license:generate-keys {--force : Overwrite existing key pair}';
protected $description = 'Generate a new application-wide license signing key pair.';
public function handle(): int
{
$directory = 'license-keys';
$privateKeyPath = $directory . '/private.pem';
$publicKeyPath = $directory . '/public.pem';
$disk = Storage::disk('local');
$privateExists = $disk->exists($privateKeyPath);
$publicExists = $disk->exists($publicKeyPath);
if (($privateExists || $publicExists) && !$this->option('force')) {
$this->error('Key pair already exists. Use --force to overwrite.');
return 1;
}
$keyPair = $this->generateKeyPair();
$disk->put($privateKeyPath, $keyPair['privateKey']);
$disk->put($publicKeyPath, $keyPair['publicKey']);
$this->info('Generated application license key pair.');
$this->line('Private key: ' . $privateKeyPath);
$this->line('Public key: ' . $publicKeyPath);
return 0;
}
protected function generateKeyPair(): array
{
$privateKey = openssl_pkey_new([
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
]);
openssl_pkey_export($privateKey, $privateKeyPem);
$publicKeyDetails = openssl_pkey_get_details($privateKey);
return [
'privateKey' => $privateKeyPem,
'publicKey' => $publicKeyDetails['key'],
];
}
}