All Projects → julie-ng → nodejs-certificate-auth

julie-ng / nodejs-certificate-auth

Licence: MIT license
Demo for Client Certificate Authentication with Node.js Tutorial

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to nodejs-certificate-auth

SSL-TLS-ECDSA-timing-attack
Timing Attack on TLS' ECDSA signature
Stars: ✭ 41 (-51.76%)
Mutual labels:  openssl
build-scripts
Utility scripts for building of 3rd-party libraries
Stars: ✭ 33 (-61.18%)
Mutual labels:  openssl
learn-ssl
A set of example programs that demonstrate various OpenSSL functions and enable "learning by doing".
Stars: ✭ 15 (-82.35%)
Mutual labels:  openssl
jruby-openssl
JRuby's OpenSSL gem
Stars: ✭ 39 (-54.12%)
Mutual labels:  openssl
RSA-via-OpenSSL-libeay32
Реализация шифрования/дешифрование строки алгоритмом RSA через библиотеку openssl на Delphi
Stars: ✭ 29 (-65.88%)
Mutual labels:  openssl
WebCrypto.swift
A small collection of cryptographic functions based on the JavaScript WebCrypto API.
Stars: ✭ 16 (-81.18%)
Mutual labels:  openssl
pki-manager
IT Freelancers : Manage small PKI for multiple projects (or clients) with 2 bash scripts
Stars: ✭ 36 (-57.65%)
Mutual labels:  openssl
Qt-SslServer
Tcp Server class with SSL support using QTcpServer and QSslSocket. Requires Qt and -std=c++11 to compile. An OpenSSL implementation must also be available on the target machine.
Stars: ✭ 22 (-74.12%)
Mutual labels:  openssl
httpsbook
《深入浅出HTTPS:从原理到实战》代码示例、勘误、反馈、讨论
Stars: ✭ 77 (-9.41%)
Mutual labels:  openssl
PASSY
This project has moved to GitLab.com
Stars: ✭ 14 (-83.53%)
Mutual labels:  openssl
iroha-ed25519
RFC8032 compatible Ed25519 implementation with pluggable hash (sha2-512, sha3-512)
Stars: ✭ 28 (-67.06%)
Mutual labels:  openssl
openssl
A functions wrapping of OpenSSL library for symmetric and asymmetric encryption and decryption.
Stars: ✭ 199 (+134.12%)
Mutual labels:  openssl
BaaSDelphiSamples
💾 Code samples for BaaS and PaaS using Delphi
Stars: ✭ 30 (-64.71%)
Mutual labels:  openssl
sslscanner
SSL Scanner written in Crystal
Stars: ✭ 18 (-78.82%)
Mutual labels:  openssl
bproxy
high-performance minimal HTTP reverse proxy
Stars: ✭ 28 (-67.06%)
Mutual labels:  openssl
ocsinventory
📚 Curso GRÁTIS OCS Inventory NG e GLPI Help Desk REPOSITÓRIO CONGELADO - Esse repositório não irá mais receber atualizações.
Stars: ✭ 58 (-31.76%)
Mutual labels:  openssl
cryptocli
The ultimate tool for data transfer, manipulation and proxy.
Stars: ✭ 16 (-81.18%)
Mutual labels:  openssl
Simple-TLS-Client-Server-with-Node.js
Simple TLS Client/Server with Node.js
Stars: ✭ 22 (-74.12%)
Mutual labels:  openssl
lua-resty-openssl
FFI-based OpenSSL binding for OpenResty
Stars: ✭ 76 (-10.59%)
Mutual labels:  openssl
hmac-sha1
Standalone implementation of `HMAC()` + `EVP_sha1()` in `OpenSSL`
Stars: ✭ 40 (-52.94%)
Mutual labels:  openssl

Client Certificate Authentication (mTLS) with Node.js

This is demo on how to do client authentication with certificates, mTLS or mutual TLS - as opposed to username and passwords with out of the box (OOTB) Node.js.

This demo has a server with two clients:

  • "Alice" who has a server-signed trusted certificate
  • "Bob" who has an invalid self-signed certificate

Diagram

Based on the following tutorials:

Demo: How to Use

First install required dependencies with npm install. Then the demo works as follows:

Step 1 - Start Server

We start a sever that by default only accepts requests authenticated by client certificates

npm run server

You can test this is working by opening https://localhost:4433/ in your browser.

Step 2 - Test Valid Client (Alice)

Alice has a valid certificate issued by server, so she can talk to the server:

$ npm run valid-client

> node ./client/valid-app.js

Hello Alice, your certificate was issued by localhost!

Step 3 - Test Invalid Client (Bob)

Bob has a self-issued certificate, which is rejected by the server:

$ npm run invalid-client

> node ./client/invalid-app.js

Sorry Bob, certificates from Bob are not welcome here.

Reference - Introduction to Creating Certificates

Server Certificates

  • CN: localhost
  • O: Client Certificate Demo
openssl req \
	-x509 \
	-newkey rsa:4096 \
	-keyout server/server_key.pem \
	-out server/server_cert.pem \
	-nodes \
	-days 365 \
	-subj "/CN=localhost/O=Client\ Certificate\ Demo"

This command shortens following three commands:

  • openssl genrsa
  • openssl req
  • openssl x509

which generates two files:

  • server_cert.pem
  • server_key.pem

Create Client Certificates

For demo, two users are created:

  • Alice, who has a valid certificate, signed by the server
  • Bob, who creates own certificate, self-signed

Create Alice's Certificate (server-signed and valid)

We create a certificate for Alice.

  • sign alice's Certificate Signing Request (CSR)...
  • with our server key via -CA server/server_cert.pem and -CAkey server/server_key.pem flags
  • and save results as certificate
# generate server-signed (valid) certifcate
openssl req \
	-newkey rsa:4096 \
	-keyout client/alice_key.pem \
	-out client/alice_csr.pem \
	-nodes \
	-days 365 \
	-subj "/CN=Alice"

# sign with server_cert.pem
openssl x509 \
	-req \
	-in client/alice_csr.pem \
	-CA server/server_cert.pem \
	-CAkey server/server_key.pem \
	-out client/alice_cert.pem \
	-set_serial 01 \
	-days 365

Create Bob's Certificate (self-signed and invalid)

Bob creates own without our server key.

# generate self-signed (invalid) certifcate
openssl req \
	-newkey rsa:4096 \
	-keyout client/bob_key.pem \
	-out client/bob_csr.pem \
	-nodes \
	-days 365 \
	-subj "/CN=Bob"

# sign with bob_csr.pem
openssl x509 \
	-req \
	-in client/bob_csr.pem \
	-signkey client/bob_key.pem \
	-out client/bob_cert.pem \
	-days 365

Notes

  • Let's Encrypt is a "free, automated, and open" Certificate Authority
  • PEM: Privacy Enhanced Mail is a Base64 encoded DER certificate

OpenSSL commands

Command Documentation Description
genrsa Docs Generates an RSA private key
req Docs Primarily creates and processes certificate requests in PKCS#10 format. It can additionally create self signed certificates for use as root CAs for example.
x509 Docs The x509 command is a multi purpose certificate utility. It can be used to display certificate information, convert certificates to various forms, sign certificate requests like a "mini CA" or edit certificate trust settings.

View all openssl commands →

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].