pddb migrations for keystore-api

This commit is contained in:
bunnie 2025-05-04 18:34:33 +08:00
parent 2c47db081d
commit 9d6223d0b2
3 changed files with 20 additions and 10 deletions

View file

@ -25,6 +25,7 @@ trng = { path = "../trng", optional = true }
spinor = { path = "../spinor", optional = true }
aes = { path = "../aes" }
root-keys = { path = "../root-keys", optional = true }
keystore-api = { path = "../../libs/keystore-api" }
cipher = "0.4.2"
bitfield = "0.13.2"
aes-gcm-siv = { version = "0.11.1", default-features = false, features = [
@ -75,13 +76,14 @@ gen1 = [
"trng",
"spinor",
"root-keys",
"keystore-api/gen1",
"llio",
"tts-frontend",
"gam",
"locales",
"modals",
]
gen2 = ["keystore"]
gen2 = ["keystore", "keystore-api/gen2"]
# gen 1 targets
precursor = ["utralib/precursor", "sha2/precursor", "gen1"]
hosted = ["utralib/hosted", "sha2/hosted", "gen1"]

View file

@ -15,9 +15,9 @@ use aes::{Aes256, BLOCK_SIZE, Block};
use aes_gcm_siv::aead::{Aead, Payload};
use aes_gcm_siv::{Aes256GcmSiv, Nonce, Tag};
use backend::bcrypt::*;
use keystore_api::rootkeys_api::AesRootkeyType;
use keystore_api::rootkeys_api::KeywrapError;
use modals::Modals;
use root_keys::api::AesRootkeyType;
use root_keys::api::KeywrapError;
use sha2::{Digest, Sha512_256Hw, Sha512_256Sw};
use spinor::SPINOR_BULK_ERASE_SIZE;
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 checksums(&self, modals: Option<&Modals>) -> root_keys::api::Checksums {
let mut checksums = root_keys::api::Checksums::default();
pub(crate) fn checksums(&self, modals: Option<&Modals>) -> keystore_api::rootkeys_api::Checksums {
let mut checksums = keystore_api::rootkeys_api::Checksums::default();
let pddb = unsafe { self.pddb_mr.as_slice() };
if let Some(m) = modals {
m.start_progress(t!("pddb.checksums", locales::LANG), 0, checksums.checksums.len() as u32, 0)
.ok();
}
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!(
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"
);
let mut hasher = Sha512_256Hw::new();

View file

@ -97,6 +97,7 @@ pub struct Pddb {
/// in the case of a basis change. Basis changes are thought to be rare; so, big changes
/// like this are probably OK.
keys: Arc<Mutex<HashMap<ApiToken, Box<dyn Fn() + 'static + Send>>>>,
#[cfg(feature = "gen1")]
trng: trng::Trng,
/// These are temporary fields only to be used by the consistency check feature.
key_count: RefCell<u32>,
@ -115,6 +116,7 @@ impl Pddb {
cb: RefCell::new(None),
cb_handle: RefCell::new(None),
keys,
#[cfg(feature = "gen1")]
trng: trng::Trng::new(&xns).unwrap(),
// These are record the result of the most recent call to list_keys()
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
/// 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.
pub fn compute_checksums(&self) -> root_keys::api::Checksums {
let alloc = root_keys::api::Checksums::default();
pub fn compute_checksums(&self) -> keystore_api::rootkeys_api::Checksums {
let alloc = keystore_api::rootkeys_api::Checksums::default();
let mut buf = Buffer::into_buf(alloc).expect("Couldn't convert memory structure");
buf.lend_mut(self.conn, Opcode::ComputeBackupHashes.to_u32().unwrap())
.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
@ -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
// dict.
#[cfg(feature = "gen1")]
let token = [
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 {
basis_specified: basis_name.is_some(),
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
// dict.
#[cfg(feature = "gen1")]
let token = [
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 {
basis_specified: basis_name.is_some(),
basis: String::from(&bname),