-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add device.cryptoki.enable,module_path,pin,serial config options
Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
- Loading branch information
Showing
11 changed files
with
178 additions
and
34 deletions.
There are no files selected for viewing
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
89 changes: 89 additions & 0 deletions
89
crates/common/tedge_config/src/tedge_config_cli/cryptoki_opts.rs
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,89 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::bail; | ||
use camino::Utf8PathBuf; | ||
use certificate::parse_root_certificate::CryptokiConfig; | ||
|
||
use crate::{TEdgeConfig, TEdgeConfigReaderDeviceCryptoki}; | ||
|
||
pub enum CryptokiOpts { | ||
Disabled, | ||
|
||
Enabled { | ||
module_path: Utf8PathBuf, | ||
pin: Arc<str>, | ||
serial: Option<Arc<str>>, | ||
}, | ||
} | ||
|
||
impl TEdgeConfigReaderDeviceCryptoki { | ||
pub fn opts(&self) -> Result<CryptokiOpts, anyhow::Error> { | ||
if !self.enable { | ||
return Ok(CryptokiOpts::Disabled); | ||
} | ||
|
||
Ok(CryptokiOpts::Enabled { | ||
module_path: self.module_path.or_config_not_set()?.clone(), | ||
pin: self.pin.clone(), | ||
serial: self.serial.or_none().cloned(), | ||
}) | ||
} | ||
|
||
pub fn config(&self) -> Result<CryptokiConfig, anyhow::Error> { | ||
if !self.enable { | ||
bail!("disabled"); | ||
} | ||
|
||
Ok(CryptokiConfig { | ||
module_path: self.module_path.or_config_not_set().unwrap().clone(), | ||
pin: self.pin.clone(), | ||
serial: self.serial.or_none().cloned(), | ||
}) | ||
} | ||
} | ||
|
||
impl TryFrom<CryptokiOpts> for CryptokiConfig { | ||
type Error = anyhow::Error; | ||
|
||
fn try_from(value: CryptokiOpts) -> Result<Self, Self::Error> { | ||
let CryptokiOpts::Enabled { | ||
module_path, | ||
pin, | ||
serial, | ||
} = value | ||
else { | ||
// TODO(marcel): eliminate error cases! | ||
anyhow::bail!("disabled"); | ||
}; | ||
|
||
Ok(CryptokiConfig { | ||
module_path, | ||
pin, | ||
serial, | ||
}) | ||
} | ||
} | ||
|
||
// impl TryFrom<&TEdgeConfigReaderDeviceCryptoki> for CryptokiOpts { | ||
// type Error = anyhow::Error; | ||
|
||
// fn try_from(reader: &TEdgeConfigReaderDeviceCryptoki) -> Result<Self, Self::Error> { | ||
// if !reader.enable { | ||
// return Ok(Self::Disabled); | ||
// } | ||
|
||
// Ok(Self::Enabled { | ||
// module_path: reader.module_path.or_config_not_set()?.clone(), | ||
// pin: reader.pin.clone(), | ||
// serial: reader.serial.or_config_not_set()?.clone(), | ||
// }) | ||
// } | ||
// } | ||
|
||
// impl TryFrom<&TEdgeConfig> for CryptokiOpts { | ||
// type Error = anyhow::Error; | ||
|
||
// fn try_from(tedge_config: &TEdgeConfig) -> Result<Self, Self::Error> { | ||
// (&tedge_config.device.cryptoki).try_into() | ||
// } | ||
// } |
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ pub mod tedge_config_location; | |
mod figment; | ||
pub mod models; | ||
pub mod tedge_config; | ||
|
||
pub mod cryptoki_opts; |
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
Oops, something went wrong.