Code Monkey home page Code Monkey logo

local-cert-generator's Introduction

HTTPS for localhost

A set of scripts to quickly generate a HTTPS certificate for your local development environment.

How-to

  1. Clone this repository and cd into it:
git clone https://github.com/dakshshah96/local-cert-generator.git
cd local-cert-generator
  1. Run the script to create a root certificate:
sh createRootCA.sh
  1. Add the root certificate we just generated to your list of trusted certificates. This step depends on the operating system you're running:

    • macOS: Open Keychain Access and import the root certificate to your System keychain. Then mark the certificate as trusted.

    Trust root certificate

    • Linux: Depending on your Linux distribution, you can use trust, update-ca-certificates or another command to mark the generated root certificate as trusted.

Note: You may need to restart your browser to load the newly trusted root certificate correctly.

  1. Run the script to create a domain certificate for localhost:
sh createSelfSigned.sh
  1. Move server.key and server.crt to an accessible location on your server and include them when starting it. In an Express app running on Node.js, you'd do something like this:
var path = require('path')
var fs = require('fs')
var express = require('express')
var https = require('https')

var certOptions = {
  key: fs.readFileSync(path.resolve('build/cert/server.key')),
  cert: fs.readFileSync(path.resolve('build/cert/server.crt'))
}

var app = express()

var server = https.createServer(certOptions, app).listen(443)

local-cert-generator's People

Contributors

adoussot avatar dakshshah96 avatar marcgraham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

local-cert-generator's Issues

Error when running createSelfSigned.sh

Thanks for the guide and repo!

When running sh createSelfSigned.sh, I get the following error:

createSelfSigned.sh: 2: createSelfSigned.sh: Syntax error: "(" unexpected

After tweaking the script to remove the parens and redirect, it works, and looks like this:

#!/usr/bin/env bash
openssl req -new -sha256 -nodes -out server.csr -newkey rsa:2048 -keyout server.key -config server.csr.cnf
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile v3.ext

My openssl version is 1.0.2g, running on Ubuntu Linux 17.10.

Add Windows compatibility

README.md steps 1-2 works fine on Windows (will create rootCA.key and rootCA.pem).
Step 3 is related only for OS X.

  1. Trust this certificate after importing it to your System keychain

Windows doesn't have System keychain.
And step 4 fails:

> sh createSelfSigned.sh
createSelfSigned.sh: cannot make pipe for process substitution: Function not implemented
req: Option -config needs a value
req: Use -help for summary.
x509: Cannot open input file server.csr, No such file or directory
x509: Use -help for summary.

net::ERR_CERT_COMMON_NAME_INVALID with IP Address

Hi Daksh,

Thanks for sharing this resource!

How can I make this work with my local IP address, 192.168.0.5 instead of localhost?

I updated server.csr.cnf to

[req]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn

[dn]
C=US
ST=RandomState
L=RandomCity
O=RandomOrganization
OU=RandomOrganizationUnit
[email protected]
CN = 192.168.0.5

and v3.ext to

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = 192.168.0.5

but Chrome throws GET https://192.168.0.5:5000/socket.io/?EIO=3&transport=polling&t=NDh899k net::ERR_CERT_COMMON_NAME_INVALID

Any help on what I'm missing here :)

Need more details for Linux

Thanks for creating this, I am trying to get this to work on my Linux Ubuntu machine and this step just doesn't have quite enough details that I need:

Linux: Depending on your Linux distribution, you can use trust, update-ca-certificates or another command to mark the generated root certificate as trusted.

I would type trust.... what?
trust Local Certificate and trust rootCA.pem do not work.

or update-ca-certificates... what? just update-ca-certificates doesn't seem to solve it either.

Any help appreciated!

Add a License File

It appears that this repository does not have a license, which may disallow anyone to use its content (read about this here). Thus, would you mind adding a 'LICENSE' file to your repository?

By the way: To choose a license, choosealicense.com and the opensource guide are great places to start looking.
Adding the license to the repo can then easily be done using one of githubs template, as shown here.

Thanks in advance!

Issue created using the licenseplate browser extension, which relies on the GitHub API to identify licenses. This is not legal advice.

[Question] Getting to work without node app? Running on https://192.168.1.11:5000 ?

Hi there I just came from reading:
https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/

And I could follow through, but I have a much simpler setup and I don't want to run a node app. I simply have an html file and I run https://www.npmjs.com/package/serve

to serve it.
Is there a way to include an ssl certificate with such a simple setup?

Also - the reason why I am doing this, is because I want to access a mobile devices deviceorientation. Unfortunately you have to run on https to get some values...
In my case I call my localhost server via the IP in the network, like:
http://192.168.1.11:5000

Of course this should be https.
Even if I got to run your way of having a valid certificate for localhost, would that also be valid for http://192.168.1.11:5000?

Thanks for some clarification. Sorry, I am really not at home with the whole certificate stuff, I just want to run a simple server to execute the most simple javascript... Hach, how darn complicated has the web world become ๐Ÿ˜…....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.