All Projects → kaysond → spki

kaysond / spki

Licence: GPL-3.0 license
A bash script wrapper for OpenSSL that generates and manages a simple PKI suitable for small deployments

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to spki

Wossl
OpenSSL对称算法、哈希校验、非对称算法、证书管理、SSL安全
Stars: ✭ 144 (+269.23%)
Mutual labels:  openssl
Openssl For Iphone
A script for compiling OpenSSL for iOS Devices (iPhone, iPad, iPod Touch, AppleTV, MacCatalyst)
Stars: ✭ 2,190 (+5515.38%)
Mutual labels:  openssl
Snuffy
Snuffy is a simple command line tool to inspect SSL/TLS data.
Stars: ✭ 236 (+505.13%)
Mutual labels:  openssl
Search Guard Ssl
Elasticsearch SSL for free. Supports native Open SSL.
Stars: ✭ 159 (+307.69%)
Mutual labels:  openssl
Lhttps
Create https for local development environment or localhost.
Stars: ✭ 172 (+341.03%)
Mutual labels:  openssl
Self Signed Ssl
Generate self-signed TLS certificate using OpenSSL
Stars: ✭ 188 (+382.05%)
Mutual labels:  openssl
Underlock
Underlock makes it dead simple to encrypt and decrypt your data and files. It comes with little to no dependencies and has a very small API surface.
Stars: ✭ 128 (+228.21%)
Mutual labels:  openssl
Check ssl cert
check_ssl_cert is a shell script (that can be used as a Nagios plugin) to check the CA and validity of an X.509 certificate
Stars: ✭ 248 (+535.9%)
Mutual labels:  openssl
Bluecryptor
Swift cross-platform crypto library using CommonCrypto/libcrypto
Stars: ✭ 171 (+338.46%)
Mutual labels:  openssl
Build Openssl Curl
Scripts to build OpenSSL, HTTP/2 (nghttp2) and cURL (libcurl) for MacOS, iOS and tvOS devices (x86_64, armv7, armv7s, arm64, arm64e). Now Supporting Apple Silicon, OpenSSL 1.1.1 with TLS 1.3 and Mac Catalyst builds.
Stars: ✭ 230 (+489.74%)
Mutual labels:  openssl
Openssl
Provides SSL, TLS and general purpose cryptography.
Stars: ✭ 166 (+325.64%)
Mutual labels:  openssl
Azure Http Proxy
A fast, secure, lightweight and cross-platform HTTP proxy written in C++.
Stars: ✭ 170 (+335.9%)
Mutual labels:  openssl
Lua Openssl
Openssl binding for Lua
Stars: ✭ 206 (+428.21%)
Mutual labels:  openssl
Cryptcheck
Verify some SSL/TLS website or XMPP implementation
Stars: ✭ 158 (+305.13%)
Mutual labels:  openssl
Libuwsc
A Lightweight and fully asynchronous WebSocket client library based on libev
Stars: ✭ 237 (+507.69%)
Mutual labels:  openssl
Nginx Ee
Automated Nginx compilation from sources with additional modules support. Compatible with WordOps, EasyEngine & Plesk
Stars: ✭ 132 (+238.46%)
Mutual labels:  openssl
Openssl Osx Ca
Simple periodic task to sync OSX Keychain certs to Homebrew installed OpenSSL & LibreSSL
Stars: ✭ 185 (+374.36%)
Mutual labels:  openssl
Openssl
TLS/SSL and crypto library
Stars: ✭ 17,157 (+43892.31%)
Mutual labels:  openssl
Lagrange
A Beautiful Gemini Client
Stars: ✭ 238 (+510.26%)
Mutual labels:  openssl
Armor
Armor is a simple Bash script designed to create encrypted macOS payloads capable of evading antivirus scanners.
Stars: ✭ 228 (+484.62%)
Mutual labels:  openssl

Build Status

Simple PKI

spki is a bash script wrapper for OpenSSL that generates and manages a simple PKI suitable for small deployments. It supports both CRL's and OCSP.

The wrapper is based on Jamie Nguyen's guide: OpenSSL Certificate Authority

Installation

Copy the latest release of spki to a location in your path. Releases use semantic versioning to identify backwards-incompatible changes.

Configuration

The top of the script contains several configuration variables; the defaults correspond to the guide. External configuration methods that do not require script modification are also supported (see below).

ROOT_DIR - The base directory where all PKI files are stored

ROOT_PREFIX - Prefix for all Root CA files

INTRMDT_PREFIX - Prefix for all Intermediate CA files

Certificate Revocation List (CRL)

CRL's are automatically generated during initialization if either or both of the DP variables are set. The Intermedate CA Certificate will use the Root CRL DP; all other generated certificates use the Intermediate CRL DP. CRL's are automatically updated on revocation. CRL's served over http should not use https. Since the CRL files are frequently regenerated, it is recommended to serve the file directly from the spki root folder, for example by using a soft link. Furthermore, the CRL's are checked during initialization and certificate creation, so it is recommended to prepare the server in advance.

ROOT_CRL_DP - CRL Distribution Point for the Root CA (e.g. 'URI:http://domain.com/my.crl,URI:http://backup.domain.com/my.crl')

INTRMDT_CRL_DP - CRL Distribution Point for the Intermediate CA (e.g. 'URI:http://domain.com/my.crl,URI:http://backup.domain.com/my.crl')

Online Certificate Status Protocol (OCSP)

OCSP signing keys are automatically generated during initialization if either or both of the OCSP variables are set.

ROOT_OCSP - Root CA OCSP Server (e.g. 'URI:http://ocsp.domain.com')

INTRMDT_OCSP- Intermediate CA OCSP (e.g. 'URI:http://ocsp.domain.com')

OpenSSL DN Defaults

spki init prompts for the default values for certificate Distinguished Name parts and stores them in the OpenSSL configuration file. These can also be specified programmatically by using the following variables:

  • countryName
  • stateOrProvinceName
  • localityName
  • organizationalUnitName
  • organizationName
  • emailAddress

(or set them to '.' to prevent prompting that field)

External Configuration

Configuration can be specified externally, without modifying the script, via environment variables. The precedence order of the configuration methods is:

  1. Configuration File
  2. Environment Variables
  3. In-script Variables

Configuration File

The configuration file can be specified in the environment variable SPKI_CONFIG_FILE. This file is loaded directly by bash and should contain a list of local variable definitions such as

ROOT_DIR=/root/ca
ROOT_PREFIX=root
countryName=US

Note: If this file is loaded, all other environment variables are ignored.

Environment Variables

Variables defined in the script itself can be overriden by environment variables. The environment variable name should be those in the script but prefixed with SPKI_ (e.g. SPKI_ROOT_DIR and SPKI_ROOT_CRL_DP).

Usage

  • spki init - Initialize the PKI. This process first sets up the default Subject fields in the OpenSSL configuration files, then generates the Root CA, Intermediate CA, and a combined CA chain file. CRL's and OCSP certificates are also generated

  • spki create (server | user | client_server) <file-prefix> - Create and sign a key pair with the Intermediate CA. server, user or client_server specifies particular extensions to use. These can be modified by changing the configuration files after initialization. The file-prefix is prepended to various file extensions (.key.pem, .cert.pem, .csr.pem)

    • server

      • nsCertType = server
      • authorityKeyIdentifier = keyid,issuer:always
      • keyUsage = critical, digitalSignature, keyEncipherment
      • extendedKeyUsage = serverAuth
    • user

      • nsCertType = client, email
      • authorityKeyIdentifier = keyid,issuer
      • keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
      • extendedKeyUsage = clientAuth, emailProtection
    • client_server

      • nsCertType = client, server
      • authorityKeyIdentifier = keyid,issuer
      • keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
      • extendedKeyUsage = clientAuth, serverAuth
  • spki create-intermediate - Recreate the Intermediate CA key and certificate. This command also regenerates the Intermediate CRL if necessary

  • spki sign (server | user | client_server) <CSR> <certificate> - Sign a specified CSR file with the server, user or client_server extensions (see above). certificate specifies the output file

  • spki list - List all of the certificates signed by the Intermediate CA, including expiration times and revocation times

  • spki verify-intermediate - Dump the intermediate CA certificate information and verify the chain of trust using the Root CA certificate

  • spki verify (certificate | file-prefix) - Dump the certificate information and verify the chain of trust using the Root CA->Intermediate CA chain. Can be specified as a file or as the prefix used in spki create

  • spki export-pkcs12 <file-prefix> - Export the key, certificate, and CA chain file to pkcs12 format

  • spki export-truststore <file-prefix> - Export CA chain file to pkcs12 format compatible with java expectations. Requires keytool (bundled with java)

  • spki revoke (certificate | file-prefix) [reason] - Revoke the specified certificate. reason can be one of: unspecified, keyCompromise, CACompromise, affiliationChanged, superseded, cessationOfOperation, certificateHold. This command automatically regenerates the Intermediate CRL

  • spki revoke-intermediate [reason] - Revoke the Intermediate CA certificate. reason can be one of the options above. This command automatically regenerates the Root CRL

  • spki list-crl - Dump information about the CRL's and the revoked certificates

  • spki generate-crl [-rootca] - Generate the Intermediate CRL file. This should be run regularly. Pass -rootca to generate the Root CRL file

  • spki generate-ocsp [-rootca] - Generate the Intermediate OCSP signing pair. Pass -rootca to generate the Root OCSP signing pair

  • spki ocsp-responder <port> [-rootca] - Start an OCSP responder on the specified port using openssl ocsp. The command by default uses the Intermediate CA database, but can be changed to the Root CA database by passing -rootca. This can be turned into a service by using systemd, for example, but the OpenSSL OCSP responder may not be suitable for high traffic.

  • spki ocsp-query <url> (certificate | file-prefix) [-rootca] - Send an OCSP query for the specified certificate to the specified url (e.g. http://127.0.0.1:12345). The command uses the full chain file by default, suitable for verifying certificates signed by the Intermediate CA. Specify -rootca to use just the Root CA, suitable for verifying the Intermediate CA certificate.

  • spki update-config - Regenerate the openssl configuration files. This allows the configuration variables, such as CRL or OCSP to be updated. It re-prompts for the certificate defaults.

Automating spki init

You can automate the PKI initialization by doing the following.

Prepare a configuration file named config, making sure to specify default DN parts (countryName, stateOrProvinceName, localityName, etc.) i.e.:

ROOT_DIR=/tmp/spki/
countryName=PL
stateOrProvinceName=Warsaw
localityName=Warsaw
organizationalUnitName=Developers
organizationName=Company Ltd
[email protected]

Then use following script to create the PKI and a certificate in one go:

SPKI_CONFIG_FILE=$(pwd)/config
export SPKI_CONFIG_FILE

source $SPKI_CONFIG_FILE

ROOT_PRIVATE_KEY_PASSWORD="<INSERT PASSWORD HERE>"
ROOT_COMMON_NAME="Root CA"
ROOT_COUNTRY_NAME="$countryName"
ROOT_PROVINCE_NAME="$stateOrProvinceName"
ROOT_LOCALITY_NAME="$localityName"
ROOT_ORGANIZATION_NAME="$organizationName"
ROOT_ORGANIZATIONAL_UNIT_NAME="$organizationalUnitName"
ROOT_MAIL="$emailAddress"

INTERMEDIATE_COMMON_NAME="Intermediate CA"
INTERMEDIATE_COUNTRY_NAME="$countryName"
INTERMEDIATE_PROVINCE_NAME="$stateOrProvinceName"
INTERMEDIATE_LOCALITY_NAME="$localityName"
INTERMEDIATE_ORGANIZATION_NAME="$organizationName"
INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME="$organizationalUnitName"
INTERMEDIATE_MAIL="$emailAddress"

INTERMEDIATE_PRIVATE_KEY_PASSWORD="<INSERT PASSWORD HERE>"

ANYKEY="k"
YES="y"

./spki init <<EOF
$ROOT_PRIVATE_KEY_PASSWORD
$ROOT_PRIVATE_KEY_PASSWORD
$ROOT_COMMON_NAME
$ROOT_COUNTRY_NAME
$ROOT_PROVINCE_NAME
$ROOT_LOCALITY_NAME
$ROOT_ORGANIZATION_NAME
$ROOT_ORGANIZATIONAL_UNIT_NAME
$ROOT_MAIL
$ANYKEY$INTERMEDIATE_PRIVATE_KEY_PASSWORD
$INTERMEDIATE_PRIVATE_KEY_PASSWORD
$INTERMEDIATE_COMMON_NAME
$INTERMEDIATE_COUNTRY_NAME
$INTERMEDIATE_PROVINCE_NAME
$INTERMEDIATE_LOCALITY_NAME
$INTERMEDIATE_ORGANIZATION_NAME
$INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME
$INTERMEDIATE_MAIL
$YES
$YES
$ANYKEY
EOF

CERT_PRIVATE_KEY_PASSWORD="<INSERT PASSWORD HERE>"
CERT_COMMON_NAME="Test client_server"
./spki create client_server test <<EOF
$CERT_PRIVATE_KEY_PASSWORD
$CERT_PRIVATE_KEY_PASSWORD
$CERT_COMMON_NAME
$ROOT_COUNTRY_NAME
$ROOT_PROVINCE_NAME
$ROOT_LOCALITY_NAME
$ROOT_ORGANIZATION_NAME
$ROOT_ORGANIZATIONAL_UNIT_NAME
$ROOT_MAIL
$INTERMEDIATE_PRIVATE_KEY_PASSWORD
$YES
$YES
$ANYKEY
EOF

Examples

Contributing

See CONTRIBUTING.md

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].