pub struct KeyPolicy {
pub persistent: bool,
pub sensitive: bool,
pub extractable: bool,
pub wrap_with_trusted_only: bool,
pub usages: KeyUsages,
}Expand description
Security and usage policy for a generated or imported key.
Backends that cannot honour a requested policy MUST return
BackendError::OperationNotPermitted rather than silently ignoring it.
For example, a PIV backend receiving extractable: true must reject it
because PIV keys are always non-extractable by hardware design.
Fields§
§persistent: boolKey persists after session ends. Always true for PIV. CKA_TOKEN in PKCS#11.
sensitive: boolKey material never revealed in plaintext. Always true for PIV. CKA_SENSITIVE.
extractable: boolKey can be wrapped and exported. Always false for PIV. CKA_EXTRACTABLE.
wrap_with_trusted_only: boolKey can only be wrapped by a CKA_TRUSTED wrapping key. PKCS#11 CKA_WRAP_WITH_TRUSTED.
usages: KeyUsagesWhat operations this key is permitted to perform.
Implementations§
Source§impl KeyPolicy
impl KeyPolicy
Sourcepub fn require(
&self,
usage: KeyUsages,
operation: &str,
) -> Result<(), BackendError>
pub fn require( &self, usage: KeyUsages, operation: &str, ) -> Result<(), BackendError>
Refuse an operation this policy does not allow.
The policy is what the ceremony asked for at generation. A token enforces it itself; a software backend has no token, so it calls this.
§Errors
Returns BackendError::OperationNotPermitted when usage is absent
from the policy, naming what the key may do instead.
Source§impl KeyPolicy
impl KeyPolicy
Sourcepub fn default_for(algorithm: KeyAlgorithm) -> Self
pub fn default_for(algorithm: KeyAlgorithm) -> Self
What a key of this algorithm may do when the ceremony says nothing.
A generation step should call this rather than Default, which is
the signing default and gives a symmetric key two usages it can never
have. Rite holds a symmetric key as a key-encryption key and nothing
else, so wrap and unwrap is the whole of what one is for here.
use rite_sdk::{KeyAlgorithm, KeyPolicy, KeyUsages};
let signing = KeyPolicy::default_for(KeyAlgorithm::EcdsaP256);
assert_eq!(signing.usages, KeyUsages::SIGN | KeyUsages::VERIFY);
let kek = KeyPolicy::default_for(KeyAlgorithm::Aes256);
assert_eq!(kek.usages, KeyUsages::WRAP | KeyUsages::UNWRAP);
// Everything else is the restrictive default either way.
assert!(!kek.extractable);