Skip to content

Commit 1a8e56e

Browse files
authored
Encryption removed (#674)
* wip: removing crypto code * refactor: remove DB encryption refs; update docs and comments * feat: bumped mostro-core version - removed some comment about encryption * chore: fix clippy * chore: fix fmt * chore: rabbit nipticks * fix: fixed in a proper way the full privacy mode child orders creation
1 parent f9d77da commit 1a8e56e

21 files changed

Lines changed: 97 additions & 445 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ lnurl-test-server/target
77
# IDE's
88
.idea
99
.vscode
10+
.cursor
1011

1112
# settings file
1213
settings.toml

Cargo.lock

Lines changed: 4 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ reqwest = { version = "0.12.1", default-features = false, features = [
7070
"json",
7171
"rustls-tls",
7272
] }
73-
mostro-core = { version = "0.7.1", features = ["sqlx"] }
73+
mostro-core = { version = "0.8.0", features = ["sqlx"] }
7474
tracing = "0.1.40"
7575
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
7676
clap = { version = "4.5.45", features = ["derive"] }

docker/ENV_VARIABLES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ These files are copied to `docker/config/lnd/` during the build process.
1818
- Used in `compose.yml` for port mapping
1919
- Example: `export MOSTRO_RELAY_LOCAL_PORT=7000`
2020

21+
- `MOSTRO_DB_PASSWORD`: Not used (database encryption was removed). Kept in `compose.yml` for backward compatibility; can be omitted or left empty.
22+
2123
## Usage Examples
2224

2325
### Linux/macOS

docker/README.md

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -74,36 +74,7 @@ To build and run the Docker container using Docker Compose, follow these steps:
7474
MOSTRO_RELAY_LOCAL_PORT=7000 make docker-up
7575
```
7676

77-
5. Configure `MOSTRO_DB_PASSWORD` for non-interactive startup (`docker compose up -d`):
78-
79-
- New DB + encryption enabled: set a strong password.
80-
- New DB + cleartext DB: set it to empty.
81-
- Existing encrypted DB: you must set the same password used when the DB was created.
82-
- Existing cleartext DB: keep it empty.
83-
84-
```sh
85-
# Enable DB encryption
86-
MOSTRO_DB_PASSWORD=YOUR_STRONG_PASSWORD_HERE
87-
```
88-
89-
```sh
90-
# Disable DB encryption (cleartext DB)
91-
MOSTRO_DB_PASSWORD=
92-
```
93-
94-
One-shot override from command line:
95-
96-
```sh
97-
MOSTRO_DB_PASSWORD="YOUR_STRONG_PASSWORD_HERE" make docker-up
98-
```
99-
100-
```sh
101-
MOSTRO_DB_PASSWORD="" make docker-up
102-
```
103-
104-
For a persistent value, place the same `MOSTRO_DB_PASSWORD=...` line in `docker/.env`.
105-
106-
For more details about environment variables, see [ENV_VARIABLES.md](ENV_VARIABLES.md).
77+
5. **Note:** Database encryption has been removed. The `MOSTRO_DB_PASSWORD` environment variable (if set in `compose.yml`) is no longer used for the database; you can omit it. For more details about environment variables, see [ENV_VARIABLES.md](ENV_VARIABLES.md).
10778

10879
6. Run the docker compose file:
10980

docs/RPC.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ Take a dispute for resolution.
7373
- `error_message`: Optional error message if operation failed
7474

7575
### 5. Validate Database Password
76-
Validate the database password for encrypted databases.
76+
Kept for backward compatibility. Database encryption has been removed; this RPC always succeeds and does not validate a password.
7777

7878
**Request:**
79-
- `password`: Database password to validate
79+
- `password`: Ignored
8080
- `request_id`: Optional request identifier
8181

8282
**Response:**
83-
- `success`: Boolean indicating password validity
84-
- `error_message`: Optional error message if validation failed
83+
- `success`: Always `true`
84+
- `error_message`: Always `None`
8585

8686
### 6. Get Version
8787
Retrieve the Mostro daemon version.

docs/RPC_RATE_LIMITING.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ with an in-memory rate limiter that tracks failed attempts per client IP.
77

88
## Problem
99

10-
The `ValidateDbPassword` endpoint accepts a password and validates it against the
11-
stored admin hash. Without protection, an attacker with network access to the RPC
12-
interface could systematically try passwords at thousands of attempts per second.
10+
The `ValidateDbPassword` endpoint is kept for backward compatibility (database
11+
encryption was removed, so it always succeeds). The rate limiter remains to
12+
throttle abuse of this endpoint.
1313

1414
See [Issue #569](https://github.com/MostroP2P/mostro/issues/569) for full details.
1515

@@ -38,9 +38,8 @@ The `validate_db_password` method now:
3838

3939
1. Extracts the client's remote address from the gRPC request
4040
2. Checks the rate limiter — returns `RESOURCE_EXHAUSTED` if locked out
41-
3. Validates the password against the stored hash
42-
4. On failure: records the attempt (triggers exponential backoff delay)
43-
5. On success: resets the client's failure state
41+
3. Does not validate a password (database encryption was removed); always succeeds
42+
4. On success: resets the client's failure state
4443

4544
### Audit Logging
4645

docs/STARTUP_AND_CONFIG.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,25 @@ Before settings initialization, the daemon performs:
4343

4444
### Database Connection (db::connect)
4545

46-
**Source**: `src/db.rs:480`
46+
**Source**: `src/db.rs`, function `connect()`.
4747

48-
**Complex initialization process**:
48+
**Initialization**:
4949

5050
1. **New database creation**:
5151
- Detects if database file exists
5252
- If new: runs all migrations from `migrations/` directory
5353
- Creates tables, indexes, and schema
5454

55-
2. **Password encryption handling**:
56-
- Checks if database is encrypted
57-
- If encrypted: prompts for password interactively
58-
- Validates password against stored hash
59-
- Stores decrypted password in `config::MOSTRO_DB_PASSWORD`
60-
61-
3. **Legacy migrations**:
55+
2. **Legacy migrations**:
6256
- Performs column migrations for backwards compatibility
6357
- Example: disputes table structure updates
6458

65-
4. **Connection pooling**:
59+
3. **Connection pooling**:
6660
- Creates `SqlitePool` with configured connection limits
6761
- Stores in global `config::DB_POOL`
6862

63+
**Note:** Database encryption has been removed; no password is used for the database.
64+
6965
**Error handling**: Database connection errors halt startup
7066

7167
### Additional Boot Steps
@@ -163,7 +159,7 @@ pub static NOSTR_CLIENT: OnceLock<Client> = OnceLock::new();
163159
pub static LN_STATUS: OnceLock<LnStatus> = OnceLock::new();
164160
pub static DB_POOL: OnceLock<Arc<sqlx::SqlitePool>> = OnceLock::new();
165161

166-
// Security
162+
// Security (MOSTRO_DB_PASSWORD unused; database encryption was removed)
167163
pub static MOSTRO_DB_PASSWORD: OnceLock<String> = OnceLock::new();
168164

169165
// Message routing

examples/rpc_client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2121
.await?;
2222

2323
let mut client = AdminServiceClient::new(channel);
24-
// Example 0: Validate database password
25-
println!("Attempting to validate database password...");
24+
// Example 0: ValidateDbPassword (backward compatibility; DB encryption removed, always succeeds)
25+
println!("Calling ValidateDbPassword (backward-compat endpoint)...");
2626
let validate_request = tonic::Request::new(ValidateDbPasswordRequest {
2727
password: std::env::var("MOSTRO_DB_TEST_PASSWORD").unwrap_or_default(),
2828
});
@@ -31,10 +31,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3131
Ok(response) => {
3232
let resp = response.get_ref();
3333
if resp.success {
34-
println!("✅ Database password validated successfully");
34+
println!("✅ ValidateDbPassword returned success");
3535
} else {
3636
println!(
37-
"❌ Failed to validate DB password: {:?}",
37+
"❌ ValidateDbPassword returned failure: {:?}",
3838
resp.error_message
3939
);
4040
}

proto/admin.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ service AdminService {
1616
// Take a dispute for resolution
1717
rpc TakeDispute(TakeDisputeRequest) returns (TakeDisputeResponse);
1818

19-
// Validate database password (when encryption is enabled)
19+
// Validate database password (kept for backward compatibility; DB encryption removed)
2020
rpc ValidateDbPassword(ValidateDbPasswordRequest) returns (ValidateDbPasswordResponse);
2121

2222
// Get Mostro version
@@ -71,7 +71,7 @@ message TakeDisputeResponse {
7171
optional string error_message = 2;
7272
}
7373

74-
// Validate database password
74+
// Validate database password (backward compatibility; no longer used for DB encryption)
7575
message ValidateDbPasswordRequest {
7676
string password = 1;
7777
}

0 commit comments

Comments
 (0)