Skip to content

Instantly share code, notes, and snippets.

@thu-san
Last active July 5, 2018 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thu-san/7220edfc83ea1485bee0aafcf0aa188a to your computer and use it in GitHub Desktop.
Save thu-san/7220edfc83ea1485bee0aafcf0aa188a to your computer and use it in GitHub Desktop.
Make valid ssl certificate in localhost with xampp or node.js

1. Create rootCA.key

  • Create rootCA.key file by following command.
  • You need to specify the password. (Record it somewhere, you'll need it later)
openssl genrsa -des3 -out rootCA.key 2048

2. Create rootCA.pem

  • You'll need to enter the password specified for rootCA.key.
  • In Distinguished fields, set the Organization Name to identify the certificate later. (We'll set it XYZ now)
  • You can also skip the fields.
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem

3. Trust the root SSL certificate

Windows

Chrome
  • Go to Settings -> Advanced -> Manage certificates -> [信頼されたルート証明機関] -> Import -> Select the rootCA.pem and complete the wizard
  • Screenshot
  • You'll find the XYZ after imported.
  • Screenshot

4. Create Domain SSL certificate

  • Run command below to create server.csr and server.key files.
  • In Distinguished fields, set the Organization Name to identify the certificate later. (We'll set it ABC now)
  • Note that, you can also skip the fields.
  • You can also left out the challenge password
openssl req -new -sha256 -nodes -out server.csr -newkey rsa:2048 -keyout server.key

5. Create server.crt

  • Create v3.ext file and add below content
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
  • And run the following command to create server.crt file.
  • You'll need to enter the password specified for rootCA.key.
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile v3.ext

6. Using Domain SSL certificate

Windows

Xampp

Go to xampp\apache\conf and replace the

  • ssl.crt/server.crt
  • ssl.csr/server.csr
  • ssl.key/server.key

files with the one we have just created.

Restart the apache server in xampp.

After that go to https://localhost and you'll see your localhost SSL certificate is valid now.

Note it takes some time. I find it working after reloading the page, restarting the chrome or sometimes restarting PC Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment