Open platform to collect and prioritize feedback
More certificate stuff.
Matt Robertsdf060dbf699f
diff --git a/.example.env b/.example.envindex f22ab3deb..a99492ca5 100644--- a/.example.env+++ b/.example.env@@ -34,18 +34,20 @@ EMAIL_SMTP_PORT=1025EMAIL_SMTP_USERNAME=EMAIL_SMTP_PASSWORD=-# Commercial License (Optional for self-hosted, Required for hosted multi-tenant)+# Commercial License (Optional)#-# 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+# COMMERCIAL_KEY: Your commercial license key from the hosted Fider platform+# - Purchase a Pro subscription to get a license key+# - Add it here to enable commercial features (content moderation)+# - Leave blank to run Fider in free/open-source mode+# COMMERCIAL_KEY=FIDER-COMMERCIAL-123-1638360000-abc123...#-# 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: (Advanced - usually not needed)+# - The public key is embedded in Fider and updates automatically+# - Only set this if instructed by support or for testing# LICENSE_PUBLIC_KEY=lPHzCZhOBBihIusKWs5lzXCgGxZEKBpCiplkmZSjGpU=-# COMMERCIAL_KEY=FIDER-COMMERCIAL-123-1638360000-abc123...+#+# LICENSE_PRIVATE_KEY: (Internal - for hosted instance only)+# - Used by the hosted Fider platform to generate license keys+# - Self-hosted users should NOT set this+# LICENSE_PRIVATE_KEY=your-base64-encoded-private-key-herediff --git a/app/services/license/validator.go b/app/services/license/validator.goindex 97b1c4dae..4b18ba33c 100644--- a/app/services/license/validator.go+++ b/app/services/license/validator.go@@ -13,6 +13,12 @@ import ("github.com/getfider/fider/app/pkg/errors")+// DefaultPublicKey is the embedded public key for license validation+// This is the public key from the hosted Fider instance+// Self-hosted instances automatically use this - no configuration needed+// Can be overridden via LICENSE_PUBLIC_KEY environment variable+const DefaultPublicKey = "EpyoY4Fc3TroE7MIEWlLHU8OGaEiPkPhOy+RVwwC1zk="+// 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@@ -46,7 +52,7 @@ type ValidationResult struct {}// ValidateKey validates a commercial license key using Ed25519 signature verification-// Requires LICENSE_PUBLIC_KEY to be set for validation+// Uses embedded DefaultPublicKey unless LICENSE_PUBLIC_KEY environment variable is setfunc ValidateKey(key string) *ValidationResult {if key == "" {return &ValidationResult{@@ -56,12 +62,10 @@ func ValidateKey(key string) *ValidationResult {}}- if env.Config.License.PublicKey == "" {- return &ValidationResult{- IsValid: false,- TenantID: 0,- Error: errors.New("LICENSE_PUBLIC_KEY environment variable must be set to validate license keys"),- }+ // Use environment variable if set, otherwise use embedded default+ publicKey := env.Config.License.PublicKey+ if publicKey == "" {+ publicKey = DefaultPublicKey}// Parse license key format@@ -95,12 +99,12 @@ func ValidateKey(key string) *ValidationResult {providedSignatureHex := parts[4]// Decode and validate the public key- publicKeyBytes, err := base64.StdEncoding.DecodeString(env.Config.License.PublicKey)+ publicKeyBytes, err := base64.StdEncoding.DecodeString(publicKey)if err != nil {return &ValidationResult{IsValid: false,TenantID: 0,- Error: errors.Wrap(err, "invalid LICENSE_PUBLIC_KEY configuration"),+ Error: errors.Wrap(err, "invalid public key configuration"),}}@@ -108,7 +112,7 @@ func ValidateKey(key string) *ValidationResult {return &ValidationResult{IsValid: false,TenantID: 0,- Error: fmt.Errorf("invalid LICENSE_PUBLIC_KEY length: expected %d bytes, got %d", ed25519.PublicKeySize, len(publicKeyBytes)),+ Error: fmt.Errorf("invalid public key length: expected %d bytes, got %d", ed25519.PublicKeySize, len(publicKeyBytes)),}}diff --git a/app/services/license/validator_test.go b/app/services/license/validator_test.goindex 6d8fbc5c8..804444b2d 100644--- a/app/services/license/validator_test.go+++ b/app/services/license/validator_test.go@@ -140,27 +140,32 @@ func TestValidateKey_InvalidFormat(t *testing.T) {}}-func TestValidateKey_NoPublicKeyConfigured(t *testing.T) {- // Clear all license configuration+func TestValidateKey_UsesEmbeddedDefault(t *testing.T) {+ // Clear LICENSE_PUBLIC_KEY to test embedded defaultoriginalPrivateKey := env.Config.License.PrivateKeyoriginalPublicKey := env.Config.License.PublicKey- env.Config.License.PrivateKey = ""- env.Config.License.PublicKey = ""+ // Set private key to match the embedded public key (lPHzCZhOBBihIusKWs5lzXCgGxZEKBpCiplkmZSjGpU=)+ // This is the corresponding private key for the DefaultPublicKey+ env.Config.License.PrivateKey = "B0Srq+DtsBI6MwY4sljCywXNLWAizfCdiJ6emGx+xIqU8fMJmE4EGKEi6wpazmXNcKAbFkQoGkKKmWSZlKMalQ=="+ env.Config.License.PublicKey = "" // Leave empty to test embedded defaultdefer func() {env.Config.License.PrivateKey = originalPrivateKeyenv.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")+ // Generate a key with the private key+ key := license.GenerateKey(123)- if result.IsValid {- t.Error("Expected validation to fail when no public key is configured")+ // Validate without setting LICENSE_PUBLIC_KEY - should use embedded default+ result := license.ValidateKey(key)++ if !result.IsValid {+ t.Errorf("Expected license key to be valid using embedded default public key, but got error: %v", result.Error)}- if result.Error == nil {- t.Error("Expected error when no public key is configured")+ if result.TenantID != 123 {+ t.Errorf("Expected tenant ID 123, got %d", result.TenantID)}}diff --git a/docs/INTERNAL_LICENSE_SETUP.md b/docs/INTERNAL_LICENSE_SETUP.mdindex dcb2a6456..7ed391cae 100644--- a/docs/INTERNAL_LICENSE_SETUP.md+++ b/docs/INTERNAL_LICENSE_SETUP.md@@ -36,17 +36,24 @@ LICENSE_PRIVATE_KEY=B0Srq+DtsBI6MwY4sljCywXNLWAizfCdiJ6emGx+xIqU8fMJmE4EGKEi6wpa- Store in secure secrets management (AWS Secrets Manager, Vault, etc.)- Restrict access to production environment-### 3. Distribute Public Key+### 3. Embed Public Key in Code-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+The **public key** is embedded in `app/services/license/validator.go` as `DefaultPublicKey`.-Current public key for distribution:+**When you generate a new key pair:**++1. Update the constant in `validator.go`:+ ```go+ const DefaultPublicKey = "your-new-public-key-here"+ ```++2. Self-hosted customers get the new key automatically when they upgrade Fider++3. No manual configuration needed by customers - it "just works"++Current embedded public key:```-LICENSE_PUBLIC_KEY=lPHzCZhOBBihIusKWs5lzXCgGxZEKBpCiplkmZSjGpU=+lPHzCZhOBBihIusKWs5lzXCgGxZEKBpCiplkmZSjGpU=```## How License Generation Works@@ -130,14 +137,22 @@ If the private key is ever compromised: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+3. **Update embedded public key** in `app/services/license/validator.go`:+ ```go+ const DefaultPublicKey = "new-public-key-here"+ ```++4. **Release new Fider version**-4. **Update documentation** with new public key+5. **Communicate to customers**:+ - "Please update to Fider vX.X.X for important security improvements"+ - They update Fider → automatically get new public key → existing licenses keep working+ - No manual configuration needed-5. **Consider**: Implement key versioning in license format for smoother transitions+**Important**: Old licenses signed with the old private key won't validate with the new public key. You'll need to:+- Regenerate licenses for all active Pro customers (using their tenant IDs)+- Send new license keys to customers+- Or: Implement multi-key support to validate both old and new licenses during transition## Monitoringdiff --git a/docs/LICENSE_SYSTEM.md b/docs/LICENSE_SYSTEM.mdindex e735eda29..c8f950451 100644--- a/docs/LICENSE_SYSTEM.md+++ b/docs/LICENSE_SYSTEM.md@@ -14,16 +14,15 @@ Visit the hosted Fider platform and subscribe to the Pro plan. After your paymen### Step 2: Configure Your Self-Hosted Instance-Add the following to your `.env` file:+Add your license key 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```+**That's it!** The public key for validation is already embedded in Fider - no additional configuration needed.+### Step 3: Restart FiderRestart your Fider instance. Commercial features (like content moderation) will now be enabled.@@ -33,11 +32,23 @@ Restart your Fider instance. Commercial features (like content moderation) willYour license key is validated locally when Fider starts:1. Reads `COMMERCIAL_KEY` from your environment-2. Verifies the cryptographic signature using `LICENSE_PUBLIC_KEY`+2. Verifies the cryptographic signature using the embedded public key3. If valid, enables commercial features**No internet connection required** - validation happens entirely on your server.+### Advanced: Overriding the Public Key++The public key is embedded in Fider's code, so it updates automatically when you upgrade Fider. However, you can override it if needed:++```env+LICENSE_PUBLIC_KEY=your-custom-public-key-here+```++You typically **don't need** to set this unless:+- You're testing with a custom license system+- Fider support specifically instructs you to update it+## Security & PrivacyFider uses **Ed25519 cryptographic signatures** to validate license keys:@@ -53,28 +64,25 @@ Fider uses **Ed25519 cryptographic signatures** to validate license keys:**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+1. `COMMERCIAL_KEY` is set in your `.env` file+2. Your license key is in the correct format: `FIDER-COMMERCIAL-{numbers}-{numbers}-{hex}`+3. You restarted Fider after adding the configuration+4. You're running a recent version of Fider (with the embedded public key)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+- You're running an outdated version of Fider (update to get the latest public key)+- License key is not valid-**Solution:** Double-check both the public key and license key match what you received from Fider. If issues persist, contact support.+**Solution:**+1. Verify your license key is copied correctly+2. Update to the latest Fider version+3. If issues persist, contact support## Support