Changeset View
Changeset View
Standalone View
Standalone View
shared/comm-opaque2/src/server/login.rs
- This file was added.
use opaque_ke::{errors::ProtocolError, ServerRegistration}; | ||||||||||
use opaque_ke::{ | ||||||||||
CredentialFinalization, CredentialRequest, ServerLogin, | ||||||||||
ServerLoginStartParameters, ServerSetup, | ||||||||||
}; | ||||||||||
use rand::rngs::OsRng; | ||||||||||
use crate::Cipher; | ||||||||||
pub struct Login { | ||||||||||
state: Option<ServerLogin<Cipher>>, | ||||||||||
rng: OsRng, | ||||||||||
varun: do we ever use this? | ||||||||||
jonAuthorUnsubmitted Done Inline ActionsYea, just forgot to use self.rng instead of OsRng directly jon: Yea, just forgot to use `self.rng` instead of `OsRng` directly | ||||||||||
pub session_key: Option<Vec<u8>>, | ||||||||||
} | ||||||||||
impl Login { | ||||||||||
pub fn new() -> Login { | ||||||||||
varunUnsubmitted Done Inline Actionswe don't need this if we just add a #[derive(Default)] attribute to the struct varun: we don't need this if we just add a `#[derive(Default)]` attribute to the struct | ||||||||||
jonAuthorUnsubmitted Done Inline ActionsI need it on the client side to decorate a constructor. And I would prefer to keep server and client as similar as possible. Also, I think new is a bit more clear in usage. comm-opaque::server::Login::new() # vs comm-opaque::server::Login::default() jon: I need it on the client side to decorate a constructor. And I would prefer to keep server and… | ||||||||||
Login { | ||||||||||
state: None, | ||||||||||
rng: OsRng, | ||||||||||
session_key: None, | ||||||||||
} | ||||||||||
} | ||||||||||
pub fn start( | ||||||||||
&mut self, | ||||||||||
server_setup: &ServerSetup<Cipher>, | ||||||||||
password_file_bytes: &[u8], | ||||||||||
credential_request: &[u8], | ||||||||||
credential_identifier: &[u8], | ||||||||||
) -> Result<Vec<u8>, ProtocolError> { | ||||||||||
let password_file = ServerRegistration::deserialize(password_file_bytes)?; | ||||||||||
let credential_request = | ||||||||||
CredentialRequest::deserialize(credential_request)?; | ||||||||||
let result = ServerLogin::start( | ||||||||||
&mut OsRng, | ||||||||||
server_setup, | ||||||||||
Some(password_file), | ||||||||||
credential_request, | ||||||||||
credential_identifier, | ||||||||||
ServerLoginStartParameters::default(), | ||||||||||
)?; | ||||||||||
self.state = Some(result.state); | ||||||||||
Ok(result.message.serialize().to_vec()) | ||||||||||
} | ||||||||||
pub fn finish( | ||||||||||
&mut self, | ||||||||||
response_payload: &[u8], | ||||||||||
) -> Result<(), ProtocolError> { | ||||||||||
let finalization_payload = | ||||||||||
CredentialFinalization::deserialize(&response_payload[..])?; | ||||||||||
varunUnsubmitted Done Inline Actions
varun: | ||||||||||
jonAuthorUnsubmitted Done Inline Actionsthanks jon: thanks | ||||||||||
let state = self | ||||||||||
.state | ||||||||||
.take() | ||||||||||
.ok_or_else(|| ProtocolError::InvalidLoginError)?; | ||||||||||
let result = state.finish(finalization_payload)?; | ||||||||||
self.session_key = Some(result.session_key.to_vec()); | ||||||||||
Ok(()) | ||||||||||
} | ||||||||||
} |
do we ever use this?