-
Notifications
You must be signed in to change notification settings - Fork 13
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
WIP: Add prompt implementation for service method unlock #173
base: main
Are you sure you want to change the base?
Conversation
SecretExchange allows exchange of secrets between two processes on the same system without exposing those secrets. https://gnome.pages.gitlab.gnome.org/gcr/gcr-4/class.SecretExchange.html Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also needs a rebase
@@ -81,6 +81,17 @@ pub(crate) fn generate_public_key(private_key: impl AsRef<[u8]>) -> Vec<u8> { | |||
public_key_uint.to_bytes_be() | |||
} | |||
|
|||
pub(crate) fn generate_public_key_for_secret_exchange(private_key: impl AsRef<[u8]>) -> Vec<u8> { | |||
let private_key_uint = BigUint::from_bytes_be(private_key.as_ref()); | |||
let dh_generator = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use LazyLock nowadays.
|
||
let mut common_secret_bytes = common_secret.to_bytes_be(); | ||
let mut common_secret_padded = vec![0; 192 - common_secret_bytes.len()]; | ||
// inefficient, but ok for now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is inefficient about it
fn powm_for_secret_exchange(base: &BigUint, mut exp: BigUint) -> BigUint { | ||
let modulus = { | ||
// for key exchange | ||
static DH_PRIME: OnceLock<BigUint> = OnceLock::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LazyLock
Dh::from_pqg( | ||
BigNum::get_rfc3526_prime_1536().unwrap(), | ||
None, | ||
BigNum::from_u32(2).unwrap(), | ||
) | ||
.and_then(|key| key.set_private_key(private_key_bn)) | ||
.unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my latest PR, don't unwrap here
None, | ||
BigNum::from_u32(2).unwrap(), | ||
) | ||
.and_then(|key| key.set_private_key(private_key_bn)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
let secret = decoded.get(SECRET); | ||
|
||
// If we cancel an ongoing prompt call, the final exchange won't have the secret | ||
// or IV. The following is to avoid `Option::unwrap()` on a `None` value | ||
secret?; | ||
|
||
let secret = secret.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let secret = decoded.get(SECRET); | |
// If we cancel an ongoing prompt call, the final exchange won't have the secret | |
// or IV. The following is to avoid `Option::unwrap()` on a `None` value | |
secret?; | |
let secret = secret.unwrap(); | |
// If we cancel an ongoing prompt call, the final exchange won't have the secret | |
// or IV. The following is to avoid `Option::unwrap()` on a `None` value | |
let secret = decoded.get(SECRET)?; | |
let false_secret: Vec<u8> = vec![0, 1]; | ||
return Some(Zeroizing::new(false_secret)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let false_secret: Vec<u8> = vec![0, 1]; | |
return Some(Zeroizing::new(false_secret)); | |
let false_secret = vec![0, 1]; | |
return Some(Zeroizing::new(false_secret)); |
let iv = decoded.get(IV).unwrap(); | ||
let decoded = decode(aes_key).unwrap(); | ||
let aes_key = Key::new(decoded.get(PRIVATE).unwrap().to_vec()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let iv = decoded.get(IV).unwrap(); | |
let decoded = decode(aes_key).unwrap(); | |
let aes_key = Key::new(decoded.get(PRIVATE).unwrap().to_vec()); | |
let iv = decoded.get(IV)?; | |
let decoded = decode(aes_key)?; | |
let aes_key = Key::new(decoded.get(PRIVATE)?.to_vec()); |
use super::*; | ||
|
||
#[test] | ||
fn test_secret_exchange() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the opposite also be tested?
let (unlocked, _not_unlocked) = self.set_locked(false, &objects).await?; | ||
let (unlocked, not_unlocked) = self.set_locked(false, &objects).await?; | ||
if !not_unlocked.is_empty() { | ||
let prompt = Prompt::new(self.clone()).await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prompt also needs a way to pass it a future that would be executed when the prompt is done
Thanks for the prompt review @bilelmoussaoui |
@@ -1,6 +1,6 @@ | |||
use std::{ | |||
ops::{Mul, Rem, Shr}, | |||
sync::LazyLock, | |||
sync::{LazyLock, OnceLock}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lacks an openssl implementation as well as that is what most distros will likely use the daemon with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do, thanks!
This is not feature complete. Please don't review.