Skip to content

Commit

Permalink
Using PrivateKey instead of SenderKey
Browse files Browse the repository at this point in the history
  • Loading branch information
petarjuki7 committed Nov 11, 2024
1 parent 7e5c7d1 commit 6833399
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
4 changes: 2 additions & 2 deletions crates/context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl ContextManager {
}

handle.put(
&ContextIdentityKey::new(context.id, identity_secret.public_key()), //local node saving its local identity
&ContextIdentityKey::new(context.id, identity_secret.public_key()),
&ContextIdentityValue {
private_key: Some(*identity_secret),
sender_key: Some(*self.new_private_key()),
Expand Down Expand Up @@ -401,7 +401,7 @@ impl ContextManager {

let Some(ContextIdentityValue {
private_key: Some(requester_secret),
sender_key: None,
..
}) = handle.get(&ContextIdentityKey::new(context_id, inviter_id))?
else {
return Ok(None);
Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn recv(
let data = match shared_key {
Some(key) => match key.decrypt(message_data, [0; 12]) {
Some(data) => data,
None => bail!("Encryption failed"),
None => bail!("decryption failed"),
},
None => message_data,
};
Expand Down
14 changes: 5 additions & 9 deletions crates/node/src/sync/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Node {
let private_key = self
.ctx_manager
.get_private_key(context.id, our_identity)?
.ok_or_eyre("expected own identity to have sender key")?;
.ok_or_eyre("expected own identity to have private key")?;

let shared_key = SharedKey::new(&private_key, &their_identity);

Expand Down Expand Up @@ -148,16 +148,12 @@ impl Node {
bail!("no identities found for context: {}", context.id);
};

let possible_sending_key = self
let private_key = self
.ctx_manager
.get_sender_key(&context.id, &our_identity)?;

let sending_key = match possible_sending_key {
Some(key) => key,
None => todo!(),
};
.get_private_key(context.id, our_identity)?
.ok_or_eyre("expected own identity to have private key")?;

let shared_key = SharedKey::new(&sending_key, &our_identity);
let shared_key = SharedKey::new(&private_key, &our_identity);

send(
stream,
Expand Down
24 changes: 8 additions & 16 deletions crates/node/src/sync/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,12 @@ impl Node {

let mut sqx_out = Sequencer::default();

let possible_sending_key = self
let private_key = self
.ctx_manager
.get_sender_key(&context.id, &our_identity)?;
.get_private_key(context.id, our_identity)?
.ok_or_eyre("expected own identity to have private key")?;

let sending_key = match possible_sending_key {
Some(key) => key,
None => todo!(),
};

let shared_key = SharedKey::new(&sending_key, &their_identity);
let shared_key = SharedKey::new(&private_key, &their_identity);

send(
stream,
Expand Down Expand Up @@ -131,16 +127,12 @@ impl Node {
bail!("no identities found for context: {}", context.id);
};

let possible_sending_key = self
let private_key = self
.ctx_manager
.get_sender_key(&context.id, &our_identity)?;

let sending_key = match possible_sending_key {
Some(key) => key,
None => todo!(),
};
.get_private_key(context.id, our_identity)?
.ok_or_eyre("expected own identity to have private key")?;

let shared_key = SharedKey::new(&sending_key, &our_identity);
let shared_key = SharedKey::new(&private_key, &our_identity);

send(
stream,
Expand Down

0 comments on commit 6833399

Please sign in to comment.