From b9c4ca04f5b59003f7e1732cfc0bc20f423e1a73 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Fri, 2 May 2025 18:48:35 +0200 Subject: [PATCH] allow to encrypt keys in db, add browser-only key generator, add hints that private keys are stored on the server (#420) --- cmd/wg-portal/main.go | 3 + docs/documentation/configuration/examples.md | 1 + docs/documentation/configuration/overview.md | 8 + frontend/src/App.vue | 3 + .../src/components/InterfaceEditModal.vue | 4 +- frontend/src/components/PeerEditModal.vue | 7 +- frontend/src/components/UserPeerEditModal.vue | 7 +- frontend/src/lang/translations/de.json | 25 +- frontend/src/lang/translations/en.json | 25 +- frontend/src/router/index.js | 12 +- frontend/src/views/KeyGeneraterView.vue | 241 ++++++++++++++++++ internal/app/gorm_encryption.go | 201 +++++++++++++++ internal/config/database.go | 3 + internal/domain/crypto.go | 2 +- internal/domain/peer.go | 4 +- 15 files changed, 529 insertions(+), 17 deletions(-) create mode 100644 frontend/src/views/KeyGeneraterView.vue create mode 100644 internal/app/gorm_encryption.go diff --git a/cmd/wg-portal/main.go b/cmd/wg-portal/main.go index 9a24566..456290c 100644 --- a/cmd/wg-portal/main.go +++ b/cmd/wg-portal/main.go @@ -9,6 +9,7 @@ import ( "github.com/go-playground/validator/v10" evbus "github.com/vardius/message-bus" + "gorm.io/gorm/schema" "github.com/h44z/wg-portal/internal" "github.com/h44z/wg-portal/internal/adapters" @@ -41,6 +42,8 @@ func main() { cfg.LogStartupValues() + dbEncryptedSerializer := app.NewGormEncryptedStringSerializer(cfg.Database.EncryptionPassphrase) + schema.RegisterSerializer("encstr", dbEncryptedSerializer) rawDb, err := adapters.NewDatabase(cfg.Database) internal.AssertNoError(err) diff --git a/docs/documentation/configuration/examples.md b/docs/documentation/configuration/examples.md index 5912e34..46e7ed1 100644 --- a/docs/documentation/configuration/examples.md +++ b/docs/documentation/configuration/examples.md @@ -31,6 +31,7 @@ database: debug: true type: sqlite dsn: data/sqlite.db + encryption_passphrase: change-this-s3cr3t-encryption-passphrase ``` ## LDAP Authentication and Synchronization diff --git a/docs/documentation/configuration/overview.md b/docs/documentation/configuration/overview.md index a155696..ca75637 100644 --- a/docs/documentation/configuration/overview.md +++ b/docs/documentation/configuration/overview.md @@ -214,6 +214,8 @@ Additional or more specialized configuration options for logging and interface c Configuration for the underlying database used by WireGuard Portal. Supported databases include SQLite, MySQL, Microsoft SQL Server, and Postgres. +If sensitive values (like private keys) should be stored in an encrypted format, set the `encryption_passphrase` option. + ### `debug` - **Default:** `false` - **Description:** If `true`, logs all database statements (verbose). @@ -234,6 +236,12 @@ Supported databases include SQLite, MySQL, Microsoft SQL Server, and Postgres. user:pass@tcp(1.2.3.4:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local ``` +### `encryption_passphrase` +- **Default:** *(empty)* +- **Description:** Passphrase for encrypting sensitive values such as private keys in the database. Encryption is only applied if this passphrase is set. + **Important:** Once you enable encryption by setting this passphrase, you cannot disable it or change it afterward. + New or updated records will be encrypted; existing data remains in plaintext until it’s next modified. + --- ## Statistics diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 6e1aa81..53a4b7c 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -85,6 +85,9 @@ const currentYear = ref(new Date().getFullYear()) +