Skip to content

Commit 69a2a4d

Browse files
author
Alex
committed
Option to print the password hash
Useful for users, who want to use different utilities with their SED drives, and also in combination with "-x -n", meaning "no hash", "hex", so no plaintext passwords are saved to scripts or shell history.
1 parent 5484270 commit 69a2a4d

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

Common/DtaDev.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ along with sedutil. If not, see <http://www.gnu.org/licenses/>.
3232
#include "DtaConstants.h"
3333
#include "DtaEndianFixup.h"
3434
#include "DtaHexDump.h"
35+
#include "DtaHashPwd.h"
3536

3637
using namespace std;
3738

@@ -211,6 +212,24 @@ void DtaDev::discovery0()
211212
while (cpos < epos);
212213

213214
}
215+
216+
uint8_t DtaDev::printPasswordHash(char * password)
217+
{
218+
LOG(D1) << "Entering DtaDev::printPasswordHash()";
219+
vector<uint8_t> hash;
220+
DtaHashPwd(hash, password, this);
221+
222+
/* std::hex overwrites flags; save them, so we do not alter other output later */
223+
ios_base::fmtflags saved_flags = cout.flags();
224+
225+
/* First two bytes are actually the opal header */
226+
for (size_t i = 2; i < hash.size(); ++i)
227+
cout << hex << setfill('0') << setw(2) << (int)hash[i];
228+
cout << endl;
229+
cout.flags(saved_flags);
230+
return 0;
231+
}
232+
214233
void DtaDev::puke()
215234
{
216235
LOG(D1) << "Entering DtaDev::puke()";

Common/DtaDev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class DtaDev {
7474
*/
7575
void discovery0();
7676

77+
/** Print password hash, computed with this device's serial number
78+
*/
79+
uint8_t printPasswordHash(char * password);
7780
/*
7881
* virtual methods required in the OS specific
7982
* device class

Common/DtaOptions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ void usage()
9696
printf(" revert the device using the PSID *ERASING* *ALL* the data \n");
9797
printf("--printDefaultPassword <device>\n");
9898
printf(" print MSID \n");
99+
printf("--printPasswordHash <password> <device>\n");
100+
printf(" print the hash of the password \n");
101+
printf(" as computed by sedutil. Hex-ecoded.\n");
99102
printf("\n");
100103
printf("Examples \n");
101104
printf("sedutil-cli --scan \n");
@@ -515,6 +518,10 @@ uint8_t DtaOptions(int argc, char * argv[], DTA_OPTIONS * opts)
515518
END_OPTION
516519
BEGIN_OPTION(objDump, 5) i += 4; OPTION_IS(device) END_OPTION
517520
BEGIN_OPTION(printDefaultPassword, 1) OPTION_IS(device) END_OPTION
521+
BEGIN_OPTION(printPasswordHash, 2)
522+
OPTION_IS(password)
523+
OPTION_IS(device)
524+
END_OPTION
518525
BEGIN_OPTION(rawCmd, 7) i += 6; OPTION_IS(device) END_OPTION
519526
else {
520527
LOG(E) << "Invalid command line argument " << argv[i];

Common/DtaOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ typedef enum _sedutiloption {
9696
validatePBKDF2,
9797
objDump,
9898
printDefaultPassword,
99+
printPasswordHash,
99100
rawCmd,
100101

101102
} sedutiloption;

Common/sedutil.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ int main(int argc, char * argv[])
261261
LOG(D) << "print default password";
262262
return d->printDefaultPassword();
263263
break;
264+
case sedutiloption::printPasswordHash:
265+
LOG(D) << "print password hash";
266+
return d->printPasswordHash(argv[opts.password]);
267+
break;
264268
case sedutiloption::rawCmd:
265269
LOG(D) << "Performing cmdDump ";
266270
return d->rawCmd(argv[argc - 7], argv[argc - 6], argv[argc - 5], argv[argc - 4], argv[argc - 3], argv[argc - 2]);

0 commit comments

Comments
 (0)