Skip to content

Conversation

xbharani
Copy link

  • Checks for fscryptctl binary presence
  • Creates a random sw encryption key
  • Applies and verifies encryption policy
  • Confirms functionality with a test file

- Checks for fscryptctl binary presence
- Creates a random sw encryption key
- Applies and verifies encryption policy
- Confirms functionality with a test file

Signed-off-by: Bharani Bhuvanagiri <[email protected]>
log_info "=== Test Initialization ==="

log_info "Checking if dependency binary is available"
check_dependencies fscryptctl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root/user -> fscrypt operations usually require root. Add a quick root check and fail early if not root.


log_info "Checking if dependency binary is available"
check_dependencies fscryptctl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kernel/filesystem precheck: Add check_kernel_config CONFIG_FS_ENCRYPTION (and optional CONFIG_FS_VERITY if you care) to SKIP gracefully on kernels without fscrypt. Also verify that the mount backing $MOUNT_DIR is ext4/f2fs with encryption support (or at least that add_key succeeds on that mountpoint).

check_dependencies fscryptctl

KEY_FILE="/data/std_key"
MOUNT_DIR="/mnt/testing"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You add_key … /mnt but set policy on $MOUNT_DIR (/mnt/testing). That’s okay if $MOUNT_DIR is on the same filesystem, but brittle. Resolve the mountpoint of $MOUNT_DIR (its parent, typically /mnt) and use that consistently for add_key and key_status.

log_info "Checking if dependency binary is available"
check_dependencies fscryptctl

KEY_FILE="/data/std_key"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use mktemp for the key path (instead of /data/std_key which may not exist), and set chmod 600.

if ! mkdir -p "$MOUNT_DIR"; then
log_fail "$TESTNAME : Failed to create mount directory"
echo "$TESTNAME FAIL" > "$res_file"
rm -f "$KEY_FILE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure the key file is always removed via a trap on exit.

if [ -z "$key_id" ]; then
log_fail "$TESTNAME : Failed to add encryption key"
echo "$TESTNAME FAIL" > "$res_file"
rm -f "$KEY_FILE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can’t “unset” policy trivially, but you can remove the fs key (fscryptctl remove_key). Do that in cleanup so subsequent tests aren’t polluted.


# Step 3: Add the key to the filesystem
log_info "Adding encryption key to the filesystem"
key_id=$(/data/fscryptctl add_key /mnt < "$KEY_FILE" 2>/dev/null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You call /data/fscryptctl … directly. That will fail on Debian/Yocto where it’s /usr/bin/fscryptctl. Use a single variable (e.g., FSCRYPTCTL="${FSCRYPTCTL:-fscryptctl}") and always call "$FSCRYPTCTL".


# Step 4: Check key status
log_info "Checking key status"
status=$(/data/fscryptctl key_status "$key_id" / 2>/dev/null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT


# Step 5: Set encryption policy
log_info "Setting encryption policy on $MOUNT_DIR"
if ! /data/fscryptctl set_policy "$key_id" "$MOUNT_DIR"; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT


# Step 6: Verify policy
log_info "Verifying encryption policy"
policy_output=$(/data/fscryptctl get_policy "$MOUNT_DIR" 2>/dev/null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

Runner/
├── suites/
│ ├── Kernel/
│ │ ├── FunctionalArea/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This folder is no more available. Please correct the structure accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants