Fabric: Save vendor id when new Fabric is created

This commit is contained in:
Kedar Sovani 2023-01-01 16:26:17 +05:30
parent 59ebfa06c9
commit 6d19a034d0
2 changed files with 19 additions and 2 deletions

View file

@ -162,6 +162,7 @@ impl NocCluster {
icac_value, icac_value,
noc_value, noc_value,
r.ipk_value.0, r.ipk_value.0,
r.vendor_id,
) )
.map_err(|_| NocStatus::TableFull)?; .map_err(|_| NocStatus::TableFull)?;
let fab_idx = self let fab_idx = self
@ -479,7 +480,7 @@ struct AddNocReq<'a> {
icac_value: OctetStr<'a>, icac_value: OctetStr<'a>,
ipk_value: OctetStr<'a>, ipk_value: OctetStr<'a>,
case_admin_subject: u64, case_admin_subject: u64,
_vendor_id: u16, vendor_id: u16,
} }
#[derive(FromTLV)] #[derive(FromTLV)]

View file

@ -39,6 +39,7 @@ macro_rules! fb_key {
}; };
} }
const ST_VID: &str = "vid";
const ST_RCA: &str = "rca"; const ST_RCA: &str = "rca";
const ST_ICA: &str = "ica"; const ST_ICA: &str = "ica";
const ST_NOC: &str = "noc"; const ST_NOC: &str = "noc";
@ -50,6 +51,7 @@ const ST_PRKEY: &str = "privkey";
pub struct Fabric { pub struct Fabric {
node_id: u64, node_id: u64,
fabric_id: u64, fabric_id: u64,
vendor_id: u16,
key_pair: Box<dyn CryptoKeyPair>, key_pair: Box<dyn CryptoKeyPair>,
pub root_ca: Cert, pub root_ca: Cert,
pub icac: Cert, pub icac: Cert,
@ -66,6 +68,7 @@ impl Fabric {
icac: Cert, icac: Cert,
noc: Cert, noc: Cert,
ipk: &[u8], ipk: &[u8],
vendor_id: u16,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let node_id = noc.get_node_id()?; let node_id = noc.get_node_id()?;
let fabric_id = noc.get_fabric_id()?; let fabric_id = noc.get_fabric_id()?;
@ -73,6 +76,7 @@ impl Fabric {
let mut f = Self { let mut f = Self {
node_id, node_id,
fabric_id, fabric_id,
vendor_id,
key_pair: Box::new(key_pair), key_pair: Box::new(key_pair),
root_ca, root_ca,
icac, icac,
@ -105,6 +109,7 @@ impl Fabric {
Ok(Self { Ok(Self {
node_id: 0, node_id: 0,
fabric_id: 0, fabric_id: 0,
vendor_id: 0,
key_pair: Box::new(KeyPairDummy::new()?), key_pair: Box::new(KeyPairDummy::new()?),
root_ca: Cert::default(), root_ca: Cert::default(),
icac: Cert::default(), icac: Cert::default(),
@ -181,6 +186,7 @@ impl Fabric {
let key = &key[..len]; let key = &key[..len];
psm.set_kv_slice(fb_key!(index, ST_PRKEY), key)?; psm.set_kv_slice(fb_key!(index, ST_PRKEY), key)?;
psm.set_kv_u64(ST_VID, self.vendor_id.into())?;
Ok(()) Ok(())
} }
@ -206,7 +212,17 @@ impl Fabric {
psm.get_kv_slice(fb_key!(index, ST_PRKEY), &mut priv_key)?; psm.get_kv_slice(fb_key!(index, ST_PRKEY), &mut priv_key)?;
let keypair = KeyPair::new_from_components(pub_key.as_slice(), priv_key.as_slice())?; let keypair = KeyPair::new_from_components(pub_key.as_slice(), priv_key.as_slice())?;
Fabric::new(keypair, root_ca, icac, noc, ipk.as_slice()) let mut vendor_id = 0;
psm.get_kv_u64(ST_VID, &mut vendor_id)?;
Fabric::new(
keypair,
root_ca,
icac,
noc,
ipk.as_slice(),
vendor_id as u16,
)
} }
} }