From: Pieter Lexis Date: Mon, 13 Nov 2017 17:44:45 +0000 (+0100) Subject: API: Implement TSIG key endpoint (GET only) X-Git-Tag: auth-4.2.0-alpha1~17^2~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa07a3cf06cae5ca782aaafbbd70d1e878fb3124;p=thirdparty%2Fpdns.git API: Implement TSIG key endpoint (GET only) --- diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 5e93f4126a..d520cb28d3 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -1237,6 +1237,56 @@ static void checkDuplicateRecords(vector& records) { } } +static void apiServerTsigKeys(HttpRequest* req, HttpResponse* resp) { + if (req->method != "GET") { + throw HttpMethodNotAllowedException(); + } + + vector keys; + + UeberBackend B; + if (!B.getTSIGKeys(keys)) { + throw ApiException("Unable to retrieve TSIG keys"); + } + + Json::array doc; + + for(const auto &key : keys) { + Json::object tsigkey = { + { "id", apiZoneNameToId(key.name) }, + { "algorithm", key.algorithm.toString() }, + { "key", key.key } + }; + doc.push_back(tsigkey); + } + + resp->setBody(doc); +} + +static void apiServerTsigKeyDetail(HttpRequest* req, HttpResponse* resp) { + if (req->method != "GET") { + throw HttpMethodNotAllowedException(); + } + + DNSName keyname = apiZoneIdToName(req->parameters["id"]); + + UeberBackend B; + DNSName algo; + string content; + + if (!B.getTSIGKey(keyname, &algo, &content)) { + throw ApiException("Unable to retrieve TSIG key with id '"+keyname.toLogString()+"'"); + } + + Json::object tsigkey = { + { "id", apiZoneNameToId(keyname) }, + { "algorithm", algo.toString() }, + { "key", content } + }; + + resp->setBody(tsigkey); +} + static void apiServerZones(HttpRequest* req, HttpResponse* resp) { UeberBackend B; DNSSECKeeper dk(&B); @@ -1937,6 +1987,8 @@ void AuthWebServer::webThread() d_ws->registerApiHandler("/api/v1/servers/localhost/search-log", &apiServerSearchLog); d_ws->registerApiHandler("/api/v1/servers/localhost/search-data", &apiServerSearchData); d_ws->registerApiHandler("/api/v1/servers/localhost/statistics", &apiServerStatistics); + d_ws->registerApiHandler("/api/v1/servers/localhost/tsigkeys/", &apiServerTsigKeyDetail); + d_ws->registerApiHandler("/api/v1/servers/localhost/tsigkeys", &apiServerTsigKeys); d_ws->registerApiHandler("/api/v1/servers/localhost/zones//axfr-retrieve", &apiServerZoneAxfrRetrieve); d_ws->registerApiHandler("/api/v1/servers/localhost/zones//cryptokeys/", &apiZoneCryptokeys); d_ws->registerApiHandler("/api/v1/servers/localhost/zones//cryptokeys", &apiZoneCryptokeys);