Bug 667327 - Require Master Password before allowing password to be copied. r+a=KaiRo sr=Neil
authorEdmund Wong <ewong@pw-wspx.org>
Sat, 28 Apr 2012 10:44:01 -0400
changeset 11290 950c8af114316eea43856db884f4b14dd11aa8bf
parent 11289 6c022d9e7c653ae9799bf293250f07f07fcf0101
child 11291 5a01c9c5e6099c0b43eb30bb2e97008c0f3d8c68
push id477
push userjh@junetz.de
push dateWed, 02 May 2012 21:37:22 +0000
treeherdercomm-beta@950c8af11431 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs667327
Bug 667327 - Require Master Password before allowing password to be copied. r+a=KaiRo sr=Neil
suite/common/dataman/dataman.js
--- a/suite/common/dataman/dataman.js
+++ b/suite/common/dataman/dataman.js
@@ -2012,23 +2012,41 @@ var gPasswords = {
     document.getElementById("pwd-context-remove").disabled =
       this.removeButton.disabled;
     document.getElementById("pwd-context-copypassword").disabled =
       this.tree.view.selection.count != 1;
     document.getElementById("pwd-context-selectall").disabled =
       this.tree.view.selection.count >= this.tree.view.rowCount;
   },
 
-  copyPassword: function passwords_copyPassword() {
+  copySelPassword: function passwords_copySelPassword() {
     // Copy selected signon's password to clipboard.
     let row = this.tree.currentIndex;
     let password = gPasswords.displayedSignons[row].password;
     gLocSvc.clipboard.copyString(password);
   },
 
+  copyPassword: function passwords_copyPassword() {
+    // Prompt for the master password upfront.
+    let token = Components.classes["@mozilla.org/security/pk11tokendb;1"]
+                          .getService(Components.interfaces.nsIPK11TokenDB)
+                          .getInternalKeyToken();
+
+    if (this.showPasswords || token.checkPassword(""))
+      this.copySelPassword();
+    else {
+      try {
+        token.login(true);
+        this.copySelPassword();
+      } catch (ex) {
+      // If user cancels an exception is expected.
+      }
+    }
+  },
+
   reactToChange: function passwords_reactToChange(aSubject, aData) {
     // aData: addLogin, modifyLogin, removeLogin, removeAllLogins
     if (aData == "removeAllLogins") {
       // Go for re-parsing the whole thing.
       if (this.displayedSignons.length) {
         this.tree.treeBoxObject.beginUpdateBatch();
         this.tree.view.selection.clearSelection();
         this.displayedSignons = [];