3 Commits
1.0.9 ... 1.1.0

Author SHA1 Message Date
Jonas Stein
8ff2e4c4eb Codecleanup, Version bump 1.1.0 2022-04-22 00:47:33 +02:00
Jonas Stein
0ad0a208d5 Drop AC_CHECK_INCLUDES_DEFAULT
AC_CHECK_INCLUDES_DEFAULT requires autoconf at least version 2.70
Bug: https://github.com/scsitape/stenc/issues/33
2022-04-21 22:44:41 +02:00
Jonas Stein
59d5c6c0fa ignore temporary files 2022-04-21 22:24:51 +02:00
6 changed files with 121 additions and 85 deletions

45
.gitignore vendored
View File

@@ -1,3 +1,6 @@
# Tempfiles
*~
# Prerequisites # Prerequisites
*.d *.d
@@ -16,10 +19,6 @@
*.dylib *.dylib
*.dll *.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries # Compiled Static libraries
*.lai *.lai
*.la *.la
@@ -30,3 +29,41 @@
*.exe *.exe
*.out *.out
*.app *.app
src/stenc
# Generated Makefile
# (meta build system like autotools,
# can automatically generate from config.status script
# (which is called by configure script))
Makefile
# http://www.gnu.org/software/automake
Makefile.in
/ar-lib
/mdate-sh
/py-compile
/test-driver
/ylwrap
.deps/
.dirstamp
# http://www.gnu.org/software/autoconf
autom4te.cache
/autoscan.log
/autoscan-*.log
/aclocal.m4
/compile
/config.cache
/config.guess
/config.h.in
/config.log
/config.status
/config.sub
/configure
/configure.scan
/depcomp
/install-sh
/missing
/stamp-h1

View File

@@ -1,3 +1,8 @@
2022-04-22 Jonas Stein <news@jonasstein.de>
* Version upgraded to 1.1.0
* Code cleanup
* Use /dev/random to create a key
2020-06-16 Jonas Stein <news@jonasstein.de> 2020-06-16 Jonas Stein <news@jonasstein.de>
* Version upgraded to 1.0.8 * Version upgraded to 1.0.8
* Merged patches to fix make files and provide more error messages * Merged patches to fix make files and provide more error messages

View File

@@ -1,4 +1,4 @@
AC_INIT([stenc],[1.0.8]) AC_INIT([stenc],[1.1.0])
AC_CONFIG_SRCDIR([src/main.cpp]) AC_CONFIG_SRCDIR([src/main.cpp])
AM_INIT_AUTOMAKE([foreign]) AM_INIT_AUTOMAKE([foreign])
@@ -15,7 +15,11 @@ m4_warn([obsolete],
ISO C90 headers unconditionally.])dnl ISO C90 headers unconditionally.])dnl
# Autoupdate added the next two lines to ensure that your configure # Autoupdate added the next two lines to ensure that your configure
# script's behavior did not change. They are probably safe to remove. # script's behavior did not change. They are probably safe to remove.
AC_CHECK_INCLUDES_DEFAULT
# Disable AC_CHECK_INCLUDES_DEFAULT, because this macro requires autoconf at
# least version 2.70 which is not default yet in many distributions.
# See: https://github.com/scsitape/stenc/issues/33
# AC_CHECK_INCLUDES_DEFAULT
AC_PROG_EGREP AC_PROG_EGREP

View File

@@ -23,6 +23,7 @@ GNU General Public License for more details.
#endif #endif
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <ios>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
@@ -73,7 +74,6 @@ void echo(bool);
std::ofstream logFile; std::ofstream logFile;
int main(int argc, char **argv) { int main(int argc, char **argv) {
bitcheck bc; bitcheck bc;
memset(&bc, 0, 1); memset(&bc, 0, 1);
bc.bit2 = 1; bc.bit2 = 1;
@@ -97,8 +97,7 @@ int main(int argc, char **argv) {
#endif #endif
break; break;
default: default:
std::cerr << "Unknown bit check result " << std::hex << check; std::cerr << "Unknown bit check result " << std::hex << check << "\n";
std::cerr << std::endl;
errorOut("Exiting program because it will not run properly"); errorOut("Exiting program because it will not run properly");
break; break;
} }
@@ -120,7 +119,7 @@ int main(int argc, char **argv) {
} }
if (thisCmd == "--version") { if (thisCmd == "--version") {
std::cout << "stenc v" << VERSION << " - SCSI Tape Encryption Manager\n"; std::cout << "stenc v" << VERSION << " - SCSI Tape Encryption Manager\n";
std::cout << "https://github.com/scsitape/stenc" << std::endl; std::cout << "https://github.com/scsitape/stenc \n";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
if (thisCmd == "-g") { // Check if the help flag was passed. If it was, if (thisCmd == "-g") { // Check if the help flag was passed. If it was,
@@ -134,7 +133,7 @@ int main(int argc, char **argv) {
keyLength = keyLength / 8; keyLength = keyLength / 8;
if (keyLength > SSP_KEY_LENGTH) { if (keyLength > SSP_KEY_LENGTH) {
std::cout << "Warning: Keys over " << (SSP_KEY_LENGTH * 8) std::cout << "Warning: Keys over " << (SSP_KEY_LENGTH * 8)
<< " bits cannot be used by this program!" << std::endl; << " bits cannot be used by this program! \n";
} }
action = 2; // generating key action = 2; // generating key
} else if (thisCmd == "-e") { } else if (thisCmd == "-e") {
@@ -214,9 +213,9 @@ int main(int argc, char **argv) {
} }
kf << newkey << keyDesc; kf << newkey << keyDesc;
kf.close(); kf.close();
std::cout << "Random key saved into '" << keyFile << "'" << std::endl; std::cout << "Random key saved into '" << keyFile << "'\n";
chmod(keyFile.c_str(), 0600); chmod(keyFile.c_str(), 0600);
std::cout << "Permissions of keyfile set to 600" << std::endl; std::cout << "Permissions of keyfile set to 600\n";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
// validate the tape device // validate the tape device
@@ -247,14 +246,14 @@ int main(int argc, char **argv) {
logFile.open(LOGFILE, std::ios::app); logFile.open(LOGFILE, std::ios::app);
if (!logFile.is_open()) { if (!logFile.is_open()) {
std::cout << "Warning: Could not open '" << LOGFILE std::cout << "Warning: Could not open '" << LOGFILE
<< "' for key change auditing!" << std::endl; << "' for key change auditing!\n";
} }
chmod(LOGFILE, 0600); chmod(LOGFILE, 0600);
if (action == 0) { if (action == 0) {
std::cout << "Status for " << tapeDrive << std::endl; std::cout << "Status for " << tapeDrive << "\n"
std::cout << "--------------------------------------------------" << "--------------------------------------------------\n";
<< std::endl;
if (detail) if (detail)
inquiryDrive(tapeDrive); inquiryDrive(tapeDrive);
showDriveStatus(tapeDrive, detail); showDriveStatus(tapeDrive, detail);
@@ -274,14 +273,13 @@ int main(int argc, char **argv) {
echo(false); echo(false);
getline(std::cin, p1); getline(std::cin, p1);
echo(true); echo(true);
std::cout << std::endl; std::cout << "\nRe-enter key in hex format: ";
std::cout << "Re-enter key in hex format: ";
echo(false); echo(false);
getline(std::cin, p2); getline(std::cin, p2);
echo(true); echo(true);
std::cout << std::endl; std::cout << "\n";
if (p1 != p2) { if (p1 != p2) {
std::cout << "Keys do not match!!" << std::endl; std::cout << "Keys do not match!\n";
} else { } else {
ki.load(p1); ki.load(p1);
if (ki.valid) { if (ki.valid) {
@@ -292,7 +290,7 @@ int main(int argc, char **argv) {
done = true; done = true;
} }
} else } else
std::cout << "Invalid key!" << std::endl; std::cout << "Invalid key!\n";
} }
} }
drvOptions.keyName = keyDesc; drvOptions.keyName = keyDesc;
@@ -367,7 +365,7 @@ int main(int argc, char **argv) {
// exits to shell with an error message // exits to shell with an error message
void errorOut(std::string const message) { void errorOut(std::string const message) {
std::cerr << "Error: " << message << std::endl; std::cerr << "Error: " << message << "\n";
showUsage(); showUsage();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@@ -376,10 +374,9 @@ void errorOut(std::string const message) {
void showUsage() { void showUsage() {
std::cout std::cout
<< "Usage: stenc --version | -g <length> -k <file> [-kd <description>] | " << "Usage: stenc --version | -g <length> -k <file> [-kd <description>] | "
"-f <device> [--detail] [-e <on/mixed/rawread/off> [-k <file>] [-kd " "-f <device> [--detail] [-e <on/mixed/rawread/off> [-k <file>] "
"<description>] [-a <index>] [--protect | --unprotect] [--ckod] ]" "[-kd <description>] [-a <index>] [--protect | --unprotect] [--ckod] ]\n\n"
<< std::endl; "Type 'man stenc' for more information.\n";
std::cout << "Type 'man stenc' for more information." << std::endl;
} }
void inquiryDrive(std::string tapeDevice) { void inquiryDrive(std::string tapeDevice) {
// todo: std::cout should not be used outside main() // todo: std::cout should not be used outside main()
@@ -422,58 +419,58 @@ void showDriveStatus(std::string tapeDrive, bool detail) {
) )
emode = "off"; emode = "off";
std::cout << emode << std::endl; std::cout << emode << "\n";
if (detail) { if (detail) {
std::cout << std::left << std::setw(25) << "Drive Output:"; std::cout << std::left << std::setw(25) << "Drive Output:";
switch ((int)opt->des.decryptionMode) { switch ((int)opt->des.decryptionMode) {
case 0x0: case 0x0:
std::cout << "Not decrypting" << std::endl; std::cout << "Not decrypting\n";
std::cout << std::setw(25) << " " std::cout << std::setw(25) << " "
<< "Raw encrypted data not outputted" << std::endl; << "Raw encrypted data not outputted\n";
break; break;
case 0x1: case 0x1:
std::cout << "Not decrypting" << std::endl; std::cout << "Not decrypting\n";
std::cout << std::setw(25) << " " std::cout << std::setw(25) << " "
<< "Raw encrypted data outputted" << std::endl; << "Raw encrypted data outputted\n";
break; break;
case 0x2: case 0x2:
std::cout << "Decrypting" << std::endl; std::cout << "Decrypting\n";
std::cout << std::setw(25) << " " std::cout << std::setw(25) << " "
<< "Unencrypted data not outputted" << std::endl; << "Unencrypted data not outputted\n";
break; break;
case 0x3: case 0x3:
std::cout << "Decrypting" << std::endl; std::cout << "Decrypting\n";
std::cout << std::setw(25) << " " std::cout << std::setw(25) << " "
<< "Unencrypted data outputted" << std::endl; << "Unencrypted data outputted\n";
break; break;
default: default:
std::cout << "Unknown '0x" << std::hex << (int)opt->des.decryptionMode std::cout << "Unknown '0x" << std::hex << (int)opt->des.decryptionMode
<< "' " << std::endl; << "' \n";
break; break;
} }
std::cout << std::setw(25) << "Drive Input:"; std::cout << std::setw(25) << "Drive Input:";
switch ((int)opt->des.encryptionMode) { switch ((int)opt->des.encryptionMode) {
case 0x0: case 0x0:
std::cout << "Not encrypting" << std::endl; std::cout << "Not encrypting\n";
break; break;
case 0x2: case 0x2:
std::cout << "Encrypting" << std::endl; std::cout << "Encrypting\n";
break; break;
default: default:
std::cout << "Unknown result '0x" << std::hex std::cout << "Unknown result '0x" << std::hex
<< (int)opt->des.encryptionMode << "'" << std::endl; << (int)opt->des.encryptionMode << "'\n";
break; break;
} }
if (opt->des.RDMD == 1) { if (opt->des.RDMD == 1) {
std::cout << std::setw(25) << " " std::cout << std::setw(25) << " "
<< "Protecting from raw read" << std::endl; << "Protecting from raw read\n";
} }
std::cout << std::setw(25) << "Key Instance Counter:" << std::dec std::cout << std::setw(25) << "Key Instance Counter:" << std::dec
<< BSLONG(opt->des.keyInstance) << std::endl; << BSLONG(opt->des.keyInstance) << "\n";
if (opt->des.algorithmIndex != 0) { if (opt->des.algorithmIndex != 0) {
std::cout << std::setw(25) << "Encryption Algorithm:" << std::hex std::cout << std::setw(25) << "Encryption Algorithm:" << std::hex
<< (int)opt->des.algorithmIndex << std::endl; << (int)opt->des.algorithmIndex << "\n";
} }
} }
if (opt->kads.size() > 0) { if (opt->kads.size() > 0) {
@@ -510,34 +507,33 @@ void showVolumeStatus(std::string tapeDrive) {
std::cout << std::left << std::setw(25) << "Volume Compressed:"; std::cout << std::left << std::setw(25) << "Volume Compressed:";
switch (opt->nbes.compressionStatus) { switch (opt->nbes.compressionStatus) {
case 0x00: case 0x00:
std::cout << "Drive cannot determine" << std::endl; std::cout << "Drive cannot determine\n";
break; break;
default: default:
std::cout << "Unknown result '" << std::hex std::cout << "Unknown result '" << std::hex
<< (int)opt->nbes.compressionStatus << "'" << std::endl; << (int)opt->nbes.compressionStatus << "'\n";
break; break;
} }
} }
std::cout << std::left << std::setw(25) << "Volume Encryption:"; std::cout << std::left << std::setw(25) << "Volume Encryption:";
switch ((int)opt->nbes.encryptionStatus) { switch ((int)opt->nbes.encryptionStatus) {
case 0x01: case 0x01:
std::cout << "Unable to determine" << std::endl; std::cout << "Unable to determine\n";
break; break;
case 0x02: case 0x02:
std::cout << "Logical block is not a logical block" << std::endl; std::cout << "Logical block is not a logical block\n";
break; break;
case 0x03: case 0x03:
std::cout << "Not encrypted" << std::endl; std::cout << "Not encrypted\n";
break; break;
case 0x05: case 0x05:
std::cout << "Encrypted and able to decrypt" << std::endl; std::cout << "Encrypted and able to decrypt\n";
if (opt->nbes.RDMDS == 1) if (opt->nbes.RDMDS == 1)
std::cout << std::left << std::setw(25) << " " std::cout << std::left << std::setw(25)
<< "Protected from raw read" << std::endl; << " Protected from raw read\n";
break; break;
case 0x06: case 0x06:
std::cout << "Encrypted, but unable to decrypt due to invalid key. " std::cout << "Encrypted, but unable to decrypt due to invalid key.\n";
<< std::endl;
if (opt->kads.size() > 0) { if (opt->kads.size() > 0) {
for (unsigned int i = 0; i < opt->kads.size(); i++) { for (unsigned int i = 0; i < opt->kads.size(); i++) {
std::stringstream lbl; std::stringstream lbl;
@@ -561,19 +557,17 @@ void showVolumeStatus(std::string tapeDrive) {
} }
} }
if (opt->nbes.RDMDS == 1) if (opt->nbes.RDMDS == 1)
std::cout << std::left << std::setw(25) << " " std::cout << std::left << std::setw(25) << " Protected from raw read\n";
<< "Protected from raw read" << std::endl;
break; break;
default: default:
std::cout << "Unknown result '" << std::hex std::cout << "Unknown result '" << std::hex
<< (int)opt->nbes.encryptionStatus << "'" << std::endl; << (int)opt->nbes.encryptionStatus << "'\n";
break; break;
} }
if (opt->nbes.algorithmIndex != 0) { if (opt->nbes.algorithmIndex != 0) {
std::cout << std::left << std::setw(25) std::cout << std::left << std::setw(25)
<< "Volume Algorithm:" << (int)opt->nbes.algorithmIndex << "Volume Algorithm:" << (int)opt->nbes.algorithmIndex << "\n";
<< std::endl;
} }
delete opt; delete opt;
@@ -586,6 +580,7 @@ void echo(bool on = true) {
on ? (settings.c_lflag | ECHO) : (settings.c_lflag & ~(ECHO)); on ? (settings.c_lflag | ECHO) : (settings.c_lflag & ~(ECHO));
tcsetattr(STDIN_FILENO, TCSANOW, &settings); tcsetattr(STDIN_FILENO, TCSANOW, &settings);
} }
std::string timestamp() { std::string timestamp() {
time_t tm{}; time_t tm{};
time(&tm); time(&tm);
@@ -611,9 +606,9 @@ std::string randomKey(int length) {
} }
random.close(); random.close();
} else { } else {
std::cout << "Enter random keys on the keyboard to seed the " std::cout << "Enter random keys on the keyboard to seed the generator.\n"
"generator.\nEnd by pressing enter..." "End by pressing enter...\n";
<< std::endl;
double check = 0; double check = 0;
char c = 0; char c = 0;
echo(false); echo(false);

View File

@@ -492,52 +492,50 @@ void readIOError(int err) {
std::cerr << "ERROR: "; std::cerr << "ERROR: ";
switch (err) { switch (err) {
case EAGAIN: case EAGAIN:
std::cerr << "Device already open" << std::endl; std::cerr << "Device already open.\n";
break; break;
case EBUSY: case EBUSY:
std::cerr << "Device Busy" << std::endl; std::cerr << "Device Busy.\n";
break; break;
case ETIMEDOUT: case ETIMEDOUT:
std::cerr << "Device operation timed out" << std::endl; std::cerr << "Device operation timed out\n";
break; break;
case EIO: case EIO:
std::cerr << "Device I/O Error." << std::endl; std::cerr << "Device I/O Error.\n";
break; break;
case EPERM: case EPERM:
std::cerr << "You do not have privileges to do this. Are you root?" std::cerr << "You do not have privileges to do this. Are you root?\n";
<< std::endl;
break; break;
#ifdef OS_AIX #ifdef OS_AIX
case EBADF: case EBADF:
std::cerr << "EBADF" << std::endl; std::cerr << "EBADF\n";
break; break;
case EFAULT: case EFAULT:
std::cerr << "EFAULT" << std::endl; std::cerr << "EFAULT\n";
break; break;
case EINTR: case EINTR:
std::cerr << "EINTR" << std::endl; std::cerr << "EINTR\n";
break; break;
case EINVAL: case EINVAL:
std::cerr << "Invalid device" << std::endl; std::cerr << "Invalid device.\n";
break; break;
case ENOTTY: case ENOTTY:
std::cerr << "ENOTTY" << std::endl; std::cerr << "ENOTTY\n";
break; break;
case ENODEV: case ENODEV:
std::cerr << "Device is not responding" << std::endl; std::cerr << "Device is not responding.\n";
break; break;
case ENXIO: case ENXIO:
std::cerr << "ENXIO" << std::endl; std::cerr << "ENXIO\n";
break; break;
#endif #endif
default: default:
if (errno != 0) { if (errno != 0) {
std::cerr << "0x" << std::hex << errno << " " << strerror(errno) std::cerr << "0x" << std::hex << errno << " " << strerror(errno) << "\n";
<< std::endl;
} }
} }
} }
@@ -571,20 +569,17 @@ void outputSense(SCSI_PAGE_SENSE *sd) {
break; break;
} }
std::cerr << " (0x" << std::hex << (sd->senseKey); std::cerr << " (0x" << std::hex << (sd->senseKey) << ")\n";
std::cerr << ")\n";
std::cerr << std::left << std::setw(25) << " ASC:" std::cerr << std::left << std::setw(25) << " ASC:"
<< "0x" << std::hex << (sd->addSenseCode); << "0x" << std::hex << (sd->addSenseCode) << "\n";
std::cerr << "\n";
std::cerr << std::left << std::setw(25) << " ASCQ:" std::cerr << std::left << std::setw(25) << " ASCQ:"
<< "0x" << std::hex << (sd->addSenseCodeQual); << "0x" << std::hex << (sd->addSenseCodeQual) << "\n";
std::cerr << "\n";
if (sd->addSenseLen > 0) { if (sd->addSenseLen > 0) {
std::cerr << std::left << std::setw(25) << " Additional data:" std::cerr << std::left << std::setw(25) << " Additional data:"
<< "0x"; << "0x";
for (int i = 0; i < sd->addSenseLen; i++) { for (int i = 0; i < sd->addSenseLen; i++) {
std::cerr << std::hex << (sd->addSenseData[i]); std::cerr << std::hex << (sd->addSenseData[i]);

View File

@@ -1,5 +1,5 @@
Name: stenc Name: stenc
Version: 1.0.9 Version: 1.1.0
Release: 3%{?dist} Release: 3%{?dist}
Summary: SCSI Tape Encryption Manager Summary: SCSI Tape Encryption Manager