Last active
December 18, 2024 16:49
-
-
Save qrkourier/510110dff31013d393537c5f5601bad0 to your computer and use it in GitHub Desktop.
error if ziti controller presents a server cert not verifiable by its well-known trust bundle
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
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
# set -o xtrace | |
: "${ZITI_ALPN:=h2,http/1.1}" | |
: "${TMPDIR:=$(mktemp -d)}" | |
BASENAME="$(basename "${0}")" | |
if (( $# )) | |
then | |
ZITI_EDGE=$1 | |
elif [[ -n "${ZITI_EDGE:-}" ]] | |
then | |
: | |
else | |
echo -e " Usage:\n"\ | |
" ${BASENAME} [ZITI_EDGE]\n"\ | |
"Example:\n"\ | |
" ${BASENAME} 127.0.0.1:1280\n"\ | |
"Options:\n"\ | |
" ZITI_ALPN\tALPN protocols to use when connecting to the controller\n"\ | |
"\t\t[h2,http/1.1|ziti-ctrl] (default: ${ZITI_ALPN})" | |
exit 1 | |
fi | |
cd "${TMPDIR}" | |
echo -e "\nINFO: getting server cert chain from ${ZITI_EDGE} with ALPN ${ZITI_ALPN}\n" | |
openssl s_client \ | |
-alpn "${ZITI_ALPN}" \ | |
-connect "${ZITI_EDGE}" \ | |
-showcerts <>/dev/null \ | |
|& openssl storeutl -certs -noout -text /dev/stdin \ | |
| grep -E '(Subject|Issuer):' | |
curl -sSk "https://${ZITI_EDGE}/.well-known/est/cacerts" \ | |
| base64 -d \ | |
| openssl pkcs7 -inform DER -outform PEM -print_certs \ | |
> ./well-known.pem | |
if openssl s_client \ | |
-alpn "${ZITI_ALPN}" \ | |
-connect "${ZITI_EDGE}" \ | |
-showcerts \ | |
-verify_return_error \ | |
-CAfile ./well-known.pem </dev/null &>/dev/null | |
then | |
echo -e '\nINFO: verified by root CA' | |
exit 0 | |
elif openssl s_client \ | |
-alpn "${ZITI_ALPN}" \ | |
-connect "${ZITI_EDGE}" \ | |
-showcerts \ | |
-verify_return_error \ | |
-CAfile ./well-known.pem \ | |
-partial_chain </dev/null &>/dev/null | |
then | |
echo -e '\nERROR: verified by intermediate CA, missing root' >&2 | |
exit 1 | |
else | |
echo -e '\aERROR: not verified' >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment