-
Notifications
You must be signed in to change notification settings - Fork 68
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
Add tests checking if key attributes are respected #135
Conversation
These tests check: * asymmetric signature operations can only be done if they is of correct type * the specific algorithm used for those operations needs to be permitted * the usage flags of the key need to allow the operation Signed-off-by: Hugues de Valon <[email protected]>
39d25b7
to
ed2978c
Compare
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.
LGTM
#[ignore] | ||
#[test] | ||
fn wrong_type() { | ||
let mut client = TestClient::new(); | ||
let key_name = String::from("wrong_type"); | ||
|
||
// Wrong key type | ||
let key_type = KeyType::Derive; | ||
let permitted_algorithm = | ||
Algorithm::AsymmetricSignature(AsymmetricSignature::RsaPkcs1v15Sign { | ||
hash_alg: Hash::Sha256, | ||
}); | ||
let key_attributes = KeyAttributes { | ||
key_type, | ||
key_bits: 1024, | ||
key_policy: KeyPolicy { | ||
key_usage_flags: UsageFlags { | ||
sign_hash: true, | ||
verify_hash: false, | ||
sign_message: false, | ||
verify_message: false, | ||
export: false, | ||
encrypt: false, | ||
decrypt: false, | ||
cache: false, | ||
copy: false, | ||
derive: false, | ||
}, | ||
key_algorithm: permitted_algorithm, | ||
}, | ||
}; | ||
|
||
client | ||
.generate_key(key_name.clone(), key_attributes) | ||
.unwrap(); | ||
let status = client | ||
.sign_with_rsa_sha256(key_name, vec![0xDE, 0xAD, 0xBE, 0xEF]) | ||
.unwrap_err(); | ||
|
||
assert_eq!(status, ResponseStatus::PsaErrorNotPermitted); | ||
} |
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.
Nice 👍
let permitted_algorithm = Algorithm::Cipher(Cipher::Ctr); | ||
let key_attributes = KeyAttributes { | ||
key_type, | ||
key_bits: 1024, | ||
key_policy: KeyPolicy { | ||
key_usage_flags: UsageFlags { | ||
sign_hash: true, | ||
verify_hash: false, | ||
sign_message: false, | ||
verify_message: false, | ||
export: false, | ||
encrypt: false, | ||
decrypt: false, | ||
cache: false, | ||
copy: false, | ||
derive: false, | ||
}, | ||
key_algorithm: permitted_algorithm, | ||
}, | ||
}; |
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'm wondering if this should even be permitted to exist. Feels like the kind of thing we can enforce, because we know what is allowed and what isn't. We can't use type checking directly, but maybe we can use constructors (e.g. for KeyAttributes
)
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.
True! Those things could be done as part of parallaxsecond/parsec-interface-rs#32
These tests check:
type
The tests are disabled for now until the checking feature is implemented.