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

WIP: Add prompt implementation for service method unlock #173

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

warusadura
Copy link
Collaborator

This is not feature complete. Please don't review.

ueno and others added 3 commits December 6, 2024 14:21
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>
Copy link
Owner

@bilelmoussaoui bilelmoussaoui left a 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 = {
Copy link
Owner

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
Copy link
Owner

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();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LazyLock

Comment on lines +99 to +105
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()
Copy link
Owner

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))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines +94 to +100
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();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)?;

Comment on lines +103 to +104
let false_secret: Vec<u8> = vec![0, 1];
return Some(Zeroizing::new(false_secret));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));

Comment on lines +107 to +109
let iv = decoded.get(IV).unwrap();
let decoded = decode(aes_key).unwrap();
let aes_key = Key::new(decoded.get(PRIVATE).unwrap().to_vec());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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() {
Copy link
Owner

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;
Copy link
Owner

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

@warusadura
Copy link
Collaborator Author

Thanks for the prompt review @bilelmoussaoui

@@ -1,6 +1,6 @@
use std::{
ops::{Mul, Rem, Shr},
sync::LazyLock,
sync::{LazyLock, OnceLock},
Copy link
Owner

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants