Skip to content

Commit

Permalink
Switch imports to crates.io
Browse files Browse the repository at this point in the history
This commit switches our imports from github-format to crates.io-format,
using the newly released crates.

Some fixes are also implemented for issues that have crawled in
recently via these imports.

Signed-off-by: Ionut Mihalcea <[email protected]>
  • Loading branch information
ionut-arm committed Aug 5, 2021
1 parent 1287ba9 commit 961329f
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 124 deletions.
70 changes: 25 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "parsec"
path = "src/bin/main.rs"

[dependencies]
parsec-interface = { git = "https://github.com/parallaxsecond/parsec-interface-rs.git", rev = "6b951390791b398b76eb02c942e24d7c91acc980"}
parsec-interface = "0.25.0"
rand = { version = "0.8.3", features = ["small_rng"], optional = true }
base64 = "0.13.0"
uuid = "0.8.2"
Expand All @@ -26,16 +26,16 @@ toml = "0.5.8"
serde = { version = "1.0.123", features = ["derive"] }
env_logger = "0.8.3"
log = { version = "0.4.14", features = ["serde"] }
cryptoki = { git = "https://github.com/parallaxsecond/rust-cryptoki", rev = "2cd54bba7a00db93b3e9e2acf50726558a1784fc", optional = true, features = ["psa-crypto-conversions"] }
cryptoki = { version = "0.2.0", optional = true, features = ["psa-crypto-conversions"] }
picky-asn1-der = { version = "<=0.2.4", optional = true }
picky-asn1 = { version = ">=0.3.1, <=0.3.1", optional = true }
tss-esapi = { git = "https://github.com/parallaxsecond/rust-tss-esapi", rev = "1f68655e278b0319c080b9804a7bf3f6e11ff721", optional = true }
tss-esapi = { version = "6.1.0", optional = true }
bincode = "1.3.1"
structopt = "0.3.21"
derivative = "2.2.0"
version = "3.0.0"
hex = { version = "0.4.2", optional = true }
psa-crypto = { git = "https://github.com/parallaxsecond/rust-psa-crypto.git", rev = "8605006d34944fa880edd3d4d347f460c5585747", default-features = false, features = ["operations"], optional = true }
psa-crypto = { version = "0.9.0", default-features = false, features = ["operations"], optional = true }
zeroize = { version = "1.2.0", features = ["zeroize_derive"] }
picky-asn1-x509 = { version = "0.4.0", optional = true }
users = "0.11.0"
Expand Down
2 changes: 1 addition & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ run_old_e2e_tests() {
# /tmp/parsec/parsec.sock. This can not be created in the Dockerfile as this is where
# the repository is checked out.
ln -s /tmp/parsec.sock /tmp/parsec/parsec.sock
RUST_BACKTRACE=1 cargo test --manifest-path /tmp/old_e2e_tests/Cargo.toml normal_tests
RUST_BACKTRACE=1 cargo test --manifest-path /tmp/old_e2e_tests/Cargo.toml normal_tests -- --skip asym_verify_fail
fi
}

Expand Down
19 changes: 6 additions & 13 deletions src/key_info_managers/on_disk_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ impl OnDiskKeyInfoManager {
})?;

for app_name_dir_path in list_dirs(&mappings_dir_path)?.iter() {
for provider_dir_path in list_dirs(&app_name_dir_path)?.iter() {
for key_name_file_path in list_files(&provider_dir_path)?.iter() {
for provider_dir_path in list_dirs(app_name_dir_path)?.iter() {
for key_name_file_path in list_files(provider_dir_path)?.iter() {
let mut key_info = Vec::new();
let mut key_info_file = File::open(&key_name_file_path).with_context(|| {
format!(
Expand Down Expand Up @@ -399,17 +399,10 @@ mod test {
key_type: Type::Derive,
bits: 1024,
policy: Policy {
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,
usage_flags: {
let mut usage_flags = UsageFlags::default();
let _ = usage_flags.set_sign_hash();
usage_flags
},
permitted_algorithms: Algorithm::AsymmetricSignature(
AsymmetricSignature::RsaPkcs1v15Sign {
Expand Down
6 changes: 3 additions & 3 deletions src/providers/cryptoauthlib/key_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ impl Provider {
.find_suitable_slot(&key_attributes, Some(Opcode::PsaImportKey))?;
let key_data = raw_key_extract(key_attributes.key_type, &op.data)?;

let atca_error_status =
self.device
.import_key(key_type, &key_data.expose_secret(), slot_id);
let atca_error_status = self
.device
.import_key(key_type, key_data.expose_secret(), slot_id);

let psa_error_status: ResponseStatus = match atca_error_status {
rust_cryptoauthlib::AtcaStatus::AtcaSuccess => {
Expand Down
74 changes: 30 additions & 44 deletions src/providers/cryptoauthlib/key_slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl AteccKeySlot {

fn is_usage_flags_ok(&self, key_attr: &Attributes) -> bool {
let mut result = true;
if key_attr.policy.usage_flags.export || key_attr.policy.usage_flags.copy {
if key_attr.policy.usage_flags.export() || key_attr.policy.usage_flags.copy() {
result &= match key_attr.key_type {
Type::EccKeyPair { .. } => {
self.config.key_type == rust_cryptoauthlib::KeyType::P256EccKey
Expand All @@ -128,7 +128,7 @@ impl AteccKeySlot {
return result;
}

if key_attr.policy.usage_flags.sign_hash || key_attr.policy.usage_flags.sign_message {
if key_attr.policy.usage_flags.sign_hash() || key_attr.policy.usage_flags.sign_message() {
result &= self.config.key_type == rust_cryptoauthlib::KeyType::P256EccKey;
result &= self.config.ecc_key_attr.is_private;
result &= self.config.ecc_key_attr.ext_sign; // The only supported mode
Expand All @@ -138,7 +138,8 @@ impl AteccKeySlot {
return result;
}

if key_attr.policy.usage_flags.verify_hash || key_attr.policy.usage_flags.verify_message {
if key_attr.policy.usage_flags.verify_hash() || key_attr.policy.usage_flags.verify_message()
{
result &= self.config.key_type == rust_cryptoauthlib::KeyType::P256EccKey;
result &= match key_attr.key_type {
Type::EccKeyPair { .. } => {
Expand Down Expand Up @@ -345,17 +346,10 @@ mod tests {
},
bits: 256,
policy: Policy {
usage_flags: UsageFlags {
sign_hash: true,
verify_hash: true,
sign_message: true,
verify_message: false,
export: false,
encrypt: false,
decrypt: false,
cache: false,
copy: false,
derive: false,
usage_flags: {
let mut flags = UsageFlags::default();
let _ = flags.set_sign_hash().set_verify_hash().set_sign_message();
flags
},
permitted_algorithms: AsymmetricSignature::DeterministicEcdsa {
hash_alg: Hash::Sha256.into(),
Expand Down Expand Up @@ -448,17 +442,10 @@ mod tests {
},
bits: 256,
policy: Policy {
usage_flags: UsageFlags {
sign_hash: false,
verify_hash: true,
sign_message: false,
verify_message: false,
export: true,
encrypt: false,
decrypt: false,
cache: false,
copy: true,
derive: false,
usage_flags: {
let mut flags = UsageFlags::default();
let _ = flags.set_verify_hash().set_export().set_copy();
flags
},
permitted_algorithms: AsymmetricSignature::DeterministicEcdsa {
hash_alg: Hash::Sha256.into(),
Expand All @@ -479,19 +466,20 @@ mod tests {
key_slot.config.ecc_key_attr.is_private = false;
assert!(key_slot.is_usage_flags_ok(&attributes));
// && export && copy == false => OK
attributes.policy.usage_flags.export = false;
attributes.policy.usage_flags.copy = false;
let mut flags = UsageFlags::default();
let _ = flags.set_verify_hash();
attributes.policy.usage_flags = flags;
assert!(key_slot.is_usage_flags_ok(&attributes));

// KeyType::Aes => NOK
attributes.policy.usage_flags.export = true;
attributes.policy.usage_flags.copy = true;
let mut flags = UsageFlags::default();
let _ = flags.set_verify_hash().set_export().set_copy();
attributes.policy.usage_flags = flags;
key_slot.config.key_type = rust_cryptoauthlib::KeyType::Aes;
assert!(!key_slot.is_usage_flags_ok(&attributes));
// && sign_hash && sign_message == false => OK
attributes.policy.usage_flags.sign_hash = false;
attributes.policy.usage_flags.sign_message = false;
assert!(!key_slot.is_usage_flags_ok(&attributes));
// && verify_hash == false => OK
attributes.policy.usage_flags = UsageFlags::default();
assert!(key_slot.is_usage_flags_ok(&attributes));
}

#[test]
Expand Down Expand Up @@ -538,17 +526,15 @@ mod tests {
},
bits: 256,
policy: Policy {
usage_flags: UsageFlags {
sign_hash: true,
verify_hash: true,
sign_message: true,
verify_message: false,
export: true,
encrypt: false,
decrypt: false,
cache: false,
copy: true,
derive: false,
usage_flags: {
let mut flags = UsageFlags::default();
let _ = flags
.set_sign_hash()
.set_verify_hash()
.set_sign_message()
.set_export()
.set_copy();
flags
},
permitted_algorithms: AsymmetricSignature::Ecdsa {
hash_alg: Hash::Sha256.into(),
Expand Down
2 changes: 1 addition & 1 deletion src/providers/cryptoauthlib/key_slot_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl KeySlotStorage {
// (2) if there are no two key triples mapping to a single ATECC slot - warning only ATM

// check (1)
match key_slots[key_id as usize].key_attr_vs_config(key_id, &key_attr, None) {
match key_slots[key_id as usize].key_attr_vs_config(key_id, key_attr, None) {
Ok(_) => (),
Err(err) => {
let error = std::format!("ATECC slot configuration mismatch: {}", err);
Expand Down
3 changes: 2 additions & 1 deletion src/providers/mbed_crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ impl Provider {
max_key_id = key_id;
}
}
Err(status::Error::DoesNotExist) => to_remove.push(key_triple.clone()),
Err(status::Error::InvalidHandle) => to_remove.push(key_triple.clone()),
Err(e) => {
println!("Key ID was {}", key_id);
format_error!("Failed to open persistent Mbed Crypto key", e);
return None;
}
Expand Down
Loading

0 comments on commit 961329f

Please sign in to comment.