Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Changed the method of validating license keys by introducing separate environment variables for private and public keys, replacing the deprecated master secret approach. Updated related documentation and added tests for the new license validation system.

Matt Robertsa46eab412901
diff --git a/.example.env b/.example.env
index c8ed924cd..f22ab3deb 100644
--- a/.example.env
+++ b/.example.env
@@ -35,11 +35,17 @@ EMAIL_SMTP_USERNAME=
EMAIL_SMTP_PASSWORD=
# Commercial License (Optional for self-hosted, Required for hosted multi-tenant)
-# LICENSE_MASTER_SECRET: Only required for hosted Fider instances that sell Pro subscriptions
-# - Used to generate and validate license keys for Pro customers
-# - Not needed for self-hosted unless you want to validate a COMMERCIAL_KEY
-# COMMERCIAL_KEY: For self-hosted Fider, set this to enable commercial features (content moderation)
-# - Leave blank to run Fider without commercial features (free/open-source mode)
-# - If you have a commercial license, set it here
-# LICENSE_MASTER_SECRET=your-secret-key-here-change-in-production
+#
+# For HOSTED INSTANCES (multi-tenant SaaS):
+# - LICENSE_PRIVATE_KEY: Ed25519 private key used to generate license keys for Pro customers
+# - Generate a key pair using: go run scripts/generate_license_keys.go
+# - Keep the private key SECRET - it's used to sign all commercial licenses
+# LICENSE_PRIVATE_KEY=your-base64-encoded-private-key-here
+#
+# For SELF-HOSTED INSTANCES:
+# - LICENSE_PUBLIC_KEY: Ed25519 public key used to validate commercial licenses
+# - This key is safe to share and is used to verify license authenticity
+# - COMMERCIAL_KEY: Your commercial license key (purchase from hosted instance)
+# - Leave both blank to run Fider in free/open-source mode
+# LICENSE_PUBLIC_KEY=lPHzCZhOBBihIusKWs5lzXCgGxZEKBpCiplkmZSjGpU=
# COMMERCIAL_KEY=FIDER-COMMERCIAL-123-1638360000-abc123...
diff --git a/.test.env b/.test.env
index 464916b20..58fed84ba 100644
--- a/.test.env
+++ b/.test.env
@@ -41,4 +41,6 @@ EMAIL_MAILGUN_DOMAIN=mydomain.com
USER_LIST_ENABLED=true
USER_LIST_APIKEY=abcdefg
-LICENSE_MASTER_SECRET=test_master_secret_for_license_generation
+# Ed25519 license keys for testing
+LICENSE_PUBLIC_KEY=9o3OnNs9tnnD780fZcTYas8uhcA90MWtin1rWGhXVPE=
+LICENSE_PRIVATE_KEY=fwRNcFEiusrH0Hx1aBlOobE+6hm2/CPXUkUTWXj3cQn2jc6c2z22ecPvzR9lxNhqzy6FwD3Qxa2KfWtYaFdU8Q==
diff --git a/app/pkg/env/env.go b/app/pkg/env/env.go
index 2559a2077..4a8a920e6 100644
--- a/app/pkg/env/env.go
+++ b/app/pkg/env/env.go
@@ -144,8 +144,9 @@ type config struct {
GoogleAnalytics string `env:"GOOGLE_ANALYTICS"`
SearchNoiseWords string `env:"SEARCH_NOISE_WORDS,default=add|support|for|implement|create|make|allow|enable|provide|some|also|include|very|make|and|for|to|a|able|function|feature|app"`
License struct {
- MasterSecret string `env:"LICENSE_MASTER_SECRET"`
- Key string `env:"COMMERCIAL_KEY"`
+ PrivateKey string `env:"LICENSE_PRIVATE_KEY"` // Ed25519 private key for hosted instances (base64 encoded)
+ PublicKey string `env:"LICENSE_PUBLIC_KEY"` // Ed25519 public key for license validation (base64 encoded)
+ Key string `env:"COMMERCIAL_KEY"` // Self-hosted instance's license key
}
}
diff --git a/app/services/license/validator.go b/app/services/license/validator.go
index 78ed3c4ea..97b1c4dae 100644
--- a/app/services/license/validator.go
+++ b/app/services/license/validator.go
@@ -1,9 +1,8 @@
package license
import (
- "crypto/hmac"
- "crypto/sha256"
- "crypto/subtle"
+ "crypto/ed25519"
+ "encoding/base64"
"encoding/hex"
"fmt"
"strconv"
@@ -14,19 +13,29 @@ import (
"github.com/getfider/fider/app/pkg/errors"
)
-// GenerateKey generates a commercial license key for a tenant
-// Format: FIDER-COMMERCIAL-{tenantID}-{timestamp}-{hmacHex}
-// Panics if LICENSE_MASTER_SECRET is not set
+// GenerateKey generates a commercial license key for a tenant using Ed25519 signatures
+// Format: FIDER-COMMERCIAL-{tenantID}-{timestamp}-{signature}
+// Panics if LICENSE_PRIVATE_KEY is not set
func GenerateKey(tenantID int) string {
- if env.Config.License.MasterSecret == "" {
- panic("LICENSE_MASTER_SECRET environment variable must be set to generate license keys. This is required for hosted Fider instances that sell Pro subscriptions.")
+ if env.Config.License.PrivateKey == "" {
+ panic("LICENSE_PRIVATE_KEY environment variable must be set to generate license keys. This is required for hosted Fider instances that sell Pro subscriptions.")
}
+
+ privateKeyBytes, err := base64.StdEncoding.DecodeString(env.Config.License.PrivateKey)
+ if err != nil {
+ panic(fmt.Sprintf("Invalid LICENSE_PRIVATE_KEY: %v", err))
+ }
+
+ if len(privateKeyBytes) != ed25519.PrivateKeySize {
+ panic(fmt.Sprintf("Invalid LICENSE_PRIVATE_KEY length: expected %d bytes, got %d", ed25519.PrivateKeySize, len(privateKeyBytes)))
+ }
+
timestamp := time.Now().Unix()
data := fmt.Sprintf("%d-%d", tenantID, timestamp)
- mac := hmac.New(sha256.New, []byte(env.Config.License.MasterSecret))
- mac.Write([]byte(data))
- hash := hex.EncodeToString(mac.Sum(nil))
- return fmt.Sprintf("FIDER-COMMERCIAL-%d-%d-%s", tenantID, timestamp, hash)
+ signature := ed25519.Sign(ed25519.PrivateKey(privateKeyBytes), []byte(data))
+ signatureHex := hex.EncodeToString(signature)
+
+ return fmt.Sprintf("FIDER-COMMERCIAL-%d-%d-%s", tenantID, timestamp, signatureHex)
}
// ValidationResult contains the result of license key validation
@@ -36,8 +45,8 @@ type ValidationResult struct {
Error error
}
-// ValidateKey validates a commercial license key and returns the tenant ID
-// Requires LICENSE_MASTER_SECRET to be set for validation
+// ValidateKey validates a commercial license key using Ed25519 signature verification
+// Requires LICENSE_PUBLIC_KEY to be set for validation
func ValidateKey(key string) *ValidationResult {
if key == "" {
return &ValidationResult{
@@ -47,20 +56,21 @@ func ValidateKey(key string) *ValidationResult {
}
}
- if env.Config.License.MasterSecret == "" {
+ if env.Config.License.PublicKey == "" {
return &ValidationResult{
IsValid: false,
TenantID: 0,
- Error: errors.New("LICENSE_MASTER_SECRET environment variable must be set to validate license keys"),
+ Error: errors.New("LICENSE_PUBLIC_KEY environment variable must be set to validate license keys"),
}
}
+ // Parse license key format
parts := strings.Split(key, "-")
if len(parts) != 5 || parts[0] != "FIDER" || parts[1] != "COMMERCIAL" {
return &ValidationResult{
IsValid: false,
TenantID: 0,
- Error: errors.New("invalid key format: expected FIDER-COMMERCIAL-{tenantID}-{timestamp}-{hmac}"),
+ Error: errors.New("invalid key format: expected FIDER-COMMERCIAL-{tenantID}-{timestamp}-{signature}"),
}
}
@@ -82,16 +92,39 @@ func ValidateKey(key string) *ValidationResult {
}
}
- providedHash := parts[4]
+ providedSignatureHex := parts[4]
- // Recompute HMAC to verify signature
- data := fmt.Sprintf("%d-%d", tenantID, timestamp)
- mac := hmac.New(sha256.New, []byte(env.Config.License.MasterSecret))
- mac.Write([]byte(data))
- expectedHash := hex.EncodeToString(mac.Sum(nil))
+ // Decode and validate the public key
+ publicKeyBytes, err := base64.StdEncoding.DecodeString(env.Config.License.PublicKey)
+ if err != nil {
+ return &ValidationResult{
+ IsValid: false,
+ TenantID: 0,
+ Error: errors.Wrap(err, "invalid LICENSE_PUBLIC_KEY configuration"),
+ }
+ }
- // Constant-time comparison to prevent timing attacks
- if subtle.ConstantTimeCompare([]byte(expectedHash), []byte(providedHash)) != 1 {
+ if len(publicKeyBytes) != ed25519.PublicKeySize {
+ return &ValidationResult{
+ IsValid: false,
+ TenantID: 0,
+ Error: fmt.Errorf("invalid LICENSE_PUBLIC_KEY length: expected %d bytes, got %d", ed25519.PublicKeySize, len(publicKeyBytes)),
+ }
+ }
+
+ // Decode the signature from the license key
+ providedSignature, err := hex.DecodeString(providedSignatureHex)
+ if err != nil {
+ return &ValidationResult{
+ IsValid: false,
+ TenantID: 0,
+ Error: errors.Wrap(err, "invalid signature format in license key"),
+ }
+ }
+
+ // Verify the signature
+ data := fmt.Sprintf("%d-%d", tenantID, timestamp)
+ if !ed25519.Verify(ed25519.PublicKey(publicKeyBytes), []byte(data), providedSignature) {
return &ValidationResult{
IsValid: false,
TenantID: 0,
diff --git a/app/services/license/validator_test.go b/app/services/license/validator_test.go
new file mode 100644
index 000000000..6d8fbc5c8
--- /dev/null
+++ b/app/services/license/validator_test.go
@@ -0,0 +1,166 @@
+package license_test
+
+import (
+ "crypto/ed25519"
+ "crypto/rand"
+ "encoding/base64"
+ "testing"
+
+ "github.com/getfider/fider/app/pkg/env"
+ "github.com/getfider/fider/app/services/license"
+)
+
+func TestGenerateAndValidateKey_Ed25519(t *testing.T) {
+ // Generate a test key pair
+ publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // Set up environment with Ed25519 keys
+ env.Config.License.PrivateKey = base64.StdEncoding.EncodeToString(privateKey)
+ env.Config.License.PublicKey = base64.StdEncoding.EncodeToString(publicKey)
+ defer func() {
+ env.Config.License.PrivateKey = ""
+ env.Config.License.PublicKey = ""
+ }()
+
+ // Generate a license key
+ tenantID := 42
+ key := license.GenerateKey(tenantID)
+
+ // Validate the license key
+ result := license.ValidateKey(key)
+
+ if !result.IsValid {
+ t.Errorf("Expected license key to be valid, but got error: %v", result.Error)
+ }
+
+ if result.TenantID != tenantID {
+ t.Errorf("Expected tenant ID %d, got %d", tenantID, result.TenantID)
+ }
+}
+
+func TestValidateKey_Ed25519_InvalidSignature(t *testing.T) {
+ // Generate a test key pair
+ publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ env.Config.License.PrivateKey = base64.StdEncoding.EncodeToString(privateKey)
+ env.Config.License.PublicKey = base64.StdEncoding.EncodeToString(publicKey)
+ defer func() {
+ env.Config.License.PrivateKey = ""
+ env.Config.License.PublicKey = ""
+ }()
+
+ // Generate a valid license key
+ key := license.GenerateKey(42)
+
+ // Tamper with the signature (last part of the key)
+ tamperedKey := key[:len(key)-4] + "XXXX"
+
+ // Validate the tampered key
+ result := license.ValidateKey(tamperedKey)
+
+ if result.IsValid {
+ t.Error("Expected tampered license key to be invalid")
+ }
+
+ if result.Error == nil {
+ t.Error("Expected validation error for tampered key")
+ }
+}
+
+func TestValidateKey_Ed25519_WrongPublicKey(t *testing.T) {
+ // Generate two different key pairs
+ _, privateKey1, err := ed25519.GenerateKey(rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ publicKey2, _, err := ed25519.GenerateKey(rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // Generate key with one private key
+ env.Config.License.PrivateKey = base64.StdEncoding.EncodeToString(privateKey1)
+ env.Config.License.PublicKey = ""
+ defer func() {
+ env.Config.License.PrivateKey = ""
+ env.Config.License.PublicKey = ""
+ }()
+
+ key := license.GenerateKey(42)
+
+ // Try to validate with a different public key
+ env.Config.License.PrivateKey = ""
+ env.Config.License.PublicKey = base64.StdEncoding.EncodeToString(publicKey2)
+
+ result := license.ValidateKey(key)
+
+ if result.IsValid {
+ t.Error("Expected license key to be invalid when validated with wrong public key")
+ }
+}
+
+func TestValidateKey_EmptyKey(t *testing.T) {
+ result := license.ValidateKey("")
+
+ if result.IsValid {
+ t.Error("Expected empty key to be invalid")
+ }
+
+ if result.Error == nil {
+ t.Error("Expected validation error for empty key")
+ }
+}
+
+func TestValidateKey_InvalidFormat(t *testing.T) {
+ testCases := []string{
+ "INVALID-KEY",
+ "FIDER-INVALID-123-456-789",
+ "FIDER-COMMERCIAL-123", // Too few parts
+ "FIDER-COMMERCIAL-abc-456-789", // Invalid tenant ID
+ "FIDER-COMMERCIAL-123-abc-789", // Invalid timestamp
+ }
+
+ for _, key := range testCases {
+ result := license.ValidateKey(key)
+
+ if result.IsValid {
+ t.Errorf("Expected key '%s' to be invalid", key)
+ }
+
+ if result.Error == nil {
+ t.Errorf("Expected validation error for key '%s'", key)
+ }
+ }
+}
+
+func TestValidateKey_NoPublicKeyConfigured(t *testing.T) {
+ // Clear all license configuration
+ originalPrivateKey := env.Config.License.PrivateKey
+ originalPublicKey := env.Config.License.PublicKey
+
+ env.Config.License.PrivateKey = ""
+ env.Config.License.PublicKey = ""
+
+ defer func() {
+ env.Config.License.PrivateKey = originalPrivateKey
+ env.Config.License.PublicKey = originalPublicKey
+ }()
+
+ // Try to validate a key (format doesn't matter, should fail on missing config)
+ result := license.ValidateKey("FIDER-COMMERCIAL-123-456-789abc")
+
+ if result.IsValid {
+ t.Error("Expected validation to fail when no public key is configured")
+ }
+
+ if result.Error == nil {
+ t.Error("Expected error when no public key is configured")
+ }
+}
diff --git a/docs/INTERNAL_LICENSE_SETUP.md b/docs/INTERNAL_LICENSE_SETUP.md
new file mode 100644
index 000000000..dcb2a6456
--- /dev/null
+++ b/docs/INTERNAL_LICENSE_SETUP.md
@@ -0,0 +1,201 @@
+# Internal: License System Setup
+
+**This document is for internal use only** - setting up the Fider hosted instance to generate commercial licenses.
+
+## Initial Setup (One-Time)
+
+### 1. Generate License Key Pair
+
+Run the key generation script:
+
+```bash
+go run scripts/generate_license_keys.go
+```
+
+This outputs:
+```
+=== Ed25519 License Key Pair Generated ===
+
+PUBLIC KEY (for self-hosted instances):
+lPHzCZhOBBihIusKWs5lzXCgGxZEKBpCiplkmZSjGpU=
+
+PRIVATE KEY (for hosted server only - KEEP SECRET!):
+B0Srq+DtsBI6MwY4sljCywXNLWAizfCdiJ6emGx+xIqU8fMJmE4EGKEi6wpazmXNcKAbFkQoGkKKmWSZlKMalQ==
+```
+
+### 2. Configure Production Environment
+
+Add **only the private key** to the hosted instance's `.env`:
+
+```env
+LICENSE_PRIVATE_KEY=B0Srq+DtsBI6MwY4sljCywXNLWAizfCdiJ6emGx+xIqU8fMJmE4EGKEi6wpazmXNcKAbFkQoGkKKmWSZlKMalQ==
+```
+
+**Security:**
+- Never commit this to git
+- Store in secure secrets management (AWS Secrets Manager, Vault, etc.)
+- Restrict access to production environment
+
+### 3. Distribute Public Key
+
+The **public key** is safe to share publicly. Include it in:
+- Self-hosted installation documentation
+- License purchase confirmation emails
+- `.example.env` file (already done)
+- Customer support materials
+
+Current public key for distribution:
+```
+LICENSE_PUBLIC_KEY=lPHzCZhOBBihIusKWs5lzXCgGxZEKBpCiplkmZSjGpU=
+```
+
+## How License Generation Works
+
+### Automatic Generation via Stripe
+
+When a customer purchases Pro via Stripe webhook (`app/handlers/webhooks/stripe.go`):
+
+1. **Checkout completed** (`handleCheckoutSessionCompleted`):
+ - Calls `license.GenerateKey(tenantID)`
+ - Stores key in database via `ActivateStripeSubscription`
+ - Key is displayed to customer in billing page
+
+2. **Subscription cancelled** (`handleSubscriptionDeleted`):
+ - Calls `CancelStripeSubscription`
+ - Sets tenant back to free plan
+
+### Manual License Generation (if needed)
+
+If you need to manually generate a license for a customer:
+
+```go
+// In Go code or via admin endpoint
+licenseKey := license.GenerateKey(tenantID)
+// Returns: FIDER-COMMERCIAL-{tenantID}-{timestamp}-{signature}
+```
+
+The tenant ID should match the customer's tenant in your database.
+
+## Code Reference
+
+### Key Files
+
+- **Generation**: `app/services/license/validator.go` - `GenerateKey()` function
+- **Webhook**: `app/handlers/webhooks/stripe.go` - Automatic generation on purchase
+- **Storage**: `app/services/sqlstore/postgres/billing.go` - Database operations
+- **Validation**: `app/services/license/validator.go` - `ValidateKey()` function (used by self-hosted)
+
+### Database Tables
+
+- `tenants.is_pro` - Boolean flag indicating Pro subscription
+- `tenants_billing` - Stores Stripe subscription ID and license key
+
+## Testing
+
+### Test Environment
+
+The `.test.env` file contains test keys for development:
+
+```env
+LICENSE_PUBLIC_KEY=9o3OnNs9tnnD780fZcTYas8uhcA90MWtin1rWGhXVPE=
+LICENSE_PRIVATE_KEY=fwRNcFEiusrH0Hx1aBlOobE+6hm2/CPXUkUTWXj3cQn2jc6c2z22ecPvzR9lxNhqzy6FwD3Qxa2KfWtYaFdU8Q==
+```
+
+These are safe for testing and are different from production keys.
+
+### Running Tests
+
+```bash
+make test-server
+# or specifically:
+godotenv -f .test.env go test -v ./app/services/license/...
+```
+
+All tests should pass:
+- `TestGenerateAndValidateKey_Ed25519`
+- `TestValidateKey_Ed25519_InvalidSignature`
+- `TestValidateKey_Ed25519_WrongPublicKey`
+- `TestValidateKey_EmptyKey`
+- `TestValidateKey_InvalidFormat`
+- `TestValidateKey_NoPublicKeyConfigured`
+
+## Key Rotation (Emergency Procedure)
+
+If the private key is ever compromised:
+
+1. **Generate new key pair**:
+ ```bash
+ go run scripts/generate_license_keys.go
+ ```
+
+2. **Update production environment** with new `LICENSE_PRIVATE_KEY`
+
+3. **Notify all self-hosted customers**:
+ - Send new `LICENSE_PUBLIC_KEY`
+ - They must update their `.env` file
+ - Previous licenses will still work with new public key
+
+4. **Update documentation** with new public key
+
+5. **Consider**: Implement key versioning in license format for smoother transitions
+
+## Monitoring
+
+### What to Monitor
+
+- License generation failures (check Stripe webhook logs)
+- Invalid license validation attempts on hosted instance
+- Customer support tickets about license issues
+
+### Logs to Watch
+
+```bash
+# License generation
+grep "GenerateKey" /var/log/fider/app.log
+
+# Stripe webhook events
+grep "stripe" /var/log/fider/app.log | grep "checkout\|subscription"
+```
+
+## Support Scenarios
+
+### Customer Reports License Not Working
+
+1. Verify they have correct `LICENSE_PUBLIC_KEY` in their `.env`
+2. Check their license key format is correct
+3. Test their license key validation locally:
+ ```bash
+ # Set up test environment with their key
+ LICENSE_PUBLIC_KEY=<current_public_key> \
+ go run scripts/validate_license.go "FIDER-COMMERCIAL-xxx-xxx-xxx"
+ ```
+4. Check if license was successfully generated in database
+5. If needed, manually regenerate license for their tenant ID
+
+### Customer Wants to Transfer License
+
+Licenses are tied to tenant ID. To transfer:
+- Generate new license for new tenant ID
+- Cancel old subscription/license
+- Update billing records
+
+## Security Best Practices
+
+1. **Never** share or commit the private key
+2. **Always** use environment variables for production
+3. **Rotate** keys if any compromise is suspected
+4. **Audit** license generation logs periodically
+5. **Monitor** for unusual patterns (same license on multiple IPs)
+6. **Backup** production environment configuration securely
+
+## Production Checklist
+
+Before deploying to production:
+
+- [ ] Production `LICENSE_PRIVATE_KEY` is set and secured
+- [ ] Public key is distributed in documentation
+- [ ] Stripe webhook is configured and tested
+- [ ] All tests pass
+- [ ] Monitoring/logging is in place
+- [ ] Support team knows how to help customers with license issues
+- [ ] Emergency key rotation procedure is documented
diff --git a/docs/LICENSE_SYSTEM.md b/docs/LICENSE_SYSTEM.md
new file mode 100644
index 000000000..e735eda29
--- /dev/null
+++ b/docs/LICENSE_SYSTEM.md
@@ -0,0 +1,84 @@
+# Commercial License System
+
+This document explains how to enable commercial features on your self-hosted Fider instance using a license key.
+
+## Overview
+
+Fider's commercial features (like content moderation) require a valid license key. When you purchase a Pro subscription from the hosted Fider platform, you'll receive a license key that you can use to unlock these features on your self-hosted instance.
+
+## Enabling Commercial Features
+
+### Step 1: Purchase a Pro Subscription
+
+Visit the hosted Fider platform and subscribe to the Pro plan. After your payment is processed, you'll receive a commercial license key.
+
+### Step 2: Configure Your Self-Hosted Instance
+
+Add the following to your `.env` file:
+
+```env
+# Public key for license validation (provided by Fider)
+LICENSE_PUBLIC_KEY=lPHzCZhOBBihIusKWs5lzXCgGxZEKBpCiplkmZSjGpU=
+
+# Your commercial license key (received after purchase)
+COMMERCIAL_KEY=FIDER-COMMERCIAL-xxx-xxx-xxx
+```
+
+### Step 3: Restart Fider
+
+Restart your Fider instance. Commercial features (like content moderation) will now be enabled.
+
+## How It Works
+
+Your license key is validated locally when Fider starts:
+
+1. Reads `COMMERCIAL_KEY` from your environment
+2. Verifies the cryptographic signature using `LICENSE_PUBLIC_KEY`
+3. If valid, enables commercial features
+
+**No internet connection required** - validation happens entirely on your server.
+
+## Security & Privacy
+
+Fider uses **Ed25519 cryptographic signatures** to validate license keys:
+
+- ✅ **Secure**: Modern elliptic curve cryptography
+- ✅ **Private**: No phone-home or tracking
+- ✅ **Offline**: Works without internet connection
+- ✅ **Trustworthy**: Public key cryptography prevents forgery
+
+## Troubleshooting
+
+### Commercial features are not enabled
+
+**Check the following:**
+
+1. Both `COMMERCIAL_KEY` and `LICENSE_PUBLIC_KEY` are set in your `.env` file
+2. The `LICENSE_PUBLIC_KEY` matches the one provided by Fider
+3. Your license key is in the correct format: `FIDER-COMMERCIAL-{numbers}-{numbers}-{hex}`
+4. You restarted Fider after adding the configuration
+5. Check your logs for validation errors
+
+### "LICENSE_PUBLIC_KEY environment variable must be set"
+
+**Problem:** Fider cannot validate your license without the public key.
+
+**Solution:** Add `LICENSE_PUBLIC_KEY` to your `.env` file (provided in your license email or documentation).
+
+### "invalid signature: license key verification failed"
+
+**Problem:** Your license key cannot be verified.
+
+**Possible causes:**
+- Wrong `LICENSE_PUBLIC_KEY` (make sure it matches what Fider provided)
+- License key was incorrectly copied (check for typos or missing characters)
+- License key is not valid for this installation
+
+**Solution:** Double-check both the public key and license key match what you received from Fider. If issues persist, contact support.
+
+## Support
+
+If you have issues with your commercial license, please contact Fider support with:
+- Your license key
+- Fider version
+- Any error messages from logs
diff --git a/scripts/generate_license_keys.go b/scripts/generate_license_keys.go
new file mode 100644
index 000000000..30c3e60ec
--- /dev/null
+++ b/scripts/generate_license_keys.go
@@ -0,0 +1,40 @@
+package main
+
+import (
+ "crypto/ed25519"
+ "crypto/rand"
+ "encoding/base64"
+ "fmt"
+ "log"
+)
+
+// This script generates an Ed25519 key pair for the commercial license system.
+// For setup instructions, see docs/INTERNAL_LICENSE_SETUP.md
+
+func main() {
+ // Generate Ed25519 key pair
+ publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Encode as base64 for easy storage in env files
+ publicKeyB64 := base64.StdEncoding.EncodeToString(publicKey)
+ privateKeyB64 := base64.StdEncoding.EncodeToString(privateKey)
+
+ fmt.Println("=== Ed25519 License Key Pair Generated ===")
+ fmt.Println()
+ fmt.Println("PUBLIC KEY (for self-hosted instances):")
+ fmt.Println(publicKeyB64)
+ fmt.Println()
+ fmt.Println("PRIVATE KEY (for hosted server only - KEEP SECRET!):")
+ fmt.Println(privateKeyB64)
+ fmt.Println()
+ fmt.Println("Add to production .env:")
+ fmt.Println("LICENSE_PRIVATE_KEY=" + privateKeyB64)
+ fmt.Println()
+ fmt.Println("Distribute to self-hosted customers:")
+ fmt.Println("LICENSE_PUBLIC_KEY=" + publicKeyB64)
+ fmt.Println()
+ fmt.Println("For full setup instructions, see docs/INTERNAL_LICENSE_SETUP.md")
+}