Skip to content
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

Return encrypted IDGraph when changed #1080

Merged
merged 44 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
eb47153
add id_graph to ocall extrinsics
Kailai-Wang Nov 29, 2022
27cd62e
adjust callback extrinsic
Kailai-Wang Nov 29, 2022
c0e7183
add cross-env&&dotenv
0xverin Nov 30, 2022
1425dea
set env
0xverin Nov 30, 2022
9baf628
random shard for testing
0xverin Nov 30, 2022
93d6634
Change the versions of @polkadot
0xverin Nov 30, 2022
c88e52f
change the version of @polkadot/types
0xverin Nov 30, 2022
782d6a7
Merge branch 'bugfix-ts-tests' into ts-tests
0xverin Nov 30, 2022
fb5bd53
rm yarn.lock
0xverin Nov 30, 2022
c81e6ac
Merge branch 'tee-dev' into 842-return-encrypted-id-graph
Kailai-Wang Nov 30, 2022
135ac8c
slight renaming
Kailai-Wang Nov 30, 2022
1cfc10e
change maxVerificationDelay to 30min
Kailai-Wang Nov 30, 2022
2999730
change yarn.lock
0xverin Dec 2, 2022
bd5b780
generateChallengeCode
0xverin Dec 2, 2022
c51f03c
modify yarn run command
0xverin Dec 2, 2022
40eb6e5
change defaultSinger
0xverin Dec 2, 2022
737dcd7
add getSinger
0xverin Dec 2, 2022
5380b94
add Sign functions
0xverin Dec 2, 2022
c88261c
add getSinger && generateChallengeCode
0xverin Dec 2, 2022
964f199
add ID_HUB_URL for sign message
0xverin Dec 2, 2022
fb2dde8
modify defaultSigner
0xverin Dec 2, 2022
2c983bf
Merge branch 'tee-dev' into ts-tests
0xverin Dec 2, 2022
9a52341
modify shard
0xverin Dec 5, 2022
7784235
add ethers provider&&wallet
0xverin Dec 6, 2022
38a1dd6
add eth endpoint
0xverin Dec 6, 2022
60048ee
add @ethersproject/providers&&ethers
0xverin Dec 7, 2022
d42c0c8
substrate&&ethereum tests
0xverin Dec 7, 2022
96d6eb2
web3 types
0xverin Dec 7, 2022
794a196
nonce
0xverin Dec 7, 2022
35ba8fd
Merge branch 'tee-dev' into ts-tests
0xverin Dec 7, 2022
fa0876c
change methods name
0xverin Dec 7, 2022
99a9cd5
change methods name
0xverin Dec 7, 2022
bce9612
change events
0xverin Dec 7, 2022
ce76092
Merge branch 'tee-dev' into 842-return-encrypted-id-graph
Kailai-Wang Dec 7, 2022
a407f90
change methods name
0xverin Dec 8, 2022
9626f4a
change event
0xverin Dec 8, 2022
c8a4c37
modify method name
0xverin Dec 8, 2022
e0cbd9c
Merge remote-tracking branch 'origin/ts-tests' into 842-return-encryp…
Dec 8, 2022
7633611
ts-test support `id_graph`
Dec 8, 2022
0393436
fix bug
Dec 8, 2022
1674ac5
remove log
Dec 8, 2022
b04c807
Merge remote-tracking branch 'origin/842-return-encrypted-id-graph' i…
Dec 8, 2022
1cb1863
Merge remote-tracking branch 'origin/tee-dev' into 842-return-encrypt…
Dec 9, 2022
b03a625
resolve conflicts
Dec 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pallets/identity-management-mock/src/identity_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::RuntimeDebugNoBound;
use scale_info::TypeInfo;

use crate::{BlockNumberOf, Config, Metadata};

// The context associated with the (litentry-account, did) pair
// TODO: maybe we have better naming
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(Clone, Eq, PartialEq, RuntimeDebugNoBound, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct IdentityContext<T: Config> {
Expand Down
28 changes: 25 additions & 3 deletions pallets/identity-management-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,34 @@ pub mod pallet {
IdentityCreatedPlain {
account: T::AccountId,
identity: Identity,
id_graph: Vec<(Identity, IdentityContext<T>)>,
},
IdentityCreated {
account: AesOutput,
identity: AesOutput,
id_graph: AesOutput,
},
// remove identity
IdentityRemovedPlain {
account: T::AccountId,
identity: Identity,
id_graph: Vec<(Identity, IdentityContext<T>)>,
},
IdentityRemoved {
account: AesOutput,
identity: AesOutput,
id_graph: AesOutput,
},
// verify identity
IdentityVerifiedPlain {
account: T::AccountId,
identity: Identity,
id_graph: Vec<(Identity, IdentityContext<T>)>,
},
IdentityVerified {
account: AesOutput,
identity: AesOutput,
id_graph: AesOutput,
},
// some error happened during processing in TEE, we use string-like
// parameters for more "generic" error event reporting
Expand Down Expand Up @@ -344,10 +350,12 @@ pub mod pallet {
Self::deposit_event(Event::<T>::IdentityCreatedPlain {
account: who.clone(),
identity: identity.clone(),
id_graph: Self::get_id_graph(&who),
});
Self::deposit_event(Event::<T>::IdentityCreated {
account: aes_encrypt_default(&key, who.encode().as_slice()),
identity: aes_encrypt_default(&key, identity.encode().as_slice()),
id_graph: aes_encrypt_default(&key, Self::get_id_graph(&who).encode().as_slice()),
});
Ok(())
}
Expand Down Expand Up @@ -375,10 +383,12 @@ pub mod pallet {
Self::deposit_event(Event::<T>::IdentityRemovedPlain {
account: who.clone(),
identity: identity.clone(),
id_graph: Self::get_id_graph(&who),
});
Self::deposit_event(Event::<T>::IdentityRemoved {
account: aes_encrypt_default(&key, who.encode().as_slice()),
identity: aes_encrypt_default(&key, identity.encode().as_slice()),
id_graph: aes_encrypt_default(&key, Self::get_id_graph(&who).encode().as_slice()),
});

Ok(())
Expand Down Expand Up @@ -450,10 +460,15 @@ pub mod pallet {
Self::deposit_event(Event::<T>::IdentityVerifiedPlain {
account: who.clone(),
identity: identity.clone(),
id_graph: Self::get_id_graph(&who),
});
Self::deposit_event(Event::<T>::IdentityVerified {
account: aes_encrypt_default(&key, who.encode().as_slice()),
identity: aes_encrypt_default(&key, identity.encode().as_slice()),
id_graph: aes_encrypt_default(
&key,
Self::get_id_graph(&who).encode().as_slice(),
),
});
Ok(())
})
Expand Down Expand Up @@ -487,9 +502,10 @@ pub mod pallet {
origin: OriginFor<T>,
account: AesOutput,
identity: AesOutput,
id_graph: AesOutput,
) -> DispatchResultWithPostInfo {
let _ = T::TEECallOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::IdentityCreated { account, identity });
Self::deposit_event(Event::IdentityCreated { account, identity, id_graph });
Ok(Pays::No.into())
}

Expand All @@ -498,9 +514,10 @@ pub mod pallet {
origin: OriginFor<T>,
account: AesOutput,
identity: AesOutput,
id_graph: AesOutput,
) -> DispatchResultWithPostInfo {
let _ = T::TEECallOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::IdentityRemoved { account, identity });
Self::deposit_event(Event::IdentityRemoved { account, identity, id_graph });
Ok(Pays::No.into())
}

Expand All @@ -509,9 +526,10 @@ pub mod pallet {
origin: OriginFor<T>,
account: AesOutput,
identity: AesOutput,
id_graph: AesOutput,
) -> DispatchResultWithPostInfo {
let _ = T::TEECallOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::IdentityVerified { account, identity });
Self::deposit_event(Event::IdentityVerified { account, identity, id_graph });
Ok(Pays::No.into())
}

Expand Down Expand Up @@ -663,5 +681,9 @@ pub mod pallet {
addr[..20].copy_from_slice(&hashed_pk[12..32]);
Ok(addr)
}

pub fn get_id_graph(who: &T::AccountId) -> Vec<(Identity, IdentityContext<T>)> {
IDGraphs::iter_prefix(who).collect::<Vec<_>>()
}
}
}
1 change: 1 addition & 0 deletions pallets/identity-management-mock/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ pub fn setup_create_identity(
System::assert_has_event(Event::IdentityManagementMock(crate::Event::IdentityCreatedPlain {
account: who,
identity: identity.clone(),
id_graph: IdentityManagementMock::get_id_graph(&who),
}));
// encrypt the result
let aes_encrypted_account = aes_encrypt_default(&key, who.encode().as_slice());
Expand Down
15 changes: 9 additions & 6 deletions pallets/identity-management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ pub mod pallet {
// event that should be triggered by TEECallOrigin
UserShieldingKeySet { account: AesOutput },
ChallengeCodeGenerated { account: AesOutput, identity: AesOutput, code: AesOutput },
IdentityCreated { account: AesOutput, identity: AesOutput },
IdentityRemoved { account: AesOutput, identity: AesOutput },
IdentityVerified { account: AesOutput, identity: AesOutput },
IdentityCreated { account: AesOutput, identity: AesOutput, id_graph: AesOutput },
IdentityRemoved { account: AesOutput, identity: AesOutput, id_graph: AesOutput },
IdentityVerified { account: AesOutput, identity: AesOutput, id_graph: AesOutput },
// some error happened during processing in TEE, we use string-like
// parameters for more "generic" error event reporting
// TODO: maybe use concrete errors instead of events when we are more sure
Expand Down Expand Up @@ -177,9 +177,10 @@ pub mod pallet {
origin: OriginFor<T>,
account: AesOutput,
identity: AesOutput,
id_graph: AesOutput,
) -> DispatchResultWithPostInfo {
let _ = T::TEECallOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::IdentityCreated { account, identity });
Self::deposit_event(Event::IdentityCreated { account, identity, id_graph });
Ok(Pays::No.into())
}

Expand All @@ -188,9 +189,10 @@ pub mod pallet {
origin: OriginFor<T>,
account: AesOutput,
identity: AesOutput,
id_graph: AesOutput,
) -> DispatchResultWithPostInfo {
let _ = T::TEECallOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::IdentityRemoved { account, identity });
Self::deposit_event(Event::IdentityRemoved { account, identity, id_graph });
Ok(Pays::No.into())
}

Expand All @@ -199,9 +201,10 @@ pub mod pallet {
origin: OriginFor<T>,
account: AesOutput,
identity: AesOutput,
id_graph: AesOutput,
) -> DispatchResultWithPostInfo {
let _ = T::TEECallOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::IdentityVerified { account, identity });
Self::deposit_event(Event::IdentityVerified { account, identity, id_graph });
Ok(Pays::No.into())
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/litmus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ ord_parameter_types! {
impl pallet_identity_management_mock::Config for Runtime {
type Event = Event;
type ManageWhitelistOrigin = EnsureRootOrAllCouncil;
type MaxVerificationDelay = ConstU32<10>;
type MaxVerificationDelay = ConstU32<{ 30 * MINUTES }>;
// intentionally use ALICE for the IMP mock
type TEECallOrigin = EnsureSignedBy<ALICE, AccountId>;
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,8 @@ ord_parameter_types! {

impl pallet_identity_management_mock::Config for Runtime {
type Event = Event;
type ManageWhitelistOrigin = EnsureRoot<Self::AccountId>;
type MaxVerificationDelay = ConstU32<10>;
type ManageWhitelistOrigin = EnsureRootOrAllCouncil;
type MaxVerificationDelay = ConstU32<{ 30 * MINUTES }>;
// intentionally use ALICE for the IMP mock
type TEECallOrigin = EnsureSignedBy<ALICE, AccountId>;
}
Expand Down
3 changes: 2 additions & 1 deletion tee-worker/app-libs/sgx-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub use sp_runtime::BuildStorage;
pub use sp_runtime::{Perbill, Permill};

// litentry
use litentry_primitives::MINUTES;
pub use pallet_imt::{self, Call as IdentityManagementCall};

/// Block type as expected by this sgx-runtime.
Expand Down Expand Up @@ -264,7 +265,7 @@ impl pallet_imt::Config for Runtime {
type Event = Event;
type ManageOrigin = EnsureRoot<AccountId>;
type MaxMetadataLength = ConstU32<128>;
type MaxVerificationDelay = ConstU32<20>;
type MaxVerificationDelay = ConstU32<{ 30 * MINUTES }>;
}

// The plain sgx-runtime without the `evm-pallet`
Expand Down
9 changes: 9 additions & 0 deletions tee-worker/app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,14 @@ where
Ok(code) => {
debug!("create_identity {} OK", account_id_to_string(&who));
if let Some(key) = IdentityManagement::user_shielding_keys(&who) {
let id_graph =
ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_id_graph(&who);
calls.push(OpaqueCall::from_tuple(&(
node_metadata_repo
.get_from_metadata(|m| m.identity_created_call_indexes())??,
aes_encrypt_default(&key, &who.encode()),
aes_encrypt_default(&key, &identity.encode()),
aes_encrypt_default(&key, &id_graph.encode()),
)));
calls.push(OpaqueCall::from_tuple(&(
node_metadata_repo.get_from_metadata(|m| {
Expand Down Expand Up @@ -486,11 +489,14 @@ where
Ok(()) => {
debug!("remove_identity {} OK", account_id_to_string(&who));
if let Some(key) = IdentityManagement::user_shielding_keys(&who) {
let id_graph =
ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_id_graph(&who);
calls.push(OpaqueCall::from_tuple(&(
node_metadata_repo
.get_from_metadata(|m| m.identity_removed_call_indexes())??,
aes_encrypt_default(&key, &who.encode()),
aes_encrypt_default(&key, &identity.encode()),
aes_encrypt_default(&key, &id_graph.encode()),
)));
} else {
calls.push(OpaqueCall::from_tuple(&(
Expand Down Expand Up @@ -535,11 +541,14 @@ where
Ok(()) => {
debug!("verify_identity {} OK", account_id_to_string(&who));
if let Some(key) = IdentityManagement::user_shielding_keys(&who) {
let id_graph =
ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_id_graph(&who);
calls.push(OpaqueCall::from_tuple(&(
node_metadata_repo
.get_from_metadata(|m| m.identity_verified_call_indexes())??,
aes_encrypt_default(&key, &who.encode()),
aes_encrypt_default(&key, &identity.encode()),
aes_encrypt_default(&key, &id_graph.encode()),
)));
} else {
calls.push(OpaqueCall::from_tuple(&(
Expand Down
11 changes: 4 additions & 7 deletions tee-worker/app-libs/stf/src/trusted_call_litentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,13 @@ impl TrustedCallSigned {
who: AccountId,
assertion: Assertion,
) -> StfResult<()> {
let v_identity_context =
ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_identity_and_identity_context(&who);
let id_graph = ita_sgx_runtime::pallet_imt::Pallet::<Runtime>::get_id_graph(&who);

let mut vec_identity: BoundedVec<Identity, MaxIdentityLength> = vec![].try_into().unwrap();

for identity_ctx in &v_identity_context {
if identity_ctx.1.is_verified {
vec_identity
.try_push(identity_ctx.0.clone())
.map_err(|_| StfError::AssertionBuildFail)?;
for id in &id_graph {
if id.1.is_verified {
vec_identity.try_push(id.0.clone()).map_err(|_| StfError::AssertionBuildFail)?;
}
}

Expand Down
4 changes: 1 addition & 3 deletions tee-worker/litentry/pallets/identity-management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
pub fn get_identity_and_identity_context(
who: &T::AccountId,
) -> Vec<(Identity, IdentityContext<T>)> {
pub fn get_id_graph(who: &T::AccountId) -> Vec<(Identity, IdentityContext<T>)> {
IDGraphs::iter_prefix(who).collect::<Vec<_>>()
}
}
Expand Down
6 changes: 3 additions & 3 deletions tee-worker/litentry/pallets/identity-management/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn verify_identity_works() {
}

#[test]
fn get_identity_and_identity_context_works() {
fn get_id_graph_works() {
new_test_ext().execute_with(|| {
let metadata3: MetadataOf<Test> = vec![0u8; 16].try_into().unwrap();
assert_ok!(IMT::create_identity(
Expand Down Expand Up @@ -141,8 +141,8 @@ fn get_identity_and_identity_context_works() {
));
assert_ok!(IMT::verify_identity(Origin::signed(1), 2, alice_web2_identity.clone(), 2));

let did_contex = IMT::get_identity_and_identity_context(&2);
assert_eq!(did_contex.len(), 2);
let id_graph = IMT::get_id_graph(&2);
assert_eq!(id_graph.len(), 2);
});
}

Expand Down
4 changes: 2 additions & 2 deletions tee-worker/litentry/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ mod validation_data;
pub use ethereum_signature::*;
pub use identity::*;
pub use parentchain_primitives::{
AesOutput, BlockNumber as ParentchainBlockNumber, UserShieldingKeyType, USER_SHIELDING_KEY_LEN,
USER_SHIELDING_KEY_NONCE_LEN, USER_SHIELDING_KEY_TAG_LEN,
AesOutput, BlockNumber as ParentchainBlockNumber, UserShieldingKeyType, MINUTES,
USER_SHIELDING_KEY_LEN, USER_SHIELDING_KEY_NONCE_LEN, USER_SHIELDING_KEY_TAG_LEN,
};
// pub use trusted_call::*;
pub use assertion::*;
Expand Down
Loading