error handling when opening storage with wrong key

master
Niko PLP 10 months ago
parent 6f943930f2
commit 7d8f0f76e6
  1. 2
      ng-app/src/App.svelte
  2. 8
      ngone/src/main.rs
  3. 2
      p2p-broker/src/broker_store/account.rs
  4. 9
      p2p-broker/src/server_storage.rs
  5. 13
      stores-lmdb/src/kcv_store.rs

@ -11,7 +11,7 @@
<script lang="ts">
// this line is needed to have the SDK working when compiling for a single file bundle (pnpm filebuild)
// import * as api from "ng-sdk-js";
import * as api from "ng-sdk-js";
import { push, default as Router } from "svelte-spa-router";
import { onMount, tick, onDestroy } from "svelte";
import {

@ -159,8 +159,12 @@ async fn main() {
log_debug!("data directory: {}", dir.to_str().unwrap());
fs::create_dir_all(dir.clone()).unwrap();
let store = LmdbKCVStore::open(&dir, key);
let server = Arc::new(Server { store });
if store.is_err() {
return;
}
let server = Arc::new(Server {
store: store.unwrap(),
});
// let (wallet_key, wallet_id) = generate_keypair();
// let content = BootstrapContentV0 { servers: vec![] };

@ -249,7 +249,7 @@ mod test {
let key: [u8; 32] = [0; 32];
fs::create_dir_all(root.path()).unwrap();
println!("{}", root.path().to_str().unwrap());
let mut store = LmdbKCVStore::open(root.path(), key);
let mut store = LmdbKCVStore::open(root.path(), key).unwrap();
let user_id = PubKey::Ed25519PubKey([1; 32]);

@ -43,7 +43,7 @@ impl LmdbServerStorage {
wallet_path.push("wallet");
std::fs::create_dir_all(wallet_path.clone()).unwrap();
//TODO redo the whole key passing mechanism in RKV so it uses zeroize all the way
let wallet_storage = LmdbKCVStore::open(&wallet_path, master_key.slice().clone());
let wallet_storage = LmdbKCVStore::open(&wallet_path, master_key.slice().clone())?;
let wallet = Wallet::open(&wallet_storage);
// create/open the ACCOUNTS storage
@ -54,7 +54,8 @@ impl LmdbServerStorage {
if admin_invite.is_some() && !accounts_path.exists() && !wallet.exists_accounts_key() {
accounts_key = wallet.create_accounts_key()?;
std::fs::create_dir_all(accounts_path.clone()).unwrap();
let accounts_storage = LmdbKCVStore::open(&accounts_path, accounts_key.slice().clone());
let accounts_storage =
LmdbKCVStore::open(&accounts_path, accounts_key.slice().clone())?;
let symkey = SymKey::random();
let invite_code = InvitationCode::Admin(symkey.clone());
let _ = Invitation::create(
@ -80,7 +81,7 @@ impl LmdbServerStorage {
}
std::fs::create_dir_all(accounts_path.clone()).unwrap();
//TODO redo the whole key passing mechanism in RKV so it uses zeroize all the way
let accounts_storage = LmdbKCVStore::open(&accounts_path, accounts_key.slice().clone());
let accounts_storage = LmdbKCVStore::open(&accounts_path, accounts_key.slice().clone())?;
// create/open the PEERS storage
@ -89,7 +90,7 @@ impl LmdbServerStorage {
peers_path.push("peers");
std::fs::create_dir_all(peers_path.clone()).unwrap();
//TODO redo the whole key passing mechanism in RKV so it uses zeroize all the way
let peers_storage = LmdbKCVStore::open(&peers_path, peers_key.slice().clone());
let peers_storage = LmdbKCVStore::open(&peers_path, peers_key.slice().clone())?;
Ok(LmdbServerStorage {
wallet_storage,

@ -445,7 +445,7 @@ impl LmdbKCVStore {
/// Opens the store and returns a KCVStore object that should be kept and used to manipulate the properties
/// The key is the encryption key for the data at rest.
pub fn open<'a>(path: &Path, key: [u8; 32]) -> LmdbKCVStore {
pub fn open<'a>(path: &Path, key: [u8; 32]) -> Result<LmdbKCVStore, StorageError> {
let mut manager = Manager::<LmdbEnvironment>::singleton().write().unwrap();
let shared_rkv = manager
.get_or_create(path, |path| {
@ -458,12 +458,17 @@ impl LmdbKCVStore {
log_info!("created env with LMDB Version: {}", env.version());
let main_store = env.open_multi("main", StoreOptions::create()).unwrap();
let main_store = env
.open_multi("main", StoreOptions::create())
.map_err(|e| {
log_debug!("open_multi failed {}", e);
StorageError::BackendError
})?;
LmdbKCVStore {
Ok(LmdbKCVStore {
environment: shared_rkv.clone(),
main_store,
path: path.to_str().unwrap().to_string(),
}
})
}
}

Loading…
Cancel
Save