diff --git a/Common/DtaDev.h b/Common/DtaDev.h index 473f7bd0..5995eec9 100644 --- a/Common/DtaDev.h +++ b/Common/DtaDev.h @@ -1,5 +1,6 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -283,6 +284,9 @@ class DtaDev { virtual uint8_t exec(DtaCommand * cmd, DtaResponse & resp, uint8_t protocol = 0x01) = 0; /** return the communications ID to be used for sessions to this device */ virtual uint16_t comID() = 0; + /* Print random number of bytes specified in the argument */ + virtual uint8_t printRandomBytes(uint8_t num_of_bytes) = 0; + bool no_hash_passwords; /** disables hashing of passwords */ sedutiloutput output_format; /** standard, readable, JSON */ protected: diff --git a/Common/DtaDevEnterprise.cpp b/Common/DtaDevEnterprise.cpp index 76e6e39d..7e4bbd09 100644 --- a/Common/DtaDevEnterprise.cpp +++ b/Common/DtaDevEnterprise.cpp @@ -1,6 +1,7 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. This software is Copyright 2017 Spectra Logic Corporation +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -1677,6 +1678,11 @@ uint8_t DtaDevEnterprise::objDump(char *sp, char * auth, char *pass, LOG(D1) << "Exiting DtaDevEnterprise::objDump"; return 0; } + +uint8_t DtaDevEnterprise::printRandomBytes(uint8_t num_of_bytes) { + LOG(E) << "printRandomBytes() is not implemented for Enterprise"; + return -1; +} #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/Common/DtaDevEnterprise.h b/Common/DtaDevEnterprise.h index 5350da5c..19e1f624 100644 --- a/Common/DtaDevEnterprise.h +++ b/Common/DtaDevEnterprise.h @@ -1,6 +1,7 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. This software is Copyright 2017 Spectra Logic Corporation +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -205,6 +206,10 @@ class DtaDevEnterprise : public DtaDevOS { uint8_t rawCmd(char *sp, char *hexauth, char *pass, char *hexinvokingUID, char *hexmethod, char *hexparms); + /** Print random number of bytes + * @param num_of_bytes Number of bytes to print + */ + uint8_t printRandomBytes(uint8_t num_of_bytes); protected: uint8_t getDefaultPassword(); private: diff --git a/Common/DtaDevGeneric.cpp b/Common/DtaDevGeneric.cpp index 6f5d57c6..efe5c72e 100644 --- a/Common/DtaDevGeneric.cpp +++ b/Common/DtaDevGeneric.cpp @@ -1,5 +1,6 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -102,6 +103,7 @@ uint16_t DtaDevGeneric::comID() uint8NOCODE(exec,DtaCommand * cmd, DtaResponse & resp, uint8_t protocol) uint8NOCODE(objDump,char *sp, char * auth, char *pass,char * objID) uint8NOCODE(rawCmd,char *sp, char * auth, char *pass,char *invoker, char *method, char *plist) +uint8NOCODE(printRandomBytes,uint8_t num_of_bytes) #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/Common/DtaDevGeneric.h b/Common/DtaDevGeneric.h index 9f5f9752..3c2bbbc2 100644 --- a/Common/DtaDevGeneric.h +++ b/Common/DtaDevGeneric.h @@ -1,5 +1,6 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -224,4 +225,6 @@ class DtaDevGeneric : public DtaDevOS { uint8_t exec(DtaCommand * cmd, DtaResponse & resp, uint8_t protocol = 1) ; /** return the communications ID to be used for sessions to this device */ uint16_t comID() ; + + uint8_t printRandomBytes(uint8_t num_of_bytes); }; diff --git a/Common/DtaDevOpal.cpp b/Common/DtaDevOpal.cpp index 3014ebb9..977fd533 100644 --- a/Common/DtaDevOpal.cpp +++ b/Common/DtaDevOpal.cpp @@ -1,5 +1,6 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -1834,3 +1835,47 @@ uint8_t DtaDevOpal::rawCmd(char *sp, char * hexauth, char *pass, LOG(D1) << "Exiting DtaDevEnterprise::rawCmd"; return 0; } + +uint8_t DtaDevOpal::printRandomBytes(uint8_t num_of_bytes) { + LOG(D1) << "Entering DtaDevOpal::printRandomBytes"; + DtaCommand *cmd = new DtaCommand(); + if (NULL == cmd) { + LOG(E) << "Create session object failed"; + return DTAERROR_OBJECT_CREATE_FAILED; + } + cmd->reset(OPAL_UID::OPAL_THISSP_UID, OPAL_METHOD::RANDOM); + cmd->addToken(OPAL_TOKEN::STARTLIST); + cmd->addToken(num_of_bytes); + cmd->addToken(OPAL_TOKEN::ENDLIST); + cmd->complete(); + + session = new DtaSession(this); + uint8_t lastRC; + if (NULL == session) { + LOG(E) << "Unable to create session object "; + return DTAERROR_OBJECT_CREATE_FAILED; + } + if ((lastRC = session->start(OPAL_UID::OPAL_ADMINSP_UID)) != 0) { + LOG(E) << "Unable to start Unauthenticated session " << dev; + delete session; + return lastRC; + } + if ((lastRC = session->sendCommand(cmd, response)) != 0) { + LOG(E) << "setupLockingRange Failed "; + delete cmd; + delete session; + return lastRC; + } + + + uint8_t data[32]; + response.getBytes(1, data); + cout << HEXON(2); + for (uint8_t i=1; i<=num_of_bytes; ++i) + cout << ((uint32_t)data[num_of_bytes-i] & 0xFF); + cout << HEXOFF << std::endl; + delete cmd; + delete session; + LOG(D1) << "Exiting DtaDevOpal::printRandomBytes"; + return 0; +} diff --git a/Common/DtaDevOpal.h b/Common/DtaDevOpal.h index 60004db4..552f9550 100644 --- a/Common/DtaDevOpal.h +++ b/Common/DtaDevOpal.h @@ -1,5 +1,6 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -260,6 +261,11 @@ class DtaDevOpal : public DtaDevOS { */ uint8_t rawCmd(char *sp, char * auth, char *pass, char *invoker, char *method, char *plist); + + /** Print random number of bytes + * @param num_of_bytes Number of bytes to print + */ + uint8_t printRandomBytes(uint8_t num_of_bytes); protected: /** Primitive to handle the setting of a value in the locking sp. * @param table_uid UID of the table diff --git a/Common/DtaOptions.cpp b/Common/DtaOptions.cpp index fdacc403..2478b44a 100644 --- a/Common/DtaOptions.cpp +++ b/Common/DtaOptions.cpp @@ -1,5 +1,6 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -95,6 +96,9 @@ void usage() printf(" revert the device using the PSID *ERASING* *ALL* the data \n"); printf("--printDefaultPassword \n"); printf(" print MSID \n"); + printf("--printRandomBytes \n"); + printf(" Print random generated bytes from \n"); + printf(" should be between 1 to 32 (both inclusive) \n"); printf("\n"); printf("Examples \n"); printf("sedutil-cli --scan \n"); @@ -511,6 +515,7 @@ uint8_t DtaOptions(int argc, char * argv[], DTA_OPTIONS * opts) END_OPTION BEGIN_OPTION(objDump, 5) i += 4; OPTION_IS(device) END_OPTION BEGIN_OPTION(printDefaultPassword, 1) OPTION_IS(device) END_OPTION + BEGIN_OPTION(printRandomBytes, 2, 2) OPTION_IS(byte_count) OPTION_IS(device) END_OPTION BEGIN_OPTION(rawCmd, 7) i += 6; OPTION_IS(device) END_OPTION else { LOG(E) << "Invalid command line argument " << argv[i]; diff --git a/Common/DtaOptions.h b/Common/DtaOptions.h index c012af1d..4ee22c3b 100644 --- a/Common/DtaOptions.h +++ b/Common/DtaOptions.h @@ -1,5 +1,6 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -44,6 +45,7 @@ typedef struct _DTA_OPTIONS { bool no_hash_passwords; /** global parameter, disables hashing of passwords */ sedutiloutput output_format; + uint8_t byte_count; } DTA_OPTIONS; /** Print a usage message */ void usage(); @@ -95,6 +97,7 @@ typedef enum _sedutiloption { validatePBKDF2, objDump, printDefaultPassword, + printRandomBytes, rawCmd, } sedutiloption; diff --git a/Common/sedutil.cpp b/Common/sedutil.cpp index fe6df19a..9e0239b9 100644 --- a/Common/sedutil.cpp +++ b/Common/sedutil.cpp @@ -1,5 +1,6 @@ /* C:B************************************************************************** This software is Copyright 2014-2017 Bright Plaza Inc. +This software is Copyright 2023 Nutanix, Inc. This file is part of sedutil. @@ -259,6 +260,15 @@ int main(int argc, char * argv[]) LOG(D) << "print default password"; return d->printDefaultPassword(); break; + case sedutiloption::printRandomBytes: + { + uint8_t num_of_bytes = atol(argv[opts.byte_count]); + LOG(D) << "print random " << num_of_bytes << " byte(s)"; + if ((num_of_bytes > 0) && (num_of_bytes <= 32)) + return d->printRandomBytes(num_of_bytes); + LOG(E) << "Random byte count between 1 to 32 are supported"; + break; + } case sedutiloption::rawCmd: LOG(D) << "Performing cmdDump "; return d->rawCmd(argv[argc - 7], argv[argc - 6], argv[argc - 5], argv[argc - 4], argv[argc - 3], argv[argc - 2]);