home *** CD-ROM | disk | FTP | other *** search
- const DEBUG = false;
- const nsPK11TokenDB = "@mozilla.org/security/pk11tokendb;1";
- const nsIPK11TokenDB = Components.interfaces.nsIPK11TokenDB;
- const nsIPK11Token = Components.interfaces.nsIPK11Token;
- const nsPKCS11ModuleDB = "@mozilla.org/security/pkcs11moduledb;1";
- const nsIPKCS11ModuleDB = Components.interfaces.nsIPKCS11ModuleDB;
- const nsIPKCS11Slot = Components.interfaces.nsIPKCS11Slot;
-
- var gpk11dbService = null;
- var gToken = null;
-
- var gkSetMasterPasswordStr = "";
- var gkChangeMasterPasswordStr = "";
- var gbStrLoaded = false;
-
- /**
- * Startup
- **/
- function mpStartup()
- {
- SetNoLoginTimeoutMsg();
-
- // retrieve Set Master Password text
- if (!gbStrLoaded)
- {
- var bundle = document.getElementById("formfillpasscardBundle");
- if (bundle != null)
- {
- gkSetMasterPasswordStr = bundle.getString("setMasterPasswordTitle");
- gkChangeMasterPasswordStr = bundle.getString("changeMasterPasswordTitle");
- gbStrLoaded = true;
- }
- }
- //MERC - Durga: added try catch
- try
- {
- // update Change Password button on Master Password panel
- UpdateChangePasswordButtonText(GetMasterPasswordText());
- }
- catch(e)
- {
- mpDebug('Exception in mpStartup() -- masterpassword.js');
- }
- }
-
- /**
- * Modify the Set/Change Master Password button text on the Master Password
- * property page depending if the master password has already been set or not
- **/
- function UpdateChangePasswordButtonText(label)
- {
- document.getElementById("changePasswordButton").setAttribute("label", label);
- document.getElementById("changePasswordTitle").setAttribute("label", label);
- }
-
- /**
- * Set or Change the Master Password
- **/
- function OnChangePassword()
- {
- // if master password already exists, pass empty string to use default text
- var dialogTitle = GetMasterPasswordText();
-
- var obj = new Object( );
- obj.res = "";
- window.openDialog("chrome://browser/content/pref/pref-masterpass.xul",
- "_blank", "chrome,dialog,modal", dialogTitle, obj);
- // TODO JVL: alt
- // window.openDialog("chrome://pippki/content/pref-masterpass.xul",
- // "_blank", "chrome,dialog,modal", dialogTitle);
-
- if (obj.res == "ok")
- {
- if (!IsOpenInDialog())
- {
- // update Change Password button on Master Password panel
- UpdateChangePasswordButtonText(GetMasterPasswordText());
- }
-
- // update the message for the timeout button and the passcard deck
- if (!IsOpenInDialog())
- {
- SetNoLoginTimeoutMsg();
- }
- // MERC JVL : Removed (4/14/05) SetNoLoginPasscardMsg();
-
- if (!IsMasterPasswordSet())
- {
- UnprotectAllPasscards();
- }
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Reset the Master Password if user forgets
- **/
- function OnResetPassword()
- {
- var param = Components.classes["@mozilla.org/embedcomp/dialogparam;1"].getService();
- param = param.QueryInterface(Components.interfaces.nsIDialogParamBlock);
- var bundle = document.getElementById("formfillpasscardBundle");
-
- //No textbox
- param.SetInt(3,0);
- //2 buttons
- param.SetInt(2,2);
-
- //title
- param.SetString(12,bundle.getString("resetMasterPasswordTitle"));
- //info
- param.SetString(0,bundle.getString("resetWarning"));
-
- // set the icon
- param.SetString(2, "question-icon");
-
- window.openDialog("chrome://global/content/commonDialog.xul",
- "_blank", "chrome,dialog,modal",param);
-
- if(param.GetInt(0) == 0)
- {
- // Delete the Datacards and Passcards before reseting the Master
- // Password because we still need the Master Password to decoded
- // encrypted Datacards and Passcards prior to deletion
- DeleteAllDatacards(true);
- DeleteEncryptedSignons(true);
-
- try
- {
- GetMasterPasswordService().reset();
- UpdateChangePasswordButtonText(gkSetMasterPasswordStr);
- SetNoLoginTimeoutMsg()
- }
- catch (e)
- {
- mpDebug('Exception in OnResetPassword() -- masterpassword.js');
- }
- }
- }
-
- /**
- * Get the dialog title/button label text
- **/
- function GetMasterPasswordText()
- {
- return IsMasterPasswordSet() ? gkChangeMasterPasswordStr : gkSetMasterPasswordStr;
- }
-
- /**
- * Change the timeout value
- **/
- function OnChangeTimeout()
- {
- window.openDialog("chrome://mozapps/content/autofill/ChangeTimeoutDialog.xul",
- "_blank", "chrome,dialog,modal");
- }
-
- /**
- * Checks if the master password is set
- **/
- function IsMasterPasswordSet()
- {
- var bIsPasswordSet = false;
- try
- {
- // return true if the master password is set to anything but an empty string
- var secmoddb = Components.classes[nsPKCS11ModuleDB].getService(nsIPKCS11ModuleDB);
- var slot = secmoddb.findSlotByName("");
- if (slot)
- {
- mpDebug('masterpassword.js : IsMasterPasswordSet() - Before check');
- bIsPasswordSet = !(slot.status == nsIPKCS11Slot.SLOT_UNINITIALIZED ||
- slot.status == nsIPKCS11Slot.SLOT_READY);
- mpDebug('masterpassword.js : IsMasterPasswordSet() - After check');
- }
- }
- catch (ex)
- {
- /*
- if the master password is not yet set and we check
- for an empty string, it will throw an exception
- (see http://lxr.mozilla.org/aviarybranch/source/security/manager/ssl/src/nsPK11TokenDB.cpp#296)
- just default to false for now
- */
- mpDebug('Exception in IsMasterPasswordSet() -- masterpassword.js');
- bIsPasswordSet = false;
- }
- mpDebug('IsMasterPasswordSet(): ' + bIsPasswordSet);
- return bIsPasswordSet;
- }
-
- /**
- * Retrieves the master password service
- **/
- function GetMasterPasswordService()
- {
- if (gToken == null && gpk11dbService == null)
- {
- var tokenName = "";
- gpk11dbService = Components.classes[nsPK11TokenDB].getService(nsIPK11TokenDB);
- if (gpk11dbService)
- gToken = gpk11dbService.findTokenByName(tokenName);
- }
-
- return gToken;
- }
-
- /**
- * Set the no login timeout message
- **/
- function SetNoLoginTimeoutMsg()
- {
- if (IsMasterPasswordSet())
- {
- document.getElementById('noLoginTimeoutMsg').setAttribute('hidden', 'true');
- document.getElementById('timeoutPasswordButton').removeAttribute('disabled');
- }
- else
- {
- document.getElementById('noLoginTimeoutMsg').removeAttribute('hidden');
- document.getElementById('timeoutPasswordButton').setAttribute('disabled', 'true');
- }
- }
-
- function mpDebug(str)
- {
- if (DEBUG)
- dump('MASTER PASSWORD: ' + str + '\n');
- }
-