Skip to content

Commit

Permalink
Filter out sensitive attributes from searches
Browse files Browse the repository at this point in the history
Signed-off-by: Simo Sorce <[email protected]>
  • Loading branch information
simo5 committed Nov 22, 2024
1 parent d0060c8 commit 8f7c9d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/storage/nssdb/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,22 @@ pub fn ignore_attribute(attr: CK_ATTRIBUTE_TYPE) -> bool {
}
return false;
}

pub static NSS_SENSITIVE_ATTRIBUTES: [CK_ATTRIBUTE_TYPE; 7] = [
CKA_VALUE,
CKA_PRIVATE_EXPONENT,
CKA_PRIME_1,
CKA_PRIME_2,
CKA_EXPONENT_1,
CKA_EXPONENT_2,
CKA_COEFFICIENT,
];

pub fn is_sensitive_attribute(attr: CK_ATTRIBUTE_TYPE) -> bool {
for a in &NSS_SENSITIVE_ATTRIBUTES {
if attr == *a {
return true;
}
}
return false;
}
8 changes: 6 additions & 2 deletions src/storage/nssdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,14 @@ impl NSSStorage {
CKO_PUBLIC_KEY | CKO_CERTIFICATE => do_keys = false,
_ => return Err(CKR_ATTRIBUTE_VALUE_INVALID)?,
}
break;
}
}
/* In NSSDB sensitive attributes are encrypted, so we can check
* if the template is searching for any of the encrypted
* attributes and if so just fail immediately */
if is_sensitive_attribute(template[idx].type_) {
return Err(CKR_ATTRIBUTE_SENSITIVE)?;
}
}

/* if neither was excluded we may be asked for both */
Expand Down Expand Up @@ -741,7 +746,6 @@ impl Storage for NSSStorage {
let mut ids = self.search_databases(template)?;
let mut result = Vec::<CK_OBJECT_HANDLE>::with_capacity(ids.len());
for id in ids.drain(..) {
/* FIXME: check for sensitive ! */
let handle = match facilities.handles.get_by_uid(&id) {
Some(h) => *h,
None => {
Expand Down

0 comments on commit 8f7c9d4

Please sign in to comment.