From d2c415259549536a16117974705e7b019d07f6fa Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Wed, 4 Aug 2021 19:05:41 +0200 Subject: [PATCH] Move the configuration of cards for card-functionality test suite into the file `config/test-cards.toml`. Add an example for this config file in `config/test-cards-example.toml`. Add handling for this toml configuration. --- .gitignore | 2 +- card-functionality/Cargo.toml | 5 +- .../config/test-cards-example.toml | 26 ++++++++++ card-functionality/src/main.rs | 47 +++++++++++++------ 4 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 card-functionality/config/test-cards-example.toml diff --git a/.gitignore b/.gitignore index de8d8f1..16f74e6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ target/ Cargo.lock _test/ notes/ - +card-functionality/config/test-cards.toml diff --git a/card-functionality/Cargo.toml b/card-functionality/Cargo.toml index 368d0dd..29b951e 100644 --- a/card-functionality/Cargo.toml +++ b/card-functionality/Cargo.toml @@ -16,4 +16,7 @@ sequoia-openpgp = "1.3" anyhow = "1" thiserror = "1.0" env_logger = "0.8" -log = "0.4" \ No newline at end of file +log = "0.4" +toml = "0.5" +serde = "1.0" +serde_derive = "1.0" \ No newline at end of file diff --git a/card-functionality/config/test-cards-example.toml b/card-functionality/config/test-cards-example.toml new file mode 100644 index 0000000..c4149ca --- /dev/null +++ b/card-functionality/config/test-cards-example.toml @@ -0,0 +1,26 @@ +# Define which cards the test suite should be performed on. +# +# NOTE that this test suite is DESTRUCTIVE. +# It will overwrite all data on test cards! +# +# The test suite looks for the configuration in 'config/test-cards.toml', +# you should configure your own set of test-card identifiers there. +# +# Normally you'll probably want to test all cards via the pcsc transport. +# +# The scdc transport is offered as an alternative, but not recommended. +# (However, currently emulated Gnuk can only be used via scdc for unknown +# reasons) + +pcsc = [ + # Yubikey 5 + "0006:12345678", + + # FLOSS Card 3.4 + "0005:0000A835", +] + +scdc = [ + # Gnuk emulated + "D276000124010200FFFEF1420A7A0000", +] diff --git a/card-functionality/src/main.rs b/card-functionality/src/main.rs index 40967d3..69103b1 100644 --- a/card-functionality/src/main.rs +++ b/card-functionality/src/main.rs @@ -26,6 +26,7 @@ //! the command data field"). use anyhow::{anyhow, Error, Result}; +use serde_derive::Deserialize; use thiserror::Error; use sequoia_openpgp::parse::Parse; @@ -41,8 +42,8 @@ mod util; #[derive(Debug)] enum TestCard { - Pcsc(&'static str), - Scdc(&'static str), + Pcsc(String), + Scdc(String), } impl TestCard { @@ -377,21 +378,39 @@ fn run_test( t(&mut ca, param) } +#[derive(Debug, Deserialize)] +struct TestConfig { + pcsc: Option>, + scdc: Option>, +} + +impl TestConfig { + fn get_cards(&self) -> Vec { + let mut cards = vec![]; + + if let Some(pcsc) = &self.pcsc { + for card in pcsc { + cards.push(TestCard::Pcsc(card.to_string())); + } + } + + if let Some(scdc) = &self.scdc { + for card in scdc { + cards.push(TestCard::Scdc(card.to_string())); + } + } + + cards + } +} + fn main() -> Result<()> { env_logger::init(); - let cards = vec![ - // TestCard::Scdc("D276000124010200FFFEF1420A7A0000"), /* Gnuk emulated */ - // TestCard::Scdc("D2760001240103040006160191800000"), /* Yubikey 5 */ - // TestCard::Scdc("D276000124010200FFFE571831460000"), /* Gnuk Rysim (green) */ - // TestCard::Scdc("D276000124010200FFFE4231EB6E0000"), /* Gnuk FST */ - // TestCard::Scdc("D27600012401030400050000A8350000"), /* FLOSS Card 3.4 */ - // TestCard::Pcsc("FFFE:F1420A7A"), /* Gnuk emulated */ - TestCard::Pcsc("0006:16019180"), /* Yubikey 5 */ - TestCard::Pcsc("FFFE:57183146"), /* Gnuk Rysim (green) */ - TestCard::Pcsc("FFFE:4231EB6E"), /* Gnuk FST */ - TestCard::Pcsc("0005:0000A835"), /* FLOSS Card 3.4 */ - ]; + let config = std::fs::read_to_string("config/test-cards.toml")?; + let config: TestConfig = toml::from_str(&config)?; + + let cards = config.get_cards(); for mut card in cards { println!("** Run tests on card {:?} **", card);