-
Notifications
You must be signed in to change notification settings - Fork 65
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
attribute extension defining Unhanled attribute type and EC Kdf improvements #241
Open
ilkerBaltaci
wants to merge
2
commits into
parallaxsecond:main
Choose a base branch
from
ilkerBaltaci:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ use crate::error::{Error, Result}; | |
use crate::mechanism::MechanismType; | ||
use crate::types::{Date, Ulong}; | ||
use cryptoki_sys::*; | ||
use log::error; | ||
use log::{error, warn}; | ||
use std::convert::TryFrom; | ||
use std::convert::TryInto; | ||
use std::ffi::c_void; | ||
|
@@ -136,6 +136,8 @@ pub enum AttributeType { | |
Wrap, | ||
/// Indicates that the key can only be wrapped with a wrapping key that has the Trusted attribute | ||
WrapWithTrusted, | ||
/// Wraps undefined and custom attribute types. | ||
Unhandled(CK_ATTRIBUTE_TYPE), | ||
} | ||
|
||
impl AttributeType { | ||
|
@@ -328,6 +330,7 @@ impl From<AttributeType> for CK_ATTRIBUTE_TYPE { | |
AttributeType::VerifyRecover => CKA_VERIFY_RECOVER, | ||
AttributeType::Wrap => CKA_WRAP, | ||
AttributeType::WrapWithTrusted => CKA_WRAP_WITH_TRUSTED, | ||
AttributeType::Unhandled(attr_type) => attr_type, | ||
} | ||
} | ||
} | ||
|
@@ -397,8 +400,10 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType { | |
CKA_WRAP => Ok(AttributeType::Wrap), | ||
CKA_WRAP_WITH_TRUSTED => Ok(AttributeType::WrapWithTrusted), | ||
attr_type => { | ||
error!("Attribute type {} not supported.", attr_type); | ||
Err(Error::NotSupported) | ||
// error!("Attribute type {} not supported.", attr_type); | ||
// Err(Error::NotSupported) | ||
warn!("Unhandled attribute type {} detected.", attr_type); | ||
Ok(AttributeType::Unhandled(attr_type)) | ||
} | ||
} | ||
} | ||
|
@@ -526,6 +531,8 @@ pub enum Attribute { | |
Wrap(bool), | ||
/// Indicates that the key can only be wrapped with a wrapping key that has the Trusted attribute | ||
WrapWithTrusted(bool), | ||
/// Not defined attributes enter this option. | ||
Unhandled(CK_ATTRIBUTE_TYPE, Vec<u8>), | ||
} | ||
|
||
impl Attribute { | ||
|
@@ -591,6 +598,7 @@ impl Attribute { | |
Attribute::VerifyRecover(_) => AttributeType::VerifyRecover, | ||
Attribute::Wrap(_) => AttributeType::Wrap, | ||
Attribute::WrapWithTrusted(_) => AttributeType::WrapWithTrusted, | ||
Attribute::Unhandled(attribute_type, _) => AttributeType::Unhandled(*attribute_type), | ||
} | ||
} | ||
|
||
|
@@ -658,6 +666,7 @@ impl Attribute { | |
Attribute::AllowedMechanisms(mechanisms) => { | ||
size_of::<CK_MECHANISM_TYPE>() * mechanisms.len() | ||
} | ||
Attribute::Unhandled(_, bytes) => bytes.len(), | ||
} | ||
} | ||
|
||
|
@@ -730,7 +739,8 @@ impl Attribute { | |
| Attribute::Subject(bytes) | ||
| Attribute::Url(bytes) | ||
| Attribute::Value(bytes) | ||
| Attribute::Id(bytes) => bytes.as_ptr() as *mut c_void, | ||
| Attribute::Id(bytes) | ||
| Attribute::Unhandled(_, bytes) => bytes.as_ptr() as *mut c_void, | ||
// Unique types | ||
Attribute::CertificateType(certificate_type) => { | ||
certificate_type as *const _ as *mut c_void | ||
|
@@ -930,6 +940,7 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute { | |
} | ||
} | ||
} | ||
AttributeType::Unhandled(_) => todo!(), | ||
} | ||
} | ||
} | ||
|
@@ -1006,6 +1017,8 @@ impl ObjectClass { | |
pub const MECHANISM: ObjectClass = ObjectClass { val: CKO_MECHANISM }; | ||
/// An OTP key object | ||
pub const OTP_KEY: ObjectClass = ObjectClass { val: CKO_OTP_KEY }; | ||
/// A profile object | ||
pub const PROFILE: ObjectClass = ObjectClass { val: CKO_PROFILE }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is perfect to add though! |
||
|
||
pub(crate) fn stringify(class: CK_OBJECT_CLASS) -> String { | ||
match class { | ||
|
@@ -1018,6 +1031,7 @@ impl ObjectClass { | |
CKO_DOMAIN_PARAMETERS => String::from(stringify!(CKO_DOMAIN_PARAMETERS)), | ||
CKO_MECHANISM => String::from(stringify!(CKO_MECHANISM)), | ||
CKO_OTP_KEY => String::from(stringify!(CKO_OTP_KEY)), | ||
CKO_PROFILE => String::from(stringify!(CKO_PROFILE)), | ||
_ => format!("unknown ({class:08x})"), | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hey @ilkerBaltaci , thanks for your PR 🙏!
I understand the idea behind the
Unhandled
types, but I think we strive to only expose in thecryptoki
crate idiomatic structures and functions which are safe to use and abstracted away from the raw PKCS11 types. That's summarized in our README:I will let other maintainers give their opinions but I think that if you have new types/algos you want to add it's best to do so in the high-level "way" where you add corresponding
cryptoki
structures/functions for those new types