Skip to content
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
858110f
adjust docker tag for tee-dev
Kailai-Wang Jul 5, 2022
6924130
Merge branch 'dev' into tee-dev
Kailai-Wang Jul 5, 2022
2a3269b
Merge branch 'dev' into tee-dev
Kailai-Wang Jul 11, 2022
6a38e62
use integritee/pallets master branch
Kailai-Wang Jul 22, 2022
69a45a8
Merge remote-tracking branch 'origin/dev' into tee-dev
Aug 4, 2022
e22fc37
Merge remote-tracking branch 'origin/dev' into tee-dev
Aug 5, 2022
ce0c5c9
Merge branch 'dev' into tee-dev
Kailai-Wang Aug 17, 2022
25e4b11
add teeracle to tee-dev
Kailai-Wang Aug 17, 2022
848c967
Merge branch 'dev' into tee-dev
Kailai-Wang Aug 17, 2022
a5258b3
Merge remote-tracking branch 'origin/dev' into tee-dev
Aug 23, 2022
9d9fb38
Merge remote-tracking branch 'origin/dev' into tee-dev
Aug 24, 2022
0d1d828
switch to sdk-v0.9.0-polkadot-v0.9.26 as release branch
Kailai-Wang Aug 28, 2022
79c9a25
Merge branch 'tee-dev' of github.com:litentry/litentry-parachain into…
Aug 31, 2022
a7d1c94
Merge remote-tracking branch 'origin/dev' into tee-dev
Aug 31, 2022
8b35b6f
add back the dummy method for testing purpose
Aug 31, 2022
c35e460
fix make clippy
Aug 31, 2022
3d3958d
Merge branch 'dev' into tee-dev
Kailai-Wang Sep 19, 2022
a81ccc6
small cleanup
Kailai-Wang Sep 19, 2022
5902a19
add back teeracle
Kailai-Wang Sep 19, 2022
a8a2475
Merge branch 'dev' into tee-dev
Kailai-Wang Sep 23, 2022
2a9cbb8
Merge branch 'dev' into tee-dev
Kailai-Wang Oct 5, 2022
d621d1d
use specific branch of tee-primitives (todo:revert it)
Kailai-Wang Oct 5, 2022
3031343
correctify branch for tee-primitives
Kailai-Wang Oct 8, 2022
0804daa
Merge branch 'dev' into tee-dev
Kailai-Wang Oct 13, 2022
3740e49
temporarily use TEE pallets master branch
Kailai-Wang Oct 15, 2022
b3d10d2
add EnsureOrigin impl and tests
Kailai-Wang Oct 16, 2022
3fd9578
its better to place it in runtime_common
Kailai-Wang Oct 16, 2022
f77fc8b
Merge branch '895-use-real-enclave-signer' into tee-dev
Kailai-Wang Oct 16, 2022
fd4d119
Merge branch 'dev' into tee-dev
Kailai-Wang Oct 17, 2022
32766da
remove the dummy extrinsic (used for testing previous)
Oct 18, 2022
784cc04
rename ruleset -> assertion
Oct 20, 2022
c45e714
update renaming
Oct 20, 2022
fc63594
revert balance type
Oct 20, 2022
3049ef8
according to upstream, update pallets branch to 'develop'
Nov 1, 2022
968c4c3
fix build error
Nov 1, 2022
4890717
add rococo docker file
Nov 2, 2022
59b698f
Cherry-Pick: 47386434
Kailai-Wang Oct 26, 2022
c76adde
Update tee-dev branch into polkadot v0.9.29 (#971)
BillyWooo Nov 23, 2022
469f769
add BUILDKIT explicitly
Nov 24, 2022
b6dda59
Merge tee worker repo (#987)
Kailai-Wang Nov 29, 2022
f85a91b
Switch to local dependencies (#1037)
Kailai-Wang Nov 30, 2022
09784f1
Try to fix the docker image pushing (#1040)
Kailai-Wang Nov 30, 2022
0b1d286
remove unneeded CI steps (#1049)
Kailai-Wang Dec 1, 2022
5041960
tee-worker ts-tests (#1039)
0xverin Dec 2, 2022
084dbf3
Ts tests (#1053)
0xverin Dec 5, 2022
1c6980e
Add more testcases for IMP mock (#1057)
Kailai-Wang Dec 5, 2022
c485920
982 renaming issue (#1052)
BillyWooo Dec 6, 2022
d4a9f58
link web3 and verify web3 (#1072)
0xverin Dec 8, 2022
b734572
Emit new challenge code for each `create_identity` (#1074)
Kailai-Wang Dec 8, 2022
cc55ce7
Return encrypted IDGraph when changed (#1080)
Kailai-Wang Dec 12, 2022
229ebe1
try to experiment with erroneous extrinsic
Kailai-Wang Dec 14, 2022
9cbb4dd
adjust start/stop parachain
Kailai-Wang Dec 14, 2022
e1821d7
adjust local binary script
Kailai-Wang Dec 14, 2022
380ab3f
add delegatee management
Kailai-Wang Dec 14, 2022
ead95ac
Tee worker polkadot v0.9.32 (#1093)
BillyWooo Dec 15, 2022
7f3c5c8
adjust tests
Kailai-Wang Dec 15, 2022
f12671c
Merge branch 'tee-dev' into 847-allow-idhcs-to-create-identity
Kailai-Wang Dec 15, 2022
e578eea
Merge remote-tracking branch 'origin/dev' into tee-dev
BillyWooo Dec 15, 2022
6305908
update tee worker ci
BillyWooo Dec 15, 2022
e03843e
Merge branch 'tee-dev' into 847-allow-idhcs-to-create-identity
Kailai-Wang Dec 15, 2022
b292284
prettier
Kailai-Wang Dec 15, 2022
2b4ca77
adjust tee-worker part
Kailai-Wang Dec 15, 2022
a47c54c
Merge branch 'dev' into 847-allow-idhcs-to-create-identity
Kailai-Wang Dec 15, 2022
73e08c8
revert to classic download
Kailai-Wang Dec 16, 2022
0a57c2b
small ajustments to ts-tests
Kailai-Wang Dec 16, 2022
715cae3
prettier
Kailai-Wang Dec 16, 2022
08075f5
fix some clippy and compilation
Kailai-Wang Dec 16, 2022
d7e8c4a
Merge branch 'dev' into 847-allow-idhcs-to-create-identity
Kailai-Wang Dec 19, 2022
0a56e2e
Merge branch 'dev' into 847-allow-idhcs-to-create-identity
Kailai-Wang Dec 20, 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
2 changes: 1 addition & 1 deletion .github/workflows/tee-worker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
runs-on: ubuntu-latest
needs: check-file-change
if: needs.check-file-change.outputs.src == 'true'
container: "integritee/integritee-dev:0.1.9"
container: "integritee/integritee-dev:0.1.10"
steps:
- uses: actions/checkout@v3
- name: init rust
Expand Down
55 changes: 33 additions & 22 deletions pallets/identity-management-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,25 @@ pub mod pallet {
pub trait Config: frame_system::Config {
/// Event
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// origin to manage caller whitelist
type ManageWhitelistOrigin: EnsureOrigin<Self::RuntimeOrigin>;
// maximum delay in block numbers between creating an identity and verifying an identity
#[pallet::constant]
type MaxVerificationDelay: Get<BlockNumberOf<Self>>;
// some extrinsics should only be called by origins from TEE
type TEECallOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// origin to manage authorised delegatee list
type DelegateeAdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
// Events from this pallet
DelegateeAdded {
account: T::AccountId,
},
DelegateeRemoved {
account: T::AccountId,
},
CreateIdentityRequested {
shard: ShardIdentifier,
},
Expand Down Expand Up @@ -171,8 +177,10 @@ pub mod pallet {
/// These are the errors that are immediately emitted from this mock pallet
#[pallet::error]
pub enum Error<T> {
/// caller is not in whitelist (therefore disallowed to call some extrinsics)
CallerNotWhitelisted,
/// a delegatee doesn't exist
DelegateeNotExist,
/// a `create_identity` request from unauthorised user
UnauthorisedUser,
/// Error when decrypting using TEE'shielding key
ShieldingKeyDecryptionFailed,
/// unexpected decoded type
Expand Down Expand Up @@ -209,10 +217,11 @@ pub mod pallet {
UnexpectedMessage,
}

/// delegatees who are authorised to send extrinsics(currently only `create_identity`)
/// on behalf of the users
#[pallet::storage]
#[pallet::getter(fn whitelisted_callers)]
pub type WhitelistedCallers<T: Config> =
StorageMap<_, Twox64Concat, T::AccountId, (), OptionQuery>;
#[pallet::getter(fn delegatee)]
pub type Delegatee<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, (), OptionQuery>;

/// user shielding key is per Litentry account
#[pallet::storage]
Expand Down Expand Up @@ -248,22 +257,23 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
/// add an account to the whitelist
/// add an account to the delegatees
#[pallet::weight(195_000_000)]
pub fn add_to_whitelist(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
let _ = T::ManageWhitelistOrigin::ensure_origin(origin)?;
WhitelistedCallers::<T>::insert(account, ());
pub fn add_delegatee(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
let _ = T::DelegateeAdminOrigin::ensure_origin(origin)?;
// we don't care if `account` already exists
Delegatee::<T>::insert(account.clone(), ());
Self::deposit_event(Event::DelegateeAdded { account });
Ok(())
}

/// remove an account from the whitelist
/// remove an account from the delegatees
#[pallet::weight(195_000_000)]
pub fn remove_from_whitelist(
origin: OriginFor<T>,
account: T::AccountId,
) -> DispatchResult {
let _ = T::ManageWhitelistOrigin::ensure_origin(origin)?;
WhitelistedCallers::<T>::remove(account);
pub fn remove_delegatee(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
let _ = T::DelegateeAdminOrigin::ensure_origin(origin)?;
ensure!(Delegatee::<T>::contains_key(&account), Error::<T>::DelegateeNotExist);
Delegatee::<T>::remove(account.clone());
Self::deposit_event(Event::DelegateeRemoved { account });
Ok(())
}

Expand All @@ -275,7 +285,6 @@ pub mod pallet {
encrypted_key: Vec<u8>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(WhitelistedCallers::<T>::contains_key(&who), Error::<T>::CallerNotWhitelisted);
Self::deposit_event(Event::SetUserShieldingKeyRequested { shard });

let decrypted_key = Self::decrypt_with_tee_shielding_key(&encrypted_key)?;
Expand All @@ -294,11 +303,15 @@ pub mod pallet {
pub fn create_identity(
origin: OriginFor<T>,
shard: ShardIdentifier,
user: T::AccountId,
encrypted_identity: Vec<u8>,
encrypted_metadata: Option<Vec<u8>>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(WhitelistedCallers::<T>::contains_key(&who), Error::<T>::CallerNotWhitelisted);
ensure!(
who == user || Delegatee::<T>::contains_key(&who),
Error::<T>::UnauthorisedUser
);
Self::deposit_event(Event::CreateIdentityRequested { shard });

let decrypted_identitty = Self::decrypt_with_tee_shielding_key(&encrypted_identity)?;
Expand Down Expand Up @@ -368,7 +381,6 @@ pub mod pallet {
encrypted_identity: Vec<u8>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(WhitelistedCallers::<T>::contains_key(&who), Error::<T>::CallerNotWhitelisted);
Self::deposit_event(Event::RemoveIdentityRequested { shard });

let decrypted_identitty = Self::decrypt_with_tee_shielding_key(&encrypted_identity)?;
Expand Down Expand Up @@ -403,7 +415,6 @@ pub mod pallet {
encrypted_validation_data: Vec<u8>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(WhitelistedCallers::<T>::contains_key(&who), Error::<T>::CallerNotWhitelisted);
Self::deposit_event(Event::VerifyIdentityRequested { shard });

let now = <frame_system::Pallet<T>>::block_number();
Expand Down
6 changes: 2 additions & 4 deletions pallets/identity-management-mock/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ ord_parameter_types! {

impl pallet_identity_management_mock::Config for Test {
type RuntimeEvent = RuntimeEvent;
type ManageWhitelistOrigin = EnsureRoot<Self::AccountId>;
type MaxVerificationDelay = ConstU64<10>;
type TEECallOrigin = EnsureSignedBy<One, u64>;
type DelegateeAdminOrigin = EnsureRoot<Self::AccountId>;
}

pub fn new_test_ext() -> sp_io::TestExternalities {
Expand All @@ -135,8 +135,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities {

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
// add to `One` to whitelist
let _ = IdentityManagementMock::add_to_whitelist(RuntimeOrigin::root(), 1u64);
System::set_block_number(1);
});
ext
Expand Down Expand Up @@ -214,7 +212,6 @@ pub fn setup_user_shieding_key(
let shielding_key = Aes256Gcm::generate_key(&mut OsRng);
let encrpted_shielding_key = tee_encrypt(&shielding_key);
// whitelist caller
assert_ok!(IdentityManagementMock::add_to_whitelist(RuntimeOrigin::root(), who));
assert_ok!(IdentityManagementMock::set_user_shielding_key(
RuntimeOrigin::signed(who),
H256::random(),
Expand Down Expand Up @@ -246,6 +243,7 @@ pub fn setup_create_identity(
assert_ok!(IdentityManagementMock::create_identity(
RuntimeOrigin::signed(who),
H256::random(),
who,
encrypted_identity.to_vec(),
None
));
Expand Down
15 changes: 1 addition & 14 deletions pallets/identity-management-mock/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ use codec::Encode;
use frame_support::assert_noop;
use sp_core::{blake2_256, Pair, H256};

#[test]
fn unpriveledged_origin_call_fails() {
new_test_ext().execute_with(|| {
assert_noop!(
IdentityManagementMock::set_user_shielding_key(
RuntimeOrigin::signed(2),
H256::random(),
vec![]
),
Error::<Test>::CallerNotWhitelisted
);
});
}

#[test]
fn set_user_shielding_key_works() {
new_test_ext().execute_with(|| {
Expand Down Expand Up @@ -118,6 +104,7 @@ fn create_twitter_identity_after_verification_fails() {
IdentityManagementMock::create_identity(
RuntimeOrigin::signed(who),
H256::random(),
who,
encrypted_identity.to_vec(),
None
),
Expand Down
5 changes: 2 additions & 3 deletions pallets/identity-management/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
}

benchmarks! {

// Benchmark `create_identity`. There are no worst conditions. The benchmark showed that
// execution time is constant irrespective of encrypted_data size.
create_identity {
let caller = whitelisted_caller();
let caller = whitelisted_caller::<T::AccountId>();
let shard = H256::from_slice(&TEST_MRENCLAVE);
let encrypted_did = vec![1u8; 2048];
let encrypted_metadata = Some(vec![1u8; 2048]);
}: _(RawOrigin::Signed(caller), shard, encrypted_did, encrypted_metadata)
}: _(RawOrigin::Signed(caller.clone()), shard, caller.clone(), encrypted_did, encrypted_metadata)
verify {
assert_last_event::<T>(Event::CreateIdentityRequested{ shard }.into());
}
Expand Down
53 changes: 45 additions & 8 deletions pallets/identity-management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ pub use pallet::*;
pub use primitives::{AesOutput, ShardIdentifier};
use sp_std::vec::Vec;

// fn types for handling inside tee-worker
pub type SetUserShieldingKeyFn = ([u8; 2], ShardIdentifier, Vec<u8>);
pub type CreateIdentityFn = ([u8; 2], ShardIdentifier, Vec<u8>, Option<Vec<u8>>);
pub type RemoveIdentityFn = ([u8; 2], ShardIdentifier, Vec<u8>);
pub type VerifyIdentityFn = ([u8; 2], ShardIdentifier, Vec<u8>, Vec<u8>);

#[frame_support::pallet]
pub mod pallet {
use super::{AesOutput, ShardIdentifier, Vec, WeightInfo};
Expand All @@ -69,11 +63,15 @@ pub mod pallet {
type WeightInfo: WeightInfo;
// some extrinsics should only be called by origins from TEE
type TEECallOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// origin to manage authorised delegatee list
type DelegateeAdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
DelegateeAdded { account: T::AccountId },
DelegateeRemoved { account: T::AccountId },
// TODO: do we need account as event parameter? This needs to be decided by F/E
CreateIdentityRequested { shard: ShardIdentifier },
RemoveIdentityRequested { shard: ShardIdentifier },
Expand All @@ -92,11 +90,42 @@ pub mod pallet {
SomeError { func: Vec<u8>, error: Vec<u8> },
}

/// delegatees who are authorised to send extrinsics(currently only `create_identity`)
/// on behalf of the users
#[pallet::storage]
#[pallet::getter(fn delegatee)]
pub type Delegatee<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, (), OptionQuery>;

#[pallet::error]
pub enum Error<T> {}
pub enum Error<T> {
/// a delegatee doesn't exist
DelegateeNotExist,
/// a `create_identity` request from unauthorised user
UnauthorisedUser,
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// add an account to the delegatees
#[pallet::weight(195_000_000)]
pub fn add_delegatee(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
let _ = T::DelegateeAdminOrigin::ensure_origin(origin)?;
// we don't care if `account` already exists
Delegatee::<T>::insert(account.clone(), ());
Self::deposit_event(Event::DelegateeAdded { account });
Ok(())
}

/// remove an account from the delegatees
#[pallet::weight(195_000_000)]
pub fn remove_delegatee(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
let _ = T::DelegateeAdminOrigin::ensure_origin(origin)?;
ensure!(Delegatee::<T>::contains_key(&account), Error::<T>::DelegateeNotExist);
Delegatee::<T>::remove(account.clone());
Self::deposit_event(Event::DelegateeRemoved { account });
Ok(())
}

/// Set or update user's shielding key
#[pallet::weight(<T as Config>::WeightInfo::set_user_shielding_key())]
pub fn set_user_shielding_key(
Expand All @@ -110,14 +139,22 @@ pub mod pallet {
}

/// Create an identity
/// We do the origin check for this extrinsic, it has to be
/// - either the caller him/herself, i.e. ensure_signed(origin)? == who
/// - or from a delegatee in the list
#[pallet::weight(<T as Config>::WeightInfo::create_identity())]
pub fn create_identity(
origin: OriginFor<T>,
shard: ShardIdentifier,
user: T::AccountId,
encrypted_identity: Vec<u8>,
encrypted_metadata: Option<Vec<u8>>,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
let who = ensure_signed(origin)?;
ensure!(
who == user || Delegatee::<T>::contains_key(&who),
Error::<T>::UnauthorisedUser
);
Self::deposit_event(Event::CreateIdentityRequested { shard });
Ok(().into())
}
Expand Down
4 changes: 4 additions & 0 deletions pallets/identity-management/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use system::EnsureRoot;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -135,13 +136,16 @@ impl pallet_identity_management::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type TEECallOrigin = EnsureEnclaveSigner;
type DelegateeAdminOrigin = EnsureRoot<Self::AccountId>;
}

pub fn new_test_ext() -> sp_io::TestExternalities {
let t = system::GenesisConfig::default().build_storage::<Test>().unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
// add `5` to delegatee
let _ = IdentityManagement::add_delegatee(RuntimeOrigin::root(), 5u64);
System::set_block_number(1);
});
ext
Expand Down
Loading