Skip to content

Commit 8934493

Browse files
authored
Merge pull request #105 from datachainlab/multiple-operators
Multiple operators Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
2 parents 16fa999 + 6220d89 commit 8934493

File tree

34 files changed

+806
-218
lines changed

34 files changed

+806
-218
lines changed

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/commands/attestation.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use clap::Parser;
77
use crypto::Address;
88
use ecall_commands::IASRemoteAttestationInput;
99
use enclave_api::{Enclave, EnclaveCommandAPI, EnclaveProtoAPI};
10+
use log::info;
1011
use store::transaction::CommitStore;
1112

1213
/// `attestation` subcommand
@@ -63,6 +64,22 @@ pub struct IASRemoteAttestation {
6364
help = "An enclave key attested by Remote Attestation"
6465
)]
6566
pub enclave_key: String,
67+
/// An operator address to perform `registerEnclaveKey` transaction on-chain
68+
#[clap(
69+
long = "operator",
70+
help = "An operator address to perform `registerEnclaveKey` transaction on-chain"
71+
)]
72+
pub operator: Option<String>,
73+
}
74+
75+
impl IASRemoteAttestation {
76+
fn get_operator(&self) -> Result<Option<Address>> {
77+
if let Some(operator) = &self.operator {
78+
Ok(Some(Address::from_hex_string(operator)?))
79+
} else {
80+
Ok(None)
81+
}
82+
}
6683
}
6784

6885
fn run_ias_remote_attestation<E: EnclaveCommandAPI<S>, S: CommitStore>(
@@ -74,10 +91,18 @@ fn run_ias_remote_attestation<E: EnclaveCommandAPI<S>, S: CommitStore>(
7491
let target_enclave_key = Address::from_hex_string(&cmd.enclave_key)?;
7592
match enclave.ias_remote_attestation(IASRemoteAttestationInput {
7693
target_enclave_key,
94+
operator: cmd.get_operator()?,
7795
spid: spid.as_bytes().to_vec(),
7896
ias_key: ias_key.as_bytes().to_vec(),
7997
}) {
80-
Ok(_) => Ok(()),
98+
Ok(res) => {
99+
info!("AVR: {:?}", res.report.avr);
100+
info!(
101+
"report_data: {}",
102+
res.report.get_avr()?.parse_quote()?.report_data()
103+
);
104+
Ok(())
105+
}
81106
Err(e) => bail!("failed to perform IAS Remote Attestation: {:?}!", e),
82107
}
83108
}
@@ -96,6 +121,13 @@ pub struct SimulateRemoteAttestation {
96121
)]
97122
pub enclave_key: String,
98123

124+
/// An operator address to perform `registerEnclaveKey` transaction on-chain
125+
#[clap(
126+
long = "operator",
127+
help = "An operator address to perform `registerEnclaveKey` transaction on-chain"
128+
)]
129+
pub operator: Option<String>,
130+
99131
/// Path to a der-encoded file that contains X.509 certificate
100132
#[clap(
101133
long = "signing_cert_path",
@@ -135,6 +167,17 @@ pub struct SimulateRemoteAttestation {
135167
pub isv_enclave_quote_status: String,
136168
}
137169

170+
#[cfg(feature = "sgx-sw")]
171+
impl SimulateRemoteAttestation {
172+
fn get_operator(&self) -> Result<Option<Address>> {
173+
if let Some(operator) = &self.operator {
174+
Ok(Some(Address::from_hex_string(operator)?))
175+
} else {
176+
Ok(None)
177+
}
178+
}
179+
}
180+
138181
#[cfg(feature = "sgx-sw")]
139182
fn run_simulate_remote_attestation<E: EnclaveCommandAPI<S>, S: CommitStore>(
140183
enclave: E,
@@ -187,13 +230,18 @@ fn run_simulate_remote_attestation<E: EnclaveCommandAPI<S>, S: CommitStore>(
187230
match enclave.simulate_remote_attestation(
188231
ecall_commands::SimulateRemoteAttestationInput {
189232
target_enclave_key,
233+
operator: cmd.get_operator()?,
190234
advisory_ids: cmd.advisory_ids.clone(),
191235
isv_enclave_quote_status: cmd.isv_enclave_quote_status.clone(),
192236
},
193237
signing_key,
194238
signing_cert,
195239
) {
196-
Ok(_) => Ok(()),
240+
Ok(res) => {
241+
info!("AVR: {:?}", res.avr);
242+
info!("report_data: {}", res.avr.parse_quote()?.report_data());
243+
Ok(())
244+
}
197245
Err(e) => bail!("failed to simulate Remote Attestation: {:?}!", e),
198246
}
199247
}

app/src/commands/enclave.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ fn run_list_keys<E: EnclaveCommandAPI<S>, S: CommitStore>(
104104
match eki.avr {
105105
Some(eavr) => {
106106
let avr = eavr.get_avr()?;
107+
let report_data = avr.parse_quote()?.report_data();
107108
list_json.push(json! {{
108109
"address": eki.address.to_hex_string(),
109110
"attested": true,
111+
"report_data": report_data.to_string(),
110112
"isv_enclave_quote_status": avr.isv_enclave_quote_status,
111113
"advisory_ids": avr.advisory_ids,
112114
"attested_at": avr.timestamp

enclave-modules/ecall-handler/src/enclave_manage/attestation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::enclave_manage::errors::Error;
22
use crate::prelude::*;
3-
use attestation_report::verify_report;
3+
use attestation_report::{verify_report, ReportData};
44
use crypto::{EnclaveKey, SealingKey};
55
use ecall_commands::{CommandContext, IASRemoteAttestationInput, IASRemoteAttestationResponse};
66
use enclave_remote_attestation::{
@@ -18,7 +18,7 @@ pub(crate) fn ias_remote_attestation(
1818
let report = {
1919
let spid = decode_spid(&input.spid);
2020
let report = create_attestation_report(
21-
pub_key.as_report_data(),
21+
ReportData::new(pub_key.as_address(), input.operator).into(),
2222
sgx_quote_sign_type_t::SGX_UNLINKABLE_SIGNATURE,
2323
spid,
2424
&input.ias_key,
@@ -39,7 +39,7 @@ pub(crate) fn simulate_remote_attestation(
3939
let pub_key =
4040
EnclaveKey::unseal(&cctx.sealed_ek.ok_or(Error::enclave_key_not_found())?)?.get_pubkey();
4141
let avr = enclave_remote_attestation::simulate::create_attestation_report(
42-
pub_key.as_report_data(),
42+
ReportData::new(pub_key.as_address(), input.operator).into(),
4343
sgx_quote_sign_type_t::SGX_UNLINKABLE_SIGNATURE,
4444
input.advisory_ids,
4545
input.isv_enclave_quote_status,

enclave-modules/ecall-handler/src/light_client/aggregate_messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn aggregate_messages<R: LightClientResolver, S: KVStore, K: Signer>(
4444
.collect::<Result<Vec<_>, _>>()?;
4545

4646
let message = ProxyMessage::from(commitments::aggregate_messages(messages)?);
47-
let proof = prove_commitment(ek, input.signer, message)?;
47+
let proof = prove_commitment(ek, message)?;
4848

4949
Ok(LightClientResponse::AggregateMessages(
5050
AggregateMessagesResponse(proof),

enclave-modules/ecall-handler/src/light_client/init_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn init_client<R: LightClientResolver, S: KVStore, K: Signer>(
3232
ctx.store_any_consensus_state(client_id.clone(), res.height, any_consensus_state)?;
3333

3434
let proof = if res.prove {
35-
prove_commitment(ek, input.signer, res.message)?
35+
prove_commitment(ek, res.message)?
3636
} else {
3737
CommitmentProof::new_with_no_signature(res.message.to_bytes())
3838
};

enclave-modules/ecall-handler/src/light_client/update_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn update_client<R: LightClientResolver, S: KVStore, K: Signer>(
3434
)?;
3535

3636
let proof = if data.prove {
37-
prove_commitment(ek, input.signer, message)?
37+
prove_commitment(ek, message)?
3838
} else {
3939
CommitmentProof::new_with_no_signature(message.to_bytes())
4040
};
@@ -45,7 +45,7 @@ pub fn update_client<R: LightClientResolver, S: KVStore, K: Signer>(
4545
UpdateClientResult::Misbehaviour(data) => {
4646
ctx.store_any_client_state(input.client_id, data.new_any_client_state)?;
4747

48-
let proof = prove_commitment(ek, input.signer, data.message.into())?;
48+
let proof = prove_commitment(ek, data.message.into())?;
4949
Ok(LightClientResponse::UpdateClient(UpdateClientResponse(
5050
proof,
5151
)))

enclave-modules/ecall-handler/src/light_client/verify_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn verify_membership<R: LightClientResolver, S: KVStore, K: Signer>(
2828
)?;
2929

3030
Ok(LightClientResponse::VerifyMembership(
31-
VerifyMembershipResponse(prove_commitment(ek, input.signer, res.message.into())?),
31+
VerifyMembershipResponse(prove_commitment(ek, res.message.into())?),
3232
))
3333
}
3434

@@ -49,6 +49,6 @@ pub fn verify_non_membership<R: LightClientResolver, S: KVStore, K: Signer>(
4949
)?;
5050

5151
Ok(LightClientResponse::VerifyNonMembership(
52-
VerifyNonMembershipResponse(prove_commitment(ek, input.signer, res.message.into())?),
52+
VerifyNonMembershipResponse(prove_commitment(ek, res.message.into())?),
5353
))
5454
}

enclave-modules/remote-attestation/src/attestation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use sgx_tstd::{
1515
net::TcpStream,
1616
sync::Arc,
1717
};
18-
use sgx_types::{c_int, sgx_spid_t};
19-
use sgx_types::{sgx_quote_nonce_t, sgx_quote_sign_type_t, sgx_report_data_t};
18+
use sgx_types::{c_int, sgx_quote_nonce_t, sgx_quote_sign_type_t, sgx_report_data_t, sgx_spid_t};
2019

2120
pub const REPORT_DATA_SIZE: usize = 32;
2221

enclave/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)