Update: Fixes and updates to two-level CA handling. Updated tests.
This commit is contained in:
57
run-tests.sh
57
run-tests.sh
@@ -7,32 +7,40 @@ set -e
|
||||
source "$(dirname "$BASH_SOURCE[0]")/cert-functions.sh"
|
||||
|
||||
function clean_up_test_dir() {
|
||||
local TEST_DIR="$1"
|
||||
|
||||
if [[ -d "$TEST_DIR" ]]; then
|
||||
echo "Cleaning up test directory $TEST_DIR..."
|
||||
rm -rf "$TEST_DIR"/*
|
||||
if [[ -d "$CERT_DIR" ]]; then
|
||||
echo "Cleaning up test directory $CERT_DIR..."
|
||||
rm -rf "$CERT_DIR"/*
|
||||
fi
|
||||
|
||||
echo "Creating test directory $TEST_DIR and ca subdirectory..."
|
||||
mkdir -p "$TEST_DIR/ca"
|
||||
echo "Creating test directory $CERT_DIR and ca subdirectory..."
|
||||
mkdir -p "$CERT_DIR/ca"
|
||||
}
|
||||
|
||||
function display_certificate() {
|
||||
local CERT_DIR="$1"
|
||||
local CERT_FILE="$2"
|
||||
local CERT_PATH="$1"
|
||||
|
||||
echo -e "\nDisplaying generated certificate for verification ($CERT_FILE):"
|
||||
echo -e "\nDisplaying generated certificate for verification ($CERT_PATH):"
|
||||
|
||||
# Display the certificate details for verification
|
||||
openssl x509 -in "$CERT_DIR/$CERT_FILE" -noout -subject -issuer -serial -hash -fingerprint
|
||||
openssl x509 -in "$CERT_PATH" -noout -subject -issuer -serial -fingerprint
|
||||
echo
|
||||
|
||||
echo -e "\nVerifying certificate against the CA ($CA_DIR)..."
|
||||
|
||||
# Verify the certificate against the CA
|
||||
if openssl verify -CApath "$CA_DIR" "$CERT_PATH" 2>/dev/null; then
|
||||
echo "Certificate verification successful."
|
||||
else
|
||||
echo "ERROR: Certificate verification failed." >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# Create a temporary directory for the test certificates
|
||||
TEMP_CERT_DIR="$(dirname "$BASH_SOURCE[0]")/tests"
|
||||
CERT_DIR="$(dirname "$BASH_SOURCE[0]")/tests"
|
||||
CA_DIR="$CERT_DIR/ca"
|
||||
|
||||
# Clean up any existing files in the temporary directory
|
||||
clean_up_test_dir "$TEMP_CERT_DIR"
|
||||
clean_up_test_dir "$CERT_DIR"
|
||||
|
||||
echo
|
||||
echo "Running tests for standalone CA..."
|
||||
@@ -40,25 +48,25 @@ echo "----------------------------------"
|
||||
echo
|
||||
|
||||
# Create a standalone CA for testing purposes
|
||||
if ! make_ca "$TEMP_CERT_DIR" "Test CA"; then
|
||||
if ! make_ca "$CA_DIR" "Test CA"; then
|
||||
echo "ERROR: Failed to create CA." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# List the generated certificates and keys for verification
|
||||
display_certificate "$TEMP_CERT_DIR" "ca_cert.pem"
|
||||
display_certificate "$CA_DIR/ca_cert.pem"
|
||||
|
||||
# Make a server certificate signed by the CA
|
||||
if ! make_server_cert "$TEMP_CERT_DIR" "test" "test.example.com" "127.0.0.1"; then
|
||||
if ! make_server_cert --ca-dir "$CA_DIR" "$CERT_DIR" "test" "test.example.com" "127.0.0.1"; then
|
||||
echo "ERROR: Failed to create server certificate." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# List the generated server certificate and key for verification
|
||||
display_certificate "$TEMP_CERT_DIR" "test_cert.pem"
|
||||
display_certificate "$CERT_DIR/test_cert.pem"
|
||||
|
||||
# Remove all files from the directory
|
||||
clean_up_test_dir "$TEMP_CERT_DIR"
|
||||
clean_up_test_dir "$CERT_DIR"
|
||||
|
||||
echo
|
||||
echo "Running tests for two-level CA..."
|
||||
@@ -66,29 +74,28 @@ echo "---------------------------------"
|
||||
echo
|
||||
|
||||
# Create a new CA with pathlen 1
|
||||
if ! make_ca --path-len 1 "$TEMP_CERT_DIR" "Test Two Level CA"; then
|
||||
if ! make_ca --path-len 1 "$CA_DIR" "Test Two Level CA"; then
|
||||
echo "ERROR: Failed to create CA." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# List the generated certificates and keys for verification
|
||||
display_certificate "$TEMP_CERT_DIR" "ca_cert.pem"
|
||||
display_certificate "$CA_DIR/ca_cert.pem"
|
||||
|
||||
# Create an issuing CA signed by the first CA
|
||||
if ! make_ca --issuing-ca "issuing_ca" "$TEMP_CERT_DIR" "Issuing CA"; then
|
||||
if ! make_ca --issuing-ca "issuing_ca" "$CA_DIR" "Issuing CA"; then
|
||||
echo "ERROR: Failed to create issuing CA." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# List the generated certificates and keys for verification
|
||||
display_certificate "$TEMP_CERT_DIR" "issuing_ca_cert.pem"
|
||||
display_certificate "$CA_DIR/issuing_ca_cert.pem"
|
||||
|
||||
# Make a server certificate signed by the CA
|
||||
if ! make_server_cert --issuing-ca "issuing_ca" "$TEMP_CERT_DIR" "test" "test.example.com" "127.0.0.1"; then
|
||||
if ! make_server_cert --ca-dir "$CA_DIR" --issuing-ca "issuing_ca" "$CERT_DIR" "test" "test.example.com" "127.0.0.1"; then
|
||||
echo "ERROR: Failed to create server certificate." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# List the generated server certificate and key for verification
|
||||
display_certificate "$TEMP_CERT_DIR" "test_cert.pem"
|
||||
|
||||
display_certificate "$CERT_DIR/test_cert.pem"
|
||||
|
||||
Reference in New Issue
Block a user