Commit 929a9cae authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[trac925] Loading the key ring

parent 04ea273e
......@@ -14,21 +14,47 @@
#include <server_common/keyring.h>
using namespace isc::dns;
using namespace isc::data;
namespace isc {
namespace server_common {
boost::shared_ptr<dns::TSIGKeyRing> keyring;
typedef boost::shared_ptr<TSIGKeyRing> KeyringPtr;
KeyringPtr keyring;
namespace {
void
updateKeyring(const std::string&, ConstElementPtr data) {
ConstElementPtr list(data->get("keys"));
KeyringPtr load(new TSIGKeyRing);
for (size_t i(0); i < list->size(); ++ i) {
load->add(TSIGKey(list->get(i)->stringValue()));
}
keyring.swap(load);
}
}
void
initKeyring(config::ModuleCCSession& session) {
// TODO
(void) session;
if (keyring) {
// We are already initialized
return;
}
session.addRemoteConfig("tsig_keys", updateKeyring);
}
void
deinitKeyring(config::ModuleCCSession& session) {
// TODO
(void) session;
if (!keyring) {
// Not initialized, ignore it
return;
}
keyring.reset();
session.removeRemoteConfig("tsig_keys");
}
}
......
......@@ -51,7 +51,7 @@ public:
"/tsig_keys.spec").
getFullSpec()));
session.getMessages()->add(createAnswer(0, Element::fromJSON(
"{\"keys\": [\"key:MTIzNAo=:sha1\"]}")));
"{\"keys\": [\"key:MTIzNAo=:hmac-sha1\"]}")));
// Now load it
EXPECT_NO_THROW(initKeyring(*mccs));
EXPECT_NE(keyring, boost::shared_ptr<TSIGKeyRing>()) <<
......@@ -74,9 +74,9 @@ TEST_F(KeyringTest, keyring) {
{
SCOPED_TRACE("Update");
session.getMessages()->add(createCommand("config_update",
Element::fromJSON(
"{\"keys\": [\"another:MTIzNAo=:sha256\"]}")));
session.addMessage(createCommand("config_update", Element::fromJSON(
"{\"keys\": [\"another:MTIzNAo=:hmac-sha256\"]}")),
"tsig_keys", "*");
mccs->checkCommand();
// Make sure it no longer contains the original key
......@@ -114,12 +114,13 @@ TEST_F(KeyringTest, initTwice) {
"it even throws at it";
}
EXPECT_EQ(backup, keyring) << "The second init replaced the data";
deinitKeyring(*mccs);
}
// deinit when not initialized
TEST_F(KeyringTest, extraDeinit) {
// It is NULL before
EXPECT_EQ(keyring, boost::shared_ptr<TSIGKeyRing>()) <<
EXPECT_EQ(boost::shared_ptr<TSIGKeyRing>(), keyring) <<
"Someone forgot to deinit it before";
// Check that it doesn't get confused when we do not have it initialized
EXPECT_NO_THROW(deinitKeyring(*mccs));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment