-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CA hardening and status URI change support #105
Merged
drybjed
merged 10 commits into
debops:master
from
ypid:ca-hardening-and-status-uri-change
Apr 25, 2017
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0d7ce10
Support to change or disable OCSP in PKI authorities using `item.ocsp`
ypid cb8ed64
Use X509v3 name constraints to limit PKI authorities to `item.domain`
ypid a64699b
Support to change or disable CRL in PKI authorities using `item.crl`
ypid 2ba7b87
No need to specify name of realm as second time using `acme_domains`
ypid a16c264
Improve changelog entry
ypid b5f4158
Use `${var}` syntax for Bash variable references
ypid ae14516
Unify interface of added authority params; Set name constrains critical
ypid 147cac7
Document newly added authority params
ypid ef600e7
Use `${var}` syntax for Bash variable references
ypid afa9b3c
Fix note in changelog that name constraints are only set in new certs
ypid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env bash | ||
# vim: foldmarker={{{,}}}:foldmethod=marker | ||
|
||
# pki-authority: CA-side PKI management | ||
# Copyright (C) 2016 Maciej Delmanowski <[email protected]> | ||
# Copyright (C) 2016-2017 Robin Schneider <[email protected]> | ||
# Homepage: https://debops.org/ | ||
|
||
set -o nounset -o pipefail -o errexit | ||
|
@@ -106,6 +108,57 @@ chgrp_idempotent () { | |
} | ||
# }}} | ||
|
||
get_openssl_ocsp_uri_directive () { | ||
local ocsp_uri | ||
case "${config['ocsp']}" in | ||
true|True) | ||
ocsp_uri="OCSP;URI.0 = \$ocsp_url" | ||
;; | ||
false|False) | ||
ocsp_uri="" | ||
;; | ||
*) | ||
ocsp_uri="OCSP;URI.0 = ${config['ocsp']}" | ||
;; | ||
esac | ||
echo "$ocsp_uri" | ||
} | ||
|
||
get_openssl_name_constraints_directive () { | ||
local config_domain="${1}" | ||
local name_constraints | ||
case "${config['name_constraints']}" in | ||
true|True) | ||
name_constraints="nameConstraints = critical, permitted;DNS:${config_domain}" | ||
;; | ||
false|False) | ||
name_constraints="" | ||
;; | ||
*) | ||
name_constraints="nameConstraints = ${config['name_constraints']}" | ||
;; | ||
esac | ||
|
||
echo "$name_constraints" | ||
} | ||
|
||
get_openssl_crl_distribution_points_directive () { | ||
local crl_distribution_points='' | ||
case "${config['crl']}" in | ||
true|True) | ||
crl_distribution_points="crlDistributionPoints = @crl_info" | ||
;; | ||
false|False) | ||
crl_distribution_points="" | ||
;; | ||
*) | ||
crl_distribution_points="crlDistributionPoints = ${config['crl']}" | ||
;; | ||
esac | ||
|
||
echo "$crl_distribution_points" | ||
} | ||
|
||
initialize_environment () { | ||
|
||
declare -gA config | ||
|
@@ -126,6 +179,7 @@ initialize_environment () { | |
config["ca_type"]="" | ||
config["issuer_name"]="" | ||
config["alt_authority"]="" | ||
config["name_constraints"]="" | ||
|
||
config["pki_default_sign_base"]="365" | ||
config["pki_default_root_sign_multiplier"]="12" | ||
|
@@ -136,6 +190,8 @@ initialize_environment () { | |
config["ca_sign_days"]="" | ||
config["cert_sign_days"]="" | ||
config["key_size"]="4096" | ||
config["crl"]="true" | ||
config["ocsp"]="true" | ||
|
||
config["public_dir_group"]="$(id -g)" | ||
config["public_file_group"]="$(id -g)" | ||
|
@@ -165,8 +221,7 @@ enter_authority () { | |
|
||
if [ -r "${config_file}" ] ; then | ||
|
||
# FIXME: Add a code that checks if the config file has no dangerous code inside | ||
# shellcheck disable=SC1090 | ||
# shellcheck source=/dev/null | ||
. "${config_file}" | ||
fi | ||
|
||
|
@@ -259,6 +314,8 @@ create_openssl_selfsign_config () { | |
local config_ca_type="${4}" | ||
|
||
if [ -n "${config_file}" ] && [ ! -r "${config_file}" ] ; then | ||
local ocsp_uri | ||
ocsp_uri="$(get_openssl_ocsp_uri_directive)" | ||
|
||
cat << EOF > "${config_file}" | ||
# Configuration file generated by pki-authority | ||
|
@@ -294,7 +351,7 @@ URI.0 = \$crl_url | |
|
||
[ issuer_info ] | ||
caIssuers;URI.0 = \$aia_url | ||
OCSP;URI.0 = \$ocsp_url | ||
${ocsp_uri} | ||
|
||
[ extension_ocsp ] | ||
authorityKeyIdentifier = keyid:always | ||
|
@@ -314,20 +371,26 @@ emailAddress = optional | |
[ extension_default ] | ||
EOF | ||
|
||
local name_constraints='' | ||
name_constraints="$(get_openssl_name_constraints_directive "$config_domain")" | ||
local crl_distribution_points='' | ||
crl_distribution_points="$(get_openssl_crl_distribution_points_directive)" | ||
if [ -z "${config_ca_type}" ] || [ "${config_ca_type}" = "root" ] ; then | ||
cat << EOF >> "${config_file}" | ||
basicConstraints = critical, CA:TRUE | ||
keyUsage = critical, keyCertSign, cRLSign | ||
subjectKeyIdentifier = hash | ||
${name_constraints} | ||
|
||
EOF | ||
elif [ "${config_ca_type}" = "service" ] ; then | ||
cat << EOF >> "${config_file}" | ||
authorityInfoAccess = @issuer_info | ||
basicConstraints = critical, CA:TRUE, pathlen:0 | ||
crlDistributionPoints = @crl_info | ||
${crl_distribution_points} | ||
keyUsage = critical, keyCertSign, cRLSign | ||
subjectKeyIdentifier = hash | ||
${name_constraints} | ||
|
||
EOF | ||
fi | ||
|
@@ -384,6 +447,8 @@ create_openssl_sign_config () { | |
local config_issuer="${5}" | ||
|
||
if [ -n "${config_file}" ] && [ ! -r "${config_file}" ] ; then | ||
local ocsp_uri | ||
ocsp_uri="$(get_openssl_ocsp_uri_directive)" | ||
|
||
cat << EOF > "${config_file}" | ||
# Configuration file generated by pki-authority | ||
|
@@ -443,7 +508,7 @@ URI.0 = \$crl_url | |
|
||
[ issuer_info ] | ||
caIssuers;URI.0 = \$aia_url | ||
OCSP;URI.0 = \$ocsp_url | ||
${ocsp_uri} | ||
|
||
[ extension_ocsp ] | ||
authorityKeyIdentifier = keyid:always | ||
|
@@ -489,15 +554,20 @@ emailAddress = optional | |
EOF | ||
fi | ||
|
||
local name_constraints='' | ||
name_constraints="$(get_openssl_name_constraints_directive "$config_domain")" | ||
local crl_distribution_points='' | ||
crl_distribution_points="$(get_openssl_crl_distribution_points_directive)" | ||
if [ -z "${config_issuer}" ] && [ -z "${config_ca_type}" ] || [ "${config_ca_type}" = "root" ] ; then | ||
cat << EOF >> "${config_file}" | ||
[ extension_default ] | ||
authorityInfoAccess = @issuer_info | ||
authorityKeyIdentifier = keyid:always | ||
basicConstraints = critical, CA:TRUE, pathlen:0 | ||
crlDistributionPoints = @crl_info | ||
${crl_distribution_points} | ||
keyUsage = critical, keyCertSign, cRLSign | ||
subjectKeyIdentifier = hash | ||
${name_constraints} | ||
|
||
EOF | ||
elif [ -z "${config_issuer}" ] && [ "${config_ca_type}" = "service" ] ; then | ||
|
@@ -506,7 +576,7 @@ EOF | |
authorityInfoAccess = @issuer_info | ||
authorityKeyIdentifier = keyid:always, issuer:always | ||
basicConstraints = critical, CA:FALSE | ||
crlDistributionPoints = @crl_info | ||
${crl_distribution_points} | ||
extendedKeyUsage = clientAuth, serverAuth | ||
keyUsage = critical, digitalSignature, keyEncipherment | ||
subjectKeyIdentifier = hash | ||
|
@@ -518,7 +588,7 @@ EOF | |
authorityInfoAccess = @issuer_info | ||
authorityKeyIdentifier = keyid:always, issuer:always | ||
basicConstraints = critical, CA:FALSE | ||
crlDistributionPoints = @crl_info | ||
${crl_distribution_points} | ||
extendedKeyUsage = clientAuth, serverAuth | ||
keyUsage = critical, digitalSignature, keyEncipherment | ||
subjectKeyIdentifier = hash | ||
|
@@ -1157,7 +1227,7 @@ sub_sign () { | |
|
||
if key_exists args "name" ; then | ||
|
||
enter_authority ${args['name']} | ||
enter_authority "${args['name']}" | ||
|
||
local library="${config['pki_library']}" | ||
local input | ||
|
@@ -1322,6 +1392,24 @@ sub_new-ca () { | |
key-size=*) | ||
args["key_size"]=${OPTARG#*=} | ||
;; | ||
crl) | ||
args["crl"]="${!OPTIND}"; OPTIND=$(( OPTIND + 1 )) | ||
;; | ||
crl=*) | ||
args["crl"]=${OPTARG#*=} | ||
;; | ||
ocsp) | ||
args["ocsp"]="${!OPTIND}"; OPTIND=$(( OPTIND + 1 )) | ||
;; | ||
ocsp=*) | ||
args["ocsp"]=${OPTARG#*=} | ||
;; | ||
name-constraints) | ||
args["name_constraints"]="${!OPTIND}"; OPTIND=$(( OPTIND + 1 )) | ||
;; | ||
name-constraints=*) | ||
args["name_constraints"]=${OPTARG#*=} | ||
;; | ||
*) | ||
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then | ||
echo "Unknown option --${OPTARG}" >&2 | ||
|
@@ -1346,7 +1434,7 @@ sub_new-ca () { | |
|
||
if key_exists args "name" ; then | ||
|
||
enter_authority ${args['name']} | ||
enter_authority "${args['name']}" | ||
|
||
local config_changed="false" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#!/usr/bin/env bash | ||
# vim: foldmarker={{{,}}}:foldmethod=marker | ||
|
||
# pki-realm: client-side PKI management | ||
# Copyright (C) 2016 Maciej Delmanowski <[email protected]> | ||
# Copyright (C) 2016-2017 Robin Schneider <[email protected]> | ||
# Homepage: https://debops.org/ | ||
|
||
set -o nounset -o pipefail -o errexit | ||
|
@@ -388,8 +390,7 @@ enter_realm () { | |
|
||
if [ -r "${config_file}" ] ; then | ||
|
||
# FIXME: Add a code that checks if the config file has no dangerous code inside | ||
# shellcheck disable=SC1090 | ||
# shellcheck source=/dev/null | ||
. "${config_file}" | ||
fi | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that there was/is no documentation for
pki_authorities
at all. My bad, thanks for starting it. It will need to be expanded upon later.