-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests checking if key attributes are respected
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]>
- Loading branch information
Showing
12 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright (c) 2020, Arm Limited, All Rights Reserved | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use parsec_client_test::TestClient; | ||
use parsec_interface::requests::ResponseStatus; | ||
use parsec_interface::operations::psa_key_attributes::{KeyType, KeyAttributes, KeyPolicy, UsageFlags}; | ||
use parsec_interface::operations::psa_algorithm::{Algorithm, AsymmetricSignature, Hash, Cipher}; | ||
|
||
#[disable] | ||
#[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); | ||
} | ||
|
||
#[disable] | ||
#[test] | ||
fn wrong_usage_flags() { | ||
let mut client = TestClient::new(); | ||
let key_name = String::from("wrong_usage_flags"); | ||
|
||
let key_type = KeyType::RsaKeyPair; | ||
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 { | ||
// Forbid signing | ||
sign_hash: false, | ||
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); | ||
} | ||
|
||
#[disable] | ||
#[test] | ||
fn wrong_permitted_algorithm() { | ||
let mut client = TestClient::new(); | ||
let key_name = String::from("wrong_permitted_algorithm"); | ||
|
||
let key_type = KeyType::RsaKeyPair; | ||
// Do not permit RSA PKCS 1v15 signing algorithm with SHA-256. | ||
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, | ||
}, | ||
}; | ||
|
||
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); | ||
} |
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ mod create_destroy_key; | |
mod export_public_key; | ||
mod import_key; | ||
mod ping; | ||
mod key_attributes; |
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