Skip to content
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

Merged
merged 1 commit into from
Mar 31, 2020

Conversation

hug-dev
Copy link
Member

@hug-dev hug-dev commented Mar 31, 2020

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

The tests are disabled for now until the checking feature is implemented.

@hug-dev hug-dev added the enhancement New feature or request label Mar 31, 2020
@hug-dev hug-dev self-assigned this Mar 31, 2020
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]>
Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +10 to +50
#[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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

Comment on lines +102 to +121
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,
},
};
Copy link
Member

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)

Copy link
Member Author

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

@hug-dev hug-dev merged commit a6df479 into parallaxsecond:master Mar 31, 2020
@hug-dev hug-dev deleted the key_attributes_tests branch March 31, 2020 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants