Merge pull request #135 from EETagent/fix_password_reset_reencrypt

Fix password reset reencrypt
This commit is contained in:
Vojtěch Jungmann 2023-01-12 20:59:25 +01:00 committed by GitHub
commit fb37538726
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 33 deletions

View file

@ -43,9 +43,18 @@ pub struct EncryptedApplicationDetails {
impl EncryptedString { impl EncryptedString {
pub async fn new(s: &str, recipients: &Vec<String>) -> Result<Self, ServiceError> { pub async fn new(s: &str, recipients: &Vec<String>) -> Result<Self, ServiceError> {
let recipients = recipients.iter().map(|s| &**s).collect(); let recipients = recipients.iter().map(|s| &**s).collect();
match crypto::encrypt_password_with_recipients(&s, &recipients).await { let encrypted_string = crypto::encrypt_password_with_recipients(&s, &recipients).await?;
Ok(encrypted) => Ok(Self(encrypted)), Ok(Self(encrypted_string))
Err(_) => Err(ServiceError::CryptoEncryptFailed), }
pub async fn new_option(s: &str, recipients: &Vec<String>) -> Result<Option<Self>, ServiceError> {
match s.is_empty() {
true => Ok(None),
false => {
let recipients = recipients.iter().map(|s| &**s).collect();
let encrypted_s = crypto::encrypt_password_with_recipients(&s, &recipients).await?;
Ok(Some(Self(encrypted_s)))
},
} }
} }
@ -109,30 +118,30 @@ impl EncryptedCandidateDetails {
) -> Result<EncryptedCandidateDetails, ServiceError> { ) -> Result<EncryptedCandidateDetails, ServiceError> {
let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string(); let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string();
let d = tokio::try_join!( let d = tokio::try_join!(
EncryptedString::new(&form.name, recipients), EncryptedString::new_option(&form.name, recipients),
EncryptedString::new(&form.surname, recipients), EncryptedString::new_option(&form.surname, recipients),
EncryptedString::new(&form.birthplace, recipients), EncryptedString::new_option(&form.birthplace, recipients),
EncryptedString::new(&birthdate_str, recipients), EncryptedString::new_option(&birthdate_str, recipients),
EncryptedString::new(&form.address, recipients), EncryptedString::new_option(&form.address, recipients),
EncryptedString::new(&form.telephone, recipients), EncryptedString::new_option(&form.telephone, recipients),
EncryptedString::new(&form.citizenship, recipients), EncryptedString::new_option(&form.citizenship, recipients),
EncryptedString::new(&form.email, recipients), EncryptedString::new_option(&form.email, recipients),
EncryptedString::new(&form.sex, recipients), EncryptedString::new_option(&form.sex, recipients),
EncryptedString::new(&form.personal_id_number, recipients), EncryptedString::new_option(&form.personal_id_number, recipients),
)?; )?;
Ok( Ok(
EncryptedCandidateDetails { EncryptedCandidateDetails {
name: Some(d.0), name: d.0,
surname: Some(d.1), surname: d.1,
birthplace: Some(d.2), birthplace: d.2,
birthdate: Some(d.3), birthdate: d.3,
address: Some(d.4), address: d.4,
telephone: Some(d.5), telephone: d.5,
citizenship: Some(d.6), citizenship: d.6,
email: Some(d.7), email: d.7,
sex: Some(d.8), sex: d.8,
personal_id_number: Some(d.9), personal_id_number: d.9,
study: Some(form.study.clone()), study: Some(form.study.clone()),
} }
) )
@ -208,18 +217,18 @@ impl EncryptedParentDetails {
recipients: &Vec<String>, recipients: &Vec<String>,
) -> Result<EncryptedParentDetails, ServiceError> { ) -> Result<EncryptedParentDetails, ServiceError> {
let d = tokio::try_join!( let d = tokio::try_join!(
EncryptedString::new(&form.name, recipients), EncryptedString::new_option(&form.name, recipients),
EncryptedString::new(&form.surname, recipients), EncryptedString::new_option(&form.surname, recipients),
EncryptedString::new(&form.telephone, recipients), EncryptedString::new_option(&form.telephone, recipients),
EncryptedString::new(&form.email, recipients), EncryptedString::new_option(&form.email, recipients),
)?; )?;
Ok( Ok(
EncryptedParentDetails { EncryptedParentDetails {
name: Some(d.0), name: d.0,
surname: Some(d.1), surname: d.1,
telephone: Some(d.2), telephone: d.2,
email: Some(d.3), email: d.3,
} }
) )
} }

View file

@ -44,8 +44,6 @@ impl ApplicationService {
db: &DbConn, db: &DbConn,
candidate: candidate::Model, candidate: candidate::Model,
) -> Result<ApplicationDetails, ServiceError> { ) -> Result<ApplicationDetails, ServiceError> {
println!("Decrypting all details: privkey: {}", private_key);
let parents = Query::find_candidate_parents(db, &candidate).await?; let parents = Query::find_candidate_parents(db, &candidate).await?;
let enc_details = EncryptedApplicationDetails::from((&candidate, parents)); let enc_details = EncryptedApplicationDetails::from((&candidate, parents));