-
Notifications
You must be signed in to change notification settings - Fork 87
Add pReserved and pkcs11 flags #329
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
base: main
Are you sure you want to change the base?
Add pReserved and pkcs11 flags #329
Conversation
d0a4f65 to
40a4111
Compare
|
There is still the docstring to change. I'll do that after I've confirmed the final state of |
Signed-off-by: Alexandru Placinta <[email protected]>
40a4111 to
816da50
Compare
hug-dev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! As said with the comments I think we don't have to continue with the enum type as it is now but start from scratch with a more straightforward implementation :)
|
|
||
| /// Flags to set for the initialize function | ||
| #[derive(Copy, Clone, Debug)] | ||
| pub enum CInitializeFlags { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to start with a new abstraction of this type it would be nice to go with a "dumber" 1-1 mapping with the C type. I think it's nicer to start simple and straightforward and then improve over time depending on usage.
I mean the following:
- making
CInitializeArgsa struct with the same fields as in the standard but no need to havepReservedfor now (it can be set to null always in theFromimplementation). - The
CInitializeFlagsflags could be created as abitflagsdefinition, similar than what is done forMechanismInfoFlags. That way it can expend easily with new flags in future versions. - The
CInitializeArgsbasic constructor would take the five arguments as inputs (Optionfor the mutex functions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the 1st point, but the purpose of the PR was to add the pReserved pointer. I see 2 ways here:
- allowing the pointer and using
unsafe - restraining the user to some known cryptokis that use
pReservedand the type of those structs. We would create safe bindings to those structs. The pointer would be then obtained viaBox::into_raw(Box::new(safe_object))and we would have to manage that pointer
pub enum Reserved {
None,
IBM(IBMInitParams),
Utimaco(UtimacoInitParams),
}
let p_reserved = Box::into_raw(Box::new(Reserved::IBM(...)));Regarding points 2 and 3 I see the following problems:
- for point 2: one could set both
CKF_OS_LOCKING_OKandCKF_LIBRARY_CANT_CREATE_OS_THREADS. Is that a valid situation? - for point 3: all 4 mutex functions must be provided according to PKCS#11 docs. Allowing
Optionwould add unnecessary runtime validation so that all matchSome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but the purpose of the PR was to add the pReserved pointer.
Yes 🤦 ! I forgot the whole purpose of the related issue 😬
for point 2: one could set both CKF_OS_LOCKING_OK and CKF_LIBRARY_CANT_CREATE_OS_THREADS. Is that a valid situation?
I think the PKCS11 API does not prevent it so I guess we should not limit either... But agree that some combinations of those two are pretty weird.
for point 3: all 4 mutex functions must be provided according to PKCS#11 docs. Allowing Option would add unnecessary runtime validation that can be avoided
Let's see what we decide with the other comment to see how we proceed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They mention that if CKF_LIBRARY_CANT_CREATE_OS_THREADS is set and the lib can't work with it then C_Initialize will return with code CKR_NEED_TO_CREATE_THREADS. So I guess I can go with bitflags
|
|
||
| /// Argument for the initialize function | ||
| /// Function pointer that creates a mutex | ||
| pub type CreateMutexFn = unsafe extern "C" fn(*mut *mut ::std::os::raw::c_void) -> CK_RV; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to also create abstraction types for those functions, which would be safe abstractions over the CK_LOCKMUTEX, CK_UNLOCKMUTEX, CK_DESTROYMUTEX and CK_CREATEMUTEX types. They would take in and return abstracted types and be converted to the C function in our code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I agree with that. the thing is I do not know how they would look like (I've never had to pass those functions when i initialize cryptoki)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are defined here but I could not come up with a nice way to do this is pure Rust.
I was thinking of defining a trait Mutex with all those methods but not sure how one could define trait methods as types 🤔
I am wondering if to not make it easier for now we could ignore those functions? As in always set them to None and remove it as parameters. Until someone needs them and then we can think about how to do it?
Unless you come up with a good way to do this.
#321: Add
pReservedtoCInitializeArgsand other flags as as stated in PKCS#11 initialize doc