diff options
author | John Klug <john.klug@multitech.com> | 2019-12-10 13:41:57 -0600 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2019-12-10 13:41:57 -0600 |
commit | 65662db674cb3529331dc5db83be9bd9220f072d (patch) | |
tree | c90bfda38d3a1bcbdcb2d758a97fa4eb16113912 /src/hashpwd.cpp | |
parent | b3c010190ffcc295dcc45781abfb1e66e1eb4c46 (diff) | |
download | mts-id-eeprom-0.5.0.tar.gz mts-id-eeprom-0.5.0.tar.bz2 mts-id-eeprom-0.5.0.zip |
Read password from stdin0.5.0
Diffstat (limited to 'src/hashpwd.cpp')
-rw-r--r-- | src/hashpwd.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/hashpwd.cpp b/src/hashpwd.cpp index 6bc322c..1ea3e2c 100644 --- a/src/hashpwd.cpp +++ b/src/hashpwd.cpp @@ -153,6 +153,7 @@ void usage(void) " -V version" << endl << " -v verbose" << endl << " -d did Device ID (serial #)" << endl << + " -i Read password from standard input" << endl << " -m mac Ethernet mac address" << endl << " -p password" << endl << " -u uuid UUID (base 16)" << endl << @@ -163,17 +164,20 @@ void usage(void) } int main(int argc, char **argv) { - int opt = 0, p = 0, d = 0, m = 0, u=0; + int opt = 0, p = 0, d = 0, m = 0, u=0, iopt = 0; + char c; unsigned long long fudge = 0; short unsigned int prefix; string did, mac, pwd, salt, uuid; + int supplied_password = 0; - while ((opt = getopt(argc,argv,"Vd:m:p:u:v")) != EOF) + while ((opt = getopt(argc,argv,"Vd:im:p:u:v")) != EOF) switch(opt) { case 'V': cout << MYVERSION << endl; exit(0); case 'v': v = 1; cout << " verbose" <<endl; break; case 'd': d = 1; did = optarg ; (v==1) && cout << "device-id is " << did << endl; break; + case 'i': iopt = 1; (v==1) && cout << "Reading password from stdin " << endl; break; case 'm': m = 1; mac = optarg ; (v==1) && cout << "Ethernet mac is " << mac << endl; break; case 'p': p = 1; pwd = optarg ; (v==1) && cout << "User defined password is \"" << pwd << "\"" << endl; break; case 'u': u = 1; uuid = optarg ; (v==1) && cout << "UUID is \"" << uuid << "\"" << endl; break; @@ -187,6 +191,15 @@ int main(int argc, char **argv) { cout << " argv[" << i << "]=\"" << argv[i] << "\"" << endl; } + if (p && iopt) { + cout << "Cannot have both a command line password and standard input password" << endl; + usage(); + } + + if (p || iopt) + supplied_password = 1; + + if ((p && d) || (p && m)) { cout << "Must use either a supplied password or Device ID and Ethernet MAC address, but not all three." << endl; usage(); @@ -212,13 +225,33 @@ int main(int argc, char **argv) { (v == 1) && cout << "prefix is " << prefixStream.str() << endl; + if(iopt) { + while(1) + { + cin.get(c); + if (cin.eof()) + break; + pwd.push_back(c); + } + } + + // Dump password in hex + if(v == 1) { + cout.width(2); + cout.fill(0); + cout << hex; + cout << right; + for(unsigned int i=0; i<pwd.length(); i++) + cout << hex << right << (int)pwd[i]; + cout << endl; + } string passwd_str; string passwd0, passwdnew; SHA256_CTX sha256; unsigned char hash[SHA256_DIGEST_LENGTH]; - if(!p) { + if(!(p || iopt)) { if (m) passwd0 = did + "|" + mac; else if (u) @@ -227,7 +260,7 @@ int main(int argc, char **argv) { while (1) { unsigned char append[9]; - (v == 1) && cout << "pwdinput: " << passwdnew << endl; + (v == 1) && cout << "pwdinput: " << passwdnew << endl; SHA256_Init(&sha256); SHA256_Update(&sha256,passwdnew.c_str(),passwdnew.length()); @@ -264,7 +297,7 @@ int main(int argc, char **argv) { cout << "pass=" << pwd << endl; - passwd_str = prefixStream.str() + pwd + salt; + passwd_str = prefixStream.str() + pwd + salt; SHA256_Init(&sha256); SHA256_Update(&sha256,passwd_str.c_str(),passwd_str.length()); |