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

index 12285832d0bd797d16bdde9953b38ac4236368e1..e9dfa7f29e82f2227687ba5389dc5cc073f6e3c5 100644 (file)
@@ -189,9 +189,11 @@ edit-zone *ZONE*
     **EDITOR** is empty, *pdnsutil* falls back to using *editor*.
 get-meta *ZONE* [*ATTRIBUTE*]...
     Get zone metadata. If no *ATTRIBUTE* given, lists all known.
-hash-password
+hash-password [*WORK-FACTOR*]
     This convenience command asks for a password and returns a hashed
     and salted version, for use as a webserver password or api key.
+    An optional scrypt work factor can be specified, in power of two,
+    otherwise it defaults to 1024.
 hash-zone-record *ZONE* *RNAME*
     This convenience command hashes the name *RNAME* according to the
     NSEC3 settings of *ZONE*. Refuses to hash for zones with no NSEC3
index ac32efc0e000c03063ff0ae87a2f0ad4275eb1a6..a4ed9a819575cffed6d9eceadde368174f1655e7 100644 (file)
@@ -2332,7 +2332,7 @@ try
     cout<<"generate-zone-key {zsk|ksk} [ALGORITHM] [BITS]"<<endl;
     cout<<"                                   Generate a ZSK or KSK to stdout with specified ALGORITHM and BITS"<<endl;
     cout<<"get-meta ZONE [KIND ...]           Get zone metadata. If no KIND given, lists all known"<<endl;
-    cout<<"hash-password                      Ask for a plaintext password or api key and output a hashed and salted version"<<endl;
+    cout<<"hash-password [WORK FACTOR]        Ask for a plaintext password or api key and output a hashed and salted version"<<endl;
     cout<<"hash-zone-record ZONE RNAME        Calculate the NSEC3 hash for RNAME in ZONE"<<endl;
 #ifdef HAVE_P11KIT1
     cout<<"hsm assign ZONE ALGORITHM {ksk|zsk} MODULE SLOT PIN LABEL"<<endl<<
@@ -2483,10 +2483,28 @@ try
 
     return 0;
   }
-  else if (cmds[0]=="hash-password") {
+  else if (cmds.at(0) == "hash-password") {
+    uint64_t workFactor = CredentialsHolder::s_defaultWorkFactor;
+    if (cmds.size() > 1) {
+      try {
+        workFactor = pdns_stou(cmds.at(1));
+      }
+      catch (const std::exception& e) {
+        cerr<<"Unable to parse the supplied work factor: "<<e.what()<<endl;
+        return 1;
+      }
+    }
+
     auto password = CredentialsHolder::readFromTerminal();
-    cout<<hashPassword(password.getString())<<endl;
-    return 0;
+
+    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 1;
+    }
   }
 
   DNSSECKeeper dk;