|
811 | 811 | cerr<<"add-zone-key ZONE zsk|ksk [bits]\n";
|
812 | 812 | cerr<<" [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384]\n";
|
813 | 813 | 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"; |
814 | 816 | cerr<<"check-zone ZONE Check a zone for correctness\n";
|
815 | 817 | cerr<<"check-all-zones Check all zones for correctness\n";
|
816 | 818 | cerr<<"create-bind-db FNAME Create DNSSEC db for BIND backend (bind-dnssec-db)\n";
|
@@ -1223,6 +1225,58 @@ try
|
1223 | 1225 | cout << zone << " IN DS "<<makeDSFromDNSKey(zone, dpk.getDNSKEY(), 2).getZoneRepresentation() << endl;
|
1224 | 1226 | }
|
1225 | 1227 | }
|
| 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 | + } |
1226 | 1280 | else {
|
1227 | 1281 | cerr<<"Unknown command '"<<cmds[0]<<"'\n";
|
1228 | 1282 | return 1;
|
|
0 commit comments