]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Allow hashing with a custom work factor
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 21 Jun 2021 16:14:02 +0000 (18:14 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 16 Sep 2021 12:12:28 +0000 (14:12 +0200)
pdns/rec_control.cc
pdns/recursordist/docs/manpages/rec_control.1.rst

index 229229d319aa7e1377cae83181322099a8533b0a..a7ab7cab1d0d72cb78f70dd4f60841a0e54512b2 100644 (file)
@@ -108,6 +108,31 @@ int main(int argc, char** argv)
     sockname.append(".controlsocket");
 
     const vector<string>&commands=arg().getCommands();
+
+    if (commands.size() >= 1 && commands.at(0) == "hash-password") {
+      uint64_t workFactor = CredentialsHolder::s_defaultWorkFactor;
+      if (commands.size() > 1) {
+        try {
+          workFactor = pdns_stou(commands.at(1));
+        }
+        catch (const std::exception& e) {
+          cerr << "Unable to parse the supplied work factor: " << e.what() << endl;
+          return EXIT_FAILURE;
+        }
+      }
+
+      auto password = CredentialsHolder::readFromTerminal();
+
+      try {
+        cout << hashPassword(password.getString(), workFactor, CredentialsHolder::s_defaultParallelFactor, CredentialsHolder::s_defaultBlockSize) << endl;
+        return EXIT_SUCCESS;
+      }
+      catch (const std::exception& e) {
+        cerr << "Error while hashing the supplied password: " << e.what() << endl;
+        return EXIT_FAILURE;
+      }
+    }
+
     string command;
     int fd = -1;
     unsigned int i = 0;
@@ -141,11 +166,6 @@ int main(int argc, char** argv)
           throw PDNSException("Command needs a file argument");
         }
       }
-      else if (commands.at(i) == "hash-password") {
-        auto password = CredentialsHolder::readFromTerminal();
-        cout << hashPassword(password.getString()) << endl;
-        return 0;
-      }
       ++i;
     }
 
index b0fb9d9d7e696d69d7e41b9dfce9aecd85463537..7bd6b857a16ff8db2155a1fe4692f1b324d54dc3 100644 (file)
@@ -152,10 +152,12 @@ get-parameter *KEY* [*KEY*]...
 get-qtypelist
     Retrieves QType statistics. Queries from cache aren't being counted yet.
 
-hash-password
+hash-password [*WORK-FACTOR*]
     Asks for a password then returns the hashed and salted version,
     to use as a webserver password or API key. This command does
     not contact the recursor but does the hashing inside rec_control.
+    An optional scrypt work factor can be specified, in power of two.
+    The default is 1024.
 
 help
     Shows a list of supported commands understood by the running