Skip to content

Ability to capture login PIN (C_Login) #470

@wiktor-k

Description

@wiktor-k

Hi,

I'm trying out your excellent library and the one thing I'm missing is the ability to capture PIN as entered by the client (basically the C_Login function).

I'm currently using this workaround:

    native_pkcs11_traits::register_backend(Box::new(Backend::default()));
    unsafe {
        info!("replacing login");
        FUNC_LIST.C_Login = Some(C_Login_2);
        FUNC_LIST.C_GetTokenInfo = Some(C_GetTokenInfo_2);
    }

with:

#[unsafe(no_mangle)]
pub extern "C" fn C_Login_2(
    _h_session: CK_SESSION_HANDLE,
    user_type: CK_USER_TYPE,
    p_pin: CK_UTF8CHAR_PTR,
    ul_pin_len: CK_ULONG,
) -> CK_RV {
    let pin = str::from_utf8(unsafe { slice::from_raw_parts(p_pin, ul_pin_len as usize) }).unwrap();

    info!("got pin {user_type:?}, {pin}");
    CKR_OK
}

which kind of works but sadly makes me deal with the low-level types.

Would support for capturing C_Login via high-level API (e.g. native_pkcs11_traits::Backend) be a good fit?

(I think it'd be possible to provide a default no-op function there so that the API stays stable).

Thanks for such a great library! 👋

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions