"active": <bool>,
"keytype": <keytype>,
"dnskey": <string>,
- "content": <string>,
+ "privatekey": <string>,
"ds": [ <ds>,
<ds>,
.... ]
`id`: read-only.
-`keytype`: `<keytype>` is one of the following: `ksk` or `zsk`, and they are
-both mutually exclusive.
+`keytype`: `<keytype>` is one of the following: `ksk`, `zsk`, `csk`.
`dnskey`: the DNSKEY for this key
`ds`: an array with all DSes for this key
+`privatekey`: private key data (in ISC format).
+
URL: /api/v1/servers/:server\_id/zones/:zone\_name/cryptokeys
-------------------------------------------------------------
#### GET
-Returns all public data about cryptokeys, but not `content`.
+Returns all public data about cryptokeys, but not `privatekey`.
#### POST
#### GET
-Returns all public data about cryptokeys, including `content`, with all the private data. An array is returned, even though a single key is requested.
+Returns all public data about cryptokeys, including `privatekey`.
#### PUT
if(req->method != "GET")
throw ApiException("Only GET is implemented");
+ bool inquireSingleKey = false;
+ int inquireKeyId;
+ if (req->parameters.count("key_id")) {
+ inquireSingleKey = true;
+ inquireKeyId = std::stoi(req->parameters["key_id"]);
+ }
+
DNSName zonename = apiZoneIdToName(req->parameters["id"]);
UeberBackend B;
+ DNSSECKeeper dk(&B);
DomainInfo di;
- DNSSECKeeper dk;
-
if(!B.getDomainInfo(zonename, di))
- throw ApiException("Could not find domain '"+zonename.toString()+"'");
+ throw HttpNotFoundException();
DNSSECKeeper::keyset_t keyset=dk.getKeys(zonename, false);
- if (keyset.empty())
- throw ApiException("No keys for zone '"+zonename.toString()+"'");
-
Json::array doc;
- for(const DNSSECKeeper::keyset_t::value_type value : keyset) {
- if (req->parameters.count("key_id")) {
- int keyid = std::stoi(req->parameters["key_id"]);
- int curid = value.second.id;
- if (keyid != curid)
- continue;
+ for(const auto& value : keyset) {
+ if (inquireSingleKey && inquireKeyId != value.second.id) {
+ continue;
}
string keyType;
{ "dnskey", value.first.getDNSKEY().getZoneRepresentation() }
};
- if (req->parameters.count("key_id")) {
- DNSSECPrivateKey dpk=dk.getKeyById(zonename, std::stoi(req->parameters["key_id"]));
- key["content"] = dpk.getKey()->convertToISC();
- }
-
if (value.second.keyType == DNSSECKeeper::KSK || value.second.keyType == DNSSECKeeper::CSK) {
Json::array dses;
for(const int keyid : { 1, 2, 3, 4 })
} catch (...) {}
key["ds"] = dses;
}
+
+ if (inquireSingleKey) {
+ key["privatekey"] = value.first.getKey()->convertToISC();
+ resp->setBody(key);
+ return;
+ }
doc.push_back(key);
}
+ if (inquireSingleKey) {
+ // we came here because we couldn't find the requested key.
+ throw HttpNotFoundException();
+ }
resp->setBody(doc);
}