Auto Light Dark
Auto Light Dark

Rekeying LUKS volume

It is recommended to take backup of your data to some external storage before performing rekey operation.

  1. Unmount the mounted volume from the mountpoint.

›_ Console

# umount /mnt/hdd 
image-3285156010-1.jpg

Unmounting the mounted volume

  1. Detach the attached LUKS volume.

›_ Console

# /usr/lib/systemd/systemd-cryptsetup detach mydisk /dev/sdc1 - pkcs11uri="auto" 
image-3285156010-2.jpg

Detach the attached LUKS volume

  1. Generate a new RSA key using p11tool2.

›_ Console

# p11tool2 Slot=<no> LoginUser=ask 

PubKeyAttr=CKA_LABEL="NEWPublicKey",CKA_ID=0x46 

PrvKeyAttr=CKA_LABEL="NEWPrivateKey",CKA_ID=0x46 GenerateKeyPair=RSA 
image-3285156010-3.jpg

Key generation output

  1. Verify that the keys are generated onto the HSM using following command.

›_ Console

# p11tool2 Slot=<no> LoginUser=ask ListObjects
image-3285778673-1.jpg

Key list using p11tool2

  1. Generate a self-signed certificate with the generated key.

›_ Console

# openssl req -x509 -engine pkcs11 -keyform engine -new -key

"pkcs11:token=UTILUKS;object=NEWPrivateKey" -sha256 -out newcert.pem subj "/CN=localhost"
image-3285778673-2.jpg

self-sign certificate generation

  1. Convert newcert.pem to newcert.der format.

›_ Console

# openssl x509 -outform der -in newcert.pem -out newcert.der
image-3285778673-3.jpg

Certificate type change output

  1. Import the certificate onto HSM.

›_ Console

# p11tool2 slot=<no> LoginUser=ask

CertAttr=CKA_LABEL="NEWCERT",CKA_ID=0x46

PubKeyAttr=CKA_LABEL="NEWPublicKey",CKA_ID=0x46

ImportCert=/opt/utimaco/bin/newcert.der
image-3285778673-4.jpg

Certificate import using p11tool2

  1. Check that the certificate is imported successfully on HSM.

›_ Console

# p11tool2 Slot=<no> LoginUser=ask ListObjects 
image-3286073529-1.jpg

Certificate list output

  1. List the objects on the slot and note down the URL of the new certificate and new private key.

›_ Console

# p11tool --provider /opt/utimaco/lib/libcs_pkcs11_R3.so --login --listall pkcs11:token=UTILUKS 
image-3286073529-2.jpg

Slot objects list

  1. Enroll the certificate on LUKS drive using systemd-cryptenroll command.

›_ Console

# systemd-cryptenroll --pkcs11-token-

uri="pkcs11:model=CryptoServer;manufacturer=Utimaco%20IS%20GmbH; serial=CS710843_0014;token=UTILUKS;id=%46;object=NEWCERT;type=cert" /dev/sdc1 
image-3286073548-1.jpg

systemd-cryptenroll command output

  1. Verify that the pkcs11 url of new certificate is added to the luks partition in the token section.

›_ Console

# cryptsetup luksDump /dev/sdc1 
image-3286073548-2.jpg

Encrypted volume information

image-3286073548-3.jpg

Encrypted volume information

  1. Open the luks volume as newbackup disk.

›_ Console

# cryptsetup luksOpen /dev/sdc1 newbackup 
image-3286073548-4.jpg

luksopen command output

  1. Export token using below command to header.json file

›_ Console

# cryptsetup token export –-token-id 0 /dev/sdc1 > header.json  
image-3286073548-5.jpg

Exporting token id information

  1. Open header.json file and replace the pkcs-uri with type=private url of new key. Example

›_ header.json file

pkcs11:model=CryptoServer;manufacturer=Utimaco%20IS%20GmbH;serial=CS71084

3_0014; token=UTILUKS;id=%46;object=NEWPrivateKey;type=private  
  1. Import the header.json file

›_ Console

# cryptsetup token import –-json-file header.json –-token-id 2 /dev/sdc1 
image-3286073548-6.jpg

Importing token id information

  1. Verify token id 2 is showing new key information using the command below.

›_ Console

# cryptsetup luksDump /dev/sdc1 
image-3286073548-7.jpg

LuksDump output

image-3286073548-8.jpg

LuksDump output

  1. Remove token id 0 and 1 and verify with the command below.

›_ Console

# cryptsetup token remove –-token-id 0 /dev/sdc1 

# cryptsetup token remove –-token-id 1 /dev/sdc1 
image-3286073548-9.jpg

Removing old token id

image-3286073548-10.jpg

Removing old token id

  1. Close the LUKS volume.

›_ Console

# cryptsetup luksClose newbackup 
image-3286073548-11.jpg

lukscolse output

  1. Attach the LUKS volume with systemd-cryptsetup.

›_ Console

# /usr/lib/systemd/systemd-cryptsetup attach luks /dev/sdc1 - pkcs11uri="auto" 
image-3286073548-12.jpg

Attaching luks volume

For Auto-Atttachig and Auto-Mounting LUKS volume refer to section Auto-Attaching and AutoMounting LUKS Volume during Boot.

This completes the Integration for Luks with Utimaco SecurityServer.