mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
pddb migrations for keystore-api
This commit is contained in:
parent
2c47db081d
commit
9d6223d0b2
3 changed files with 20 additions and 10 deletions
|
|
@ -25,6 +25,7 @@ trng = { path = "../trng", optional = true }
|
||||||
spinor = { path = "../spinor", optional = true }
|
spinor = { path = "../spinor", optional = true }
|
||||||
aes = { path = "../aes" }
|
aes = { path = "../aes" }
|
||||||
root-keys = { path = "../root-keys", optional = true }
|
root-keys = { path = "../root-keys", optional = true }
|
||||||
|
keystore-api = { path = "../../libs/keystore-api" }
|
||||||
cipher = "0.4.2"
|
cipher = "0.4.2"
|
||||||
bitfield = "0.13.2"
|
bitfield = "0.13.2"
|
||||||
aes-gcm-siv = { version = "0.11.1", default-features = false, features = [
|
aes-gcm-siv = { version = "0.11.1", default-features = false, features = [
|
||||||
|
|
@ -75,13 +76,14 @@ gen1 = [
|
||||||
"trng",
|
"trng",
|
||||||
"spinor",
|
"spinor",
|
||||||
"root-keys",
|
"root-keys",
|
||||||
|
"keystore-api/gen1",
|
||||||
"llio",
|
"llio",
|
||||||
"tts-frontend",
|
"tts-frontend",
|
||||||
"gam",
|
"gam",
|
||||||
"locales",
|
"locales",
|
||||||
"modals",
|
"modals",
|
||||||
]
|
]
|
||||||
gen2 = ["keystore"]
|
gen2 = ["keystore", "keystore-api/gen2"]
|
||||||
# gen 1 targets
|
# gen 1 targets
|
||||||
precursor = ["utralib/precursor", "sha2/precursor", "gen1"]
|
precursor = ["utralib/precursor", "sha2/precursor", "gen1"]
|
||||||
hosted = ["utralib/hosted", "sha2/hosted", "gen1"]
|
hosted = ["utralib/hosted", "sha2/hosted", "gen1"]
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ use aes::{Aes256, BLOCK_SIZE, Block};
|
||||||
use aes_gcm_siv::aead::{Aead, Payload};
|
use aes_gcm_siv::aead::{Aead, Payload};
|
||||||
use aes_gcm_siv::{Aes256GcmSiv, Nonce, Tag};
|
use aes_gcm_siv::{Aes256GcmSiv, Nonce, Tag};
|
||||||
use backend::bcrypt::*;
|
use backend::bcrypt::*;
|
||||||
|
use keystore_api::rootkeys_api::AesRootkeyType;
|
||||||
|
use keystore_api::rootkeys_api::KeywrapError;
|
||||||
use modals::Modals;
|
use modals::Modals;
|
||||||
use root_keys::api::AesRootkeyType;
|
|
||||||
use root_keys::api::KeywrapError;
|
|
||||||
use sha2::{Digest, Sha512_256Hw, Sha512_256Sw};
|
use sha2::{Digest, Sha512_256Hw, Sha512_256Sw};
|
||||||
use spinor::SPINOR_BULK_ERASE_SIZE;
|
use spinor::SPINOR_BULK_ERASE_SIZE;
|
||||||
use subtle::ConstantTimeEq;
|
use subtle::ConstantTimeEq;
|
||||||
|
|
@ -2939,18 +2939,18 @@ impl PddbOs {
|
||||||
|
|
||||||
pub(crate) fn reset_dont_ask_init(&self) { self.rootkeys.do_reset_dont_ask_init(); }
|
pub(crate) fn reset_dont_ask_init(&self) { self.rootkeys.do_reset_dont_ask_init(); }
|
||||||
|
|
||||||
pub(crate) fn checksums(&self, modals: Option<&Modals>) -> root_keys::api::Checksums {
|
pub(crate) fn checksums(&self, modals: Option<&Modals>) -> keystore_api::rootkeys_api::Checksums {
|
||||||
let mut checksums = root_keys::api::Checksums::default();
|
let mut checksums = keystore_api::rootkeys_api::Checksums::default();
|
||||||
let pddb = unsafe { self.pddb_mr.as_slice() };
|
let pddb = unsafe { self.pddb_mr.as_slice() };
|
||||||
if let Some(m) = modals {
|
if let Some(m) = modals {
|
||||||
m.start_progress(t!("pddb.checksums", locales::LANG), 0, checksums.checksums.len() as u32, 0)
|
m.start_progress(t!("pddb.checksums", locales::LANG), 0, checksums.checksums.len() as u32, 0)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
for (index, region) in
|
for (index, region) in
|
||||||
pddb.chunks(root_keys::api::CHECKSUM_BLOCKLEN_PAGE as usize * PAGE_SIZE).enumerate()
|
pddb.chunks(keystore_api::rootkeys_api::CHECKSUM_BLOCKLEN_PAGE as usize * PAGE_SIZE).enumerate()
|
||||||
{
|
{
|
||||||
assert!(
|
assert!(
|
||||||
region.len() == root_keys::api::CHECKSUM_BLOCKLEN_PAGE as usize * PAGE_SIZE,
|
region.len() == keystore_api::rootkeys_api::CHECKSUM_BLOCKLEN_PAGE as usize * PAGE_SIZE,
|
||||||
"CHECKSUM_BLOCKLEN_PAGE is not an even divisor of the PDDB size"
|
"CHECKSUM_BLOCKLEN_PAGE is not an even divisor of the PDDB size"
|
||||||
);
|
);
|
||||||
let mut hasher = Sha512_256Hw::new();
|
let mut hasher = Sha512_256Hw::new();
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ pub struct Pddb {
|
||||||
/// in the case of a basis change. Basis changes are thought to be rare; so, big changes
|
/// in the case of a basis change. Basis changes are thought to be rare; so, big changes
|
||||||
/// like this are probably OK.
|
/// like this are probably OK.
|
||||||
keys: Arc<Mutex<HashMap<ApiToken, Box<dyn Fn() + 'static + Send>>>>,
|
keys: Arc<Mutex<HashMap<ApiToken, Box<dyn Fn() + 'static + Send>>>>,
|
||||||
|
#[cfg(feature = "gen1")]
|
||||||
trng: trng::Trng,
|
trng: trng::Trng,
|
||||||
/// These are temporary fields only to be used by the consistency check feature.
|
/// These are temporary fields only to be used by the consistency check feature.
|
||||||
key_count: RefCell<u32>,
|
key_count: RefCell<u32>,
|
||||||
|
|
@ -115,6 +116,7 @@ impl Pddb {
|
||||||
cb: RefCell::new(None),
|
cb: RefCell::new(None),
|
||||||
cb_handle: RefCell::new(None),
|
cb_handle: RefCell::new(None),
|
||||||
keys,
|
keys,
|
||||||
|
#[cfg(feature = "gen1")]
|
||||||
trng: trng::Trng::new(&xns).unwrap(),
|
trng: trng::Trng::new(&xns).unwrap(),
|
||||||
// These are record the result of the most recent call to list_keys()
|
// These are record the result of the most recent call to list_keys()
|
||||||
key_count: RefCell::new(0),
|
key_count: RefCell::new(0),
|
||||||
|
|
@ -263,12 +265,12 @@ impl Pddb {
|
||||||
/// Computes checksums on the entire PDDB database. This operation can take some time and causes a
|
/// Computes checksums on the entire PDDB database. This operation can take some time and causes a
|
||||||
/// progress bar to pop up. This should be called only after the PDDB has been unmounted, to ensure
|
/// progress bar to pop up. This should be called only after the PDDB has been unmounted, to ensure
|
||||||
/// that the disk contents do not change after the checksums have been computed.
|
/// that the disk contents do not change after the checksums have been computed.
|
||||||
pub fn compute_checksums(&self) -> root_keys::api::Checksums {
|
pub fn compute_checksums(&self) -> keystore_api::rootkeys_api::Checksums {
|
||||||
let alloc = root_keys::api::Checksums::default();
|
let alloc = keystore_api::rootkeys_api::Checksums::default();
|
||||||
let mut buf = Buffer::into_buf(alloc).expect("Couldn't convert memory structure");
|
let mut buf = Buffer::into_buf(alloc).expect("Couldn't convert memory structure");
|
||||||
buf.lend_mut(self.conn, Opcode::ComputeBackupHashes.to_u32().unwrap())
|
buf.lend_mut(self.conn, Opcode::ComputeBackupHashes.to_u32().unwrap())
|
||||||
.expect("Couldn't execute ComputeBackupHashes");
|
.expect("Couldn't execute ComputeBackupHashes");
|
||||||
buf.to_original::<root_keys::api::Checksums, _>().expect("Couldn't convert IPC structure")
|
buf.to_original::<keystore_api::rootkeys_api::Checksums, _>().expect("Couldn't convert IPC structure")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return a list of all open bases
|
/// return a list of all open bases
|
||||||
|
|
@ -746,12 +748,15 @@ impl Pddb {
|
||||||
};
|
};
|
||||||
// this is a two-phase query, because it's quite likely that the number of keys can be very large in a
|
// this is a two-phase query, because it's quite likely that the number of keys can be very large in a
|
||||||
// dict.
|
// dict.
|
||||||
|
#[cfg(feature = "gen1")]
|
||||||
let token = [
|
let token = [
|
||||||
self.trng.get_u32().unwrap(),
|
self.trng.get_u32().unwrap(),
|
||||||
self.trng.get_u32().unwrap(),
|
self.trng.get_u32().unwrap(),
|
||||||
self.trng.get_u32().unwrap(),
|
self.trng.get_u32().unwrap(),
|
||||||
self.trng.get_u32().unwrap(),
|
self.trng.get_u32().unwrap(),
|
||||||
];
|
];
|
||||||
|
#[cfg(feature = "gen2")]
|
||||||
|
let token = xous::create_server_id().unwrap().to_array();
|
||||||
let request = PddbDictRequest {
|
let request = PddbDictRequest {
|
||||||
basis_specified: basis_name.is_some(),
|
basis_specified: basis_name.is_some(),
|
||||||
basis: String::from(&bname),
|
basis: String::from(&bname),
|
||||||
|
|
@ -859,12 +864,15 @@ impl Pddb {
|
||||||
};
|
};
|
||||||
// this is a two-phase query, because it's quite likely that the number of keys can be very large in a
|
// this is a two-phase query, because it's quite likely that the number of keys can be very large in a
|
||||||
// dict.
|
// dict.
|
||||||
|
#[cfg(feature = "gen1")]
|
||||||
let token = [
|
let token = [
|
||||||
self.trng.get_u32().unwrap(),
|
self.trng.get_u32().unwrap(),
|
||||||
self.trng.get_u32().unwrap(),
|
self.trng.get_u32().unwrap(),
|
||||||
self.trng.get_u32().unwrap(),
|
self.trng.get_u32().unwrap(),
|
||||||
self.trng.get_u32().unwrap(),
|
self.trng.get_u32().unwrap(),
|
||||||
];
|
];
|
||||||
|
#[cfg(feature = "gen2")]
|
||||||
|
let token = xous::create_server_id().unwrap().to_array();
|
||||||
let request = PddbDictRequest {
|
let request = PddbDictRequest {
|
||||||
basis_specified: basis_name.is_some(),
|
basis_specified: basis_name.is_some(),
|
||||||
basis: String::from(&bname),
|
basis: String::from(&bname),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue