#!/bin/bash
# SPDX-Version: 3.0
# SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.installer.git
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
# SPDX-PackageName: CISS.debian.installer
# SPDX-Security-Contact: security@coresecret.eu

guard_sourcing

#######################################
# Entropy collection improvements '/usr/lib/modules-load.d/30_security-misc.conf'.
# Globals:
#   TARGET
# Arguments:
#   None
# Returns:
#   0: on success
#######################################
kernel_modules() {
  ### Entropy collection improvements
  mkdir -p "${TARGET}/usr/lib/modules-load.d"
  cat << EOF >| "${TARGET}/usr/lib/modules-load.d/30_security-misc.conf"
# SPDX-Version: 3.0
# SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.installer.git
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
# SPDX-PackageName: CISS.debian.installer
# SPDX-Security-Contact: security@coresecret.eu

# Static file system information: /usr/lib/modules-load.d/30_security-misc.conf
# Generated by CISS.debian.installer ${VAR_VERSION}
# Architecture: ${VAR_ARCHITECTURE}
# Distribution: ${VAR_CODENAME}

# The jitterentropy_rng kernel module provides a reliable and hardware-independent source of cryptographic entropy by measuring
# minute variations in CPU execution timing (jitter). These microsecond-level differences are unpredictable and rooted in
# physical randomness, making them suitable for high-quality entropy generation. Unlike other RNG methods that rely on hardware
# features like TPMs or Intel's RDRAND, which may not be available or trusted, jitterentropy_rng works across all platforms,
# including virtual machines and air-gapped systems. It is compliant with NIST SP 800-90B and BSI TR-02102-4, ensuring secure
# entropy even during early boot stages, such as in initramfs or before full userland is available. It is the most secure,
# standards-compliant, and universally applicable entropy source for hardened Linux environments.
# https://www.whonix.org/wiki/Dev/Entropy
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=927972
# https://forums.whonix.org/t/jitterentropy-rngd/7204

jitterentropy_rng

# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
EOF
  chmod 0644 "${TARGET}/usr/lib/modules-load.d/30_security-misc.conf"

  do_log "info" "file_only" "4400() Installed: '/usr/lib/modules-load.d/30_security-misc.conf'."

  guard_dir && return 0
}

#######################################
# Blacklist some kind of potential hazardous modules via '/etc/modprobe.d/0000_ciss_debian_installer.conf'.
# Globals:
#   TARGET
#   VAR_SETUP_PATH
# Arguments:
#   None
# Returns:
#   0: on success
#######################################
kernel_modprobe() {
 install -D -m 0755 -o root -g root "${VAR_SETUP_PATH}/includes/target/etc/modprobe.d/0000_ciss_debian_installer.cnf" \
    "${TARGET}/etc/modprobe.d/0000_ciss_debian_installer.conf"

  insert_comments "${TARGET}/etc/modprobe.d/0000_ciss_debian_installer.conf"

  do_log "info" "file_only" "4400() Installed: '/etc/modprobe.d/0000_ciss_debian_installer.conf'."

  guard_dir && return 0
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
