#! /bin/bash # # Copyright (c) 2016 Viktor Dukhovni <openssl-users@dukhovni.org>. # All rights reserved. # # Licensed under the terms of the Postfix SECURE MAILER license # included with the Postfix source code. # # This file is dual-licensed and is also available under other terms. # Please contact the author.
# 100 years should be enough for now if [ -z "$DAYS" ]; then
DAYS=36525 fi
if [ -z "$OPENSSL_SIGALG" ]; then
OPENSSL_SIGALG=sha256 fi
case ${OPENSSL_SIGALG} in
null) dopts=();;
*) dopts=(-"${OPENSSL_SIGALG}");;
esac
genroot() {
local cn=$1; shift
local key=$1; shift
local cert=$1; shift
local skid="subjectKeyIdentifier = hash"
local akid="authorityKeyIdentifier = keyid"
genca() {
local cn=$1; shift
local key=$1; shift
local cert=$1; shift
local cakey=$1; shift
local cacert=$1; shift
local skid="subjectKeyIdentifier = hash"
local akid="authorityKeyIdentifier = keyid"
exts=$(printf "%s\n%s\n%s\n""$skid""$akid""basicConstraints = critical,CA:true") for eku in "$@" do
exts=$(printf "%s\nextendedKeyUsage = %s\n""$exts""$eku") done if [ -n "$NC" ]; then
exts=$(printf "%s\nnameConstraints = %s\n""$exts""$NC") fi
csr=$(req "$key""CN = $cn") || return 1 echo"$csr" |
cert "$cert""$exts" -CA "${cacert}.pem" -CAkey "${cakey}.pem" \
-set_serial 2 -days "${DAYS}"
}
gen_nonbc_ca() {
local cn=$1; shift
local key=$1; shift
local cert=$1; shift
local cakey=$1; shift
local cacert=$1; shift
local skid="subjectKeyIdentifier = hash"
local akid="authorityKeyIdentifier = keyid"
# Usage: $0 geneealt keyname certname eekeyname eecertname alt1 alt2 ... # # Note: takes csr on stdin, so must be used with $0 req like this: # # $0 req keyname dn | $0 geneealt keyname certname eekeyname eecertname alt ...
geneealt() {
local key=$1; shift
local cert=$1; shift
local cakey=$1; shift
local ca=$1; shift