Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta secret core version 2 #3

Merged
merged 50 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
87d6521
Update Cargo.toml
cypherkitty Mar 17, 2023
f96d142
core: add commit log
cypherkitty Mar 18, 2023
bea6dca
core: commit log
cypherkitty Mar 18, 2023
497c195
core: commit log
cypherkitty Mar 18, 2023
b0fb985
core: a draft implementation of a join/accept functionality on "commi…
cypherkitty Mar 21, 2023
44c0288
core v2: initial version
cypherkitty Apr 10, 2023
1974b00
core v2: implement genesis event for commit log (#4)
cypherkitty Apr 11, 2023
8635070
core v2: implement "sing_up" functionality on commit log level (#5)
cypherkitty Apr 11, 2023
4adc2c8
Merge branch 'main' into v2
cypherkitty Apr 12, 2023
7627955
v2, github actions: trigger tests for pr-s (#6)
cypherkitty Apr 12, 2023
a1a8bce
core v2: fix gh actions (path to target directory)
cypherkitty Apr 12, 2023
91d6215
core v2: implement basic join_cluster functionality on top of commit …
cypherkitty Apr 12, 2023
5ea03c0
core v2: redesign commit log operation types enums (#9)
cypherkitty Apr 13, 2023
afa2bf6
V2: initial (draft) version of a communication protocol between clien…
cypherkitty Apr 17, 2023
80ed771
V2 new project architecture (structure) (#12)
cypherkitty Apr 19, 2023
5e8011d
v2, commit log: link events in a blockchain-style way (#13)
cypherkitty Apr 22, 2023
b3e919b
v2, sqlite mock server implementation (#14)
cypherkitty Apr 25, 2023
505060b
v2 object layer and commit_log architecture redesign (#15)
cypherkitty May 8, 2023
4830741
v2: sing up and global index (#20)
cypherkitty May 12, 2023
7181457
v2: implement join_cluster operation (#21)
cypherkitty May 20, 2023
9c7f8fb
v2 serverless (#22)
cypherkitty Jun 5, 2023
0b66965
v2: integrate cf worker with meta-server (#23)
cypherkitty Jun 5, 2023
96def56
V2 wasm and impementing a "send" command (#24)
cypherkitty Jun 6, 2023
d92b4b2
V2 type-driven design (#25)
cypherkitty Jun 11, 2023
38dc37d
v2: generic object layer (#26)
cypherkitty Jun 15, 2023
76f2bec
v2: add meta vault, make service code more generic (#27)
cypherkitty Jun 17, 2023
08bc44e
v2: redesign KvLogEvent's architecture (#28)
cypherkitty Jun 21, 2023
4468701
V2 di architectural changes (#29)
cypherkitty Jun 28, 2023
dede092
v2, wasm: registration basics (#30)
cypherkitty Jun 30, 2023
05cb97e
V2: wasm server, db synchronization, object lifetime (events lifetime…
cypherkitty Jul 10, 2023
4ba3218
v2, db synchronization (meta server and client) (#32)
cypherkitty Jul 11, 2023
1408fcf
V2 db sync improvements (#33)
cypherkitty Jul 12, 2023
d5dbbcb
v2, state sync: synchronization improvements (#34)
cypherkitty Jul 24, 2023
aa86791
v2: add vault into the app state (#35)
cypherkitty Jul 25, 2023
bbd7250
Docs: "Join Cluster" schema (#36)
cypherkitty Jul 26, 2023
9ba4c67
v2 meta password initial implementation (#37)
cypherkitty Jul 27, 2023
8435286
V2 sync refactoring (#38)
cypherkitty Aug 9, 2023
c3f3614
v2, meta server (#39)
cypherkitty Aug 11, 2023
4cc5056
v2: migrate to dynamic dispatching from generics (static ones) it red…
cypherkitty Aug 11, 2023
ea3e891
V2 secret sharing (#41)
cypherkitty Aug 18, 2023
0e39512
V2: sync shares (#42)
cypherkitty Aug 19, 2023
ba02962
Device pool sync (#43)
cypherkitty Aug 28, 2023
4b4f2a7
v2 application architecture improvements (#44)
cypherkitty Sep 13, 2023
2434063
v2: move app manager initialization code from wasm to the core (#45)
cypherkitty Sep 15, 2023
cf4dc27
v2, design improvements (#46)
cypherkitty Sep 21, 2023
ae20b02
v2, multiplatform (#47)
cypherkitty Sep 28, 2023
ee8e079
V2 tracing and cluster join fix (#48)
cypherkitty Sep 29, 2023
920fec9
v2, "join cluster" fix (#49)
cypherkitty Sep 30, 2023
074e9f4
v2, "secret sharing" design improvements (#50)
cypherkitty Dec 21, 2023
20a3d14
v2, tests (#54)
cypherkitty Feb 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ jobs:
with:
path: |
~/.cargo
core/target
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Generate rust models
working-directory: schema
run: |
npm install @openapitools/openapi-generator-cli -g
openapi-generator-cli version-manager set 6.2.1
make clean generate_schema

- name: Run tests
working-directory: core
run: |
cargo test

Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/core.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Core Testing"

on:
pull_request:

jobs:
core-test:
runs-on: ubuntu-latest

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

steps:
- uses: actions/checkout@v3

- uses: actions/cache@v3
with:
path: |
~/.cargo
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Generate rust models
working-directory: schema
run: |
make clean generate_schema

- name: Run tests
run: |
cargo test
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,19 @@ schema/target
/schema/node_modules/
/schema/package.json
/schema/package-lock.json

/meta-server-serverless/.idea/
/meta-server-serverless/node_modules/
/meta-server-serverless/build/
/meta-server-serverless/Cargo.lock
/meta-server-serverless/package-lock.json
/meta-server-serverless/target

/wasm/target
/wasm/pkg
/wasm/**/*.rs.bk
/wasm/Cargo.lock
/wasm/bin/
/wasm/wasm-pack.log

.vscode
48 changes: 46 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
[workspace]

resolver = "2"

members = [
"core",
"core-swift-lib"
]
"meta-server-emulator",
"core-swift-lib",
"wasm"
]

exclude = [
"meta-server-serverless"
]

[workspace.dependencies]
# Error handling
thiserror = "1.0.49"
anyhow = "1.0.75"

# Logging and tracing
tracing = "0.1"
tracing-subscriber = { version = "0.3" }

# Json
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
serde_derive = "1.0.188"

# Async utils
async-std = { version = "1.12.0" }
async-trait = "0.1"
flume = "0.11"
async-mutex = "1.4"

# Cryptography
ed25519-dalek = "1.0.1"
crypto_box = { version = "0.8.2", features = ["std"] }
rand = "0.8.5"
getrandom = { version = "0.2.8", features = ["js"] }
sha2 = { version = "0.10.6", features = ["oid"] }
base64 = "0.20.0"
hex = "0.4"
#https://github.com/dsprenkels/sss-rs
shamirsecretsharing = "0.1"

# Sql
diesel = { version = "2.0.0" }
diesel_migrations = { version = "2.0.0" }
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

clean:
rm -rf schema/target

build_wasm:
cd wasm && wasm-pack build --target web

#rm -rf ui/pkg
#cp -R wasm/pkg ui

build_js: build_wasm
cd ui && npm install vue-tsc
cd ui && npm run build

generate_typescript_models:
cd ../meta-secret-core/schema && make generate_schema_type_script
cp -r ../meta-secret-core/schema/target/core-models-ts/model ui/src

install_wasm_pack:
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
cargo install cargo-generate

wasm_test:
cd wasm && wasm-pack test --firefox

wasm_test_headless:
cd wasm && wasm-pack test --headless --firefox
20 changes: 12 additions & 8 deletions core-swift-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ name = "meta_secret_core_swift"

[dependencies]
meta-secret-core = { path = "../core"}
serde_json = "1.0.87"
serde = { version = "1.0", features = ["derive"] }
ed25519-dalek = "1.0"
crypto_box = "0.8.1"
base64 = "0.20.0-alpha.1"
sha2 = "0.10.6"
hex = "0.4"
anyhow = "1.0.66"

anyhow.workspace = true

serde.workspace = true
serde_json.workspace = true
serde_derive.workspace = true

ed25519-dalek.workspace = true
crypto_box.workspace = true
base64.workspace = true
sha2.workspace = true
hex.workspace = true
79 changes: 41 additions & 38 deletions core-swift-lib/src/swift_to_rust.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use anyhow::Context;
use meta_secret_core::crypto::keys::KeyManager;
use meta_secret_core::crypto::encoding::base64::Base64Text;
use meta_secret_core::crypto::keys::{KeyManager, SecretBox};
use meta_secret_core::errors::CoreError;
use meta_secret_core::shared_secret::data_block::common::SharedSecretConfig;
use meta_secret_core::shared_secret::shared_secret::UserShareDto;
use meta_secret_core::node::common::model::secret::SecretDistributionData;
use meta_secret_core::recover_from_shares;
use meta_secret_core::secret::data_block::common::SharedSecretConfig;
use meta_secret_core::secret::shared_secret::UserShareDto;
use meta_secret_core::CoreResult;
use meta_secret_core::{recover_from_shares, shared_secret};
use serde::{Deserialize, Serialize};
use std::ffi::CString;
use std::os::raw::c_char;
use std::slice;
use std::str;
use meta_secret_core::models::{Base64EncodedText, SecretDistributionDocData, SerializedKeyManager};

type SizeT = usize;

Expand Down Expand Up @@ -73,12 +74,14 @@ fn to_c_str(str: String) -> *mut c_char {
}

mod internal {
use meta_secret_core::models::{AeadCipherText, AeadPlainText, MetaPasswordId};
use meta_secret_core::crypto::key_pair::KeyPair;
use super::*;
use meta_secret_core::node::common::model::crypto::{AeadCipherText, AeadPlainText, EncryptedMessage};
use meta_secret_core::node::common::model::secret::MetaPasswordId;
use meta_secret_core::secret;

pub fn generate_security_box(vault_name_bytes: *const u8, len: SizeT) -> CoreResult<String> {
let device_name = data_to_string(vault_name_bytes, len)?;
let security_box = KeyManager::generate_security_box(device_name);
let security_box = KeyManager::generate_secret_box();
let user = serde_json::to_string_pretty(&security_box)?;
Ok(user)
}
Expand All @@ -92,7 +95,7 @@ mod internal {

// JSON parsing
let json_string: String = data_to_string(strings_bytes, string_len)?;
let shares: Vec<UserShareDto> = shared_secret::split(json_string, cfg)?;
let shares: Vec<UserShareDto> = secret::split(json_string, cfg)?;

// Shares to JSon
let result_json = serde_json::to_string_pretty(&shares)?;
Expand All @@ -116,7 +119,7 @@ mod internal {

// Encrypt shares
let encrypted_share: AeadCipherText = key_manager
.transport_key_pair
.transport
.encrypt_string(json_struct.secret, json_struct.receiver_pub_key)?;

// Shares to JSon
Expand All @@ -131,10 +134,9 @@ mod internal {

println!("restore_task {:?}", restore_task.doc);
// Decrypt shares
let share_json: AeadPlainText = key_manager
.transport_key_pair
.decrypt(&restore_task.doc.secret_message.encrypted_text)?;
let share_json = UserShareDto::try_from(share_json.msg.as_ref())?;
let EncryptedMessage::CipherShare { share, .. } = restore_task.doc.secret_message;
let share_json: AeadPlainText = share.decrypt(&key_manager.transport.secret_key)?;
let share_json = UserShareDto::try_from(&share_json.msg)?;

// Decrypted Share to JSon
let result_json = serde_json::to_string_pretty(&share_json)?;
Expand All @@ -146,16 +148,16 @@ mod internal {
let restore_task = RestoreTask::try_from(&data_string)?;

let key_manager = KeyManager::try_from(&restore_task.key_manager)?;
let share_from_device_2_json: AeadPlainText = key_manager
.transport_key_pair
.decrypt(&restore_task.doc_two.secret_message.encrypted_text)?;
let share_from_device_2_json = UserShareDto::try_from(share_from_device_2_json.msg.as_ref())?;
let EncryptedMessage::CipherShare {
share: second_share, ..
} = restore_task.doc_two.secret_message;
let share_from_device_2_json: AeadPlainText = second_share.decrypt(&key_manager.transport.secret_key)?;
let share_from_device_2_json = UserShareDto::try_from(&share_from_device_2_json.msg)?;

let share_from_device_1_json: AeadPlainText = key_manager
.transport_key_pair
.decrypt(&restore_task.doc_one.secret_message.encrypted_text)?;
let EncryptedMessage::CipherShare { share: first_share, .. } = restore_task.doc_one.secret_message;
let share_from_device_1_json: AeadPlainText = first_share.decrypt(&key_manager.transport.secret_key)?;

let share_from_device_1_json = UserShareDto::try_from(share_from_device_1_json.msg.as_ref())?;
let share_from_device_1_json = UserShareDto::try_from(&share_from_device_1_json.msg)?;

// Restored Password to JSon
let password = recover_from_shares(vec![share_from_device_2_json, share_from_device_1_json])?;
Expand Down Expand Up @@ -185,8 +187,8 @@ fn data_to_string(bytes: *const u8, len: SizeT) -> CoreResult<String> {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JsonMappedData {
sender_key_manager: SerializedKeyManager,
receiver_pub_key: Base64EncodedText,
sender_key_manager: SecretBox,
receiver_pub_key: Base64Text,
secret: String,
}

Expand All @@ -202,16 +204,16 @@ impl TryFrom<&String> for JsonMappedData {
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct RestoreTask {
key_manager: SerializedKeyManager,
doc_one: SecretDistributionDocData,
doc_two: SecretDistributionDocData,
key_manager: SecretBox,
doc_one: SecretDistributionData,
doc_two: SecretDistributionData,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct DecryptTask {
key_manager: SerializedKeyManager,
doc: SecretDistributionDocData,
key_manager: SecretBox,
doc: SecretDistributionData,
}

impl TryFrom<&String> for RestoreTask {
Expand All @@ -235,12 +237,13 @@ impl TryFrom<&String> for DecryptTask {
//TESTS
#[cfg(test)]
pub mod test {
use meta_secret_core::crypto::encoding::base64::Base64Text;
use meta_secret_core::crypto::key_pair::KeyPair;
use meta_secret_core::crypto::keys::KeyManager;
use meta_secret_core::shared_secret::data_block::common::SharedSecretConfig;
use meta_secret_core::shared_secret::shared_secret::UserShareDto;
use meta_secret_core::{shared_secret, CoreResult};
use meta_secret_core::models::AeadCipherText;
use meta_secret_core::node::common::model::crypto::AeadCipherText;
use meta_secret_core::secret::data_block::common::SharedSecretConfig;
use meta_secret_core::secret::shared_secret::UserShareDto;
use meta_secret_core::{secret, CoreResult};

#[test]
fn split_and_encrypt() -> CoreResult<()> {
Expand All @@ -257,15 +260,15 @@ pub mod test {
let key_manager_2 = KeyManager::generate();

// Split
let shares: Vec<UserShareDto> = shared_secret::split("Secret".to_string(), cfg)?;
let shares: Vec<UserShareDto> = secret::split("Secret".to_string(), cfg)?;

// Encrypt shares
let secret = shares[0].clone();
let password_share: String = secret.share_blocks[0].data.base64_text.clone();
let receiver_pk = key_manager_2.transport_key_pair.public_key();
let Base64Text(password_share_text) = secret.share_blocks[0].data.clone();
let receiver_pk = key_manager_2.transport.public_key();
let encrypted_share: AeadCipherText = key_manager_1
.transport_key_pair
.encrypt_string(password_share, receiver_pk)?;
.transport
.encrypt_string(password_share_text, receiver_pk)?;

println!("result {:?}", encrypted_share);

Expand Down
Loading
Loading