Skip to content

Instantly share code, notes, and snippets.

@fobbyal
Forked from mtigas/gist:952344
Created December 5, 2018 00:44
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 fobbyal/21ce4d3be57321cf4ee5151c6c3998b7 to your computer and use it in GitHub Desktop.
Save fobbyal/21ce4d3be57321cf4ee5151c6c3998b7 to your computer and use it in GitHub Desktop.
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt

Create the Client Key and CSR

Organization & Common Name = Person name

openssl genrsa -des3 -out client.key 4096
openssl req -new -key client.key -out client.csr
# self-signed
openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt

Convert Client Key to PKCS

So that it may be installed in most browsers.

openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12

Convert Client Key to (combined) PEM

Combines client.crt and client.key into a single PEM file for programs using openssl.

openssl pkcs12 -in client.p12 -out client.pem -clcerts

Install Client Key on client device (OS or browser)

Use client.p12. Actual instructions vary.

Install CA cert on nginx

So that the Web server knows to ask for (and validate) a user's Client Key against the internal CA certificate.

ssl_client_certificate /path/to/ca.crt;
ssl_verify_client optional; # or `on` if you require client key

Configure nginx to pass the authentication data to the backend application:

Using CACert Keys

@fobbyal
Copy link
Author

fobbyal commented Dec 5, 2018

keytool -importkeystore -srckeystore client.p12 \
        -srcstoretype PKCS12 \
        -destkeystore client.jks \
        -deststoretype JKS

@fobbyal
Copy link
Author

fobbyal commented Dec 5, 2018

openssl verify -CAfile ca.crt client.crt

@fobbyal
Copy link
Author

fobbyal commented Nov 16, 2019

curl -v -k --cacert ca.crt --key client.key --cert ./client.pem:integ123 https://cps-ma-sb.integportal.com/api/alive/db

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