I've been trying to create a self-signed certificate, use it in a simple Node.js server, and install it into the system to the system trusted. However, something is not working, the 'SSL certificate installing' in particular, so here are my steps:

  1. Create a certificate, with:
    openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
    The certificate should be a .pem, since Node.js' https module demands one.

  2. Write the server app:

    var https = require('https');  
    var fs = require('fs');
    var options = {
      key: fs.readFileSync('key.pem'),
      cert: fs.readFileSync('cert.pem')
    https.createServer(options, function (req, res) {
      res.end("hello world\n");
  3. Install the certificate (OS X): From what I've read online, I added the cert.pem to the System certificates, right-clicked on it and opened information, and could then change it to being trusted.

What have I done wrong?

  • What does 'is not working' mean exactly? – nKn Aug 25 '15 at 21:45
  • @nKn I just tested it with Safari and curl, it seems to work fine there (without any warnings), but Chrome still says 'NET::ERR_CERT_COMMON_NAME_INVALID' – Zocker3333 Aug 25 '15 at 22:08
  • So, what's the Subject Common Name in your cert? And, does it match the hostname in the URL you're feeding into Chrome? – Spiff Aug 26 '15 at 3:40
  • Make also sure that the name is not only an unqualified name like 'hostname' but instead FQDN like 'hostname.example.com'. – Steffen Ullrich Aug 26 '15 at 4:58
  • Well I would like to use the certificate for localhost, since it works in Safari but not in Firefox and Chrome, could someone give instructions how to generate a self-signed certificate for localhost and install it in the right place so all browsers trust it? The certificate should be a .pem as mentioned above. – Zocker3333 Aug 26 '15 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.