Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nssdb: Add missing attrs for getting skipped attributes #131

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/storage/nssdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ impl Storage for NSSStorage {
* is not a key, the attribute will simply not be returned
* in that case */
attrs.add_missing_ulong(CKA_KEY_TYPE, &dnm);
attrs.add_missing_ulong(CKA_CERTIFICATE_TYPE, &dnm);
attrs.add_missing_ulong(CKA_EXTRACTABLE, &dnm);
attrs.add_missing_ulong(CKA_SENSITIVE, &dnm);
/* we can not query a DB for these */
Expand Down
24 changes: 23 additions & 1 deletion src/tests/nssdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn test_nssdb_init_token() {

/* add a public object to ensure attributes are handled correctly
* CKA_VALUE is encrypted only for private objects */
let _ = ret_or_panic!(import_object(
let cert_handle = ret_or_panic!(import_object(
session,
CKO_CERTIFICATE,
&[(CKA_CERTIFICATE_TYPE, CKC_X_509)],
Expand All @@ -218,6 +218,28 @@ fn test_nssdb_init_token() {
&[(CKA_TOKEN, true), (CKA_TRUSTED, false)],
));

/* Read the cert back */
let mut template =
make_ptrs_template(&[(CKA_VALUE, std::ptr::null_mut(), 0)]);
let ret = fn_get_attribute_value(
session,
cert_handle,
template.as_mut_ptr(),
template.len() as CK_ULONG,
);
assert_eq!(ret, CKR_OK);
assert_eq!(template[0].ulValueLen, 5);
let mut value = vec![0u8; 5];
template[0].pValue = void_ptr!(value.as_mut_ptr());
let ret = fn_get_attribute_value(
session,
cert_handle,
template.as_mut_ptr(),
template.len() as CK_ULONG,
);
assert_eq!(ret, CKR_OK);
assert_eq!(value.as_slice(), "value".as_bytes());

let ret = fn_logout(session);
assert_eq!(ret, CKR_OK);

Expand Down