Bug 1498223 - Always add security devices at startup if they aren't there. r=Felipe
authorMichael Kaply <mozilla@kaply.com>
Fri, 12 Oct 2018 19:25:58 +0000
changeset 489388 4e01769b6baf126a8f70713291e03592a090a379
parent 489387 1122d74466326f6389e3728d9bf883af73303770
child 489389 bbfaee2b27709a9450b7401d0312eaeb2bf0010d
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersFelipe
bugs1498223
milestone64.0a1
Bug 1498223 - Always add security devices at startup if they aren't there. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D8574
browser/components/enterprisepolicies/Policies.jsm
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -779,29 +779,36 @@ var Policies = {
         }
       });
     },
   },
 
   "SecurityDevices": {
     onProfileAfterChange(manager, param) {
       let securityDevices = param;
-      runOncePerModification("securityDevices",
-                             JSON.stringify(securityDevices),
-                             () => {
-        let pkcs11 = Cc["@mozilla.org/security/pkcs11moduledb;1"].getService(Ci.nsIPKCS11ModuleDB);
-        for (let deviceName in securityDevices) {
-          try {
-            pkcs11.addModule(deviceName, securityDevices[deviceName], 0, 0);
-          } catch (ex) {
-            log.error(`Unable to add security device ${deviceName}`);
-            log.debug(ex);
+      let pkcs11db = Cc["@mozilla.org/security/pkcs11moduledb;1"].getService(Ci.nsIPKCS11ModuleDB);
+      let moduleList = pkcs11db.listModules();
+      for (let deviceName in securityDevices) {
+        let foundModule = false;
+        for (let module of moduleList) {
+          if (module && module.libName === securityDevices[deviceName]) {
+            foundModule = true;
+            break;
           }
         }
-      });
+        if (foundModule) {
+          continue;
+        }
+        try {
+          pkcs11db.addModule(deviceName, securityDevices[deviceName], 0, 0);
+        } catch (ex) {
+          log.error(`Unable to add security device ${deviceName}`);
+          log.debug(ex);
+        }
+      }
     },
   },
 
   "WebsiteFilter": {
     onBeforeUIStartup(manager, param) {
       this.filter = new WebsiteFilter(param.Block || [], param.Exceptions || []);
     },
   },