Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Random bytes feature #458

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Common/DtaDev.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions Common/DtaDevEnterprise.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2017 Spectra Logic Corporation
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions Common/DtaDevEnterprise.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2017 Spectra Logic Corporation
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions Common/DtaDevGeneric.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions Common/DtaDevGeneric.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -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);
};
45 changes: 45 additions & 0 deletions Common/DtaDevOpal.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions Common/DtaDevOpal.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Common/DtaOptions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -95,6 +96,9 @@ void usage()
printf(" revert the device using the PSID *ERASING* *ALL* the data \n");
printf("--printDefaultPassword <device>\n");
printf(" print MSID \n");
printf("--printRandomBytes <count> <device>\n");
printf(" Print random generated <count> bytes from <device> \n");
printf(" <count> should be between 1 to 32 (both inclusive) \n");
printf("\n");
printf("Examples \n");
printf("sedutil-cli --scan \n");
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 3 additions & 0 deletions Common/DtaOptions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -95,6 +97,7 @@ typedef enum _sedutiloption {
validatePBKDF2,
objDump,
printDefaultPassword,
printRandomBytes,
rawCmd,

} sedutiloption;
Expand Down
10 changes: 10 additions & 0 deletions Common/sedutil.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>
This software is Copyright 2023 Nutanix, Inc. <opensource@nutanix.com>

This file is part of sedutil.

Expand Down Expand Up @@ -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]);
Expand Down