Giter VIP home page Giter VIP logo

self-signed-certificate-tutorial's Introduction

Self-Signed Certificate Tutorial

This repository aims to guide creation of a Self-Signed Certificate with localhost development purpose.

Prerequisites

  • Have a Java JDK installed
  • Have OpenSSL installed

Steps

NOTE: The below steps consider the very essential content in order to get everything in place and working.

  1. Create a Private Key (domain.key) and CSR (domain.csr) file entering localhost value for Common Name and leaving all the rest with default values.
openssl req -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr
...
...
...
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:localhost <<<<<<<<-----------------
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
  1. Create a self-signed certificate (domain.crt) with existing private key and CSR files:
openssl x509 -signkey domain.key -in domain.csr -req -days 730 -out domain.crt
  1. Create self-signed certificate authority (CA) files: private key (rootCA.key) and self-signed root CA certificate (rootCA.crt). When asked enter any password (take not of it!) and localhost value for Common Name:
openssl req -newkey rsa:2048 -x509 -sha256 -days 1825 -keyout rootCA.key -out rootCA.crt
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:localhost
Email Address []:
  1. Create a configuration text-file (domain.ext) with the following content:
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
  1. Sign the previously generated CSR (domain.csr) file with the root CA certificate and its private key. When asked enter the password for root CA certificate (previous step):
openssl x509 -req -CA rootCA.crt -CAkey rootCA.key -in domain.csr -out domain.crt -days 730 -CAcreateserial -extfile domain.ext
Certificate request self-signature ok
subject=C=AU, ST=Some-State, O=Internet Widgits Pty Ltd, CN=localhost
Enter pass phrase for rootCA.key:
  1. In order to avoid PKIX path building failed error, import the root CA certificate to local cacerts keystore. When asked enter yes: PS: keystore password may be different. changeit is the default one.
sudo keytool -import -alias rootCA -keystore $JAVA_HOME/lib/security/cacerts -file rootCA.crt -storepass changeit
...
...
Trust this certificate? [no]:  yes
Certificate was added to keystore
  1. Check rootCA alias exists in cacerts list:
keytool -list -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit > list.txt
...
...
rootca, Mar 7, 2024, trustedCertEntry, 
Certificate fingerprint (SHA-256): 84:D9:1C.....
...
...
  1. If necessary, delete the entry with the below command:
keytool -delete -alias rootCA -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit
  1. Finally, for local development use the now self-signed domain.crt and domain.key files (maybe also the password set on steps above).

Sources:

self-signed-certificate-tutorial's People

Contributors

chbhernani avatar

Watchers

 avatar

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.