kassandra-client 0.0.1-alpha

Interact with an FMD service
Documentation
use chacha20poly1305::Key;
use fmd::fmd2_compact::CompactSecretKey;
use hkdf::Hkdf;
use shared::db::EncKey;
use shared::{ClientMsg, ServerMsg};
use tracing_subscriber::fmt::SubscriberBuilder;

use crate::com::OutgoingTcp;

pub mod ratls;

pub mod com;
pub mod config;
pub mod query;
#[cfg(feature = "tdx")]
pub mod tdx;
#[cfg(feature = "transparent")]
pub mod transparent;

const GAMMA: usize = 12;

pub fn init_logging() {
    SubscriberBuilder::default().with_ansi(true).init();
}

fn get_host_uuid(url: &str) -> String {
    let mut stream = OutgoingTcp::new(url);
    stream.write(ClientMsg::RequestUUID);
    match stream.read() {
        Ok(ServerMsg::UUID(uuid)) => uuid,
        Ok(ServerMsg::Error(err)) => panic!("{err}"),
        _ => panic!("Requesting UUID from host failed. Could not parse response."),
    }
}

fn encryption_key(csk_key: &CompactSecretKey, salt: &str) -> EncKey {
    let hk = Hkdf::<sha2::Sha256>::new(
        Some(salt.as_bytes()),
        serde_json::to_string(csk_key).unwrap().as_bytes(),
    );
    let mut encryption_key = [0u8; 32];
    hk.expand("Database encryption key".as_bytes(), &mut encryption_key)
        .unwrap();
    let enc_key: Key = encryption_key.into();
    enc_key.into()
}