-
-
Notifications
You must be signed in to change notification settings - Fork 0
Update to support Pro level #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,21 @@ | ||
| <?php | ||
|
|
||
| use LycheeVerify\Http\Middleware\VerifyProStatus; | ||
| use LycheeVerify\Http\Middleware\VerifySupporterStatus; | ||
| use LycheeVerify\Validators\ValidateHash; | ||
| use LycheeVerify\Validators\ValidatePro; | ||
| use LycheeVerify\Validators\ValidateSignature; | ||
| use LycheeVerify\Validators\ValidateSupporter; | ||
| use LycheeVerify\Verify; | ||
| use LycheeVerify\VerifyServiceProvider; | ||
|
|
||
| return [ | ||
| 'validation' => [ | ||
| ValidateHash::class => 'e2511ed0f1adc865c7c8b40bec19d656323d81f6', | ||
| ValidateSignature::class => '1bae28471b402e73ddad2ea871b15835954822c3', | ||
| Verify::class => '6dd9c193b7505dff9d4ba0f19f0e2b3a3171d83a', | ||
| ValidateSupporter::class => 'ef1a42701af6dc36e052556a0ee1c762394f9428', | ||
| ValidatePro::class => '482b48f1a026684b6c1754e45ca180ffc52483ff', | ||
| ValidateSignature::class => '5a8a855d4b59c44c298daa66801c79f2aba20492', | ||
| Verify::class => 'ffd01909f5189bc7bae21266e356f83c898ccd37', | ||
| VerifySupporterStatus::class => '6358c45ed0414c1e2697e0881238659fa6221bed', | ||
| VerifyServiceProvider::class => '927a8f3c811fc82cb8a0ac2667c06e7d292c3633', | ||
| VerifyProStatus::class => '212e6ada794587ee8e2b81cf76e243d134a7e823', | ||
| VerifyServiceProvider::class => '923b63b15d25e69b95ed1d5ec1c82ba57f1a7d74', | ||
| ], | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Generate a cryptographically secure key in the format: | ||
| * XXXXX-XXXXX-XXXXX-XXXXX-XXXXX | ||
| * | ||
| * Each segment contains 5 uppercase alphanumeric characters (A-Z, 0-9) | ||
| */ | ||
| function generateSecureKey(): string | ||
| { | ||
| $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | ||
| $segments = []; | ||
|
|
||
| // Generate 5 segments | ||
| for ($i = 0; $i < 5; $i++) { | ||
| $segment = ''; | ||
|
|
||
| // Generate 5 characters per segment | ||
| for ($j = 0; $j < 5; $j++) { | ||
| $randomIndex = random_int(0, strlen($characters) - 1); | ||
| $segment .= $characters[$randomIndex]; | ||
| } | ||
|
|
||
| $segments[] = $segment; | ||
| } | ||
|
|
||
| return implode('-', $segments); | ||
| } | ||
|
|
||
| // Generate and display the key | ||
| $key = generateSecureKey(); | ||
| $hash = password_hash($key, PASSWORD_BCRYPT); | ||
|
|
||
| echo "Generated key: " . $key . PHP_EOL; | ||
| echo "Bcrypt hash: " . $hash . PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <?php | ||
|
|
||
| namespace LycheeVerify\Console\Commands; | ||
|
|
||
| use Illuminate\Console\Command; | ||
| use LycheeVerify\Contract\Status; | ||
| use LycheeVerify\Validators\ValidatePro; | ||
| use LycheeVerify\Validators\ValidateSupporter; | ||
| use function Safe\json_encode; | ||
|
|
||
| class CheckKeyCommand extends Command | ||
| { | ||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'verify:check-key {key : The license key to check}'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'Check the sponsorship level for a given license key'; | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| */ | ||
| public function handle(): int | ||
| { | ||
| if (!$this->hasArgument('key')) { | ||
| $this->error('No key provided. Please provide a license key to check.'); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
|
|
||
| if (!is_string($this->argument('key'))) { | ||
| $this->error('Invalid key format. The key must be a string.'); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
|
|
||
| $key = $this->argument('key'); | ||
|
|
||
| $validateSupporter = new ValidateSupporter(); | ||
| $validatePro = new ValidatePro(); | ||
|
|
||
| // We use a dummy verifiable string for checking | ||
| $verifiable = json_encode(['url' => '', 'email' => '']); | ||
|
|
||
| // Check Pro edition first (highest tier) | ||
| if ($validatePro->validate($verifiable, $key)) { | ||
| $this->info('Key: ' . $key); | ||
| $this->info('Sponsorship Level: ' . Status::PRO_EDITION->value . ' (Pro Edition)'); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
|
|
||
| // Check Supporter edition | ||
| if ($validateSupporter->validate($verifiable, $key)) { | ||
| $this->info('Key: ' . $key); | ||
| $this->info('Sponsorship Level: ' . Status::SUPPORTER_EDITION->value . ' (Supporter Edition)'); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
|
|
||
| // Key doesn't match any known tier | ||
| $this->warn('Key: ' . $key); | ||
| $this->warn('Sponsorship Level: ' . Status::FREE_EDITION->value . ' (No valid sponsorship found)'); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
|
|
||
| namespace LycheeVerify\Http\Middleware; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use LycheeVerify\Contract\Status; | ||
| use LycheeVerify\Contract\VerifyException; | ||
| use LycheeVerify\Exceptions\SupporterOnlyOperationException; | ||
| use LycheeVerify\Verify; | ||
|
|
||
| /** | ||
| * This class checks whether the use on a supporter installation. | ||
| * If it is not, then the request is aborted. | ||
| */ | ||
ildyria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class VerifyProStatus | ||
| { | ||
| private Verify $verify; | ||
|
|
||
| public function __construct(?Verify $verify) | ||
| { | ||
| $this->verify = $verify ?? new Verify(); | ||
| } | ||
|
|
||
| /** | ||
| * Handle an incoming request. | ||
| * | ||
| * @param Request $request the incoming request to serve | ||
| * @param \Closure $next the next operation to be applied to the | ||
| * request | ||
| * | ||
| * @return mixed | ||
| * | ||
| * @throws VerifyException | ||
| */ | ||
| public function handle(Request $request, \Closure $next, string $required_status): mixed | ||
| { | ||
| $required_status = Status::tryFrom($required_status) ?? Status::PRO_EDITION; | ||
|
|
||
| if ($this->verify->check($required_status)) { | ||
| return $next($request); | ||
| } | ||
|
|
||
| throw new SupporterOnlyOperationException(Status::PRO_EDITION); | ||
| } | ||
ildyria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
|
|
||
| namespace LycheeVerify\Validators; | ||
|
|
||
| use Illuminate\Support\Facades\Hash; | ||
| use LycheeVerify\Contract\Status; | ||
| use LycheeVerify\Contract\ValidatorInterface; | ||
|
|
||
| /** | ||
| * This is the validator for supporters. | ||
| */ | ||
| class ValidatePro implements ValidatorInterface | ||
ildyria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| private string $hash; | ||
|
|
||
| public function __construct(#[\SensitiveParameter] ?string $hash = null) | ||
| { | ||
| $this->hash = $hash ?? '$2y$12$HCan1i4raFBRltqPSy2imeDAIf7UQxSQTJpA3Jv0cJ/fplNc4mEta'; | ||
| } | ||
|
|
||
| /** | ||
| * Validate whether the static license key provided matches with the hash. | ||
| */ | ||
| public function validate(string $verifiable, string $license): bool | ||
| { | ||
| if ($license === '') { | ||
| return false; | ||
| } | ||
|
|
||
| return Hash::check($license, $this->hash); | ||
| } | ||
|
|
||
| /** | ||
| * If the hash passes, we grant the user the supporter edition. | ||
| * | ||
| * @return Status::PRO_EDITION | ||
| */ | ||
| public function grant(): Status | ||
| { | ||
| return Status::PRO_EDITION; | ||
| } | ||
ildyria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.