Skip to content
Snippets Groups Projects
Commit 7c7e351b authored by nimrod's avatar nimrod
Browse files

- Added "namespaced" die and usage functions.

- Fix for bundle creation.
parent af02608f
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,20 @@ alias subject_hash='openssl x509 -noout -subject_hash -in' ...@@ -11,6 +11,20 @@ alias subject_hash='openssl x509 -noout -subject_hash -in'
# Returns the issuer hash of the certificate path provided. # Returns the issuer hash of the certificate path provided.
alias issuer_hash='openssl x509 -noout -issuer_hash -in' alias issuer_hash='openssl x509 -noout -issuer_hash -in'
__bc_die () {
echo "$@" >> /dev/stderr
return 1
}
__bc_usage () {
if (is_sourced)
then
__bc_die "Usage: bundle_certs filename [filename2 [filename3 ...]]"
else
__bc_die "Usage: $(basename "$0") filename [filename2 [filename3 ...]]"
fi
}
find_root_cert () { find_root_cert () {
# Returns the (first) root (self-signed) certificate found in the list # Returns the (first) root (self-signed) certificate found in the list
# of file paths provided. # of file paths provided.
...@@ -64,26 +78,21 @@ bundle_certs () { ...@@ -64,26 +78,21 @@ bundle_certs () {
local filename issuer issued bundle local filename issuer issued bundle
if [ $# -eq 0 ] if [ $# -eq 0 ]
then then
echo "Usage: bundle_certs filename [filename2 [filename3 ...]]" >> /dev/stderr __bc_usage
return 1
fi fi
for filename in "$@" for filename in "$@"
do do
[ -f "$filename" ] && unbundle_cert "$filename" [ -f "$filename" ] && unbundle_cert "$filename"
done done
issuer="$(find_root_cert certs/*)" issuer="$(find_root_cert certs/*)"
if [ -z "$issuer" ] [ -z "$issuer" ] && __bc_die "Failed to find root certificate."
then bundle="$(cat "$issuer")"
echo "Failed to find root certificate." >> /dev/stderr
return 1
fi
issued="$(find_cert_by_issuer_hash "$(basename "$issuer")" certs/*)" issued="$(find_cert_by_issuer_hash "$(basename "$issuer")" certs/*)"
bundle="$(cat "$issued")"
while [ -n "$issued" ] while [ -n "$issued" ]
do do
bundle="$(cat "$issued"; echo "${bundle:-}")"
issuer="$issued" issuer="$issued"
issued="$(find_cert_by_issuer_hash "$(basename "$issuer")" certs/*)" issued="$(find_cert_by_issuer_hash "$(basename "$issuer")" certs/*)"
[ -n "$issued" ] && bundle="$(echo "${bundle:-}"; cat "$issued")"
done done
echo "$bundle" echo "$bundle"
rm -r certs rm -r certs
...@@ -92,11 +101,6 @@ bundle_certs () { ...@@ -92,11 +101,6 @@ bundle_certs () {
if ! (is_sourced) if ! (is_sourced)
then then
set -eu set -eu
if [ $# -eq 0 ] [ $# -eq 0 ] && __bc_usage
then
echo "Usage: $(basename "$0") filename [filename2 [filename3 ...]]" >> /dev/stderr
return 1
else
bundle_certs "$@" bundle_certs "$@"
fi fi
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment