Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add init.sh script for initial setup (#33)

Leendert de Borst383145814add
diff --git a/.env b/.env
new file mode 100644
index 000000000..ec4d9f306
--- /dev/null
+++ b/.env
@@ -0,0 +1 @@
+JWT_KEY=YprFMYAzrqY/R/DmDYZI1PS7qTyZYp4g
diff --git a/.env.example b/.env.example
index 0c875568f..67eed3107 100644
--- a/.env.example
+++ b/.env.example
@@ -1 +1 @@
-JWT_Key=
+JWT_KEY=
diff --git a/README.md b/README.md
index a929a1a34..076c46642 100644
--- a/README.md
+++ b/README.md
@@ -1,56 +1,70 @@
-<div align="center">
-
-<h1>AliasVault</h1>
-
-[<img src="https://img.shields.io/github/v/release/lanedirt/AliasVault?include_prereleases&logo=github">](https://github.com/lanedirt/OGameX/releases)
-[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/docker-compose-build.yml?label=docker-compose%20build">](https://github.com/lanedirt/AliasVault/actions/workflows/docker-compose-build.yml)
-[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/dotnet-build-run-tests.yml?label=unit tests">](https://github.com/lanedirt/AliasVault/actions/workflows/dotnet-build-run-tests.yml)
-[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/dotnet-integration-tests.yml?label=e2e tests">](https://github.com/lanedirt/AliasVault/actions/workflows/dotnet-integration-tests.yml)
-[<img src="https://img.shields.io/sonar/coverage/lanedirt_AliasVault?server=https%3A%2F%2Fsonarcloud.io&label=test code coverage">](https://sonarcloud.io/summary/new_code?id=lanedirt_AliasVault)
-[<img src="https://img.shields.io/sonar/quality_gate/lanedirt_AliasVault?server=https%3A%2F%2Fsonarcloud.io&label=sonarcloud&logo=sonarcloud">](https://sonarcloud.io/summary/new_code?id=lanedirt_AliasVault)
-</div>
-
-> Disclaimer: This repository is currently in an alpha state and is NOT ready for production use. Critical features, such as encryption, are not yet fully implemented. AliasVault is a work in progress and as of this moment serves as a research playground. Users are welcome to explore and use this project, but please be aware that there are no guarantees regarding its security or stability. Use at your own risk!
-
-AliasVault is an open-source password manager that can generate virtual identities complete with virtual email addresses. AliasVault can be self-hosted on your own server with Docker, providing a secure and private solution for managing your online identities and passwords.
-
-## Features
-- **Password Management:** Securely store and manage your passwords.
-- **Virtual Identities:** Generate virtual identities with virtual (working) email addresses that are assigned to one or more passwords.
-- **Zero-knowledge architecture:** Ensures that all sensitive data is end-to-end encrypted on the client and stored in encrypted state on the database. The server never has access to your data.
-
-## Installation
-
-1. Clone this repository.
-
-```bash
-git clone https://github.com/lanedirt/AliasVault.git
-```
-
-2. Build and run the app via Docker:
-
-```bash
-docker compose up -d --build --force-recreate
-```
-
-### Note for first time build:
-- When running the app for the first time, it may take a few minutes to build the Docker image.
-- Two files will be created during build (if they don't yet exist):
- - **Database:** `./database/aliasdb.sqlite`
- - This SQLite file contains the database and in it all (encrypted) password vaults. It should be kept secure and not shared.
- - **Encryption secrets:** `./.env`
- - This file contains the JWT secret that is used to generate user access tokens for login and should be kept secret.
-
-
-
-After the Docker containers have started the app will be available at http://localhost:80
-
-## Tech stack / credits
-The following technologies, frameworks and libraries are used in this project:
-
-- [C#](https://docs.microsoft.com/en-us/dotnet/csharp/) - A simple, modern, object-oriented, and type-safe programming language.
-- [ASP.NET Core](https://dotnet.microsoft.com/apps/aspnet) - An open-source framework for building modern, cloud-based, internet-connected applications.
-- [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) - A lightweight, extensible, open-source and cross-platform version of the popular Entity Framework data access technology. - [Blazor WASM](https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor) - A framework for building interactive web UIs using C# instead of JavaScript. It's a single-page app framework that runs in the browser via WebAssembly. - [Docker](https://www.docker.com/) - A platform for building, sharing, and running containerized applications. - [SQLite](https://www.sqlite.org/index.html) - A C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine.
-- [Tailwind CSS](https://tailwindcss.com/) - A utility-first CSS framework for rapidly building custom designs.
-- [Flowbite](https://flowbite.com/) - A free and open-source UI component library based on Tailwind CSS.
-- [Konscious.Security.Cryptography](https://github.com/kmaragon/Konscious.Security.Cryptography) - A .NET library that implements Argon2id, a memory-hard password hashing algorithm.
+<div align="center">
+
+<h1>AliasVault</h1>
+
+[<img src="https://img.shields.io/github/v/release/lanedirt/AliasVault?include_prereleases&logo=github">](https://github.com/lanedirt/OGameX/releases)
+[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/docker-compose-build.yml?label=docker-compose%20build">](https://github.com/lanedirt/AliasVault/actions/workflows/docker-compose-build.yml)
+[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/dotnet-build-run-tests.yml?label=unit tests">](https://github.com/lanedirt/AliasVault/actions/workflows/dotnet-build-run-tests.yml)
+[<img src="https://img.shields.io/github/actions/workflow/status/lanedirt/AliasVault/dotnet-integration-tests.yml?label=e2e tests">](https://github.com/lanedirt/AliasVault/actions/workflows/dotnet-integration-tests.yml)
+[<img src="https://img.shields.io/sonar/coverage/lanedirt_AliasVault?server=https%3A%2F%2Fsonarcloud.io&label=test code coverage">](https://sonarcloud.io/summary/new_code?id=lanedirt_AliasVault)
+[<img src="https://img.shields.io/sonar/quality_gate/lanedirt_AliasVault?server=https%3A%2F%2Fsonarcloud.io&label=sonarcloud&logo=sonarcloud">](https://sonarcloud.io/summary/new_code?id=lanedirt_AliasVault)
+</div>
+
+> Disclaimer: This repository is currently in an alpha state and is NOT ready for production use. Critical features, such as encryption, are not yet fully implemented. AliasVault is a work in progress and as of this moment serves as a research playground. Users are welcome to explore and use this project, but please be aware that there are no guarantees regarding its security or stability. Use at your own risk!
+
+AliasVault is an open-source password manager that can generate virtual identities complete with virtual email addresses. AliasVault can be self-hosted on your own server with Docker, providing a secure and private solution for managing your online identities and passwords.
+
+## Features
+- **Password Management:** Securely store and manage your passwords.
+- **Virtual Identities:** Generate virtual identities with virtual (working) email addresses that are assigned to one or more passwords.
+- **Zero-knowledge architecture:** Ensures that all sensitive data is end-to-end encrypted on the client and stored in encrypted state on the database. The server never has access to your data.
+
+## Installation
+
+### 1. Clone this repository.
+
+```bash
+# Clone this Git repository to "AliasVault" directory
+$ git clone https://github.com/lanedirt/AliasVault.git
+```
+
+### 2. Run the init script to set up the .env file and generate a random encryption secret.
+This script will create a .env file in the root directory of the project if it does not yet exist and populate it with a random encryption secret.
+```bash
+# Go to the project directory
+$ cd AliasVault
+
+# Make init script executable
+$ chmod +x init.sh
+
+# Run the init script
+$ ./init.sh
+```
+
+### 3. Build and run the app via Docker:
+
+```bash
+# Build and run the app via Docker Compose
+$ docker compose up -d --build --force-recreate
+```
+> Note: the container binds to port 80 by default. If you have another service running on port 80, you can change the port in the `docker-compose.yml` file.
+
+
+#### Note for first time build:
+- When running the app for the first time, it may take a few minutes to build the Docker image.
+- A SQLite database file will be created in `./database/aliasdb.sqlite`. This file will store all (encrypted) password vaults. It should be kept secure and not shared.
+
+After the Docker containers have started the app will be available at http://localhost:80
+
+## Tech stack / credits
+The following technologies, frameworks and libraries are used in this project:
+
+- [C#](https://docs.microsoft.com/en-us/dotnet/csharp/) - A simple, modern, object-oriented, and type-safe programming language.
+- [ASP.NET Core](https://dotnet.microsoft.com/apps/aspnet) - An open-source framework for building modern, cloud-based, internet-connected applications.
+- [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) - A lightweight, extensible, open-source and cross-platform version of the popular Entity Framework data access technology.
+- [Blazor WASM](https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor) - A framework for building interactive web UIs using C# instead of JavaScript. It's a single-page app framework that runs in the browser via WebAssembly.
+- [Docker](https://www.docker.com/) - A platform for building, sharing, and running containerized applications.
+- [SQLite](https://www.sqlite.org/index.html) - A C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine.
+- [Tailwind CSS](https://tailwindcss.com/) - A utility-first CSS framework for rapidly building custom designs.
+- [Flowbite](https://flowbite.com/) - A free and open-source UI component library based on Tailwind CSS.
+- [Konscious.Security.Cryptography](https://github.com/kmaragon/Konscious.Security.Cryptography) - A .NET library that implements Argon2id, a memory-hard password hashing algorithm.
diff --git a/init.sh b/init.sh
new file mode 100755
index 000000000..0790d3e0c
--- /dev/null
+++ b/init.sh
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+# Define colors for CLI output
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[0;33m'
+BLUE='\033[0;34m'
+MAGENTA='\033[0;35m'
+CYAN='\033[0;36m'
+NC='\033[0m' # No Color
+
+# Define the path to the .env and .env.example files
+ENV_FILE=".env"
+ENV_EXAMPLE_FILE=".env.example"
+
+# Function to generate a new 32-character JWT key
+generate_jwt_key() {
+ dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 | head -c 32
+}
+
+# Function to create .env file from .env.example if it doesn't exist
+create_env_file() {
+ if [ ! -f "$ENV_FILE" ]; then
+ if [ -f "$ENV_EXAMPLE_FILE" ]; then
+ cp "$ENV_EXAMPLE_FILE" "$ENV_FILE"
+ echo "${GREEN}> .env file created from .env.example.${NC}"
+ else
+ touch "$ENV_FILE"
+ echo "${YELLOW}> .env file created as empty because .env.example was not found.${NC}"
+ fi
+ else
+ echo "${CYAN}> .env file already exists.${NC}"
+ fi
+}
+
+# Function to check and populate the .env file with JWT_KEY
+populate_jwt_key() {
+ if ! grep -q "^JWT_KEY=" "$ENV_FILE" || [ -z "$(grep "^JWT_KEY=" "$ENV_FILE" | cut -d '=' -f2)" ]; then
+ echo "${YELLOW}JWT_KEY not found or empty in $ENV_FILE. Generating a new JWT key...${NC}"
+ JWT_KEY=$(generate_jwt_key)
+ if grep -q "^JWT_KEY=" "$ENV_FILE"; then
+ awk -v key="$JWT_KEY" '/^JWT_KEY=/ {$0="JWT_KEY="key} 1' "$ENV_FILE" > "$ENV_FILE.tmp" && mv "$ENV_FILE.tmp" "$ENV_FILE"
+ else
+ echo "JWT_KEY=${JWT_KEY}" >> "$ENV_FILE"
+ fi
+ echo "${GREEN}> JWT_KEY has been added to $ENV_FILE.${NC}"
+ else
+ echo "${CYAN}> JWT_KEY already exists and has a value in $ENV_FILE.${NC}"
+ fi
+}
+
+# Function to print the CLI logo
+print_logo() {
+ echo "${MAGENTA}"
+ echo "========================================================="
+ echo " _ _ __ __ _ _ "
+ echo " /\ | (_) \ \ / / | | | "
+ echo " / \ | |_ __ _ __\ \ / /_ _ _ _| | |_"
+ echo " / /\ \ | | |/ _ / __\ \/ / _ | | | | | __|"
+ echo " / ____ \| | | (_| \__ \\ / (_| | |_| | | |_ "
+ echo " /_/ \_\_|_|\__,_|___/ \/ \__,_|\__,_|_|\__|"
+ echo ""
+ echo "========================================================="
+ echo "${NC}"
+}
+
+# Run the functions and print status
+print_logo
+echo "${BLUE}Initializing AliasVault...${NC}"
+create_env_file
+populate_jwt_key
+echo "${BLUE}Initialization complete.${NC}"
+echo ""
+echo "To build the images and start the containers, run the following command:"
+echo ""
+echo "${CYAN}$ docker compose up -d --build --force-recreate${NC}"
+echo ""
+echo ""
diff --git a/src/AliasGenerators/Identity/Implementations/FigIdentityGenerator.cs b/src/AliasGenerators/Identity/Implementations/FigIdentityGenerator.cs
index ecf246297..b5128eadb 100644
--- a/src/AliasGenerators/Identity/Implementations/FigIdentityGenerator.cs
+++ b/src/AliasGenerators/Identity/Implementations/FigIdentityGenerator.cs
@@ -13,9 +13,9 @@ using System.Text.Json;
/// </summary>
public class FigIdentityGenerator : IIdentityGenerator
{
- private static readonly HttpClient _httpClient = new();
- private static readonly string _url = "https://api.identiteitgenerator.nl/generate/identity";
- private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
+ private static readonly HttpClient HttpClient = new();
+ private static readonly string Url = "https://api.identiteitgenerator.nl/generate/identity";
+ private static readonly JsonSerializerOptions JsonSerializerOptions = new()
{
PropertyNameCaseInsensitive = true,
};
@@ -23,11 +23,11 @@ public class FigIdentityGenerator : IIdentityGenerator
/// <inheritdoc/>
public async Task<Identity.Models.Identity> GenerateRandomIdentityAsync()
{
- var response = await _httpClient.GetAsync(_url);
+ var response = await HttpClient.GetAsync(Url);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
- var identity = JsonSerializer.Deserialize<Identity.Models.Identity>(json, _jsonSerializerOptions);
+ var identity = JsonSerializer.Deserialize<Identity.Models.Identity>(json, JsonSerializerOptions);
if (identity is null)
{
diff --git a/src/AliasVault.Api/Controllers/AuthController.cs b/src/AliasVault.Api/Controllers/AuthController.cs
index 56152228b..c68cf1b97 100644
--- a/src/AliasVault.Api/Controllers/AuthController.cs
+++ b/src/AliasVault.Api/Controllers/AuthController.cs
@@ -195,7 +195,13 @@ public class AuthController(AliasDbContext context, UserManager<IdentityUser> us
new(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
};
- var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"] ?? string.Empty));
+ var jwtKey = Environment.GetEnvironmentVariable("JWT_KEY");
+ if (jwtKey is null)
+ {
+ throw new KeyNotFoundException("JWT_KEY environment variable is not set.");
+ }
+
+ var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var token = new JwtSecurityToken(
diff --git a/src/AliasVault.Api/Dockerfile b/src/AliasVault.Api/Dockerfile
index cdbea45c7..e44dc1af0 100644
--- a/src/AliasVault.Api/Dockerfile
+++ b/src/AliasVault.Api/Dockerfile
@@ -14,17 +14,6 @@ COPY ["src/AliasVault.Shared/AliasVault.Shared.csproj", "src/AliasVault.Shared/"
COPY ["src/AliasGenerators/AliasGenerators.csproj", "src/AliasGenerators/"]
RUN dotnet restore "src/AliasVault.Api/AliasVault.Api.csproj"
-# Copy .env.example to .env if .env does not exist
-RUN test -f .env || cp .env.example .env
-
-# Generate a random JWT key if not set
-RUN if [ -z "$(grep ^JWT_KEY= .env | cut -d '=' -f2)" ]; then \
- echo "Generating JWT key..."; \
- JWT_KEY=$(openssl rand -base64 32); \
- sed -i "/^JWT_KEY=/c\JWT_KEY=${JWT_KEY}" .env; \
- dos2unix .env; \
-fi
-
# Copy the rest of the application code
COPY . .
diff --git a/src/AliasVault.Api/Properties/launchSettings.json b/src/AliasVault.Api/Properties/launchSettings.json
index b3e6b7f8f..e6d132568 100644
--- a/src/AliasVault.Api/Properties/launchSettings.json
+++ b/src/AliasVault.Api/Properties/launchSettings.json
@@ -6,7 +6,7 @@
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
- "JWT_Key": "12345678901234567890123456789012"
+ "JWT_KEY": "12345678901234567890123456789012"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5092"
@@ -17,7 +17,7 @@
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
- "JWT_Key": "12345678901234567890123456789012"
+ "JWT_KEY": "12345678901234567890123456789012"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7223;http://localhost:5092"
@@ -40,4 +40,4 @@
"sslPort": 44368
}
}
-}
\ No newline at end of file
+}