Skip to content

Commit 950bddd

Browse files
author
Peter van Dijk
committed
add pdnssec generate-zone-key command, thanks Aki. Closes #711
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@3124 d19b8d6e-7fed-0310-83ef-9ca221ded41b
1 parent 96ff30f commit 950bddd

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

pdns/pdnssec.cc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,8 @@ try
811811
cerr<<"add-zone-key ZONE zsk|ksk [bits]\n";
812812
cerr<<" [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384]\n";
813813
cerr<<" Add a ZSK or KSK to zone and specify algo&bits\n";
814+
cerr<<"generate-zone-key zsk|ksk [bits] [algorithm]\n";
815+
cerr<<" Generate a ZSK or KSK to stdout with specified algo&bits\n";
814816
cerr<<"check-zone ZONE Check a zone for correctness\n";
815817
cerr<<"check-all-zones Check all zones for correctness\n";
816818
cerr<<"create-bind-db FNAME Create DNSSEC db for BIND backend (bind-dnssec-db)\n";
@@ -1223,6 +1225,58 @@ try
12231225
cout << zone << " IN DS "<<makeDSFromDNSKey(zone, dpk.getDNSKEY(), 2).getZoneRepresentation() << endl;
12241226
}
12251227
}
1228+
else if(cmds[0] == "generate-zone-key") {
1229+
if(cmds.size() < 2 ) {
1230+
cerr << "Syntax: pdnssec generate-zone-key zsk|ksk [bits] [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384]"<<endl;
1231+
return 0;
1232+
}
1233+
// need to get algorithm, bits & ksk or zsk from commandline
1234+
bool keyOrZone=false;
1235+
int tmp_algo=0;
1236+
int bits=0;
1237+
int algorithm=8;
1238+
for(unsigned int n=1; n < cmds.size(); ++n) {
1239+
if(pdns_iequals(cmds[n], "zsk"))
1240+
keyOrZone = false;
1241+
else if(pdns_iequals(cmds[n], "ksk"))
1242+
keyOrZone = true;
1243+
else if((tmp_algo = shorthand2algorithm(cmds[n]))>0) {
1244+
algorithm = tmp_algo;
1245+
} else if(atoi(cmds[n].c_str()))
1246+
bits = atoi(cmds[n].c_str());
1247+
else {
1248+
cerr<<"Unknown algorithm, key flag or size '"<<cmds[n]<<"'"<<endl;
1249+
return 0;
1250+
}
1251+
}
1252+
cerr<<"Generating a " << (keyOrZone ? "KSK" : "ZSK")<<" with algorithm = "<<algorithm<<endl;
1253+
if(bits)
1254+
cerr<<"Requesting specific key size of "<<bits<<" bits"<<endl;
1255+
1256+
DNSSECPrivateKey dspk;
1257+
shared_ptr<DNSCryptoKeyEngine> dpk(DNSCryptoKeyEngine::make(algorithm)); // defaults to RSA for now, could be smart w/algorithm! XXX FIXME
1258+
if(!bits) {
1259+
if(algorithm <= 10)
1260+
bits = keyOrZone ? 2048 : 1024;
1261+
else {
1262+
if(algorithm == 12 || algorithm == 13 || algorithm == 250) // ECDSA, GOST, ED25519
1263+
bits = 256;
1264+
else if(algorithm == 14)
1265+
bits = 384;
1266+
else {
1267+
throw runtime_error("Can't guess key size for algoritm "+lexical_cast<string>(algorithm));
1268+
}
1269+
}
1270+
}
1271+
dpk->create(bits);
1272+
dspk.setKey(dpk);
1273+
dspk.d_algorithm = algorithm;
1274+
dspk.d_flags = keyOrZone ? 257 : 256;
1275+
1276+
// print key to stdout
1277+
cout << "Flags: " << dspk.d_flags << endl <<
1278+
dspk.getKey()->convertToISC() << endl;
1279+
}
12261280
else {
12271281
cerr<<"Unknown command '"<<cmds[0]<<"'\n";
12281282
return 1;

0 commit comments

Comments
 (0)