Blog | G5 Cyber Security

Secure Certificate Storage: LUKS vs. SoftHSM

TL;DR

Both LUKS and SoftHSM can securely store certificates, but they offer different levels of protection and convenience. LUKS encrypts the entire disk partition, providing broader security but requiring more setup. SoftHSM creates a dedicated hardware-backed key store for your certificates, offering stronger isolation but potentially being less flexible. For most users, SoftHSM is the better choice if you need strong certificate protection without full disk encryption.

Understanding the Options

Let’s break down each method:

Step-by-step Guide: Setting up SoftHSM

  1. Install SoftHSM2: Use your distribution’s package manager.
    sudo apt install softhsm2  # Debian/Ubuntu
    sudo yum install softhsm   # CentOS/RHEL/Fedora
  2. Create a SoftHSM token: This creates the secure storage area.
    softhsm2-init -type pkcs11 --label 'MyCertToken' --pin 12345678

    Important: Choose a strong PIN. This PIN protects access to your keys.

  3. Configure PKCS#11 URI: SoftHSM uses the PKCS#11 standard for accessing its storage.

    The URI will typically be something like pkcs11:token=MyCertToken. Note this down; you’ll need it later.

  4. Import your Certificate and Private Key: Use OpenSSL or a similar tool to import the certificate and key into SoftHSM.
    openssl pkcs12 -i mycert.p12 -nokeys -out cert.pem -nodes
    openssl pkcs12 -i mycert.p12 -nocerts -out key.pem -nodes
    pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --label 'MyCertToken' --pin 12345678 --import cert.pem --type cert
    pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --label 'MyCertToken' --pin 12345678 --import key.pem --type privkey
  5. Verify the Import: List the objects in your SoftHSM token to confirm they are present.
    pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --label 'MyCertToken' --pin 12345678 --list

Step-by-step Guide: Using LUKS for Certificate Storage

  1. Create an Encrypted Partition: Use a tool like cryptsetup to create and encrypt a partition.
    sudo cryptsetup luksFormat /dev/sdX1

    Warning: This will erase all data on the specified partition. Back up any important files first.

  2. Open the Encrypted Partition: Mount the encrypted partition after unlocking it.
    sudo cryptsetup luksOpen /dev/sdX1 myencryptedvolume
  3. Create a Filesystem: Format the unlocked volume with a filesystem (e.g., ext4).
    sudo mkfs.ext4 /dev/mapper/myencryptedvolume
  4. Mount the Filesystem: Mount the newly formatted filesystem.
    sudo mount /dev/mapper/myencryptedvolume /mnt/certs
  5. Store Certificates: Copy your certificates into the /mnt/certs directory.
  6. Unmount and Close: Unmount the filesystem when finished.
    sudo umount /mnt/certs
    sudo cryptsetup luksClose myencryptedvolume

Security Considerations

Exit mobile version