Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
matrix-react-sdk
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Matrix.org
matrix-react-sdk
Commits
07a8835a
Commit
07a8835a
authored
1 year ago
by
Valere
Browse files
Options
Downloads
Patches
Plain Diff
sonar : reduce Cognitive Complexity
parent
84644485
Branches
valere/remove_deprecated_secret_storage_call
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/SecurityManager.ts
+56
-38
56 additions, 38 deletions
src/SecurityManager.ts
with
56 additions
and
38 deletions
src/SecurityManager.ts
+
56
−
38
View file @
07a8835a
...
...
@@ -350,31 +350,11 @@ export async function accessSecretStorage(func = async (): Promise<void> => {},
async
function
doAccessSecretStorage
(
func
:
()
=>
Promise
<
void
>
,
forceReset
:
boolean
):
Promise
<
void
>
{
try
{
const
cli
=
MatrixClientPeg
.
safeGet
();
if
(
!
(
await
cli
.
secretStorage
.
hasKey
())
||
forceReset
)
{
// This dialog calls bootstrap itself after guiding the user through
// passphrase creation.
const
{
finished
}
=
Modal
.
createDialogAsync
(
import
(
"
./async-components/views/dialogs/security/CreateSecretStorageDialog
"
)
as
unknown
as
Promise
<
typeof
CreateSecretStorageDialog
>
,
{
forceReset
,
},
undefined
,
/* priority = */
false
,
/* static = */
true
,
/* options = */
{
onBeforeClose
:
async
(
reason
):
Promise
<
boolean
>
=>
{
// If Secure Backup is required, you cannot leave the modal.
if
(
reason
===
"
backgroundClick
"
)
{
return
!
isSecureBackupRequired
(
cli
);
}
return
true
;
},
},
);
const
[
confirmed
]
=
await
finished
;
if
(
!
confirmed
)
{
const
isSecretStorageConfigured
=
await
cli
.
secretStorage
.
hasKey
();
const
shouldCreateSecretStorage
=
!
isSecretStorageConfigured
||
forceReset
;
if
(
shouldCreateSecretStorage
)
{
const
created
=
await
performSecretStorageCreationFlow
(
cli
,
forceReset
);
if
(
!
created
)
{
throw
new
Error
(
"
Secret storage creation canceled
"
);
}
}
else
{
...
...
@@ -400,6 +380,55 @@ async function doAccessSecretStorage(func: () => Promise<void>, forceReset: bool
getKeyBackupPassphrase
:
promptForBackupPassphrase
,
});
await
handleDeviceDehydration
(
cli
);
}
// `return await` needed here to ensure `finally` block runs after the
// inner operation completes.
return
await
func
();
}
catch
(
e
)
{
SecurityCustomisations
.
catchAccessSecretStorageError
?.(
e
);
logger
.
error
(
e
);
// Re-throw so that higher level logic can abort as needed
throw
e
;
}
}
/**
* Opens the CreateSecretStorageDialog and returns whether the user completed the flow.
* This will create the secret storage then bootstrap cross-signing and backup if needed.
*
* @param {MatrixClient} cli The client to use for the operation.
* @param {bool} forceReset Reset secret storage even if it's already set up
*/
async
function
performSecretStorageCreationFlow
(
cli
:
MatrixClient
,
forceReset
:
boolean
):
Promise
<
boolean
|
undefined
>
{
// This dialog calls bootstrap itself after guiding the user through
// passphrase creation.
const
{
finished
}
=
Modal
.
createDialogAsync
(
import
(
"
./async-components/views/dialogs/security/CreateSecretStorageDialog
"
)
as
unknown
as
Promise
<
typeof
CreateSecretStorageDialog
>
,
{
forceReset
,
},
undefined
,
/* priority = */
false
,
/* static = */
true
,
/* options = */
{
onBeforeClose
:
async
(
reason
):
Promise
<
boolean
>
=>
{
// If Secure Backup is required, you cannot leave the modal.
if
(
reason
===
"
backgroundClick
"
)
{
return
!
isSecureBackupRequired
(
cli
);
}
return
true
;
},
},
);
const
[
confirmed
]
=
await
finished
;
return
confirmed
;
}
async
function
handleDeviceDehydration
(
cli
:
MatrixClient
):
Promise
<
void
>
{
const
keyId
=
Object
.
keys
(
secretStorageKeys
)[
0
];
if
(
keyId
&&
SettingsStore
.
getValue
(
"
feature_dehydration
"
))
{
let
dehydrationKeyInfo
=
{};
...
...
@@ -415,17 +444,6 @@ async function doAccessSecretStorage(func: () => Promise<void>, forceReset: bool
}
}
// `return await` needed here to ensure `finally` block runs after the
// inner operation completes.
return
await
func
();
}
catch
(
e
)
{
SecurityCustomisations
.
catchAccessSecretStorageError
?.(
e
);
logger
.
error
(
e
);
// Re-throw so that higher level logic can abort as needed
throw
e
;
}
}
// FIXME: this function name is a bit of a mouthful
export
async
function
tryToUnlockSecretStorageWithDehydrationKey
(
client
:
MatrixClient
):
Promise
<
void
>
{
const
key
=
dehydrationCache
.
key
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment