nazrulalif/laravel-pem-license-validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nazrulalif/laravel-pem-license-validator

Composer 安装命令:

composer require nazrulalif/laravel-pem-license-validator

包简介

Offline PEM license validation for Laravel applications using RSA-4096 signatures

README 文档

README

Offline license validation for Laravel applications using RSA-4096 signed PEM files.

Features

  • ✅ Offline validation (no internet required)
  • ✅ RSA-4096 signature verification
  • ✅ Configurable caching
  • ✅ Optional grace period
  • ✅ Hardware binding support
  • ✅ Product key validation
  • ✅ Feature flags (JSON-based)
  • ✅ Laravel middleware included
  • ✅ Facade support

Requirements

  • PHP 8.1+
  • Laravel 9.0+
  • OpenSSL extension
  • JSON extension

Installation

composer require nazrulalif/laravel-pem-license-validator:dev-master

Publish Configuration

php artisan vendor:publish --provider="Nazrulalif\LaravelPemLicenseValidator\LicenseServiceProvider"

This creates config/license.php

Place License File

Place your license.pem file in:

storage/app/license.pem

Configuration

Edit config/license.php:

return [
    'license_path' => storage_path('app/license.pem'),

    'cache' => [
        'enabled' => true,
        'ttl' => 86400, // 24 hours
        'driver' => 'file',
    ],

    'grace_period_days' => 0, // 0=disabled, 7=7 days after expiry

    'product_key' => env('LICENSE_PRODUCT_KEY'), // Optional product validation

    'public_key' => env('LICENSE_PUBLIC_KEY', '-----BEGIN PUBLIC KEY-----...'),

    'on_failure' => [
        'redirect' => '/license-expired',
        'log' => true,
    ],
];

Environment Variables

Add these to your .env file:

LICENSE_PATH=storage/app/license.pem
LICENSE_CACHE_ENABLED=true
LICENSE_CACHE_TTL=86400
LICENSE_GRACE_PERIOD_DAYS=0
LICENSE_PRODUCT_KEY=your-product-key
LICENSE_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
...your public key here...
-----END PUBLIC KEY-----"
LICENSE_FAILURE_REDIRECT=/license-expired
LICENSE_FAILURE_LOG=true
LICENSE_FAILURE_ABORT_CODE=403

Note: LICENSE_PRODUCT_KEY is optional. If set, the license must contain a matching productKey field for validation to pass.

Usage

Basic Validation

use Nazrulalif\LaravelPemLicenseValidator\LicenseValidator;

$validator = new LicenseValidator(config('license'));

if ($validator->isValid()) {
    $license = $validator->getLicenseData();
    echo "Valid until: " . $license['expiryDate'];
} else {
    abort(403, 'Invalid license');
}

Using Facade

use Nazrulalif\LaravelPemLicenseValidator\Facades\License;

if (License::isValid()) {
    $daysLeft = License::getDaysRemaining();
    echo "License expires in {$daysLeft} days";
}

Middleware Protection

Register in app/Http/Kernel.php:

protected $middlewareAliases = [
    'license' => \Nazrulalif\LaravelPemLicenseValidator\Middleware\ValidateLicense::class,
];

Use in routes:

Route::middleware('license')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
    Route::get('/settings', [SettingsController::class, 'index']);
});

Bootstrap Validation

In app/Providers/AppServiceProvider.php:

public function boot()
{
    try {
        $validator = app(\Nazrulalif\LaravelPemLicenseValidator\LicenseValidator::class);

        if (!$validator->isValid()) {
            abort(403, 'Invalid or expired license: ' . $validator->getError());
        }

        // Check grace period
        if ($validator->isInGracePeriod()) {
            logger()->warning('License in grace period. Days remaining: ' . $validator->getDaysRemaining());
        }

    } catch (\Exception $e) {
        abort(500, 'License validation error: ' . $e->getMessage());
    }
}

Feature Checks

use Nazrulalif\LaravelPemLicenseValidator\Facades\License;

// Check if feature exists
if (License::hasFeature('api_access')) {
    // Enable API routes
}

// Get feature value with default
$maxUsers = License::getFeature('UserLimit', 10);

// Get all features
$features = License::getLicenseData()['features'];

API Reference

LicenseValidator

// Validate license
$validator->validate(): array

// Check if valid
$validator->isValid(): bool

// Get license data
$validator->getLicenseData(): array

// Get days remaining
$validator->getDaysRemaining(): int

// Check grace period
$validator->isInGracePeriod(): bool

// Get feature value
$validator->getFeature(string $key, mixed $default = null): mixed

// Check feature exists
$validator->hasFeature(string $key): bool

// Get error message
$validator->getError(): ?string

License Data Structure

{
  "productKey": "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX",
  "licenseId": "LIC-1234567890",
  "licenseType": "PROFESSIONAL",
  "companyName": "Acme Corporation",
  "email": "customer@example.com",
  "maxDevices": 5,
  "features": {
    "UserLimit": 50,
    "sso": true,
    "api_access": true,
    "storage_gb": 100
  },
  "hardwareId": null,
  "issueDate": "2025-01-01T00:00:00Z",
  "expiryDate": "2026-01-01T00:00:00Z"
}

Exception Handling

use Nazrulalif\LaravelPemLicenseValidator\Exceptions\LicenseException;

try {
    $validator->validate();
} catch (LicenseException $e) {
    switch ($e->getCode()) {
        case LicenseException::FILE_NOT_FOUND:
            // Handle missing file
            break;
        case LicenseException::INVALID_SIGNATURE:
            // Handle tampered license
            break;
        case LicenseException::EXPIRED:
            // Handle expiry
            break;
        case LicenseException::HARDWARE_MISMATCH:
            // Handle hardware binding
            break;
        case LicenseException::PRODUCT_KEY_MISMATCH:
            // Handle product key validation failure
            break;
    }
}

Troubleshooting

License file not found

Ensure license.pem exists at the configured path (default: storage/app/license.pem)

Invalid signature

  • License file may be corrupted or tampered
  • Public key in config doesn't match the key used to sign the license

Product key mismatch

  • The productKey in the license doesn't match LICENSE_PRODUCT_KEY in your .env
  • License was issued for a different product
  • Remove LICENSE_PRODUCT_KEY from .env to disable product key validation

Permission denied

chmod 644 storage/app/license.pem

Cache issues

Clear license cache:

License::clearCache();

Security

  • Never commit license.pem to version control
  • Add to .gitignore: storage/app/license.pem
  • Keep public key secure in .env file
  • Use HTTPS when transferring license files

Support

For issues or questions, contact: nazrulism17@gmail.com

License

MIT License - see LICENSE file

nazrulalif/laravel-pem-license-validator 适用场景与选型建议

nazrulalif/laravel-pem-license-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「validation」 「rsa」 「laravel」 「license」 「offline」 「pem」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nazrulalif/laravel-pem-license-validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nazrulalif/laravel-pem-license-validator 我们能提供哪些服务?
定制开发 / 二次开发

基于 nazrulalif/laravel-pem-license-validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-19