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

Should not access group after being leaved #1728

Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aba617c
fix: error to access group after being kicked
Silver-IT Sep 18, 2023
85b2859
Merge branch 'e2e-protocol' into 1716-should-not-be-accessible-to-the…
Silver-IT Sep 22, 2023
fde1026
Merge branch 'e2e-protocol' into 1716-should-not-be-accessible-to-the…
Silver-IT Sep 24, 2023
8c9a05b
fix: resolved conflicts
Silver-IT Oct 6, 2023
1a05f9f
fix: errors in login process
Silver-IT Oct 23, 2023
9658650
fix: error in importing file
Silver-IT Oct 23, 2023
a791fb6
feat: remove unnecessary variables
Silver-IT Oct 23, 2023
5b81bcb
fix: error in login process after being removed
Silver-IT Oct 24, 2023
5f8d495
fix: simplified codes
Silver-IT Oct 25, 2023
318d313
fix: should wait until contracts are fully removed
Silver-IT Oct 26, 2023
e5a8c96
fix: error in working with queue invocations
Silver-IT Oct 26, 2023
ec5002b
wip: fix error while logging in after leaving group
Silver-IT Oct 26, 2023
74be27a
npm: recovered lost package.json
Silver-IT Oct 27, 2023
957bcbf
fix: wrong params of package
Silver-IT Oct 27, 2023
793cb87
wip: fixing login issue
Silver-IT Oct 30, 2023
9c717db
fix: login issues
Silver-IT Nov 6, 2023
8826ed5
chore: added comment
Silver-IT Nov 6, 2023
8f7519c
fix: error
Silver-IT Nov 6, 2023
433f2ff
fix: login issue regarding join after leaving
Silver-IT Nov 8, 2023
f30bbc0
fix: renamed function to get vuex state
Silver-IT Nov 8, 2023
88cb305
fix: error in chelonia
Silver-IT Nov 9, 2023
c2cada5
fix: error handling intermediate undefined
Silver-IT Nov 9, 2023
7c997c3
fix: error in using variable name
Silver-IT Nov 9, 2023
45d056e
wip: fixing unauthorized error
Silver-IT Nov 9, 2023
255f1ac
fix: error in chelonia
Silver-IT Nov 10, 2023
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
25 changes: 12 additions & 13 deletions contracts/0.2.0/chatroom-slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -7497,24 +7497,23 @@ ${this.getErrorInfo()}`;
},
"gi.contracts/chatroom/leave": {
validate: objectOf({
username: optional(string),
member: string
username: string,
showKickedBy: optional(string)
}),
process({ data, meta, hash, id, contractID }, { state }) {
const { member } = data;
const isKicked = data.username && member !== data.username;
if (!state.onlyRenderMessage && !state.users[member]) {
console.warn(`Can not leave the chatroom ${contractID} which ${member} is not part of`);
return;
const { username, showKickedBy } = data;
const isKicked = showKickedBy && username !== showKickedBy;
if (!state.onlyRenderMessage && !state.users[username]) {
throw new Error(`Can not leave the chatroom ${contractID} which ${username} is not part of`);
}
import_common.Vue.delete(state.users, member);
import_common.Vue.delete(state.users, username);
if (!state.onlyRenderMessage || state.attributes.type === CHATROOM_TYPES.DIRECT_MESSAGE) {
return;
}
const notificationType = !isKicked ? MESSAGE_NOTIFICATIONS.LEAVE_MEMBER : MESSAGE_NOTIFICATIONS.KICK_MEMBER;
const notificationData = createNotificationData(notificationType, isKicked ? { username: member } : {});
const notificationType = isKicked ? MESSAGE_NOTIFICATIONS.KICK_MEMBER : MESSAGE_NOTIFICATIONS.LEAVE_MEMBER;
const notificationData = createNotificationData(notificationType, isKicked ? { username } : {});
const newMessage = createMessage({
meta: isKicked ? meta : { ...meta, username: member },
meta: { ...meta, username: showKickedBy || username },
hash,
id,
data: notificationData,
Expand All @@ -7523,7 +7522,7 @@ ${this.getErrorInfo()}`;
state.messages.push(newMessage);
},
sideEffect({ data, hash, contractID, meta }, { state }) {
if (data.member === (0, import_sbp6.default)("state/vuex/state").loggedIn.username) {
if (data.username === (0, import_sbp6.default)("state/vuex/state").loggedIn.username) {
if ((0, import_sbp6.default)("chelonia/contract/isSyncing", contractID)) {
return;
}
Expand All @@ -7536,7 +7535,7 @@ ${this.getErrorInfo()}`;
}
}
const rootGetters = (0, import_sbp6.default)("state/vuex/getters");
const userID = rootGetters.ourContactProfiles[data.member]?.contractID;
const userID = rootGetters.ourContactProfiles[data.username]?.contractID;
if (userID) {
(0, import_sbp6.default)("gi.contracts/chatroom/removeForeignKeys", contractID, userID, state);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/0.2.0/chatroom.0.2.0.manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNMSuCrnYWd5k4rfgiER52edE4n4ZsMuMxxgLB8tEXRfpQ\",\"file\":\"chatroom.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"chatroom-slim.js\",\"hash\":\"21XWnNTNdo9ejZSdvNfCFHnh3kQPqNTXesNScNcXaezGTfJfYF\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNLTMXN39SuXeHJSiVEkUNKasv24USEvKLbCJ1m4o4wJsm\",\"file\":\"chatroom.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"chatroom-slim.js\",\"hash\":\"21XWnNVjYVPQK69Zskrdf85GgEma6j2rmKZSithKKviWStgwXg\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
25 changes: 12 additions & 13 deletions contracts/0.2.0/chatroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -16591,24 +16591,23 @@ ${this.getErrorInfo()}`;
},
"gi.contracts/chatroom/leave": {
validate: objectOf({
username: optional(string),
member: string
username: string,
showKickedBy: optional(string)
}),
process({ data, meta, hash: hash2, id, contractID }, { state }) {
const { member } = data;
const isKicked = data.username && member !== data.username;
if (!state.onlyRenderMessage && !state.users[member]) {
console.warn(`Can not leave the chatroom ${contractID} which ${member} is not part of`);
return;
const { username, showKickedBy } = data;
const isKicked = showKickedBy && username !== showKickedBy;
if (!state.onlyRenderMessage && !state.users[username]) {
throw new Error(`Can not leave the chatroom ${contractID} which ${username} is not part of`);
}
vue_esm_default.delete(state.users, member);
vue_esm_default.delete(state.users, username);
if (!state.onlyRenderMessage || state.attributes.type === CHATROOM_TYPES.DIRECT_MESSAGE) {
return;
}
const notificationType = !isKicked ? MESSAGE_NOTIFICATIONS.LEAVE_MEMBER : MESSAGE_NOTIFICATIONS.KICK_MEMBER;
const notificationData = createNotificationData(notificationType, isKicked ? { username: member } : {});
const notificationType = isKicked ? MESSAGE_NOTIFICATIONS.KICK_MEMBER : MESSAGE_NOTIFICATIONS.LEAVE_MEMBER;
const notificationData = createNotificationData(notificationType, isKicked ? { username } : {});
const newMessage = createMessage({
meta: isKicked ? meta : { ...meta, username: member },
meta: { ...meta, username: showKickedBy || username },
hash: hash2,
id,
data: notificationData,
Expand All @@ -16617,7 +16616,7 @@ ${this.getErrorInfo()}`;
state.messages.push(newMessage);
},
sideEffect({ data, hash: hash2, contractID, meta }, { state }) {
if (data.member === (0, import_sbp7.default)("state/vuex/state").loggedIn.username) {
if (data.username === (0, import_sbp7.default)("state/vuex/state").loggedIn.username) {
if ((0, import_sbp7.default)("chelonia/contract/isSyncing", contractID)) {
return;
}
Expand All @@ -16630,7 +16629,7 @@ ${this.getErrorInfo()}`;
}
}
const rootGetters = (0, import_sbp7.default)("state/vuex/getters");
const userID = rootGetters.ourContactProfiles[data.member]?.contractID;
const userID = rootGetters.ourContactProfiles[data.username]?.contractID;
if (userID) {
(0, import_sbp7.default)("gi.contracts/chatroom/removeForeignKeys", contractID, userID, state);
}
Expand Down
88 changes: 38 additions & 50 deletions contracts/0.2.0/group-slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -7311,8 +7311,8 @@ ${this.getErrorInfo()}`;
};
const message = { data: messageData, meta, contractID };
(0, import_sbp.default)("gi.contracts/group/removeMember/process", message, state);
(0, import_sbp.default)("gi.contracts/group/pushSideEffect", contractID, ["gi.contracts/group/removeMember/sideEffect", message]);
archiveProposal({ state, proposalHash, proposal, contractID });
(0, import_sbp.default)("gi.contracts/group/pushSideEffect", contractID, ["gi.contracts/group/removeMember/sideEffect", message]);
},
[VOTE_AGAINST]: voteAgainst
},
Expand Down Expand Up @@ -8398,34 +8398,36 @@ ${this.getErrorInfo()}`;
process({ data, meta, contractID }, { state, getters }) {
memberLeaves({ username: data.member, dateLeft: meta.createdDate }, { contractID, meta, state, getters });
},
async sideEffect({ data, meta, contractID }, { state, getters }) {
sideEffect({ data, meta, contractID }, { state, getters }) {
const rootState = (0, import_sbp6.default)("state/vuex/state");
const rootGetters = (0, import_sbp6.default)("state/vuex/getters");
const contracts = rootState.contracts || {};
const { username } = rootState.loggedIn;
if (data.member === username) {
if ((0, import_sbp6.default)("okTurtles.data/get", "JOINING_GROUP-" + contractID)) {
return;
}
await (0, import_sbp6.default)("gi.contracts/group/removeArchivedProposals", contractID);
await (0, import_sbp6.default)("gi.contracts/group/removeArchivedPayments", contractID);
const groupIdToSwitch = Object.keys(contracts).filter((cID) => contracts[cID].type === "gi.contracts/group" && cID !== contractID).sort((cID1, cID2) => rootState[cID1].profiles?.[username] ? -1 : 1)[0] || null;
(0, import_sbp6.default)("state/vuex/commit", "setCurrentChatRoomId", {});
(0, import_sbp6.default)("state/vuex/commit", "setCurrentGroupId", groupIdToSwitch);
(0, import_sbp6.default)("chelonia/contract/remove", contractID).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown by /remove ${contractID}:`, e);
});
(0, import_sbp6.default)("chelonia/queueInvocation", contractID, ["gi.actions/identity/saveOurLoginState"]).then(function() {
const router = (0, import_sbp6.default)("controller/router");
const switchFrom = router.currentRoute.path;
const switchTo = groupIdToSwitch ? "/dashboard" : "/";
if (switchFrom !== "/join" && switchFrom !== switchTo) {
router.push({ path: switchTo }).catch(console.warn);
(0, import_sbp6.default)("chelonia/queueInvocation", contractID, async () => {
if (rootState[contractID]?.profiles?.[username]?.status === PROFILE_STATUS.REMOVED) {
await (0, import_sbp6.default)("gi.contracts/group/removeArchivedProposals", contractID);
await (0, import_sbp6.default)("gi.contracts/group/removeArchivedPayments", contractID);
const groupIdToSwitch = Object.keys(contracts).filter((cID) => contracts[cID].type === "gi.contracts/group" && cID !== contractID).sort((cID1, cID2) => rootState[cID1].profiles?.[username] ? -1 : 1)[0] || null;
(0, import_sbp6.default)("state/vuex/commit", "setCurrentChatRoomId", {});
(0, import_sbp6.default)("state/vuex/commit", "setCurrentGroupId", groupIdToSwitch);
await (0, import_sbp6.default)("chelonia/contract/remove", contractID).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown by /remove ${contractID}:`, e);
});
await (0, import_sbp6.default)("gi.actions/identity/saveOurLoginState").then(function() {
const router = (0, import_sbp6.default)("controller/router");
const switchFrom = router.currentRoute.path;
const switchTo = groupIdToSwitch ? "/dashboard" : "/";
if (switchFrom !== "/join" && switchFrom !== switchTo) {
router.push({ path: switchTo }).catch(console.warn);
}
}).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown during queueEvent to ${contractID} by saveOurLoginState:`, e);
});
await (0, import_sbp6.default)("gi.contracts/group/revokeGroupKeyAndRotateOurPEK", contractID, true).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown during revokeGroupKeyAndRotateOurPEK to ${contractID}:`, e);
});
}
}).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown during queueEvent to ${contractID} by saveOurLoginState:`, e);
}).then(() => (0, import_sbp6.default)("gi.contracts/group/revokeGroupKeyAndRotateOurPEK", contractID, true)).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown during revokeGroupKeyAndRotateOurPEK to ${contractID}:`, e);
});
for (const notification of rootGetters.notificationsByGroup(contractID)) {
(0, import_sbp6.default)("state/vuex/commit", REMOVE_NOTIFICATION, notification);
Expand Down Expand Up @@ -8652,30 +8654,15 @@ ${this.getErrorInfo()}`;
"gi.contracts/group/leaveChatRoom": {
validate: objectOf({
chatRoomID: string,
member: string,
leavingGroup: boolean
username: string
}),
process({ data, meta }, { state }) {
import_common3.Vue.set(state.chatRooms[data.chatRoomID], "users", state.chatRooms[data.chatRoomID].users.filter((u) => u !== data.member));
},
async sideEffect({ meta, data, contractID }, { state }) {
const rootState = (0, import_sbp6.default)("state/vuex/state");
if (meta.username === rootState.loggedIn.username && !(0, import_sbp6.default)("okTurtles.data/get", "JOINING_GROUP-" + contractID)) {
const sendingData = data.leavingGroup ? { member: data.member } : { member: data.member, username: meta.username };
await (0, import_sbp6.default)("gi.actions/chatroom/leave", {
contractID: data.chatRoomID,
data: sendingData,
...data.leavingGroup && {
signingKeyId: (0, import_sbp6.default)("chelonia/contract/currentKeyIdByName", state, "csk"),
innerSigningContractID: null
}
});
}
import_common3.Vue.set(state.chatRooms[data.chatRoomID], "users", state.chatRooms[data.chatRoomID].users.filter((u) => u !== data.username));
}
},
"gi.contracts/group/joinChatRoom": {
validate: objectMaybeOf({
username: string,
validate: objectOf({
username: optional(string),
chatRoomID: string
}),
process({ data, meta }, { state }) {
Expand All @@ -8686,9 +8673,8 @@ ${this.getErrorInfo()}`;
const rootState = (0, import_sbp6.default)("state/vuex/state");
const username = data.username || meta.username;
if (username === rootState.loggedIn.username) {
if (!(0, import_sbp6.default)("okTurtles.data/get", "JOINING_GROUP-" + contractID) || (0, import_sbp6.default)("okTurtles.data/get", "JOINING_GROUP_CHAT")) {
if (!(0, import_sbp6.default)("okTurtles.data/get", "JOINING_GROUP-" + contractID)) {
await (0, import_sbp6.default)("chelonia/contract/sync", data.chatRoomID);
(0, import_sbp6.default)("okTurtles.data/set", "JOINING_GROUP_CHAT", false);
}
}
}
Expand Down Expand Up @@ -8877,14 +8863,16 @@ ${this.getErrorInfo()}`;
const CEKid = findKeyIdByName(state, "cek");
import_common3.Vue.set(state._volatile.pendingKeyRevocations, CSKid, true);
import_common3.Vue.set(state._volatile.pendingKeyRevocations, CEKid, true);
return (0, import_sbp6.default)("chelonia/queueInvocation", contractID, ["gi.actions/out/rotateKeys", contractID, "gi.contracts/group", "pending", "gi.actions/group/shareNewKeys"]).catch((e) => {
console.warn(`rotateKeys: ${e.name} thrown during queueEvent to ${contractID}:`, e);
return (0, import_sbp6.default)("gi.actions/out/rotateKeys", contractID, "gi.contracts/group", "pending", "gi.actions/group/shareNewKeys").catch((e) => {
console.warn(`rotateKeys: ${e.name} thrown:`, e);
});
},
"gi.contracts/group/revokeGroupKeyAndRotateOurPEK": (groupContractID, disconnectGroup) => {
const rootState = (0, import_sbp6.default)("state/vuex/state");
const { identityContractID } = rootState.loggedIn;
const state = rootState[identityContractID];
if (!state._volatile)
import_common3.Vue.set(state, "_volatile", /* @__PURE__ */ Object.create(null));
if (!state._volatile.pendingKeyRevocations)
import_common3.Vue.set(state._volatile, "pendingKeyRevocations", /* @__PURE__ */ Object.create(null));
const CSKid = findKeyIdByName(state, "csk");
Expand All @@ -8910,7 +8898,7 @@ ${this.getErrorInfo()}`;
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during queueEvent to ${identityContractID}:`, e);
});
}
return (0, import_sbp6.default)("chelonia/queueInvocation", identityContractID, ["gi.actions/out/rotateKeys", identityContractID, "gi.contracts/identity", "pending", "gi.actions/identity/shareNewPEK"]).catch((e) => {
(0, import_sbp6.default)("chelonia/queueInvocation", identityContractID, ["gi.actions/out/rotateKeys", identityContractID, "gi.contracts/identity", "pending", "gi.actions/identity/shareNewPEK"]).catch((e) => {
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during queueEvent to ${identityContractID}:`, e);
});
},
Expand All @@ -8922,13 +8910,13 @@ ${this.getErrorInfo()}`;
const CEKid = findKeyIdByName(state, "cek");
if (!CEKid)
throw new Error("Missing encryption key");
(0, import_sbp6.default)("chelonia/queueInvocation", contractID, ["chelonia/out/keyDel", {
(0, import_sbp6.default)("chelonia/out/keyDel", {
contractID,
contractName: "gi.contracts/group",
data: keyIds,
signingKeyId: CSKid
}]).catch((e) => {
console.warn(`removeForeignKeys: ${e.name} thrown during queueEvent to ${contractID}:`, e);
}).catch((e) => {
console.warn(`removeForeignKeys: ${e.name} error thrown:`, e);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/0.2.0/group.0.2.0.manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNFFQqoQ2fFncUoEPYCnKyaPuZKVYBxRdR6nY9MypMVyQu\",\"file\":\"group.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"group-slim.js\",\"hash\":\"21XWnNUobHkRALuMvw7jNjkr3o1sWc4YJufJhEg1wDo1ECuy8L\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNKv52PmMj5KXfAfMgq1PXALzY6j5dxMheQyXg2uqbk7Xs\",\"file\":\"group.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"group-slim.js\",\"hash\":\"21XWnNUhDAtLQrJvy2nN9NzHh7z8VwRtyqCmde6S9M2RUQgCjT\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
Loading