feat: add hratls_pubkey and mrsigner_pubkey to config AccountData and update related methods
This commit is contained in:
parent
a0bc0958fc
commit
f220e200ec
@ -16,6 +16,10 @@ pub struct AccountData {
|
|||||||
locked_funds: f64,
|
locked_funds: f64,
|
||||||
wallet_address: String,
|
wallet_address: String,
|
||||||
wallet_path: String,
|
wallet_path: String,
|
||||||
|
pub hratls_pubkey: String,
|
||||||
|
pub hratls_path: String,
|
||||||
|
pub mrsigner: [u8; 32],
|
||||||
|
pub signing_key_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::HumanOutput for AccountData {
|
impl super::HumanOutput for AccountData {
|
||||||
@ -331,18 +335,20 @@ impl Config {
|
|||||||
Ok(path) => account_data.wallet_path = path,
|
Ok(path) => account_data.wallet_path = path,
|
||||||
Err(_) => log::error!("This error should never happen. Please report this bug."),
|
Err(_) => log::error!("This error should never happen. Please report this bug."),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
account_data.hratls_pubkey = Self::get_hratls_pubkey_hex();
|
||||||
|
account_data.hratls_path = Self::hratls_private_key_path();
|
||||||
|
account_data.mrsigner = Self::get_mr_signer();
|
||||||
|
account_data.signing_key_path = Self::signing_key_path();
|
||||||
|
|
||||||
account_data
|
account_data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn get_hratls_private_key() -> (String, String) {
|
pub fn get_hratls_private_key() -> String {
|
||||||
(
|
std::fs::read_to_string(Self::hratls_private_key_path())
|
||||||
std::fs::read_to_string(Self::hratls_private_key_path()).unwrap_or_else(|_| {
|
.unwrap_or_else(|_| Self::create_hratls_key().expect("Failed to create HRATLS key"))
|
||||||
Self::create_hratls_key().expect("Failed to create HRATLS key")
|
|
||||||
}),
|
|
||||||
Self::hratls_private_key_path(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_hratls_key() -> Result<String, Box<dyn std::error::Error>> {
|
fn create_hratls_key() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
@ -359,7 +365,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_hratls_pubkey_hex() -> String {
|
pub fn get_hratls_pubkey_hex() -> String {
|
||||||
let private_key_pem_str = Self::get_hratls_private_key().0;
|
let private_key_pem_str = Self::get_hratls_private_key();
|
||||||
let private_key = PKey::private_key_from_pem(private_key_pem_str.as_ref()).unwrap();
|
let private_key = PKey::private_key_from_pem(private_key_pem_str.as_ref()).unwrap();
|
||||||
let pubkey = private_key.raw_public_key().unwrap();
|
let pubkey = private_key.raw_public_key().unwrap();
|
||||||
pubkey.iter().fold(String::new(), |acc, x| acc + &format!("{:02X?}", x))
|
pubkey.iter().fold(String::new(), |acc, x| acc + &format!("{:02X?}", x))
|
||||||
@ -371,8 +377,8 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn get_mr_signer() -> [u8; 32] {
|
fn get_mr_signer() -> [u8; 32] {
|
||||||
let mut signing_key_mod = Self::get_signing_key().0.n().to_vec();
|
let mut signing_key_mod = Self::get_signing_key().n().to_vec();
|
||||||
signing_key_mod.reverse(); // make it little endian
|
signing_key_mod.reverse(); // make it little endian
|
||||||
|
|
||||||
let mut hasher = Hasher::new(MessageDigest::sha256()).unwrap();
|
let mut hasher = Hasher::new(MessageDigest::sha256()).unwrap();
|
||||||
@ -386,13 +392,13 @@ impl Config {
|
|||||||
mr_signer
|
mr_signer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_signing_key() -> (Rsa<Private>, String) {
|
fn get_signing_key() -> Rsa<Private> {
|
||||||
let signing_key_pem_str =
|
let signing_key_pem_str =
|
||||||
std::fs::read_to_string(Self::signing_key_path()).unwrap_or_else(|_| {
|
std::fs::read_to_string(Self::signing_key_path()).unwrap_or_else(|_| {
|
||||||
Self::create_signing_key().expect("Failed to create enclave signing key")
|
Self::create_signing_key().expect("Failed to create enclave signing key")
|
||||||
});
|
});
|
||||||
|
|
||||||
(Rsa::private_key_from_pem(signing_key_pem_str.as_ref()).unwrap(), Self::signing_key_path())
|
Rsa::private_key_from_pem(signing_key_pem_str.as_ref()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_signing_key() -> Result<String, Box<dyn std::error::Error>> {
|
fn create_signing_key() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
@ -429,7 +435,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hratls_private_key() {
|
fn test_hratls_private_key() {
|
||||||
let hratls_private_key = Config::get_hratls_private_key().0;
|
let hratls_private_key = Config::get_hratls_private_key();
|
||||||
println!("hratls_private_key:\n{hratls_private_key}");
|
println!("hratls_private_key:\n{hratls_private_key}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ pub async fn connect_dtpm_grpc_client(
|
|||||||
hratls_uri: String,
|
hratls_uri: String,
|
||||||
package_mr_enclave: Option<[u8; 32]>,
|
package_mr_enclave: Option<[u8; 32]>,
|
||||||
) -> Result<DtpmConfigManagerClient<Channel>> {
|
) -> Result<DtpmConfigManagerClient<Channel>> {
|
||||||
let private_key_pem = Config::get_hratls_private_key().0;
|
let private_key_pem = Config::get_hratls_private_key();
|
||||||
let mr_signer = vec![Config::get_mr_signer()];
|
let mr_signer = vec![Config::get_account_data().mrsigner];
|
||||||
|
|
||||||
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
|
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ pub fn package_enclave(
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(" ");
|
.join(" ");
|
||||||
|
|
||||||
let signing_key_path = Config::get_signing_key().1;
|
let signing_key_path = Config::get_account_data().signing_key_path;
|
||||||
let hratls_key_path = Config::get_hratls_private_key().1;
|
let hratls_key_path = Config::get_account_data().hratls_path;
|
||||||
|
|
||||||
let docker_package_str = if package_type == "public" {
|
let docker_package_str = if package_type == "public" {
|
||||||
format!(
|
format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user