diff options
author | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2020-08-31 09:53:46 +0200 |
---|---|---|
committer | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2020-12-11 16:21:05 +0100 |
commit | 9d2be868385689fc02b7e0c67763cf2740ff8072 (patch) | |
tree | 537515221da61170fbe7c8ac115f7831e85a9936 /openpgp/src/policy.rs | |
parent | a3789e42d892fd2f1412a83b97b1206d192ea569 (diff) |
openpgp: Change Policy trait default to reject.
Diffstat (limited to 'openpgp/src/policy.rs')
-rw-r--r-- | openpgp/src/policy.rs | 200 |
1 files changed, 190 insertions, 10 deletions
diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs index c763abd9..90349485 100644 --- a/openpgp/src/policy.rs +++ b/openpgp/src/policy.rs @@ -13,7 +13,7 @@ //! to ignore keys using MD5, even though [RFC 4880] deprecates MD5. //! //! Rather than not provide this mid-level functionality, the `Policy` -//! trait allows callers to specify their prefer policy. This can be +//! trait allows callers to specify their preferred policy. This can be //! highly customized by providing a custom implementation of the //! `Policy` trait, or it can be slightly refined by tweaking the //! `StandardPolicy`'s parameters. @@ -77,10 +77,8 @@ pub trait Policy : fmt::Debug + Send + Sync { /// signatures, one should be more liberal when considering /// revocations: if you reject a revocation certificate, it may /// inadvertently make something else valid! - fn signature(&self, _sig: &Signature, _sec: HashAlgoSecurity) - -> Result<()> - { - Ok(()) + fn signature(&self, _sig: &Signature, _sec: HashAlgoSecurity) -> Result<()> { + Err(anyhow::anyhow!("By default all signatures are rejected.")) } /// Returns an error if the key violates the policy. @@ -101,7 +99,7 @@ pub trait Policy : fmt::Debug + Send + Sync { fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) -> Result<()> { - Ok(()) + Err(anyhow::anyhow!("By default all keys are rejected.")) } /// Returns an error if the symmetric encryption algorithm @@ -113,7 +111,7 @@ pub trait Policy : fmt::Debug + Send + Sync { /// With this function, you can prevent the use of insecure /// symmetric encryption algorithms. fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { - Ok(()) + Err(anyhow::anyhow!("By default all symmetric algorithms are rejected.")) } /// Returns an error if the AEAD mode violates the policy. @@ -126,7 +124,7 @@ pub trait Policy : fmt::Debug + Send + Sync { /// /// This feature is [experimental](../index.html#experimental-features). fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { - Ok(()) + Err(anyhow::anyhow!("By default all AEAD algorithms are rejected.")) } /// Returns an error if the packet violates the policy. @@ -138,7 +136,7 @@ pub trait Policy : fmt::Debug + Send + Sync { /// encryption containers, notably the *Symmetrically Encrypted /// Data Packet*. fn packet(&self, _packet: &Packet) -> Result<()> { - Ok(()) + Err(anyhow::anyhow!("By default all packets are rejected.")) } } @@ -724,7 +722,9 @@ impl<'a> StandardPolicy<'a> { /// /// The current time is None. /// - /// See `StandardPolicy::at` for details. + /// See [`StandardPolicy::at`] for details. + /// + /// [`StandardPolicy::at`]: struct.StandardPolicy.html#method.at pub fn time(&self) -> Option<SystemTime> { self.time.map(Into::into) } @@ -1263,6 +1263,28 @@ impl NullPolicy { } impl Policy for NullPolicy { + fn signature(&self, _sig: &Signature, _sec: HashAlgoSecurity) -> Result<()> { + Ok(()) + } + + fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) + -> Result<()> + { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } + } #[cfg(test)] @@ -1319,6 +1341,24 @@ mod test { _ => Ok(()), } } + + fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) + -> Result<()> + { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } } let p = &NoDirectKeySigs {}; @@ -1338,6 +1378,24 @@ mod test { _ => Ok(()), } } + + fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) + -> Result<()> + { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } } let p = &NoSubkeySigs {}; @@ -1377,6 +1435,24 @@ mod test { _ => Ok(()), } } + + fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) + -> Result<()> + { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } } let p = &NoPositiveCertifications {}; assert_eq!(cert.userids().with_policy(p, None).count(), 0); @@ -1416,6 +1492,24 @@ mod test { _ => Ok(()), } } + + fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) + -> Result<()> + { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } } let p = &NoCertificationRevocation {}; @@ -1452,6 +1546,24 @@ mod test { _ => Ok(()), } } + + fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) + -> Result<()> + { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } } let p = &NoSubkeyRevocation {}; @@ -1534,6 +1646,24 @@ mod test { _ => Ok(()), } } + + fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) + -> Result<()> + { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } } let no_binary_signatures = &NoBinarySigantures {}; @@ -1551,6 +1681,24 @@ mod test { _ => Ok(()), } } + + fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) + -> Result<()> + { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } } let no_subkey_signatures = &NoSubkeySigs {}; @@ -1800,6 +1948,22 @@ mod test { Ok(()) } } + + fn signature(&self, _sig: &Signature, _sec: HashAlgoSecurity) -> Result<()> { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } } let norsa = &NoRsa {}; @@ -1901,6 +2065,22 @@ mod test { Ok(()) } } + + fn signature(&self, _sig: &Signature, _sec: HashAlgoSecurity) -> Result<()> { + Ok(()) + } + + fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { + Ok(()) + } + + fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { + Ok(()) + } + + fn packet(&self, _packet: &Packet) -> Result<()> { + Ok(()) + } } let norsa = &NoRsa {}; |