Path: blob/master/tools/testing/selftests/dm-verity/test-dm-verity-keyring.sh
121838 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Test script for dm-verity keyring functionality4#5# This script has two modes depending on kernel configuration:6#7# 1. keyring_unsealed=1 AND require_signatures=1:8# - Upload a test key to the .dm-verity keyring9# - Seal the keyring10# - Create a dm-verity device with a signed root hash11# - Verify signature verification works12#13# 2. keyring_unsealed=0 (default) OR require_signatures=0:14# - Verify the keyring is already sealed (if unsealed=0)15# - Verify keys cannot be added to a sealed keyring16# - Verify the keyring is inactive (not used for verification)17#18# Requirements:19# - Root privileges20# - openssl21# - veritysetup (cryptsetup)22# - keyctl (keyutils)2324set -e2526WORK_DIR=""27DATA_DEV=""28HASH_DEV=""29DM_NAME="verity-test-$$"30CLEANUP_DONE=03132# Module parameters (detected at runtime)33KEYRING_UNSEALED=""34REQUIRE_SIGNATURES=""3536# Colors for output37RED='\033[0;31m'38GREEN='\033[0;32m'39YELLOW='\033[1;33m'40NC='\033[0m' # No Color4142log_info() {43echo -e "${GREEN}[INFO]${NC} $*"44}4546log_warn() {47echo -e "${YELLOW}[WARN]${NC} $*"48}4950log_error() {51echo -e "${RED}[ERROR]${NC} $*" >&252}5354log_pass() {55echo -e "${GREEN}[PASS]${NC} $*"56}5758log_fail() {59echo -e "${RED}[FAIL]${NC} $*" >&260}6162log_skip() {63echo -e "${YELLOW}[SKIP]${NC} $*"64}6566cleanup() {67if [ "$CLEANUP_DONE" -eq 1 ]; then68return69fi70CLEANUP_DONE=17172log_info "Cleaning up..."7374# Remove dm-verity device if it exists75if dmsetup info "$DM_NAME" &>/dev/null; then76dmsetup remove "$DM_NAME" 2>/dev/null || true77fi7879# Detach loop devices80if [ -n "$DATA_DEV" ] && [[ "$DATA_DEV" == /dev/loop* ]]; then81losetup -d "$DATA_DEV" 2>/dev/null || true82fi83if [ -n "$HASH_DEV" ] && [[ "$HASH_DEV" == /dev/loop* ]]; then84losetup -d "$HASH_DEV" 2>/dev/null || true85fi8687# Remove work directory88if [ -n "$WORK_DIR" ] && [ -d "$WORK_DIR" ]; then89rm -rf "$WORK_DIR"90fi91}9293trap cleanup EXIT9495die() {96log_error "$*"97exit 198}99100find_dm_verity_keyring() {101# The .dm-verity keyring is not linked to user-accessible keyrings,102# so we need to find it via /proc/keys103local serial_hex104serial_hex=$(awk '/\.dm-verity/ {print $1}' /proc/keys 2>/dev/null)105106if [ -z "$serial_hex" ]; then107return 1108fi109110# Convert hex to decimal for keyctl111echo $((16#$serial_hex))112}113114get_module_param() {115local param="$1"116local path="/sys/module/dm_verity/parameters/$param"117118if [ -f "$path" ]; then119cat "$path"120else121echo ""122fi123}124125check_requirements() {126log_info "Checking requirements..."127128# Check for root129if [ "$(id -u)" -ne 0 ]; then130die "This script must be run as root"131fi132133# Check for required tools134for cmd in openssl veritysetup keyctl losetup dmsetup dd awk; do135if ! command -v "$cmd" &>/dev/null; then136die "Required command not found: $cmd"137fi138done139140# Check for dm-verity module141if ! modprobe -n dm-verity &>/dev/null; then142die "dm-verity module not available"143fi144145# Verify OpenSSL can create signatures146# OpenSSL cms -sign with -binary -outform DER creates detached signatures by default147log_info "Using OpenSSL for PKCS#7 signatures"148}149150load_dm_verity_module() {151local keyring_unsealed="${1:-0}"152local require_signatures="${2:-0}"153154log_info "Loading dm-verity module with keyring_unsealed=$keyring_unsealed require_signatures=$require_signatures"155156# Unload if already loaded157if lsmod | grep -q '^dm_verity'; then158log_info "Unloading existing dm-verity module..."159modprobe -r dm-verity 2>/dev/null || \160die "Failed to unload dm-verity module (may be in use)"161sleep 1162fi163164# Load with specified parameters165modprobe dm-verity keyring_unsealed="$keyring_unsealed" require_signatures="$require_signatures" || \166die "Failed to load dm-verity module"167168# Wait for keyring to be created (poll with timeout)169local keyring_id=""170local timeout=50 # 5 seconds (50 * 0.1s)171while [ $timeout -gt 0 ]; do172keyring_id=$(find_dm_verity_keyring) && break173sleep 0.1174timeout=$((timeout - 1))175done176177if [ -z "$keyring_id" ]; then178die "dm-verity keyring not found after module load (timeout)"179fi180181log_info "Found .dm-verity keyring: $keyring_id"182echo "$keyring_id" > "$WORK_DIR/keyring_id"183184# Read and display module parameters185KEYRING_UNSEALED=$(get_module_param "keyring_unsealed")186REQUIRE_SIGNATURES=$(get_module_param "require_signatures")187188log_info "Module parameters:"189log_info " keyring_unsealed=$KEYRING_UNSEALED"190log_info " require_signatures=$REQUIRE_SIGNATURES"191}192193unload_dm_verity_module() {194log_info "Unloading dm-verity module..."195196# Clean up any dm-verity devices first197local dm_dev198while read -r dm_dev _; do199[ -n "$dm_dev" ] || continue200log_info "Removing dm-verity device: $dm_dev"201dmsetup remove "$dm_dev" 2>/dev/null || true202done < <(dmsetup ls --target verity 2>/dev/null)203204if lsmod | grep -q '^dm_verity'; then205modprobe -r dm-verity 2>/dev/null || \206log_warn "Failed to unload dm-verity module"207sleep 1208fi209}210211generate_keys() {212log_info "Generating signing key pair..."213214# Generate private key (2048-bit for faster test execution)215openssl genrsa -out "$WORK_DIR/private.pem" 2048 2>/dev/null216217# Create OpenSSL config for certificate extensions218# The kernel requires digitalSignature key usage for signature verification219# Both subjectKeyIdentifier and authorityKeyIdentifier are needed for220# the kernel to match keys in the keyring (especially for self-signed certs)221cat > "$WORK_DIR/openssl.cnf" << 'EOF'222[req]223distinguished_name = req_distinguished_name224x509_extensions = v3_ca225prompt = no226227[req_distinguished_name]228CN = dm-verity-test-key229230[v3_ca]231basicConstraints = critical,CA:FALSE232keyUsage = digitalSignature233subjectKeyIdentifier = hash234authorityKeyIdentifier = keyid235EOF236237# Generate self-signed certificate with proper extensions238openssl req -new -x509 -key "$WORK_DIR/private.pem" \239-out "$WORK_DIR/cert.pem" -days 365 \240-config "$WORK_DIR/openssl.cnf" 2>/dev/null241242# Convert certificate to DER format for kernel243openssl x509 -in "$WORK_DIR/cert.pem" -outform DER \244-out "$WORK_DIR/cert.der"245246# Show certificate info for debugging247log_info "Certificate details:"248openssl x509 -in "$WORK_DIR/cert.pem" -noout -text 2>/dev/null | \249grep -E "Subject:|Issuer:|Key Usage|Extended" | head -10250251log_info "Keys generated successfully"252}253254seal_keyring() {255log_info "Sealing the .dm-verity keyring..."256257local keyring_id258keyring_id=$(cat "$WORK_DIR/keyring_id")259260keyctl restrict_keyring "$keyring_id" || \261die "Failed to seal keyring"262263log_info "Keyring sealed successfully"264}265266create_test_device() {267log_info "Creating test device images..."268269# Create data image with random content (8MB is sufficient for testing)270dd if=/dev/urandom of="$WORK_DIR/data.img" bs=1M count=8 status=none271272# Create hash image (will be populated by veritysetup)273dd if=/dev/zero of="$WORK_DIR/hash.img" bs=1M count=1 status=none274275# Setup loop devices276DATA_DEV=$(losetup --find --show "$WORK_DIR/data.img")277HASH_DEV=$(losetup --find --show "$WORK_DIR/hash.img")278279log_info "Data device: $DATA_DEV"280log_info "Hash device: $HASH_DEV"281}282283create_verity_hash() {284log_info "Creating dm-verity hash tree..."285286local root_hash output287output=$(veritysetup format "$DATA_DEV" "$HASH_DEV" 2>&1)288root_hash=$(echo "$output" | grep "Root hash:" | awk '{print $3}')289290if [ -z "$root_hash" ]; then291log_error "veritysetup format output:"292echo "$output" | sed 's/^/ /'293die "Failed to get root hash from veritysetup format"294fi295296echo "$root_hash" > "$WORK_DIR/root_hash"297log_info "Root hash: $root_hash"298}299300create_detached_signature() {301local infile="$1"302local outfile="$2"303local cert="$3"304local key="$4"305306# Use openssl smime (not cms) for PKCS#7 signatures compatible with kernel307# Flags from working veritysetup example:308# -nocerts: don't include certificate in signature309# -noattr: no signed attributes310# -binary: binary input mode311if openssl smime -sign -nocerts -noattr -binary \312-in "$infile" \313-inkey "$key" \314-signer "$cert" \315-outform der \316-out "$outfile" 2>/dev/null; then317return 0318fi319320log_error "Failed to create signature"321return 1322}323324activate_verity_device() {325local with_sig="$1"326local root_hash327root_hash=$(cat "$WORK_DIR/root_hash")328329# Clear dmesg and capture any kernel messages during activation330dmesg -C 2>/dev/null || true331332if [ "$with_sig" = "yes" ]; then333log_info "Activating dm-verity device with signature..."334veritysetup open "$DATA_DEV" "$DM_NAME" "$HASH_DEV" "$root_hash" \335--root-hash-signature="$WORK_DIR/root_hash.p7s" 2>&1336local ret=$?337else338log_info "Activating dm-verity device without signature..."339veritysetup open "$DATA_DEV" "$DM_NAME" "$HASH_DEV" "$root_hash" 2>&1340local ret=$?341fi342343# Show relevant kernel messages344local kmsg345kmsg=$(dmesg 2>/dev/null | grep -i -E 'verity|pkcs|signature|asymmetric|key' | tail -10)346if [ -n "$kmsg" ]; then347log_info "Kernel messages:"348echo "$kmsg" | while read -r line; do echo " $line"; done349fi350351return $ret352}353354deactivate_verity_device() {355if dmsetup info "$DM_NAME" &>/dev/null; then356dmsetup remove "$DM_NAME" 2>/dev/null || true357fi358}359360show_keyring_status() {361log_info "Keyring status:"362363local keyring_id364keyring_id=$(find_dm_verity_keyring) || true365366if [ -n "$keyring_id" ]; then367echo " Keyring ID: $keyring_id"368keyctl show "$keyring_id" 2>/dev/null || true369grep '\.dm-verity' /proc/keys 2>/dev/null || true370fi371}372373list_keyring_keys() {374log_info "Keys in .dm-verity keyring:"375376local keyring_id377keyring_id=$(cat "$WORK_DIR/keyring_id" 2>/dev/null) || \378keyring_id=$(find_dm_verity_keyring) || true379380if [ -z "$keyring_id" ]; then381log_warn "Could not find keyring"382return383fi384385# List all keys in the keyring386local keys387keys=$(keyctl list "$keyring_id" 2>/dev/null)388if [ -z "$keys" ] || [ "$keys" = "keyring is empty" ]; then389echo " (empty)"390else391echo "$keys" | while read -r line; do392echo " $line"393done394395# Show detailed info for each key396log_info "Key details:"397keyctl list "$keyring_id" 2>/dev/null | awk '{print $1}' | grep -E '^[0-9]+$' | while read -r key_id; do398echo " Key $key_id:"399keyctl describe "$key_id" 2>/dev/null | sed 's/^/ /'400done401fi402}403404generate_named_key() {405local name="$1"406local key_dir="$WORK_DIR/keys/$name"407408mkdir -p "$key_dir"409410# Log to stderr so it doesn't interfere with return value411echo "[INFO] Generating key pair: $name" >&2412413# Generate private key414openssl genrsa -out "$key_dir/private.pem" 2048 2>/dev/null415416# Create OpenSSL config for certificate extensions417# Both subjectKeyIdentifier and authorityKeyIdentifier are needed for418# the kernel to match keys in the keyring (especially for self-signed certs)419cat > "$key_dir/openssl.cnf" << EOF420[req]421distinguished_name = req_distinguished_name422x509_extensions = v3_ca423prompt = no424425[req_distinguished_name]426CN = dm-verity-test-$name427428[v3_ca]429basicConstraints = critical,CA:FALSE430keyUsage = digitalSignature431subjectKeyIdentifier = hash432authorityKeyIdentifier = keyid433EOF434435# Generate self-signed certificate with proper extensions436openssl req -new -x509 -key "$key_dir/private.pem" \437-out "$key_dir/cert.pem" -days 365 \438-config "$key_dir/openssl.cnf" 2>/dev/null439440# Convert certificate to DER format for kernel441openssl x509 -in "$key_dir/cert.pem" -outform DER \442-out "$key_dir/cert.der"443444# Return the key directory path (only this goes to stdout)445echo "$key_dir"446}447448upload_named_key() {449local name="$1"450local key_dir="$2"451452local keyring_id453keyring_id=$(cat "$WORK_DIR/keyring_id")454455log_info "Uploading key '$name' to keyring..."456457local key_id458if key_id=$(keyctl padd asymmetric "$name" "$keyring_id" \459< "$key_dir/cert.der" 2>&1); then460log_info "Key '$name' uploaded with ID: $key_id"461echo "$key_id" > "$key_dir/key_id"462return 0463else464log_error "Failed to upload key '$name': $key_id"465return 1466fi467}468469#470# Test: Verify sealed keyring rejects key additions471#472test_sealed_keyring_rejects_keys() {473log_info "TEST: Verify sealed keyring rejects key additions"474475local keyring_id476keyring_id=$(cat "$WORK_DIR/keyring_id")477478generate_keys479480# Try to add a key - should fail481if keyctl padd asymmetric "dm-verity-test" "$keyring_id" \482< "$WORK_DIR/cert.der" 2>/dev/null; then483log_fail "Key addition should have been rejected on sealed keyring"484return 1485else486log_pass "Sealed keyring correctly rejected key addition"487return 0488fi489}490491#492# Test: Multiple keys in keyring493#494test_multiple_keys() {495log_info "TEST: Multiple keys in keyring"496497local key1_dir key2_dir key3_dir498499# Generate three different keys500key1_dir=$(generate_named_key "vendor-a")501key2_dir=$(generate_named_key "vendor-b")502key3_dir=$(generate_named_key "vendor-c")503504# Upload all three keys505upload_named_key "vendor-a" "$key1_dir" || return 1506upload_named_key "vendor-b" "$key2_dir" || return 1507upload_named_key "vendor-c" "$key3_dir" || return 1508509log_info ""510log_info "Keys in keyring before sealing:"511list_keyring_keys512show_keyring_status513514# Seal the keyring515log_info ""516seal_keyring517518# List keys after sealing519log_info ""520log_info "Keys in keyring after sealing:"521list_keyring_keys522show_keyring_status523524log_pass "Key upload and keyring sealing succeeded"525526# Create test device527log_info ""528create_test_device529create_verity_hash530531# Test 1: Sign with key1, should verify successfully532log_info ""533log_info "Sub-test: Verify with vendor-a key"534if ! sign_root_hash_with_key "$key1_dir"; then535log_fail "Failed to sign with vendor-a key"536return 1537fi538if activate_verity_device "yes"; then539log_pass "Verification with vendor-a key succeeded"540deactivate_verity_device541else542log_fail "Verification with vendor-a key should succeed"543return 1544fi545546# Test 2: Sign with key2, should also verify successfully547log_info ""548log_info "Sub-test: Verify with vendor-b key"549if ! sign_root_hash_with_key "$key2_dir"; then550log_fail "Failed to sign with vendor-b key"551return 1552fi553if activate_verity_device "yes"; then554log_pass "Verification with vendor-b key succeeded"555deactivate_verity_device556else557log_fail "Verification with vendor-b key should succeed"558return 1559fi560561# Test 3: Sign with key3, should also verify successfully562log_info ""563log_info "Sub-test: Verify with vendor-c key"564if ! sign_root_hash_with_key "$key3_dir"; then565log_fail "Failed to sign with vendor-c key"566return 1567fi568if activate_verity_device "yes"; then569log_pass "Verification with vendor-c key succeeded"570deactivate_verity_device571else572log_fail "Verification with vendor-c key should succeed"573return 1574fi575576# Test 4: Generate a key NOT in the keyring, should fail577log_info ""578log_info "Sub-test: Verify with unknown key (should fail)"579local unknown_key_dir580unknown_key_dir=$(generate_named_key "unknown-vendor")581if ! sign_root_hash_with_key "$unknown_key_dir"; then582log_fail "Failed to sign with unknown-vendor key"583return 1584fi585if activate_verity_device "yes"; then586log_fail "Verification with unknown key should fail"587deactivate_verity_device588return 1589else590log_pass "Verification with unknown key correctly rejected"591fi592593log_info ""594log_pass "Multiple keys test completed successfully"595return 0596}597598sign_root_hash_with_key() {599local key_dir="$1"600601local root_hash602root_hash=$(cat "$WORK_DIR/root_hash")603604# Create the data to sign (hex string, not binary)605echo -n "$root_hash" > "$WORK_DIR/root_hash.txt"606607# Debug: show exactly what we're signing608log_info "Root hash (hex): $root_hash"609log_info "Root hash hex string size: $(wc -c < "$WORK_DIR/root_hash.txt") bytes"610611# Create detached PKCS#7 signature612if ! create_detached_signature "$WORK_DIR/root_hash.txt" "$WORK_DIR/root_hash.p7s" \613"$key_dir/cert.pem" "$key_dir/private.pem"; then614log_error "Failed to sign root hash with key from $key_dir"615return 1616fi617618# Debug: show signing certificate info619log_info "Signed with certificate:"620openssl x509 -in "$key_dir/cert.pem" -noout -subject 2>/dev/null | sed 's/^/ /'621622# Debug: verify signature locally623# -nointern: cert not in signature, use -certfile624# -noverify: skip certificate chain validation (self-signed)625if openssl smime -verify -binary -inform der -nointern -noverify \626-in "$WORK_DIR/root_hash.p7s" \627-content "$WORK_DIR/root_hash.txt" \628-certfile "$key_dir/cert.pem" \629-out /dev/null 2>/dev/null; then630log_info "Local signature verification: PASSED"631else632log_warn "Local signature verification: FAILED"633fi634return 0635}636637#638# Test: Verify corrupted signatures are rejected639#640test_corrupted_signature() {641log_info "TEST: Verify corrupted signatures are rejected"642643# This test requires a valid setup from test_multiple_keys or similar644# It modifies the signature file and verifies rejection645646if [ ! -f "$WORK_DIR/root_hash.p7s" ]; then647log_warn "No signature file found, skipping corrupted signature test"648return 0649fi650651# Save original signature652cp "$WORK_DIR/root_hash.p7s" "$WORK_DIR/root_hash.p7s.orig"653654# Test 1: Truncated signature655log_info "Sub-test: Truncated signature (should fail)"656head -c 100 "$WORK_DIR/root_hash.p7s.orig" > "$WORK_DIR/root_hash.p7s"657if activate_verity_device "yes"; then658log_fail "Truncated signature should be rejected"659deactivate_verity_device660cp "$WORK_DIR/root_hash.p7s.orig" "$WORK_DIR/root_hash.p7s"661return 1662else663log_pass "Truncated signature correctly rejected"664fi665666# Test 2: Corrupted signature (flip some bytes)667log_info "Sub-test: Corrupted signature bytes (should fail)"668cp "$WORK_DIR/root_hash.p7s.orig" "$WORK_DIR/root_hash.p7s"669# Corrupt bytes in the middle of the signature670local sig_size671sig_size=$(wc -c < "$WORK_DIR/root_hash.p7s")672local corrupt_offset=$((sig_size / 2))673printf '\xff\xff\xff\xff' | dd of="$WORK_DIR/root_hash.p7s" bs=1 seek=$corrupt_offset conv=notrunc 2>/dev/null674if activate_verity_device "yes"; then675log_fail "Corrupted signature should be rejected"676deactivate_verity_device677cp "$WORK_DIR/root_hash.p7s.orig" "$WORK_DIR/root_hash.p7s"678return 1679else680log_pass "Corrupted signature correctly rejected"681fi682683# Test 3: Signature over wrong data (sign different content)684log_info "Sub-test: Signature over wrong data (should fail)"685# Create a different root hash (all zeros as hex string)686printf '%064d' 0 > "$WORK_DIR/wrong_hash.txt"687# Get the first key directory that was used688local key_dir="$WORK_DIR/keys/vendor-a"689if [ -d "$key_dir" ]; then690create_detached_signature "$WORK_DIR/wrong_hash.txt" "$WORK_DIR/root_hash.p7s" \691"$key_dir/cert.pem" "$key_dir/private.pem"692if activate_verity_device "yes"; then693log_fail "Signature over wrong data should be rejected"694deactivate_verity_device695cp "$WORK_DIR/root_hash.p7s.orig" "$WORK_DIR/root_hash.p7s"696return 1697else698log_pass "Signature over wrong data correctly rejected"699fi700else701log_warn "Key directory not found, skipping wrong data test"702fi703704# Restore original signature705cp "$WORK_DIR/root_hash.p7s.orig" "$WORK_DIR/root_hash.p7s"706707log_pass "Corrupted signature test completed successfully"708return 0709}710711#712# Test: Verify keyring is sealed when keyring_unsealed=0713#714test_keyring_sealed_by_default() {715log_info "TEST: Verify keyring is sealed by default (keyring_unsealed=0)"716717local keyring_id718keyring_id=$(cat "$WORK_DIR/keyring_id")719720log_info "Current keyring state (should be empty and sealed):"721list_keyring_keys722show_keyring_status723724generate_keys725726# Try to add a key - should fail if keyring is sealed727log_info "Attempting to add key to sealed keyring..."728if keyctl padd asymmetric "dm-verity-test" "$keyring_id" \729< "$WORK_DIR/cert.der" 2>/dev/null; then730log_fail "Keyring should be sealed when keyring_unsealed=0"731list_keyring_keys732return 1733else734log_pass "Keyring is correctly sealed when keyring_unsealed=0"735log_info "Keyring state after failed add attempt:"736list_keyring_keys737return 0738fi739}740741#742# Test: Verify dm-verity keyring is inactive when sealed empty743#744test_keyring_inactive_when_empty() {745log_info "TEST: Verify dm-verity keyring is inactive when sealed empty"746747# When keyring_unsealed=0, the keyring is sealed immediately while empty748# This means it should NOT be used for verification (nr_leaves_on_tree=0)749750log_info "Keyring state (should be empty and sealed):"751list_keyring_keys752show_keyring_status753754create_test_device755create_verity_hash756757# Without any keys in the dm-verity keyring, and with it sealed,758# verification should fall through to the secondary/platform keyrings759# and likely succeed (if require_signatures=0) or fail (if =1)760761log_info "Sub-test: Device activation with sealed empty keyring"762if [ "$REQUIRE_SIGNATURES" = "Y" ] || [ "$REQUIRE_SIGNATURES" = "1" ]; then763if activate_verity_device "no"; then764log_fail "Device should NOT activate without signature when require_signatures=1"765deactivate_verity_device766return 1767else768log_pass "Device correctly rejected (require_signatures=1, no valid signature)"769fi770else771if activate_verity_device "no"; then772log_pass "Device activated (require_signatures=0, empty dm-verity keyring is inactive)"773deactivate_verity_device774else775log_fail "Device should activate when require_signatures=0"776return 1777fi778fi779780return 0781}782783main() {784local rc=0785786log_info "=== dm-verity keyring test ==="787log_info ""788789# Create work directory790WORK_DIR=$(mktemp -d -t dm-verity-test.XXXXXX)791log_info "Work directory: $WORK_DIR"792793check_requirements794795#796# Test 1: UNSEALED keyring mode (keyring_unsealed=1)797#798log_info ""799log_info "========================================"800log_info "=== TEST MODE: UNSEALED KEYRING ==="801log_info "========================================"802log_info ""803804load_dm_verity_module 1 1 # keyring_unsealed=1, require_signatures=1805show_keyring_status806807log_info ""808if ! test_multiple_keys; then809rc=1810fi811812# After sealing, verify it rejects new keys813log_info ""814if ! test_sealed_keyring_rejects_keys; then815rc=1816fi817818# Test corrupted signatures are rejected819log_info ""820if ! test_corrupted_signature; then821rc=1822fi823824# Clean up devices before reloading module825deactivate_verity_device826if [ -n "$DATA_DEV" ] && [[ "$DATA_DEV" == /dev/loop* ]]; then827losetup -d "$DATA_DEV" 2>/dev/null || true828DATA_DEV=""829fi830if [ -n "$HASH_DEV" ] && [[ "$HASH_DEV" == /dev/loop* ]]; then831losetup -d "$HASH_DEV" 2>/dev/null || true832HASH_DEV=""833fi834835#836# Test 2: SEALED keyring mode (keyring_unsealed=0, default)837#838log_info ""839log_info "========================================"840log_info "=== TEST MODE: SEALED KEYRING (default) ==="841log_info "========================================"842log_info ""843844load_dm_verity_module 0 0 # keyring_unsealed=0, require_signatures=0845show_keyring_status846847log_info ""848if ! test_keyring_sealed_by_default; then849rc=1850fi851852log_info ""853if ! test_keyring_inactive_when_empty; then854rc=1855fi856857#858# Summary859#860log_info ""861log_info "========================================"862if [ $rc -eq 0 ]; then863log_info "=== All tests PASSED ==="864else865log_error "=== Some tests FAILED ==="866fi867log_info "========================================"868869return $rc870}871872main "$@"873874875