title: Where to find my FireFox profile? NSS cannot find external installed module/token in secmod.db
body: <p>NOTE: I have found the answer to this question so I would close it. It's due to that the method returning the FireFox profile folder is not working, it just locates the directory where all profiles are located, but does not enter <strong>my profile</strong> folder. And under this folder (for example, <code>/home/myUserName/.mozilla/firefox/</code>, there are also <code>key3.db</code>, <code>cert8.db</code> and <code>secmod.db</code>, but it does not contain any user-specific settings, and I guess they serve as the base for creating all profiles the moment they are created. That's why they are not containing my added modules. Under this folder, I have <code>5yasix1g.default-1475600224376</code> where my profile is located, and that's where my <code>key3.db</code>, <code>cert8.db</code> and <code>secmod.db</code> are located.</p>
  
  <p>I leave the question here and change the title to warn people who like me may have difficulties finding where their FF profiles are.</p>
  
  <hr>
  
  <p>I managed to get NSS/JSS to work in my Ubuntu 16.04, but it only finds one module, the default NSS internal one. </p>
  
  <p>I have these modules installed:</p>
  
  <p><a href="https://i.stack.imgur.com/FAtgL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FAtgL.png" alt="enter image description here"></a></p>
  
  <p>What I must load, is that one of Izenpe and DNIe. But when I debug, it only loads the first one.</p>
  
  <p>With <code>modutil</code> shipped with NSS/NSPR, I have found the same. A checking of </p>
  
  <pre><code>modutil -list -dbdir /home/myUserName/.mozilla/firefox
  </code></pre>
  
  <p>only shows one module.</p>
  
  <p>(Another thing is that <code>-dbdir</code>'s value should end with the directory where <code>secmod.db</code> is located, not the file itself, or <code>modutil</code> throws confusing error message, complaining: </p>
  
  <pre><code>modutil: function failed: SEC_ERROR_LEGACY_DATABASE: The certificate/key database is in an old, unsupported format.
  </code></pre>
  
  <p>)</p>
  
  <p>I know I can add them and I am doing it, but it's weird that it's listed in FireFox but not in <code>secmod.db</code>. Isn't this file the database for all the installed modules that FF uses?</p>
  
  <p>Also, after adding it, I cannot get access to external module. <code>modutil -dbdir "/some/dir/properly/quoted" -list</code> shows me this:</p>
  
  <pre><code>easternfox@easternfox-Ubuntu:~$ modutil -dbdir /home/easternfox/.mozilla/firefox -list
  Listing of PKCS #11 Modules
  -----------------------------------------------------------
    1. NSS Internal PKCS #11 Module
       slots: 2 slots attached
      status: loaded
  
       slot: NSS Internal Cryptographic Services
      token: NSS Generic Crypto Services
  
       slot: NSS User Private Key and Certificate Services
      token: NSS Certificate DB
  
    2. Izenpe PKCS#11
      library name: /usr/lib/libbit4ipki.so
       slots: 1 slot attached
      status: loaded
  
       slot: Cherry GmbH SmartBoard XX44 [Smart Card Reader USB] 00 00
      token: Izenpe 0
  </code></pre>
  
  <p>I use this code to load the PKCS#11 Provider:</p>
  
  <pre><code>if (OSUtil.isLinux()) {
      String config = "library=/usr/lib/i386-linux-gnu/nss/libsoftokn3.so\n"
      + "name=NSSCrypto-Firma\n"
      + "attributes=compatibility\n"
      + "slot=2\n"
      + "showInfo=true\n"
      + "allowSingleThreadedModules=true\n"
      + "nssArgs=\"configdir='" + NSS_JSS_Utils.getFireFoxProfilePath() + "' certPrefix='' keyPrefix='' secmod='secmod.db' + flags='readOnly'\" ";
  
      Provider provider = new SunPKCS11(new ByteArrayInputStream(config.getBytes()));
      Security.removeProvider("IAIK");
      //Security.addProvider(provider);
      Security.insertProviderAt(provider, 1);
      KeyStore.Builder builder = null;
      prevTryFailes = true;
      try {
          if (tries &lt; 3 &amp;&amp; prevTryFailes) {
              keystore = KeyStore.getInstance("PKCS11", provider);
              builder = KeyStore.Builder.newInstance("PKCS11", provider, new KeyStore.CallbackHandlerProtection(new UtilTarjetas(). new callback()));
              keystore = builder.getKeyStore();
              prevTryFailes = false;
          } 
  
          if (tries &gt;= 3) {
              throw new KeyStoreException("Have entered 3 times password and not correct. ");
          }
  
      } catch (Exception e) {
          Traza.error(e);
          tries ++;
      }
  }
  </code></pre>
  
  <p>Assuming from an exception thrown when specifying more then once the <code>name</code> property in the <code>config</code>, I suppose that I can load only one module in the Provider. </p>
  
  <p>And, with these code I initialize the <code>CryptoManager</code>:</p>
  
  <pre><code>try {
      InitializationValues iv = new InitializationValues(NSS_JSS_Utils.getFireFoxProfilePath());
      iv.installJSSProvider = false;
      CryptoManager.initialize(iv);
      cm = CryptoManager.getInstance();
  } catch (KeyDatabaseException | CertDatabaseException | GeneralSecurityException | NotInitializedException e) {
      e.printStackTrace();
  } catch (AlreadyInitializedException e) {
      cm = CryptoManager.getInstance();
  }
  CustomPasswordCallback pcb = new CustomPasswordCallback();
  cm.setPasswordCallback(pcb);
  
  Enumeration&lt; ? &gt; emModules = cm.getModules();
  </code></pre>
  
  <p>When it reaches the final line, it only loads the internal module, not mine external ones.</p>
  
  <p>Any help is appreciated. Thanks!</p>