Skip to content

Commit

Permalink
fix: do not allow decryption with "Plaintext" algorithm
Browse files Browse the repository at this point in the history
According to
<https://datatracker.ietf.org/doc/html/rfc4880#section-13.4>
"plaintext" MUST NOT be used to encrypt data packets.
  • Loading branch information
link2xt committed Feb 13, 2024
1 parent 4d9144d commit e07d51f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/composed/message/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl Message {
self.encrypt_symmetric(rng, esk, alg, session_key)
}

/// Encrytp the message using the given password.
/// Encrypt the message using the given password.
pub fn encrypt_with_password<R, F>(
&self,
rng: &mut R,
Expand Down Expand Up @@ -544,6 +544,7 @@ impl Message {
};

let ids = session_keys.into_iter().map(|(k, _)| k).collect();
ensure!(alg != SymmetricKeyAlgorithm::Plaintext, "algorithm cannot be plaintext");

Ok((MessageDecrypter::new(session_key, alg, edata), ids))
}
Expand Down Expand Up @@ -575,6 +576,7 @@ impl Message {

let (session_key, alg) =
decrypt_session_key_with_password(skesk.expect("checked above"), msg_pw)?;
ensure!(alg != SymmetricKeyAlgorithm::Plaintext, "algorithm cannot be plaintext");

Ok(MessageDecrypter::new(session_key, alg, edata))
}
Expand Down

0 comments on commit e07d51f

Please sign in to comment.