remove local db
This commit is contained in:
parent
e490eac7c4
commit
ae380a2cca
1 changed files with 10 additions and 56 deletions
|
@ -1,16 +1,12 @@
|
||||||
use cw_client::{CliClient, CwClient};
|
use cw_client::{CliClient, CwClient};
|
||||||
use der::DecodePem;
|
|
||||||
use mc_attestation_verifier::SignedTcbInfo;
|
use mc_attestation_verifier::SignedTcbInfo;
|
||||||
use p256::ecdsa::VerifyingKey;
|
use p256::ecdsa::VerifyingKey;
|
||||||
use quartz_tcbinfo_msgs::ExecuteMsg;
|
use quartz_tcbinfo_msgs::ExecuteMsg;
|
||||||
use quoted_string::strip_dquotes;
|
use quoted_string::strip_dquotes;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::{fs, path::Path};
|
|
||||||
use x509_cert::Certificate;
|
|
||||||
|
|
||||||
type TcbInfo = String;
|
|
||||||
type Fmspc = String;
|
type Fmspc = String;
|
||||||
type Update = String;
|
type Update = String;
|
||||||
|
|
||||||
|
@ -52,32 +48,6 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
|
||||||
let client = CliClient::neutrond(testnet);
|
let client = CliClient::neutrond(testnet);
|
||||||
let fmspc_list = get_fmspc_list().await;
|
let fmspc_list = get_fmspc_list().await;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut store: HashMap<Fmspc, TcbInfo> = if Path::new("./standard").exists() {
|
|
||||||
let data = fs::read_to_string("./standard").expect("Unable to read file");
|
|
||||||
serde_json::from_str(&data).unwrap()
|
|
||||||
} else {
|
|
||||||
fs::File::create("./standard").expect("couldn't create file");
|
|
||||||
HashMap::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let certificate = TCB_SIGNER.to_string();
|
|
||||||
let parsed_certificate =
|
|
||||||
Certificate::from_pem(certificate.clone()).expect("failed to parse PEM");
|
|
||||||
|
|
||||||
let key = VerifyingKey::from_sec1_bytes(
|
|
||||||
parsed_certificate
|
|
||||||
.tbs_certificate
|
|
||||||
.subject_public_key_info
|
|
||||||
.subject_public_key
|
|
||||||
.as_bytes()
|
|
||||||
.expect("Failed to parse public key"),
|
|
||||||
)
|
|
||||||
.expect("Failed to decode public key");
|
|
||||||
|
|
||||||
for fmspc in fmspc_list {
|
for fmspc in fmspc_list {
|
||||||
|
|
||||||
let tcbinfo_from_api = get_tcbinfo(fmspc.clone(), "standard".to_string()).await;
|
let tcbinfo_from_api = get_tcbinfo(fmspc.clone(), "standard".to_string()).await;
|
||||||
|
@ -86,28 +56,21 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
|
||||||
"neutron1r4m59786vmxrx866585ze5ugjx9egcyja0nuxhn2y6d7ht6680sspa89zk"
|
"neutron1r4m59786vmxrx866585ze5ugjx9egcyja0nuxhn2y6d7ht6680sspa89zk"
|
||||||
.parse()
|
.parse()
|
||||||
.expect("failed to parse contract address");
|
.expect("failed to parse contract address");
|
||||||
let query_msg = format!("{\"get_tcb_info\": {\"fmspc\": \"{}\"}}", fmspc) ;
|
let query_msg = format!("{{\"get_tcb_info\": {{\"fmspc\": \"{}\"}}}}", fmspc) ;
|
||||||
let tcbinfo_on_chain = client.query_smart(&contract_address, query_msg).await;
|
let tcbinfo_on_chain: Value = client.query_smart(&contract_address, json!(query_msg)).await.expect("contract query failed");
|
||||||
println!("{tcbinfo_on_chain}");
|
println!("{tcbinfo_on_chain:?}");
|
||||||
exit();
|
|
||||||
let store_entry = if store.contains_key(&fmspc) {
|
if tcbinfo_on_chain.to_string() != tcbinfo_from_api {
|
||||||
&store[&fmspc]
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
};
|
|
||||||
if *store_entry != tcbinfo {
|
|
||||||
println!("updating local TCBInfo for FMSPC: {fmspc}");
|
|
||||||
store.insert(fmspc.clone(), tcbinfo.clone());
|
|
||||||
println!("updating on-chain TCBInfo for FMSPC: {fmspc}");
|
println!("updating on-chain TCBInfo for FMSPC: {fmspc}");
|
||||||
let chain_id = tendermint::chain::id::Id::try_from("pion-1").expect("invalid chain id");
|
let chain_id = tendermint::chain::id::Id::try_from("pion-1").expect("invalid chain id");
|
||||||
let sender = "ajinkya";
|
let sender = "ajinkya";
|
||||||
|
|
||||||
let execute_msg = ExecuteMsg {
|
let execute_msg = ExecuteMsg {
|
||||||
tcb_info: tcbinfo.to_string(),
|
tcb_info: tcbinfo_from_api.to_string(),
|
||||||
certificate: certificate.clone(),
|
certificate: TCB_SIGNER.to_string(),
|
||||||
time: None,
|
time: None,
|
||||||
};
|
};
|
||||||
let res = client
|
let _ = client
|
||||||
.tx_execute(
|
.tx_execute(
|
||||||
&contract_address,
|
&contract_address,
|
||||||
&chain_id,
|
&chain_id,
|
||||||
|
@ -123,19 +86,10 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
|
||||||
println!("TCBInfo for FMSPC: {fmspc} up to date")
|
println!("TCBInfo for FMSPC: {fmspc} up to date")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let serialized = serde_json::to_string(&store).unwrap();
|
|
||||||
fs::write("./standard", serialized).expect("Unable to write file");
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_signature(tcbinfo: String, key: VerifyingKey) -> bool {
|
|
||||||
let signed_tcbinfo =
|
|
||||||
SignedTcbInfo::try_from(tcbinfo.as_ref()).expect("tcbinfo string parsing failed");
|
|
||||||
if signed_tcbinfo.verify(Some(&key), None).is_err() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn main() {
|
pub async fn main() {
|
||||||
|
|
Loading…
Reference in a new issue