From c3bbcce6a3c3c02d73b72f9cbdede57753c6447a Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Tue, 15 Jun 2021 23:07:22 +0200 Subject: [PATCH] Simplify KeyPair handling --- Cargo.lock | 2 +- Cargo.toml | 2 +- app/Cargo.lock | 2 +- model/Cargo.lock | 2 +- model/Cargo.toml | 2 +- model/src/opaque.rs | 44 +++++-------------------------- src/domain/sql_backend_handler.rs | 4 +-- src/infra/configuration.rs | 2 +- 8 files changed, 14 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 32338bf..dee98c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1679,7 +1679,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "opaque-ke" version = "0.5.1-pre.1" -source = "git+https://github.com/novifinancial/opaque-ke?rev=cd85efc603f5d98ed794cdd56a6e59236cce3d32#cd85efc603f5d98ed794cdd56a6e59236cce3d32" +source = "git+https://github.com/novifinancial/opaque-ke?rev=98f1821897cd2800e5bffb2a70541056145e99cc#98f1821897cd2800e5bffb2a70541056145e99cc" dependencies = [ "base64", "curve25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index b0505b6..011233a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ rand = { version = "0.8", features = ["small_rng", "getrandom"] } # TODO: update to 0.6 when out. [dependencies.opaque-ke] git = "https://github.com/novifinancial/opaque-ke" -rev = "cd85efc603f5d98ed794cdd56a6e59236cce3d32" +rev = "98f1821897cd2800e5bffb2a70541056145e99cc" [dependencies.sqlx] version = "0.5.1" diff --git a/app/Cargo.lock b/app/Cargo.lock index 19b3a0c..1a1803e 100644 --- a/app/Cargo.lock +++ b/app/Cargo.lock @@ -997,7 +997,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "opaque-ke" version = "0.5.1-pre.1" -source = "git+https://github.com/novifinancial/opaque-ke?rev=cd85efc603f5d98ed794cdd56a6e59236cce3d32#cd85efc603f5d98ed794cdd56a6e59236cce3d32" +source = "git+https://github.com/novifinancial/opaque-ke?rev=98f1821897cd2800e5bffb2a70541056145e99cc#98f1821897cd2800e5bffb2a70541056145e99cc" dependencies = [ "base64", "curve25519-dalek", diff --git a/model/Cargo.lock b/model/Cargo.lock index 4f47bf7..816fecd 100644 --- a/model/Cargo.lock +++ b/model/Cargo.lock @@ -825,7 +825,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "opaque-ke" version = "0.5.1-pre.1" -source = "git+https://github.com/novifinancial/opaque-ke?rev=cd85efc603f5d98ed794cdd56a6e59236cce3d32#cd85efc603f5d98ed794cdd56a6e59236cce3d32" +source = "git+https://github.com/novifinancial/opaque-ke?rev=98f1821897cd2800e5bffb2a70541056145e99cc#98f1821897cd2800e5bffb2a70541056145e99cc" dependencies = [ "base64", "curve25519-dalek", diff --git a/model/Cargo.toml b/model/Cargo.toml index 13cc4bb..40b1989 100644 --- a/model/Cargo.toml +++ b/model/Cargo.toml @@ -23,7 +23,7 @@ thiserror = "*" # TODO: update to 0.6 when out. [dependencies.opaque-ke] git = "https://github.com/novifinancial/opaque-ke" -rev = "cd85efc603f5d98ed794cdd56a6e59236cce3d32" +rev = "98f1821897cd2800e5bffb2a70541056145e99cc" [dependencies.chrono] version = "*" diff --git a/model/src/opaque.rs b/model/src/opaque.rs index eb28a8b..962b033 100644 --- a/model/src/opaque.rs +++ b/model/src/opaque.rs @@ -9,40 +9,8 @@ pub enum AuthenticationError { pub type AuthenticationResult = std::result::Result; -/// Wrapper around an opaque KeyPair to have type-checked public and private keys. -#[derive(Debug, Clone)] -pub struct KeyPair(pub opaque_ke::keypair::KeyPair<::Group>); - -pub struct PublicKey<'a>(&'a opaque_ke::keypair::Key); -pub struct PrivateKey<'a>(&'a opaque_ke::keypair::Key); - -impl <'a> std::ops::Deref for PublicKey<'a> { - type Target = &'a opaque_ke::keypair::Key; - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl <'a> std::ops::Deref for PrivateKey<'a> { - type Target = &'a opaque_ke::keypair::Key; - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl KeyPair { - pub fn private(&self) -> PrivateKey<'_> { - PrivateKey(self.0.private()) - } - - pub fn public(&self) -> PublicKey<'_> { - PublicKey(self.0.public()) - } - - pub fn from_private_key_slice(input: &[u8]) -> std::result::Result { - opaque_ke::keypair::KeyPair::<::Group>::from_private_key_slice(input).map(Self) - } -} +pub use opaque_ke::keypair::{PublicKey, PrivateKey}; +pub type KeyPair = opaque_ke::keypair::KeyPair<::Group>; /// A wrapper around argon2 to provide the [`opaque_ke::slow_hash::SlowHash`] trait. pub struct ArgonHasher; @@ -177,12 +145,12 @@ pub mod server { pub fn start_registration( rng: &mut R, registration_request: RegistrationRequest, - server_public_key: PublicKey<'_>, + server_public_key: &PublicKey, ) -> AuthenticationResult { Ok(ServerRegistration::start( rng, registration_request, - *server_public_key, + server_public_key, )?) } @@ -211,13 +179,13 @@ pub mod server { pub fn start_login( rng: &mut R, password_file: ServerRegistration, - server_private_key: PrivateKey<'_>, + server_private_key: &PrivateKey, credential_request: CredentialRequest, ) -> AuthenticationResult { Ok(ServerLogin::start( rng, password_file, - *server_private_key, + server_private_key, credential_request, ServerLoginStartParameters::default(), )?) diff --git a/src/domain/sql_backend_handler.rs b/src/domain/sql_backend_handler.rs index 73735cc..2d0b1e8 100644 --- a/src/domain/sql_backend_handler.rs +++ b/src/domain/sql_backend_handler.rs @@ -23,7 +23,7 @@ impl SqlBackendHandler { fn get_password_file( clear_password: &str, - server_public_key: opaque::PublicKey<'_>, + server_public_key: &opaque::PublicKey, ) -> Result { use opaque::{client, server}; let mut rng = rand::rngs::OsRng; @@ -51,7 +51,7 @@ fn get_password_file( fn passwords_match( password_file_bytes: &[u8], clear_password: &str, - server_private_key: opaque::PrivateKey<'_>, + server_private_key: &opaque::PrivateKey, ) -> Result<()> { use opaque::{client, server}; let mut rng = rand::rngs::OsRng; diff --git a/src/infra/configuration.rs b/src/infra/configuration.rs index 387d012..c184f46 100644 --- a/src/infra/configuration.rs +++ b/src/infra/configuration.rs @@ -103,7 +103,7 @@ fn get_server_keys(file_path: &str) -> Result { e ) })?; - Ok(KeyPair(keypair)) + Ok(keypair) } }