Commit 5b87ec5f authored by François Degros's avatar François Degros Committed by Commit Bot

[Files App] Ask for password again when opening archive

When opening an encrypted archive and the provided password was wrong,
ask for the password again.

BUG=chromium:912236

Cq-Depend: chromium:2327352
Change-Id: I06af54ab0abe6960ffc266c622bd95d985d41e2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354372
Commit-Queue: François Degros <fdegros@chromium.org>
Reviewed-by: default avatarJeremie Boulic <jboulic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800394}
parent 9efa7907
......@@ -134,19 +134,24 @@ class FilesPasswordDialog extends HTMLElement {
/**
* Asks the user for a password to open the given file.
* @param {string} filename name of the file to mount.
* @return {!Promise<!string>} a password string if the user provides a
* password. The returned promise is rejected with
* FilesPasswordDialog.USER_CANCELLED if the user presses Cancel.
* @public
* @param {string} filename Name of the file to open.
* @param {?string} password Previously entered password. If not null, it
* indicates that an invalid password was previously tried.
* @return {!Promise<!string>} Password provided by the user. The returned
* promise is rejected with FilesPasswordDialog.USER_CANCELLED if the user
* presses Cancel.
*/
async askForPassword(filename) {
async askForPassword(filename, password = null) {
const mutexUnlock = await this.mutex.lock();
try {
return await new Promise((resolve, reject) => {
this.success_ = false;
this.resolve_ = resolve;
this.reject_ = reject;
if (password != null) {
this.input_.value = password;
// TODO(jboulic) Set visual clue that invalid password was entered.
}
this.showModal_(filename);
this.input_.focus();
});
......
......@@ -443,6 +443,7 @@ js_library("file_tasks") {
":task_history",
"metadata:metadata_model",
"ui:file_manager_ui",
"//ui/file_manager/file_manager/common/js:async_util",
]
externs_list = [
"//ui/file_manager/externs/background/crostini.js",
......
......@@ -64,6 +64,12 @@ class FileTasks {
/** @private @const {!ProgressCenter} */
this.progressCenter_ = progressCenter;
/**
* Mutex used to serialize password dialogs.
* @private @const {!AsyncUtil.Queue}
*/
this.mutex_ = new AsyncUtil.Queue();
}
/**
......@@ -874,20 +880,39 @@ class FileTasks {
*/
async mountArchive_(url) {
// First time, try without providing a password.
let password = undefined;
const filename = util.extractFilePath(url).split('/').pop();
while (true) {
try {
return await this.volumeManager_.mountArchive(url, password);
} catch (error) {
// If error is not about needing a password, propagate it.
if (error !== VolumeManagerCommon.VolumeError.NEED_PASSWORD) {
throw error;
}
try {
return await this.volumeManager_.mountArchive(url);
} catch (error) {
// If error is not about needing a password, propagate it.
if (error !== VolumeManagerCommon.VolumeError.NEED_PASSWORD) {
throw error;
}
}
// Prompt password.
password = await this.ui_.passwordDialog.askForPassword(filename);
// We need a password.
const unlock = await this.mutex_.lock();
try {
/** @type {?string} */ let password = null;
const filename = util.extractFilePath(url).split('/').pop();
while (true) {
// Ask for password.
do {
password =
await this.ui_.passwordDialog.askForPassword(filename, password);
} while (!password);
// Mount archive with password.
try {
return await this.volumeManager_.mountArchive(url, password);
} catch (error) {
// If error is not about needing a password, propagate it.
if (error !== VolumeManagerCommon.VolumeError.NEED_PASSWORD) {
throw error;
}
}
}
} finally {
unlock();
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment