-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rpc: add attesteer_forward_dcap_quote call * rpc: add attesteer_forward_ias_attestation_report * remove unused variables * enclave-runtime/attestation: remove duplicate code * enclave-runtime/attestation: extract extrinsic sending * enclave-runtime/attestaion: refactor generate_dcap_ra_extrinsic_internal to reduce code duplication * attesteer: add attesteer RPC calls to the CLI * compiling * cli: attesteer dcap quote verification takes a filename (to a hex encoded quote) instead of contents * cli: attesteer ias attestation report takes a filename (to a hex encoded report) instead of its contents * clippy: fix needless borrow * rename: match substrate convention for RPC method names * rename: SendDCAPQuoteCmd -> SendDcapQuoteCmd * rename: SendIASAttestationReportCmd -> SendIasAttestationReportCmd * rename: attesteer_callForwardIASAttestationReport -> attesteer_ForwardIasAttestationReport * rename: attesteer_callForwardDCAPQuote -> attesteer_ForwardDcapQuote * cli: refactor attesteer comamnds to use a neat match expressions * cli: attesteer commands use let-else pattern * cli: attesteer commands send to chain * rename: attesteer_Forward -> attesteer_forward
- Loading branch information
Showing
8 changed files
with
308 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Copyright 2021 Integritee AG and Supercomputing Systems AG | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
mod send_dcap_quote; | ||
mod send_ias_attestation; | ||
|
||
pub use self::{ | ||
send_dcap_quote::SendDcapQuoteCmd, send_ias_attestation::SendIasAttestationReportCmd, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2021 Integritee AG and Supercomputing Systems AG | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use crate::{command_utils::get_worker_api_direct, Cli}; | ||
use itc_rpc_client::direct_client::DirectApi; | ||
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue}; | ||
use itp_types::DirectRequestStatus; | ||
use itp_utils::FromHexPrefixed; | ||
use log::*; | ||
use std::fs::read_to_string; | ||
|
||
/// Forward DCAP quote for verification. | ||
#[derive(Debug, Clone, Parser)] | ||
pub struct SendDcapQuoteCmd { | ||
/// Hex encoded DCAP quote filename. | ||
quote: String, | ||
} | ||
|
||
impl SendDcapQuoteCmd { | ||
pub fn run(&self, cli: &Cli) { | ||
let direct_api = get_worker_api_direct(cli); | ||
let hex_encoded_quote = match read_to_string(&self.quote) { | ||
Ok(hex_encoded_quote) => hex_encoded_quote, | ||
Err(e) => panic!("Opening hex encoded DCAP quote file failed: {:#?}", e), | ||
}; | ||
|
||
let rpc_method = "attesteer_forwardDcapQuote".to_owned(); | ||
let jsonrpc_call: String = | ||
RpcRequest::compose_jsonrpc_call(rpc_method, vec![hex_encoded_quote]).unwrap(); | ||
|
||
let rpc_response_str = direct_api.get(&jsonrpc_call).unwrap(); | ||
|
||
// Decode RPC response. | ||
let Ok(rpc_response) = serde_json::from_str::<RpcResponse>(&rpc_response_str) else { | ||
panic!("Can't parse RPC response: '{rpc_response_str}'"); | ||
}; | ||
let rpc_return_value = match RpcReturnValue::from_hex(&rpc_response.result) { | ||
Ok(rpc_return_value) => rpc_return_value, | ||
Err(e) => panic!("Failed to decode RpcReturnValue: {:?}", e), | ||
}; | ||
|
||
match rpc_return_value.status { | ||
DirectRequestStatus::Ok => println!("DCAP quote verification succeded."), | ||
_ => error!("DCAP quote verification failed"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright 2021 Integritee AG and Supercomputing Systems AG | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use itc_rpc_client::direct_client::DirectApi; | ||
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue}; | ||
use itp_types::DirectRequestStatus; | ||
use itp_utils::FromHexPrefixed; | ||
use log::*; | ||
use std::fs::read_to_string; | ||
|
||
use crate::{command_utils::get_worker_api_direct, Cli}; | ||
|
||
/// Forward IAS attestation report for verification. | ||
#[derive(Debug, Clone, Parser)] | ||
pub struct SendIasAttestationReportCmd { | ||
/// Hex encoded IAS attestation report filename. | ||
report: String, | ||
} | ||
|
||
impl SendIasAttestationReportCmd { | ||
pub fn run(&self, cli: &Cli) { | ||
let direct_api = get_worker_api_direct(cli); | ||
let hex_encoded_report = match read_to_string(&self.report) { | ||
Ok(hex_encoded_report) => hex_encoded_report, | ||
Err(e) => panic!("Opening hex encoded IAS attestation report file failed: {:#?}", e), | ||
}; | ||
|
||
//let request = Request { shard, cyphertext: hex_encoded_quote.to_vec() }; | ||
|
||
let rpc_method = "attesteer_forwardIasAttestationReport".to_owned(); | ||
let jsonrpc_call: String = | ||
RpcRequest::compose_jsonrpc_call(rpc_method, vec![hex_encoded_report]).unwrap(); | ||
|
||
let rpc_response_str = direct_api.get(&jsonrpc_call).unwrap(); | ||
|
||
// Decode RPC response. | ||
let Ok(rpc_response) = serde_json::from_str::<RpcResponse>(&rpc_response_str) else { | ||
panic!("Can't parse RPC response: '{rpc_response_str}'"); | ||
}; | ||
let rpc_return_value = match RpcReturnValue::from_hex(&rpc_response.result) { | ||
Ok(rpc_return_value) => rpc_return_value, | ||
Err(e) => panic!("Failed to decode RpcReturnValue: {:?}", e), | ||
}; | ||
|
||
match rpc_return_value.status { | ||
DirectRequestStatus::Ok => println!("IAS attestation report verification succeded."), | ||
_ => error!("IAS attestation report verification failed"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2021 Integritee AG and Supercomputing Systems AG | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use crate::Cli; | ||
|
||
use self::commands::{SendDcapQuoteCmd, SendIasAttestationReportCmd}; | ||
|
||
mod commands; | ||
|
||
/// Attesteer subcommands for the CLI. | ||
#[derive(Debug, clap::Subcommand)] | ||
pub enum AttesteerCommand { | ||
/// Forward DCAP quote for verification. | ||
SendDCAPQuote(SendDcapQuoteCmd), | ||
|
||
/// Forward IAS attestation report for verification. | ||
SendIASAttestationReport(SendIasAttestationReportCmd), | ||
} | ||
|
||
impl AttesteerCommand { | ||
pub fn run(&self, cli: &Cli) { | ||
match self { | ||
AttesteerCommand::SendDCAPQuote(cmd) => cmd.run(cli), | ||
AttesteerCommand::SendIASAttestationReport(cmd) => cmd.run(cli), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.