Adds key into local storage. See [`getDomainKeys`](#getdomainkeys) for more information.
* Mandatory: No
-* Parameters: name, key=`<flags,active,content>`
-* Reply: id (>= 0) for success, -1 for failure
+* Parameters: name, key=`<flags,active,content>`, id
+* Reply: true for success, false for failure
#### Example JSON/RPC
Query:
virtual bool setDomainMetadata(const DNSName& name, const std::string& kind, const std::vector<std::string>& meta);
virtual bool getDomainKeys(const DNSName& name, unsigned int kind, std::vector<KeyData>& keys);
virtual bool removeDomainKey(const DNSName& name, unsigned int id);
- virtual int addDomainKey(const DNSName& name, const KeyData& key);
+ virtual bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id);
virtual bool activateDomainKey(const DNSName& name, unsigned int id);
virtual bool deactivateDomainKey(const DNSName& name, unsigned int id);
virtual bool getTSIGKey(const DNSName& name, DNSName* algorithm, string* content);
bool Bind2Backend::removeDomainKey(const DNSName& name, unsigned int id)
{ return false; }
-int Bind2Backend::addDomainKey(const DNSName& name, const KeyData& key)
+bool Bind2Backend::addDomainKey(const DNSName& name, const KeyData& key, int64_t& id)
{ return -1; }
bool Bind2Backend::activateDomainKey(const DNSName& name, unsigned int id)
return true;
}
-int Bind2Backend::addDomainKey(const DNSName& name, const KeyData& key)
+bool Bind2Backend::addDomainKey(const DNSName& name, const KeyData& key, int64_t& id)
{
if(!d_dnssecdb || d_hybrid)
- return -1;
+ return false;
try {
d_insertDomainKeyQuery_stmt->
try {
d_GetLastInsertedKeyIdQuery_stmt->execute();
- if (!d_GetLastInsertedKeyIdQuery_stmt->hasNextRow())
- throw PDNSException("GSQLBackend unable to get id");
+ if (!d_GetLastInsertedKeyIdQuery_stmt->hasNextRow()) {
+ id = -2;
+ return true;
+ }
SSqlStatement::row_t row;
d_GetLastInsertedKeyIdQuery_stmt->nextRow(row);
int id = std::stoi(row[0]);
d_GetLastInsertedKeyIdQuery_stmt->reset();
- return id;
+ return true;
}
catch (SSqlException &e) {
- throw PDNSException("DNSSEC database in BIND backend unable to get id: "+e.txtReason());
+ id = -2;
+ return true;
}
- return -1;
+ return false;
}
bool Bind2Backend::activateDomainKey(const DNSName& name, unsigned int id)
return false;
}
-int GeoIPBackend::addDomainKey(const DNSName& name, const KeyData& key) {
+bool GeoIPBackend::addDomainKey(const DNSName& name, const KeyData& key, int64_t& id) {
if (!d_dnssec) return false;
WriteLock rl(&s_state_lock);
unsigned int nextid=1;
ofstream ofs(pathname.str().c_str());
ofs.write(key.content.c_str(), key.content.size());
ofs.close();
- return nextid;
+ id = nextid;
+ return true;
}
}
return false;
virtual bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta);
virtual bool getDomainKeys(const DNSName& name, unsigned int kind, std::vector<DNSBackend::KeyData>& keys);
virtual bool removeDomainKey(const DNSName& name, unsigned int id);
- virtual int addDomainKey(const DNSName& name, const KeyData& key);
+ virtual bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id);
virtual bool activateDomainKey(const DNSName& name, unsigned int id);
virtual bool deactivateDomainKey(const DNSName& name, unsigned int id);
return ok;
}
-int LUABackend::addDomainKey(const DNSName& name, const KeyData& key) {
+bool LUABackend::addDomainKey(const DNSName& name, const KeyData& key, int64_t& id) {
// there is no logging function in pdnsutil when running this routine?
//key = id, flags, active, content
if(f_lua_adddomainkey == 0)
- return -1;
+ return false;
if(logging)
//L << Logger::Info << backend_name << "(addDomainKey) BEGIN name: '" << name << "' id: '" << id << endl;
lua_pop(lua, 1);
throw runtime_error(e);
- return -1;
}
size_t returnedwhat = lua_type(lua, -1);
lua_pop(lua, 1);
if(logging)
- cerr << backend_name << "(addDomainKey) END" << endl;
-
- return ok;
+ cerr << backend_name << "(addDomainKey) END" << endl;
+
+ return ok >= 0;
}
bool LUABackend::getDomainKeys(const DNSName& name, unsigned int kind, std::vector<KeyData>& keys) {
bool activateDomainKey(const DNSName& name, unsigned int id) override ;
bool deactivateDomainKey(const DNSName& name, unsigned int id) override ;
bool getTSIGKey(const DNSName& name, DNSName* algorithm, string* content) override ;
- int addDomainKey(const DNSName& name, const KeyData& key) override ;
+ bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id) override ;
bool updateDNSSECOrderAndAuthAbsolute(uint32_t domain_id, const DNSName& qname, const std::string& ordername, bool auth);
bool getBeforeAndAfterNamesAbsolute(uint32_t id, const string& qname, DNSName& unhashed, string& before, string& after) override;
bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& zonename, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY) override;
return true;
}
-int
-OracleBackend::addDomainKey (const DNSName& name, const KeyData& key)
+bool
+OracleBackend::addDomainKey (const DNSName& name, const KeyData& key, int64_t& id)
{
if(!d_dnssecQueries)
- return -1;
+ return false;
DomainInfo di;
if (getDomainInfo(name, di) == false) return false;
throw OracleException("Oracle addDomainKey COMMIT", oraerr);
}
- return key_id;
+ id = key_id;
+ return key_id >= 0;
}
bool
bool getDomainKeys(const DNSName& name, unsigned int kind, vector<KeyData>& keys);
bool removeDomainKey(const DNSName& name, unsigned int id);
- int addDomainKey(const DNSName& name, const KeyData& key);
+ bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id);
bool activateDomainKey(const DNSName& name, unsigned int id);
bool deactivateDomainKey(const DNSName& name, unsigned int id);
return true;
}
-int RemoteBackend::addDomainKey(const DNSName& name, const KeyData& key) {
+bool RemoteBackend::addDomainKey(const DNSName& name, const KeyData& key, int64_t& id) {
// no point doing dnssec if it's not supported
if (d_dnssec == false) return false;
if (this->send(query) == false || this->recv(answer) == false)
return false;
- return answer["result"].int_value();
+ id = answer["result"].int_value();
+ return id >= 0;
}
bool RemoteBackend::activateDomainKey(const DNSName& name, unsigned int id) {
virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const string& qname, DNSName& unhashed, string& before, string& after);
virtual bool setDomainMetadata(const DNSName& name, const string& kind, const std::vector<std::basic_string<char> >& meta);
virtual bool removeDomainKey(const DNSName& name, unsigned int id);
- virtual int addDomainKey(const DNSName& name, const KeyData& key);
+ virtual bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id);
virtual bool activateDomainKey(const DNSName& name, unsigned int id);
virtual bool deactivateDomainKey(const DNSName& name, unsigned int id);
virtual bool getDomainInfo(const DNSName& domain, DomainInfo& di);
return true;
}
-int GSQLBackend::addDomainKey(const DNSName& name, const KeyData& key)
+bool GSQLBackend::addDomainKey(const DNSName& name, const KeyData& key, int64_t& id)
{
if(!d_dnssecQueries)
- return -1;
+ return false;
try {
d_AddDomainKeyQuery_stmt->
try {
d_GetLastInsertedKeyIdQuery_stmt->execute();
- if (!d_GetLastInsertedKeyIdQuery_stmt->hasNextRow())
- throw PDNSException("GSQLBackend unable to get id");
+ if (!d_GetLastInsertedKeyIdQuery_stmt->hasNextRow()) {
+ id = -2;
+ return true;
+ }
SSqlStatement::row_t row;
d_GetLastInsertedKeyIdQuery_stmt->nextRow(row);
- int id = std::stoi(row[0]);
+ id = std::stoi(row[0]);
d_GetLastInsertedKeyIdQuery_stmt->reset();
- return id;
+ return true;
}
catch (SSqlException &e) {
- throw PDNSException("GSQLBackend unable to get id: "+e.txtReason());
+ id = -2;
+ return true;
}
- return -1;
+ return false;
}
bool GSQLBackend::activateDomainKey(const DNSName& name, unsigned int id)
bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset);
bool listSubZone(const DNSName &zone, int domain_id);
- int addDomainKey(const DNSName& name, const KeyData& key);
+ bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id);
bool getDomainKeys(const DNSName& name, unsigned int kind, std::vector<KeyData>& keys);
bool getAllDomainMetadata(const DNSName& name, std::map<std::string, std::vector<std::string> >& meta);
bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta);
return meta=="1";
}
-int DNSSECKeeper::addKey(const DNSName& name, bool setSEPBit, int algorithm, int bits, bool active)
+bool DNSSECKeeper::addKey(const DNSName& name, bool setSEPBit, int algorithm, int64_t& id, int bits, bool active)
{
if(!bits) {
if(algorithm <= 10)
dspk.setKey(dpk);
dspk.d_algorithm = algorithm;
dspk.d_flags = setSEPBit ? 257 : 256;
- return addKey(name, dspk, active);
+ return addKey(name, dspk, id, active);
}
void DNSSECKeeper::clearAllCaches() {
}
-int DNSSECKeeper::addKey(const DNSName& name, const DNSSECPrivateKey& dpk, bool active)
+bool DNSSECKeeper::addKey(const DNSName& name, const DNSSECPrivateKey& dpk, int64_t& id, bool active)
{
clearCaches(name);
DNSBackend::KeyData kd;
kd.active = active;
kd.content = dpk.getKey()->convertToISC();
// now store it
- return d_keymetadb->addDomainKey(name, kd);
+ return d_keymetadb->addDomainKey(name, kd, id);
}
virtual bool getDomainKeys(const DNSName& name, unsigned int kind, std::vector<KeyData>& keys) { return false;}
virtual bool removeDomainKey(const DNSName& name, unsigned int id) { return false; }
- virtual int addDomainKey(const DNSName& name, const KeyData& key){ return -1; }
+ virtual bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id){ return false; }
virtual bool activateDomainKey(const DNSName& name, unsigned int id) { return false; }
virtual bool deactivateDomainKey(const DNSName& name, unsigned int id) { return false; }
keyset_t getEntryPoints(const DNSName& zname);
keyset_t getKeys(const DNSName& zone, bool useCache = true);
DNSSECPrivateKey getKeyById(const DNSName& zone, unsigned int id);
- int addKey(const DNSName& zname, bool setSEPBit, int algorithm, int bits=0, bool active=true);
- int addKey(const DNSName& zname, const DNSSECPrivateKey& dpk, bool active=true);
+ bool addKey(const DNSName& zname, bool setSEPBit, int algorithm, int64_t& id, int bits=0, bool active=true);
+ bool addKey(const DNSName& zname, const DNSSECPrivateKey& dpk, int64_t& id, bool active=true);
bool removeKey(const DNSName& zname, unsigned int id);
bool activateKey(const DNSName& zname, unsigned int id);
bool deactivateKey(const DNSName& zname, unsigned int id);
vector<string> k_algos;
vector<string> z_algos;
int k_size;
- int z_size;
+ int z_size;
+ // temp var for addKey
+ int64_t id;
stringtok(k_algos, ::arg()["default-ksk-algorithms"], " ,");
k_size = ::arg().asNum("default-ksk-size");
if (k_algos.empty()) { /* only a ZSK was requested by the defaults, set the SEP bit */
}
-
for(auto &k_algo: k_algos) {
cout << "Adding "<<(z_algos.empty()? "CSK (257)" : "KSK")<<" with algorithm " << k_algo << endl;
int algo = DNSSECKeeper::shorthand2algorithm(k_algo);
- if(dk.addKey(zone, true, algo, k_size, true) < 0) {
+ if (!dk.addKey(zone, true, algo, id, k_size, true)) {
cerr<<"No backend was able to secure '"<<zone<<"', most likely because no DNSSEC"<<endl;
cerr<<"capable backends are loaded, or because the backends have DNSSEC disabled."<<endl;
cerr<<"For the Generic SQL backends, set the 'gsqlite3-dnssec', 'gmysql-dnssec' or"<<endl;
int algo = DNSSECKeeper::shorthand2algorithm(z_algo);
- if(!dk.addKey(zone, false, algo, z_size, true) < 0) {
+ if (!dk.addKey(zone, false, algo, id, z_size, true)) {
cerr<<"No backend was able to secure '"<<zone<<"', most likely because no DNSSEC"<<endl;
cerr<<"capable backends are loaded, or because the backends have DNSSEC disabled."<<endl;
cerr<<"For the Generic SQL backends, set the 'gsqlite3-dnssec', 'gmysql-dnssec' or"<<endl;
exit(EXIT_FAILURE);;
}
}
- int id;
- if((id = dk.addKey(zone, keyOrZone, algorithm, bits, active)) < 0) {
+ int64_t id;
+ if (!dk.addKey(zone, keyOrZone, algorithm, id, bits, active)) {
cerr<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl;
exit(1);
- }
- else {
+ } else {
cerr<<"Added a " << (keyOrZone ? "KSK" : "ZSK")<<" with algorithm = "<<algorithm<<", active="<<active<<endl;
- if(bits)
+ if (bits)
cerr<<"Requested specific key size of "<<bits<<" bits"<<endl;
- cout<<std::to_string(id)<<endl;
+ if (id == -1) {
+ cerr<<std::to_string(id)<<"Key was added, but backend does not support returning of key id"<<endl;
+ } else if (id < -1) {
+ cerr<<std::to_string(id)<<"Key was added, but there was a failure while returning the key id"<<endl;
+ } else {
+ cout<<std::to_string(id)<<endl;
+ }
}
}
else if(cmds[0] == "remove-zone-key") {
else
dpk.d_flags = 257; // ksk
- int id;
- if((id = dk.addKey(DNSName(zone), dpk)) < 0) {
+ int64_t id;
+ if (!dk.addKey(DNSName(zone), dpk, id)) {
cerr<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl;
exit(1);
}
- cout<<std::to_string(id)<<endl;
+ if (id == -1) {
+ cerr<<std::to_string(id)<<"Key was added, but backend does not support returning of key id"<<endl;
+ } else if (id < -1) {
+ cerr<<std::to_string(id)<<"Key was added, but there was a failure while returning the key id"<<endl;
+ } else {
+ cout<<std::to_string(id)<<endl;
+ }
}
else if(cmds[0]=="import-zone-key") {
exit(1);
}
}
- int id;
- if((id = dk.addKey(DNSName(zone), dpk, active)) < 0) {
+ int64_t id;
+ if (!dk.addKey(DNSName(zone), dpk, id, active)) {
cerr<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl;
exit(1);
}
- cout<<std::to_string(id)<<endl;
+ if (id == -1) {
+ cerr<<std::to_string(id)<<"Key was added, but backend does not support returning of key id"<<endl;
+ } else if (id < -1) {
+ cerr<<std::to_string(id)<<"Key was added, but there was a failure while returning the key id"<<endl;
+ } else {
+ cout<<std::to_string(id)<<endl;
+ }
}
else if(cmds[0]=="export-zone-dnskey") {
if(cmds.size() < 3) {
return 1;
}
- int id;
+ int64_t id;
bool keyOrZone = (cmds[4] == "ksk" ? true : false);
string module = cmds[5];
string slot = cmds[6];
"PIN: " << pin << std::endl <<
"Label: " << label << std::endl;
- DNSKEYRecordContent drc;
- DNSSECPrivateKey dpk;
- dpk.d_flags = (keyOrZone ? 257 : 256);
-
- shared_ptr<DNSCryptoKeyEngine> dke(DNSCryptoKeyEngine::makeFromISCString(drc, iscString.str()));
- if(!dke->checkKey()) {
- cerr << "Invalid DNS Private Key in engine " << module << " slot " << slot << std::endl;
- return 1;
- }
- dpk.setKey(dke);
-
- // make sure this key isn't being reused.
- B.getDomainKeys(zone, 0, keys);
- id = -1;
-
- for(DNSBackend::KeyData& kd : keys) {
- if (kd.content == iscString.str()) {
- // it's this one, I guess...
- id = kd.id;
- break;
- }
- }
+ DNSKEYRecordContent drc;
+ DNSSECPrivateKey dpk;
+ dpk.d_flags = (keyOrZone ? 257 : 256);
- if (id > -1) {
- cerr << "You have already assigned this key with ID=" << id << std::endl;
- return 1;
- }
+ shared_ptr<DNSCryptoKeyEngine> dke(DNSCryptoKeyEngine::makeFromISCString(drc, iscString.str()));
+ if(!dke->checkKey()) {
+ cerr << "Invalid DNS Private Key in engine " << module << " slot " << slot << std::endl;
+ return 1;
+ }
+ dpk.setKey(dke);
- if (!(id = dk.addKey(zone, dpk))) {
- cerr << "Unable to assign module slot to zone" << std::endl;
- return 1;
- }
+ // make sure this key isn't being reused.
+ B.getDomainKeys(zone, 0, keys);
+ id = -1;
- // figure out key id.
+ for(DNSBackend::KeyData& kd : keys) {
+ if (kd.content == iscString.str()) {
+ // it's this one, I guess...
+ id = kd.id;
+ break;
+ }
+ }
- B.getDomainKeys(zone, 0, keys);
+ if (id > -1) {
+ cerr << "You have already assigned this key with ID=" << id << std::endl;
+ return 1;
+ }
- // validate which one got the key...
- for(DNSBackend::KeyData& kd : keys) {
- if (kd.content == iscString.str()) {
- // it's this one, I guess...
- id = kd.id;
- break;
- }
- }
+ if (!dk.addKey(zone, dpk, id)) {
+ cerr << "Unable to assign module slot to zone" << std::endl;
+ return 1;
+ }
- cerr << "Module " << module << " slot " << slot << " assigned to " << zone << " with key id " << id << endl;
+ cerr << "Module " << module << " slot " << slot << " assigned to " << zone << " with key id " << id << endl;
- return 0;
+ return 0;
} else if (cmds[1] == "create-key") {
if (cmds.size() < 4) {
}
// move keys
nk=0;
+ // temp var for KeyID
+ int64_t keyID;
std::vector<DNSBackend::KeyData> keys;
if (src->getDomainKeys(di.zone, 0, keys)) {
for(const DNSBackend::KeyData& k: keys) {
- tgt->addDomainKey(di.zone, k);
+ tgt->addDomainKey(di.zone, k, keyID);
nk++;
}
}
return false;
}
-int UeberBackend::addDomainKey(const DNSName& name, const DNSBackend::KeyData& key)
+bool UeberBackend::addDomainKey(const DNSName& name, const DNSBackend::KeyData& key, int64_t& id)
{
- int ret;
+ id = -1;
for(DNSBackend* db : backends) {
- if((ret = db->addDomainKey(name, key)) >= 0)
- return ret;
+ if(db->addDomainKey(name, key, id))
+ return true;
}
- return -1;
+ return false;
}
bool UeberBackend::getDomainKeys(const DNSName& name, unsigned int kind, std::vector<DNSBackend::KeyData>& keys)
{
bool getDomainInfo(const DNSName &domain, DomainInfo &di);
bool createDomain(const DNSName &domain);
- int addDomainKey(const DNSName& name, const DNSBackend::KeyData& key);
+ bool addDomainKey(const DNSName& name, const DNSBackend::KeyData& key, int64_t& id);
bool getDomainKeys(const DNSName& name, unsigned int kind, std::vector<DNSBackend::KeyData>& keys);
bool getAllDomainMetadata(const DNSName& name, std::map<std::string, std::vector<std::string> >& meta);
bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta);