Skip to content
Open
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ minimal = ["sqlitedb", "aes", "ecc_min", "hash_all", "rsa"]

ossl400 = ["ossl/ossl400"]
vsprintf = ["dep:vsprintf"]

hotp = []
6 changes: 6 additions & 0 deletions src/enabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ mod hkdf;
#[cfg(feature = "hmac")]
mod hmac;

#[cfg(feature = "hotp")]
mod hotp;

#[cfg(feature = "pbkdf2")]
mod pbkdf2;

Expand Down Expand Up @@ -88,6 +91,9 @@ fn register_all(mechs: &mut Mechanisms, ot: &mut ObjectFactories) {
#[cfg(feature = "hmac")]
hmac::register(mechs, ot);

#[cfg(feature = "hotp")]
hotp::register(mechs, ot);

#[cfg(feature = "pbkdf2")]
pbkdf2::register(mechs, ot);

Expand Down
50 changes: 50 additions & 0 deletions src/fns/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fn sign(
}
let rstate = STATE.rlock()?;
let mut session = rstate.get_session_mut(s_handle)?;
let slot_id = session.get_slot_id();
let operation = session.get_operation::<dyn Sign>()?;
let signature_len = operation.signature_len()?;
let sig_len =
Expand All @@ -112,6 +113,14 @@ fn sign(
unsafe { std::slice::from_raw_parts_mut(psignature, signature_len) };

operation.sign(data, signature)?;

if let Some((handle, attrs)) = operation.updates_object() {
let mut token = rstate.get_token_from_slot_mut(slot_id)?;
if token.set_object_attrs(handle, attrs.as_slice()).is_err() {
return Err(CKR_GENERAL_ERROR)?;
}
}

unsafe {
*pul_signature_len = sig_len;
}
Expand Down Expand Up @@ -213,6 +222,7 @@ fn sign_final(
}
let rstate = STATE.rlock()?;
let mut session = rstate.get_session_mut(s_handle)?;
let slot_id = session.get_slot_id();
let operation = session.get_operation::<dyn Sign>()?;
let signature_len = operation.signature_len()?;
let sig_len =
Expand All @@ -231,6 +241,14 @@ fn sign_final(
let signature: &mut [u8] =
unsafe { std::slice::from_raw_parts_mut(psignature, signature_len) };
operation.sign_final(signature)?;

if let Some((handle, attrs)) = operation.updates_object() {
let mut token = rstate.get_token_from_slot_mut(slot_id)?;
if token.set_object_attrs(handle, attrs.as_slice()).is_err() {
return Err(CKR_GENERAL_ERROR)?;
}
}

unsafe {
*pul_signature_len = sig_len;
}
Expand Down Expand Up @@ -363,6 +381,7 @@ fn verify(
}
let rstate = STATE.rlock()?;
let mut session = rstate.get_session_mut(s_handle)?;
let slot_id = session.get_slot_id();
let operation = session.get_operation::<dyn Verify>()?;
let signature_len = operation.signature_len()?;
let sig_len =
Expand All @@ -376,6 +395,13 @@ fn verify(
unsafe { std::slice::from_raw_parts(psignature, signature_len) };
operation.verify(data, signature)?;

if let Some((handle, attrs)) = operation.updates_object() {
let mut token = rstate.get_token_from_slot_mut(slot_id)?;
if token.set_object_attrs(handle, attrs.as_slice()).is_err() {
return Err(CKR_GENERAL_ERROR)?;
}
}

#[cfg(feature = "fips")]
{
let approved = operation.fips_approved();
Expand Down Expand Up @@ -473,6 +499,7 @@ fn verify_final(
}
let rstate = STATE.rlock()?;
let mut session = rstate.get_session_mut(s_handle)?;
let slot_id = session.get_slot_id();
let operation = session.get_operation::<dyn Verify>()?;
let signature_len = operation.signature_len()?;
let sig_len =
Expand All @@ -484,6 +511,13 @@ fn verify_final(
unsafe { std::slice::from_raw_parts_mut(psignature, signature_len) };
operation.verify_final(signature)?;

if let Some((handle, attrs)) = operation.updates_object() {
let mut token = rstate.get_token_from_slot_mut(slot_id)?;
if token.set_object_attrs(handle, attrs.as_slice()).is_err() {
return Err(CKR_GENERAL_ERROR)?;
}
}

#[cfg(feature = "fips")]
{
let approved = operation.fips_approved();
Expand Down Expand Up @@ -757,11 +791,19 @@ fn verify_signature(
}
let rstate = STATE.rlock()?;
let mut session = rstate.get_session_mut(s_handle)?;
let slot_id = session.get_slot_id();
let operation = session.get_operation::<dyn VerifySignature>()?;
let dlen = usize::try_from(data_len).map_err(|_| CKR_ARGUMENTS_BAD)?;
let data: &[u8] = unsafe { std::slice::from_raw_parts(pdata, dlen) };
operation.verify(data)?;

if let Some((handle, attrs)) = operation.updates_object() {
let mut token = rstate.get_token_from_slot_mut(slot_id)?;
if token.set_object_attrs(handle, attrs.as_slice()).is_err() {
return Err(CKR_GENERAL_ERROR)?;
}
}

#[cfg(feature = "fips")]
{
let approved = operation.fips_approved();
Expand Down Expand Up @@ -837,9 +879,17 @@ pub extern "C" fn fn_verify_signature_update(
fn verify_signature_final(s_handle: CK_SESSION_HANDLE) -> Result<()> {
let rstate = STATE.rlock()?;
let mut session = rstate.get_session_mut(s_handle)?;
let slot_id = session.get_slot_id();
let operation = session.get_operation::<dyn VerifySignature>()?;
operation.verify_final()?;

if let Some((handle, attrs)) = operation.updates_object() {
let mut token = rstate.get_token_from_slot_mut(slot_id)?;
if token.set_object_attrs(handle, attrs.as_slice()).is_err() {
return Err(CKR_GENERAL_ERROR)?;
}
}

#[cfg(feature = "fips")]
{
let approved = operation.fips_approved();
Expand Down
Loading
Loading