Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

upload-certificate: improve validation step output #63

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions imageroot/actions/upload-certificate/21validate_certificates
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,28 @@ elif openssl ec -check -in $KEY_FILE >/dev/null 2>&1; then
fi

if [ $VALID_KEY -eq 0 ]; then
echo "Key validation failed."
echo "Key validation failed." 1>&2
echo "set-status validation-failed" >&${AGENT_COMFD:-2}
printf '{"field":"keyFile","parameter":"keyFile","value":"","error":"invalid_key"}\n'
del_certs
exit 2
fi

# check if certificate is properly pam formatted
if ! openssl x509 -text -noout -in $CERT_FILE >/dev/null 2>&1; then
echo "Certificate not well formatted."
echo "Certificate not well formatted." 1>&2
echo "set-status validation-failed" >&${AGENT_COMFD:-2}
printf '{"field":"certFile","parameter":"certFile","value":"","error":"invalid_format"}\n'
del_certs
exit 4
fi

# check it the common name is present and is not empty
cn_name=$(openssl x509 -noout -subject -nameopt=multiline -in $CERT_FILE | sed -n 's/ *commonName *= //p')
if [ -z "$cn_name" ]; then
echo "Certificate doesn't have a common name."
echo "Certificate doesn't have a common name." 1>&2
echo "set-status validation-failed" >&${AGENT_COMFD:-2}
printf '{"field":"certFile","parameter":"certFile","value":"","error":"empty_common_name"}\n'
del_certs
exit 5
fi
Expand All @@ -55,7 +61,9 @@ key_public_key="$(openssl pkey -pubout -in $KEY_FILE | openssl md5)"


if [ "$cert_public_key" != "$key_public_key" ]; then
echo "Key didn't generate certificate."
echo "Key didn't generate certificate." 1>&2
echo "set-status validation-failed" >&${AGENT_COMFD:-2}
printf '{"field":"certFile","parameter":"certFile","value":"","error":"key_mismatch"}\n'
del_certs
exit 3
fi
Loading