From 1c58899558bbbbe94f1c55c58d16b013d1c3efb0 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 14 Mar 2024 11:59:40 +1100 Subject: [PATCH] fix: rekey explicitely when creating a group --- ts/components/dialog/SessionSeedModal.tsx | 11 ++++++++--- .../registration/RegistrationUserDetails.tsx | 11 ++++++++++- ts/components/registration/SignUpTab.tsx | 4 ++-- ts/receiver/contentMessage.ts | 4 ++-- .../swarm_polling_config/SwarmPollingGroupConfig.ts | 1 + ts/session/utils/job_runners/jobs/GroupSyncJob.ts | 7 +++++-- .../libsession_utils_convo_info_volatile.ts | 6 +++--- ts/state/selectors/groups.ts | 1 - .../workers/browser/libsession_worker_interface.ts | 4 ++++ 9 files changed, 35 insertions(+), 14 deletions(-) diff --git a/ts/components/dialog/SessionSeedModal.tsx b/ts/components/dialog/SessionSeedModal.tsx index ba6eba3a0..659e28f2f 100644 --- a/ts/components/dialog/SessionSeedModal.tsx +++ b/ts/components/dialog/SessionSeedModal.tsx @@ -12,6 +12,7 @@ import { mnDecode } from '../../session/crypto/mnemonic'; import { recoveryPhraseModal } from '../../state/ducks/modalDialog'; import { SpacerSM } from '../basic/Text'; +import { isAutoLogin } from '../../shared/env_vars'; import { saveQRCode } from '../../util/saveQRCode'; import { getCurrentRecoveryPhrase } from '../../util/storage'; import { SessionWrapperModal } from '../SessionWrapperModal'; @@ -131,6 +132,12 @@ const Seed = (props: SeedProps) => { dispatch(recoveryPhraseModal(null)); }; + useMount(() => { + if (isAutoLogin()) { + copyRecoveryPhrase(recoveryPhrase); + } + }); + return ( <>
@@ -186,7 +193,7 @@ interface ModalInnerProps { onClickOk?: () => any; } -const SessionSeedModalInner = (props: ModalInnerProps) => { +export const SessionSeedModal = (props: ModalInnerProps) => { const { onClickOk } = props; const [loadingPassword, setLoadingPassword] = useState(true); const [loadingSeed, setLoadingSeed] = useState(true); @@ -247,5 +254,3 @@ const SessionSeedModalInner = (props: ModalInnerProps) => { ); }; - -export const SessionSeedModal = SessionSeedModalInner; diff --git a/ts/components/registration/RegistrationUserDetails.tsx b/ts/components/registration/RegistrationUserDetails.tsx index 2aee802bf..063ea8c80 100644 --- a/ts/components/registration/RegistrationUserDetails.tsx +++ b/ts/components/registration/RegistrationUserDetails.tsx @@ -1,5 +1,6 @@ import classNames from 'classnames'; import React from 'react'; +import useMount from 'react-use/lib/useMount'; import useTimeoutFn from 'react-use/lib/useTimeoutFn'; import { MAX_USERNAME_BYTES } from '../../session/constants'; import { isAutoLogin, isDevProd } from '../../shared/env_vars'; @@ -26,7 +27,7 @@ function useAutoRegister(props: DisplayNameProps) { }, 100); useTimeoutFn(() => { - if (isDevProd() && props.displayName) { + if (isAutoLogin() && props.displayName) { props.handlePressEnter(); } }, 200); @@ -56,6 +57,14 @@ const RecoveryPhraseInput = (props: { handlePressEnter: () => any; stealAutoFocus?: boolean; }) => { + useMount(() => { + if (isAutoLogin()) { + const seed = window.clipboard.readText() as string | undefined; + if (seed?.split(' ').length === 13) { + props.onSeedChanged(seed); + } + } + }); return ( function useAutoContinue(props: { continueSignUp: () => void }) { useTimeoutFn(() => { - if (isDevProd() && isAutoLogin()) { + if (isAutoLogin()) { props.continueSignUp(); } }, 100); diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index e520ed68c..515a8c79a 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -475,7 +475,7 @@ export async function innerHandleSwarmContentMessage({ * For a private conversation message, this is just the conversation with that user */ if (!isPrivateConversationMessage) { - console.warn('conversationModelForUIUpdate might need to be checked for groupv2 case'); + console.info('conversationModelForUIUpdate might need to be checked for groupv2 case'); // debugger // this is a closed group message, we have a second conversation to make sure exists conversationModelForUIUpdate = await ConvoHub.use().getOrCreateAndWait( envelope.source, @@ -818,7 +818,7 @@ async function handleMessageRequestResponse( if (previousApprovedMe) { await conversationToApprove.commit(); - window.log.inf( + window.log.info( `convo ${ed25519Str(conversationToApprove.id)} previousApprovedMe is already true. Nothing to do ` ); await IncomingMessageCache.removeFromCache(envelope); diff --git a/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts b/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts index f3c9d618d..52a887422 100644 --- a/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts +++ b/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts @@ -53,6 +53,7 @@ async function handleGroupSharedConfigMessages( ); // do the merge with our current state await MetaGroupWrapperActions.metaMerge(groupPk, toMerge); + // save updated dumps to the DB right away await LibSessionUtil.saveDumpsToDb(groupPk); diff --git a/ts/session/utils/job_runners/jobs/GroupSyncJob.ts b/ts/session/utils/job_runners/jobs/GroupSyncJob.ts index 9b91221d2..e560a66f6 100644 --- a/ts/session/utils/job_runners/jobs/GroupSyncJob.ts +++ b/ts/session/utils/job_runners/jobs/GroupSyncJob.ts @@ -17,6 +17,7 @@ import { TTL_DEFAULT } from '../../../constants'; import { ConvoHub } from '../../../conversations'; import { GroupUpdateInfoChangeMessage } from '../../../messages/outgoing/controlMessage/group_v2/to_group/GroupUpdateInfoChangeMessage'; import { GroupUpdateMemberChangeMessage } from '../../../messages/outgoing/controlMessage/group_v2/to_group/GroupUpdateMemberChangeMessage'; +import { ed25519Str } from '../../../onions/onionPath'; import { MessageSender } from '../../../sending/MessageSender'; import { PubKey } from '../../../types'; import { allowOnlyOneAtATime } from '../../Promise'; @@ -288,9 +289,9 @@ class GroupSyncJob extends PersistedJob { public async run(): Promise { const start = Date.now(); + const thisJobDestination = this.persistedData.identifier; try { - const thisJobDestination = this.persistedData.identifier; if (!PubKey.is03Pubkey(thisJobDestination)) { return RunJobResult.PermanentFailure; } @@ -318,7 +319,9 @@ class GroupSyncJob extends PersistedJob { } catch (e) { throw e; } finally { - window.log.debug(`UserSyncJob run() took ${Date.now() - start}ms`); + window.log.debug( + `GroupSyncJob ${ed25519Str(thisJobDestination)} run() took ${Date.now() - start}ms` + ); // this is a simple way to make sure whatever happens here, we update the lastest timestamp. // (a finally statement is always executed (no matter if exception or returns in other try/catch block) diff --git a/ts/session/utils/libsession/libsession_utils_convo_info_volatile.ts b/ts/session/utils/libsession/libsession_utils_convo_info_volatile.ts index 02d7142af..a903e2eec 100644 --- a/ts/session/utils/libsession/libsession_utils_convo_info_volatile.ts +++ b/ts/session/utils/libsession/libsession_utils_convo_info_volatile.ts @@ -86,9 +86,9 @@ async function insertConvoFromDBIntoWrapperAndRefresh(convoId: string): Promise< ? timestampFromDbMs : 0; - window.log.debug( - `inserting into convoVolatile wrapper: ${convoId} lastMessageReadTimestamp:${lastReadMessageTimestamp} forcedUnread:${isForcedUnread}...` - ); + // window.log.debug( + // `inserting into convoVolatile wrapper: ${convoId} lastMessageReadTimestamp:${lastReadMessageTimestamp} forcedUnread:${isForcedUnread}...` + // ); const convoType = getConvoType(foundConvo); switch (convoType) { diff --git a/ts/state/selectors/groups.ts b/ts/state/selectors/groups.ts index 340a88a2b..b94f5af49 100644 --- a/ts/state/selectors/groups.ts +++ b/ts/state/selectors/groups.ts @@ -40,7 +40,6 @@ function getIsMemberGroupChangePendingFromUI(state: StateType): boolean { export function getLibAdminsPubkeys(state: StateType, convo?: string): Array { const members = getMembersOfGroup(state, convo); - return members.filter(m => m.promoted).map(m => m.pubkeyHex); } diff --git a/ts/webworker/workers/browser/libsession_worker_interface.ts b/ts/webworker/workers/browser/libsession_worker_interface.ts index f7c875b7e..91620a556 100644 --- a/ts/webworker/workers/browser/libsession_worker_interface.ts +++ b/ts/webworker/workers/browser/libsession_worker_interface.ts @@ -565,6 +565,10 @@ export const MetaGroupWrapperActions: MetaGroupWrapperActionsCalls = { callLibSessionWorker([`MetaGroupConfig-${groupPk}`, 'keysNeedsRekey']) as Promise< ReturnType >, + keyGetAll: async (groupPk: GroupPubkeyType) => + callLibSessionWorker([`MetaGroupConfig-${groupPk}`, 'keyGetAll']) as Promise< + ReturnType + >, currentHashes: async (groupPk: GroupPubkeyType) => callLibSessionWorker([`MetaGroupConfig-${groupPk}`, 'currentHashes']) as Promise< ReturnType