]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
make pdnsutil support base64 encoded keys for ipcipher
authorbert hubert <bert.hubert@netherlabs.nl>
Mon, 19 Feb 2018 09:21:19 +0000 (10:21 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 25 Mar 2019 09:22:41 +0000 (10:22 +0100)
pdns/pdnsutil.cc

index b73bbf39b102b74ee259577296f583a486b4a5e1..ffad92e75bd45d2881e5a529e4a1d4b732ba4f63 100644 (file)
@@ -1003,9 +1003,9 @@ int editZone(DNSSECKeeper& dk, const DNSName &zone) {
   return EXIT_SUCCESS;
 }
 
-static int xcryptIP(const std::string& cmd, const std::string& ip, const std::string& key)
+static int xcryptIP(const std::string& cmd, const std::string& ip, const std::string& rkey)
 {
-  string rkey = makeIPCipherKey(key);
+
   ComboAddress ca(ip), ret;
   
   if(cmd=="ipencrypt")
@@ -1970,9 +1970,9 @@ try
     cout<<"increase-serial ZONE               Increases the SOA-serial by 1. Uses SOA-EDIT"<<endl;
     cout<<"import-tsig-key NAME ALGORITHM KEY Import TSIG key"<<endl;
     cout<<"import-zone-key ZONE FILE          Import from a file a private key, ZSK or KSK"<<endl;
-    cout<<"       [active|inactive] [ksk|zsk]  Defaults to KSK and active"<<endl;
-    cout<<"ipdecrypt IP key                   Encrypt an IP address using 'key' (string or base64)"<<endl;    
-    cout<<"ipencrypt IP key                   Encrypt an IP address using 'key' (string or base64)"<<endl;
+    cout<<"       [active|inactive] [ksk|zsk] Defaults to KSK and active"<<endl;
+    cout<<"ipdecrypt IP passphrase/key [key]  Encrypt IP address using passphrase or base64 key"<<endl;    
+    cout<<"ipencrypt IP passphrase/key [key]  Encrypt IP address using passphrase or base64 key"<<endl;
     cout<<"load-zone ZONE FILE                Load ZONE from FILE, possibly creating zone or atomically"<<endl;
     cout<<"                                   replacing contents"<<endl;
     cout<<"list-algorithms [with-backend]     List all DNSSEC algorithms supported, optionally also listing the crypto library used"<<endl;
@@ -2022,11 +2022,21 @@ try
   }
 
   if(cmds[0] == "ipencrypt" || cmds[0]=="ipdecrypt") {
-    if(cmds.size() != 3) {
-      cerr<<"Syntax: pdnsutil [ipencrypt|ipdecrypt] IP password"<<endl;
+    if(cmds.size() < 3 || (cmds.size()== 4 && cmds[3]!="key")) {
+      cerr<<"Syntax: pdnsutil [ipencrypt|ipdecrypt] IP passphrase [key]"<<endl;
       return 0;
     }
-    exit(xcryptIP(cmds[0], cmds[1], cmds[2]));
+    string key;
+    if(cmds.size()==4) {
+      if(B64Decode(cmds[2], key) < 0) {
+        cerr<<"Could not parse '"<<cmds[3]<<"' as base64"<<endl;
+        return 0;
+      }
+    }
+    else {
+      key = makeIPCipherKey(cmds[2]);
+    }
+    exit(xcryptIP(cmds[0], cmds[1], key));
   }