title: How to use NSS with Jetty?
body: <p>I am trying to setup Jetty to use NSS as its cryptographic engine. I have gotten it to the point where the server starts BUT any client that tries to connect seems to hang in the browser.</p>
  
  <p>The setup process / code I am following is as follows (32-bit Windows 1.6 JVM).</p>
  
  <h2>NSS Database Creation</h2>
  
  <pre><code>modutil.exe -create -dbdir C:\nssdb
  modutil.exe -create -fips true -dbdir C:\nssdb
  modutil.exe -create -changepw "NSS FIPS 140-2 Certificate DB" -dbdir C:\nssdb
  </code></pre>
  
  <h2>Load NSS into Java</h2>
  
  <pre class="lang-java prettyprint-override"><code>String config = "name = NSS\n";
  config += "nssLibraryDirectory = C:\\nss\\lib\n";
  config += "nssSecmodDirectory = C:\\nssdb\n";
  config += "nssDbMode = readWrite\n";
  config += "nssModule = fips";
  
  InputStream stream = new ByteArrayInputStream(config.getBytes("UTF-8"));
  
  Provider nss = new sun.security.pkcs11.SunPKCS11(stream);
  Security.addProvider(nss);
  
  int sunJssePosition = -1;
  int currentIndex = 0;
  for (Provider provider : Security.getProviders()) {
      if ("SunJSSE".equals(provider.getName())) {
          sunJssePosition = currentIndex + 1;
          break;
      }
  
      currentIndex++;
  }
  
  Security.removeProvider("SunJSSE");
  
  Provider sunJsse = new com.sun.net.ssl.internal.ssl.Provider(nss);
  if (sunJssePosition == -1) {
      Security.addProvider(sunJsse);
  } else {
      Security.insertProviderAt(sunJsse, sunJssePosition);
  }
  </code></pre>
  
  <h2>NSS Self Sign Certificate Generation</h2>
  
  <pre><code>C:\nss\bin\certutil.exe -S -n 127.0.0.1 -x -t "u,u,u" -s "CN=127.0.0.1, OU=Foo, O=Bar, L=City, ST=NY, C=US" -m 25001 -d C:\nssdb
  </code></pre>
  
  <h2>Jetty Startup</h2>
  
  <pre class="lang-java prettyprint-override"><code>    KeyStore ks = KeyStore.getInstance("PKCS11");
      ks.load(null, "SuperSecret");
  
      //Start setting up Jetty
      Server server = new Server();
  
      SslContextFactory sslContextFactory = new SslContextFactory();
      //sslContextFactory.setKeyStoreProvider("SunPKCS11-NSS");
      sslContextFactory.setKeyStore(ks);
      //sslContextFactory.setKeyStorePassword(new String("SuperSecret"));
  
      SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(sslContextFactory);
      sslConnector.setPort(443);
      server.addConnector(sslConnector);
  
      WebAppContext context = new WebAppContext();
  
      //Blah Blah Blah, setup Jetty
  
      server.setHandler(context);
  
      server.start();
      server.join();
  </code></pre>
  
  <p>Any ideas?</p>
  
  <hr>
  
  <p>Edit: This seems extremely odd but I can access the server using Internet Explorer just fine. Firefox seems to be the one having an issue.</p>