-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add quote guards to ServerInfo
related extrinsics
#1123
Changes from 11 commits
fe47faa
6c18434
641134b
ae73f0d
b2e5d01
8613c80
fdff83a
abec5a9
9296095
d5f1545
8daaa24
2e39ce9
edc2f7c
ed5db5e
cc71358
68c8f4c
f7571c5
5a0283c
3518cd0
70da5e3
a4f41c7
f70db4b
c68a4ed
f237a73
212628d
21bdfa7
492b9d6
2434d4d
1628f8a
fe7aadd
5a7ab4d
dd695c9
6424b7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,17 +11,23 @@ use crate::{ | |
}, | ||
get_api, get_rpc, EntropyConfig, | ||
}, | ||
change_endpoint, change_threshold_accounts, register, remove_program, store_program, | ||
change_endpoint, change_threshold_accounts, register, remove_program, request_attestation, | ||
store_program, | ||
substrate::query_chain, | ||
update_programs, | ||
}; | ||
|
||
use entropy_testing_utils::{ | ||
constants::{TEST_PROGRAM_WASM_BYTECODE, TSS_ACCOUNTS}, | ||
constants::{TEST_PROGRAM_WASM_BYTECODE, TSS_ACCOUNTS, X25519_PUBLIC_KEYS}, | ||
helpers::{derive_mock_pck_verifying_key, encode_verifying_key}, | ||
jump_start_network, spawn_testing_validators, | ||
substrate_context::test_context_stationary, | ||
test_node_process_testing_state, ChainSpecType, | ||
}; | ||
use rand::{ | ||
rngs::{OsRng, StdRng}, | ||
SeedableRng, | ||
}; | ||
use serial_test::serial; | ||
use sp_core::{sr25519, Pair, H256}; | ||
use sp_keyring::AccountKeyring; | ||
|
@@ -36,7 +42,33 @@ async fn test_change_endpoint() { | |
let api = get_api(&substrate_context.node_proc.ws_url).await.unwrap(); | ||
let rpc = get_rpc(&substrate_context.node_proc.ws_url).await.unwrap(); | ||
|
||
let result = change_endpoint(&api, &rpc, one.into(), "new_endpoint".to_string()).await.unwrap(); | ||
// By using this `Alice` account we can skip the `request_attestation` step since this is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok, i was thinking we were going to ditch having the pending attestation set at genesis because it wasn't used anymore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ya can't remove it yet. It would be nice to do so if we could streamline the quote generation for tests/benches a bit more in the future |
||
// already set up at genesis. | ||
let tss_account_id = &TSS_ACCOUNTS[0]; | ||
let x25519_public_key = X25519_PUBLIC_KEYS[0]; | ||
|
||
// This nonce is what was used in the genesis config for `Alice`. | ||
let nonce = [0; 32]; | ||
|
||
let quote = { | ||
let signing_key = tdx_quote::SigningKey::random(&mut OsRng); | ||
let public_key = sr25519::Public(tss_account_id.0); | ||
|
||
// We need to add `1` here since the quote is being checked in the next block | ||
let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; | ||
|
||
let input_data = | ||
entropy_shared::QuoteInputData::new(public_key, x25519_public_key, nonce, block_number); | ||
|
||
let mut pck_seeder = StdRng::from_seed(public_key.0); | ||
let pck = tdx_quote::SigningKey::random(&mut pck_seeder); | ||
|
||
tdx_quote::Quote::mock(signing_key.clone(), pck, input_data.0).as_bytes().to_vec() | ||
}; | ||
|
||
let result = | ||
change_endpoint(&api, &rpc, one.into(), "new_endpoint".to_string(), quote).await.unwrap(); | ||
|
||
assert_eq!( | ||
format!("{:?}", result), | ||
format!( | ||
|
@@ -57,13 +89,66 @@ async fn test_change_threshold_accounts() { | |
|
||
let api = get_api(&substrate_context.node_proc.ws_url).await.unwrap(); | ||
let rpc = get_rpc(&substrate_context.node_proc.ws_url).await.unwrap(); | ||
let x25519_public_key = [0u8; 32]; | ||
|
||
// By using this `Alice` account we can skip the `request_attestation` step since this is | ||
// already set up at genesis. | ||
// let tss_account_id = &TSS_ACCOUNTS[0]; | ||
// let x25519_public_key = X25519_PUBLIC_KEYS[0]; | ||
|
||
use entropy_testing_utils::get_signer_and_x25519_secret_from_mnemonic; | ||
let (tss_signer_pair, x25519_secret) = get_signer_and_x25519_secret_from_mnemonic( | ||
"gospel prosper cactus remember snap enact refuse review bind rescue guard sock", | ||
) | ||
.unwrap(); | ||
|
||
let tss_public_key = tss_signer_pair.signer().public(); | ||
let x25519_public_key = x25519_dalek::PublicKey::from(&x25519_secret); | ||
|
||
// We need to give our new TSS account some funds before it can request an attestation. | ||
let dest = tss_public_key; | ||
let balance_transfer_tx = entropy::tx() | ||
.balances() | ||
.transfer_allow_death((tss_signer_pair.account_id().clone()).into(), 100_000_000_000); | ||
let result = crate::substrate::submit_transaction_with_pair( | ||
&api, | ||
&rpc, | ||
&one.pair(), | ||
&balance_transfer_tx, | ||
None, | ||
) | ||
.await; | ||
dbg!(&result); | ||
|
||
let nonce = request_attestation(&api, &rpc, tss_signer_pair.signer().clone()).await.unwrap(); | ||
let nonce: [u8; 32] = nonce.try_into().unwrap(); | ||
|
||
let quote = { | ||
let signing_key = tdx_quote::SigningKey::random(&mut OsRng); | ||
// let public_key = sr25519::Public(tss_account_id.0); | ||
|
||
// We need to add `1` here since the quote is being checked in the next block | ||
let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; | ||
|
||
let input_data = entropy_shared::QuoteInputData::new( | ||
tss_public_key, | ||
*x25519_public_key.as_bytes(), | ||
nonce, | ||
block_number, | ||
); | ||
|
||
let mut pck_seeder = StdRng::from_seed(tss_public_key.0); | ||
let pck = tdx_quote::SigningKey::random(&mut pck_seeder); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ameba23 sorry since this test is a bit of a mess right now, but do you have any idea why the PCK verification might be failing? Should I be using a different input than the I've commented out the line in the Attestation crate where this fails. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay so in this case we're using the old PCK for quote verification. I thought the PCK was a fixed thing, but since it's probably tied to the hardware it does need to change then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry i somehow missed this. Yes the idea was to use tss account id as the seed. I guess with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With With That said, what if in the second case we just spin up a second instance of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In my understanding PCK would be the same but the 'attestation key' should change. A quote contains two signatures: the quote data is signed with the attestation key, and the attestation public key is signed with the PCK. I chose not to store the attestation public key on chain, because we can already see from the quote itself that it has been endorsed by the PCK - so the PCK is the thing we are interested in. But this does mean that there can be several TSS nodes associated with the same PCK. I can't think of a reason why this would be a problem but worth being aware of. |
||
|
||
tdx_quote::Quote::mock(signing_key.clone(), pck, input_data.0).as_bytes().to_vec() | ||
}; | ||
|
||
let result = change_threshold_accounts( | ||
&api, | ||
&rpc, | ||
one.into(), | ||
AccountId32(one.pair().public().0.into()).to_string(), | ||
hex::encode(x25519_public_key), | ||
tss_public_key.to_string(), | ||
hex::encode(*x25519_public_key.as_bytes()), | ||
quote, | ||
) | ||
.await | ||
.unwrap(); | ||
|
@@ -80,8 +165,8 @@ async fn test_change_threshold_accounts() { | |
events::ThresholdAccountChanged( | ||
AccountId32(one.pair().public().0), | ||
ServerInfo { | ||
tss_account: AccountId32(one.pair().public().0), | ||
x25519_public_key, | ||
tss_account: AccountId32(tss_public_key.0), | ||
x25519_public_key: *x25519_public_key.as_bytes(), | ||
endpoint: "127.0.0.1:3001".as_bytes().to_vec(), | ||
provisioning_certification_key, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For followup: If this is going to also be called by
entropy-tss
, which i think we probably will want to when we add a generate quote endpoint - it will need to go in a different module as stuff in this one is behind thefull-client
feature flag.