stenc icon indicating copy to clipboard operation
stenc copied to clipboard

Throw an error if encryption is enabled but the algorithm isn't specified

Open MichaelBurge opened this issue 3 years ago • 0 comments

When I first tried to use this tool, I forgot to set the -a parameter to specify the encryption algorithm. After comparing strace -e ioctl output with a SCSI command reference manual, I saw that the algorithmIndex wasn't being set and specifying this parameter allowed the drive to accept it.

This change causes this command:

$ sudo stenc -f /dev/nst0 -e on -k backup.key
Provided key length is 256 bits.
Key checksum is 4c7.
Turning on encryption on device '/dev/nst0'...
Sense Code:              Illegal Request (0x05)
 ASC:                    0x26
 ASCQ:                   0x00
 Additional data:        0x00000000000000000000000000000000
 Raw Sense:              0x700005000000001000000000260000ffffff8f000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Error: Turning encryption on for '/dev/nst0' failed!
Usage: stenc --version | -g <length> -k <file> [-kd <description>] | -f <device> [--detail] [-e <on/mixed/rawread/off> [-k <file>] [-kd <description>] [-a <index>] [--protect | --unprotect] [--ckod] ]
Type 'man stenc' for more information.

to instead output:

$ sudo stenc -f /dev/st0 -e on -k backup.key
Error: Encryption enabled but no algorithm index was set. Use 1 for 256-bit AES.
Usage: stenc --version | -g <length> -k <file> [-kd <description>] | -f <device> [--detail] [-e <on/mixed/rawread/off> [-k <file>] [-kd <description>] [-a <index>] [--protect | --unprotect] [--ckod] ]
Type 'man stenc' for more information.

if the -e on, -e mixed, or -e rawread options are set but no algorithm index is set.

MichaelBurge avatar Dec 08 '21 03:12 MichaelBurge