diff --git a/Cargo.toml b/Cargo.toml index 1ed3006..b1f8bde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clevis-pin-tpm2" -version = "0.1.2" +version = "0.1.3" description = "Clevis TPM2 PIN with policy support" authors = ["Patrick Uiterwijk "] edition = "2018" diff --git a/src/cli.rs b/src/cli.rs index 71dda0e..b861ed9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -110,12 +110,20 @@ impl TPM2Config { } fn normalize_pcr_ids(&mut self) -> Result<(), PinError> { + // Normalize from array with one string to just string + if let Some(serde_json::Value::Array(vals)) = &self.pcr_ids { + if vals.len() == 1 { + if let serde_json::Value::String(val) = &vals[0] { + self.pcr_ids = Some(serde_json::Value::String(val.to_string())); + } + } + } // Normalize pcr_ids from comma-separated string to array if let Some(serde_json::Value::String(val)) = &self.pcr_ids { // Was a string, do a split let newval: Vec = val .split(',') - .map(|x| serde_json::Value::String(x.to_string())) + .map(|x| serde_json::Value::String(x.trim().to_string())) .collect(); self.pcr_ids = Some(serde_json::Value::Array(newval)); } @@ -124,7 +132,7 @@ impl TPM2Config { let newvals: Result, _> = vals .iter() .map(|x| match x { - serde_json::Value::String(val) => match val.parse::() { + serde_json::Value::String(val) => match val.trim().parse::() { Ok(res) => { let new = serde_json::Value::Number(res); if !new.is_u64() {