summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv
diff options
context:
space:
mode:
authormayya <mayya@itwm.fraunhofer.de>2018-07-07 09:39:09 +0200
committerTomek Mrugalski <tomasz@isc.org>2018-07-23 13:35:50 +0200
commitbeeadf3d59899b43253dc9b74ceee9e3bdaa4ade (patch)
treeabf2d96a897e25b60cf5b291d740ead81f25cccf /src/lib/dhcpsrv
parent[lib] Extend host structure to support auth keys for reconfiguration. (diff)
downloadkea-beeadf3d59899b43253dc9b74ceee9e3bdaa4ade.tar.xz
kea-beeadf3d59899b43253dc9b74ceee9e3bdaa4ade.zip
[lib] Address review comments for #83
See #88 for review comments modified upgrade files modified tests
Diffstat (limited to 'src/lib/dhcpsrv')
-rw-r--r--src/lib/dhcpsrv/cql_host_data_source.cc10
-rw-r--r--src/lib/dhcpsrv/host.cc77
-rw-r--r--src/lib/dhcpsrv/host.h91
-rw-r--r--src/lib/dhcpsrv/mysql_host_data_source.cc6
-rw-r--r--src/lib/dhcpsrv/pgsql_host_data_source.cc15
-rw-r--r--src/lib/dhcpsrv/tests/host_unittest.cc86
-rw-r--r--src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc18
-rw-r--r--src/lib/dhcpsrv/testutils/host_data_source_utils.cc4
8 files changed, 208 insertions, 99 deletions
diff --git a/src/lib/dhcpsrv/cql_host_data_source.cc b/src/lib/dhcpsrv/cql_host_data_source.cc
index 0c0609cb11..9b6c93e25f 100644
--- a/src/lib/dhcpsrv/cql_host_data_source.cc
+++ b/src/lib/dhcpsrv/cql_host_data_source.cc
@@ -374,7 +374,7 @@ private:
cass_int32_t reserved_ipv6_prefix_address_type_;
/// @brief Key for authentication
- std::string reserved_key_;
+ std::string key_;
/// @brief The reservation's IAID
cass_int32_t iaid_;
@@ -825,7 +825,7 @@ CqlHostExchange::createBindForSelect(AnyArray& data, StatementTag /* not used */
// reserved_ipv6_prefix_address_type: int
data.add(&reserved_ipv6_prefix_address_type_);
// reserved_key: text
- data.add(&reserved_key_);
+ data.add(&key_);
// iaid: int
data.add(&iaid_);
/// @}
@@ -959,7 +959,7 @@ CqlHostExchange::prepareExchange(const HostPtr& host,
reservation->getType() == IPv6Resrv::TYPE_NA ? 0 : 2;
// reserved_key: text
- reserved_key_ = reservation->getKeys();
+ key_ = reservation->getKey().getAuthKey();
// iaid: int
/// @todo: We don't support iaid in the IPv6Resrv yet.
@@ -1080,7 +1080,7 @@ CqlHostExchange::createBindForMutation(const HostPtr& host,
data.add(&reserved_ipv6_prefix_address_);
data.add(&reserved_ipv6_prefix_length_);
data.add(&reserved_ipv6_prefix_address_type_);
- data.add(&reserved_key_);
+ data.add(&key_);
data.add(&iaid_);
// Option
@@ -1248,7 +1248,7 @@ CqlHostExchange::retrieveReservation() const {
}
return (IPv6Resrv(type, IOAddress(reserved_ipv6_prefix_address_),
- reserved_ipv6_prefix_length_, reserved_key_));
+ reserved_ipv6_prefix_length_, key_));
}
const OptionWrapper
diff --git a/src/lib/dhcpsrv/host.cc b/src/lib/dhcpsrv/host.cc
index 12897280da..45cf01cf52 100644
--- a/src/lib/dhcpsrv/host.cc
+++ b/src/lib/dhcpsrv/host.cc
@@ -21,29 +21,69 @@ using namespace isc::asiolink;
namespace isc {
namespace dhcp {
+
+AuthKey::AuthKey(const std::string key) {
+ setAuthKey(key);
+}
+
+AuthKey::AuthKey(void) {
+ authKey_ = AuthKey::getRandomKeyString();
+}
+
+std::string
+AuthKey::getRandomKeyString() {
+ std::array <char, AuthKey::KEY_LEN> randomString;
+
+ std::random_device rd;
+ boost::random::mt19937 gen(rd());
+
+ std::for_each(randomString.begin(), randomString.end() - 1,
+ [&gen](char& a){ boost::random::uniform_int_distribution<char> dist('!', '~');
+ a = dist(gen); } );
+
+ return std::string(randomString.begin(), randomString.end());
+}
+
+void
+AuthKey::setAuthKey(const std::string& key) {
+ authKey_ = key;
+ if (authKey_.size() > AuthKey::KEY_LEN) {
+ authKey_.resize(AuthKey::KEY_LEN);
+ }
+}
+
+bool
+AuthKey::operator==(const AuthKey& other) const {
+ return (authKey_ == other.authKey_);
+}
+
+bool
+AuthKey::operator!=(const AuthKey& other) const {
+ return (authKey_ != other.authKey_);
+}
+
IPv6Resrv::IPv6Resrv(const Type& type,
const asiolink::IOAddress& prefix,
const uint8_t prefix_len)
: type_(type), prefix_(asiolink::IOAddress("::")),
- prefix_len_(128), keys_("") {
+ prefix_len_(128), key_("") {
// Validate and set the actual values.
set(type, prefix, prefix_len);
}
-
IPv6Resrv::IPv6Resrv(const Type& type,
const asiolink::IOAddress& prefix,
- const std::string& keys,
+ const AuthKey& key,
const uint8_t prefix_len)
: type_(type), prefix_(asiolink::IOAddress("::")),
- prefix_len_(128), keys_("") {
+ prefix_len_(128), key_("") {
// Validate and set the actual values.
- set(type, prefix, prefix_len, keys);
+ set(type, prefix, prefix_len, key);
}
void
IPv6Resrv::set(const Type& type, const asiolink::IOAddress& prefix,
- const uint8_t prefix_len, const std::string& keys) {
+ const uint8_t prefix_len, const AuthKey& key) {
if (!prefix.isV6() || prefix.isV6Multicast()) {
isc_throw(isc::BadValue, "invalid prefix '" << prefix
<< "' for new IPv6 reservation");
@@ -57,37 +97,22 @@ IPv6Resrv::set(const Type& type, const asiolink::IOAddress& prefix,
isc_throw(isc::BadValue, "invalid prefix length '"
<< static_cast<int>(prefix_len)
<< "' for reserved IPv6 address, expected 128");
- } else if (!keys.empty()) {
- //Don't overwrite with an empty string
- keys_ = keys;
}
+ if ( key.getAuthKey().size() != 0 ) {
+ key_ = key;
+ }
type_ = type;
prefix_ = prefix;
prefix_len_ = prefix_len;
}
std::string
-IPv6Resrv::getRandomKeyString()
-{
- std::array <char, 128> randomString;
-
- std::random_device rd;
- boost::random::mt19937 gen(rd());
-
- std::for_each(randomString.begin(), randomString.end() - 1,
- [&gen](char& a){ boost::random::uniform_int_distribution<char> dist('!', '~');
- a = dist(gen); } );
-
- return std::string(randomString.begin(), randomString.end());
-}
-
-std::string
IPv6Resrv::toText() const {
std::ostringstream s;
s << prefix_;
// For PD, append prefix length.
- // @todo: add to text for keys
+ // @todo: add to text for key
if (getType() == TYPE_PD) {
s << "/" << static_cast<int>(prefix_len_);
}
@@ -99,7 +124,7 @@ IPv6Resrv::operator==(const IPv6Resrv& other) const {
return (type_ == other.type_ &&
prefix_ == other.prefix_ &&
prefix_len_ == other.prefix_len_ &&
- keys_ == other.keys_ );
+ key_ == other.key_ );
}
bool
diff --git a/src/lib/dhcpsrv/host.h b/src/lib/dhcpsrv/host.h
index 444c17b07d..177d5fe2db 100644
--- a/src/lib/dhcpsrv/host.h
+++ b/src/lib/dhcpsrv/host.h
@@ -27,6 +27,70 @@ namespace dhcp {
/// @brief HostID (used only when storing in MySQL, PostgreSQL or Cassandra)
typedef uint64_t HostID;
+/// @brief Authentication keys
+///
+/// This class represents authentication keys to be used for
+/// calculating HMAC in the authentication field of the recofigure message
+class AuthKey {
+public:
+ /// @brief Length of the key - 128 bits
+ const static uint8_t KEY_LEN = 16;
+
+ /// @brief Constructor
+ ///
+ /// Constructor for assigning auth keys in host reservation
+ /// Throws if the key length is greater than 16 bytes
+ /// appends 0 to the the input if the key value is less
+ /// than 16 bytes. Provide flexibility to store initialise the value as a string or a vector of bytes.
+ /// @param string auth key to be stored
+ AuthKey(const std::string key);
+
+ /// @brief Constructor
+ ///
+ /// Constructor for generating auth keys, with no argument
+ /// shall use the internal function for generationg random keys
+ AuthKey(void);
+
+ // @brief get random string
+ ///
+ /// Random string is generated by default will be used for
+ /// the keys to be used for signing Reconfigure Message.
+ /// @return auth keys
+ /// @todo Move randomization function to cryptolink
+ static std::string getRandomKeyString();
+
+ /// @brief get auth key value
+ ///
+ /// Returns 16 Byte long key
+ std::string getAuthKey() const {
+ return authKey_;
+ }
+
+
+ /// @brief set auth key value
+ ///
+ /// Set the key value. If the value is less than 16 bytes
+ /// append 0. If the size is greater than 16 bytes, we shall
+ /// throw an exception
+ /// @param string key to be stored
+ void setAuthKey(const std::string& key);
+
+ /// @brief equality operator
+ ///
+ /// equality operator to compare two AuthKey classes
+ /// @param Authkey to be compared against
+ bool operator==(const AuthKey& other) const;
+
+ /// @brief inequality operator
+ ///
+ /// inequality operator to compare two AuthKey classes
+ /// @param Authkey to be compared against
+ bool operator!=(const AuthKey& other) const;
+
+private:
+ std::string authKey_;
+};
+
/// @brief IPv6 reservation for a host.
///
/// This class represents a reservation for a host of a single IPv6
@@ -79,7 +143,7 @@ public:
/// multicast address or the prefix length is greater than 128.
IPv6Resrv(const Type& type,
const asiolink::IOAddress& prefix,
- const std::string& keys,
+ const AuthKey& key,
const uint8_t prefix_len = 128);
/// @brief Returns prefix for the reservation.
@@ -101,12 +165,19 @@ public:
return (type_);
}
- /// @brief Returns the keys.
+ /// @brief Returns the key.
+ ///
+ /// Keys are used for signing the Reconfigure Message.
+ AuthKey getKey() const {
+ return(key_);
+ }
+
+ /// @brief sets key.
///
/// Keys are used for signing the Reconfigure Message.
/// The accessor should ensure 128 characters
- std::string getKeys() const {
- return (keys_);
+ void setKey(const AuthKey& key) {
+ key_ = key;
}
/// @brief Sets a new prefix and prefix length.
@@ -118,18 +189,11 @@ public:
/// @throw isc::BadValue if prefix is not IPv6 prefix, is a
/// multicast address or the prefix length is greater than 128.
void set(const Type& type, const asiolink::IOAddress& prefix,
- const uint8_t prefix_len, const std::string& keys = "");
+ const uint8_t prefix_len, const AuthKey& key = std::string(""));
/// @brief Returns information about the reservation in the textual format.
std::string toText() const;
- /// @brief Generates random 128 bit string
- ///
- /// Random string is generated by default will be used for
- /// the keys to be used for signing Reconfigure Message.
-
- static std::string getRandomKeyString();
-
/// @brief Equality operator.
///
/// @param other Reservation to compare to.
@@ -145,8 +209,7 @@ private:
Type type_; ///< Reservation type.
asiolink::IOAddress prefix_; ///< Prefix
uint8_t prefix_len_; ///< Prefix length.
- std::string keys_; ///< keys for authentication.
-
+ AuthKey key_; ///< keys for authentication.
};
/// @brief Collection of IPv6 reservations for the host.
diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc
index a6cd094abb..b7a70f630f 100644
--- a/src/lib/dhcpsrv/mysql_host_data_source.cc
+++ b/src/lib/dhcpsrv/mysql_host_data_source.cc
@@ -74,7 +74,7 @@ const size_t SERVER_HOSTNAME_MAX_LEN = 64;
const size_t BOOT_FILE_NAME_MAX_LEN = 128;
/// @brief Maximum length of keys.
-const size_t KEY_MAX_LEN = 128;
+const size_t KEY_LEN = 16;
/// @brief Numeric value representing last supported identifier.
/// @brief Numeric value representing last supported identifier.
@@ -1537,7 +1537,7 @@ private:
uint32_t iaid_;
/// @brief Buffer length for holding keys in textual format.
- char key_buffer_[KEY_MAX_LEN + 1];
+ char key_buffer_[KEY_LEN + 1];
/// @brief Length of the keys
unsigned long key_len_;
@@ -1671,7 +1671,7 @@ public:
// key VARCHAR(128)
// why we need member for len
- key_ = resv.getKeys();
+ key_ = resv.getKey().getAuthKey();
key_len_ = key_.length();
bind_[5].buffer_type = MYSQL_TYPE_BLOB;
bind_[5].buffer = reinterpret_cast<char*>
diff --git a/src/lib/dhcpsrv/pgsql_host_data_source.cc b/src/lib/dhcpsrv/pgsql_host_data_source.cc
index bcbddd88af..983fe428a8 100644
--- a/src/lib/dhcpsrv/pgsql_host_data_source.cc
+++ b/src/lib/dhcpsrv/pgsql_host_data_source.cc
@@ -877,7 +877,7 @@ public:
columns_[iaid_index_] = "dhcp6_iaid";
columns_[key_index_] = "auth_key";
- BOOST_STATIC_ASSERT(4 < RESERVATION_COLUMNS);
+ BOOST_STATIC_ASSERT(5 < RESERVATION_COLUMNS);
}
/// @brief Reinitializes state information
@@ -946,7 +946,7 @@ public:
// getColumnValue(r, row, iaid_index_, iaid);
// Create the reservation.
- IPv6Resrv reservation(resv_type, IOAddress(address), key, prefix_len);
+ IPv6Resrv reservation(resv_type, IOAddress(address), AuthKey(key), prefix_len);
return (reservation);
};
@@ -1090,12 +1090,11 @@ public:
/// @todo: We don't support iaid in the IPv6Resrv yet.
bind_array->addNull();
+ // type: VARCHAR(16) NULL
+ bind_array->add(resv.getKey().getAuthKey());
+
// host_id: BIGINT NOT NULL
bind_array->add(host_id);
-
- // type: VARCHAR(128) NOT NULL
- bind_array->add(resv.getKeys());
-
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
"Could not create bind array from IPv6 Reservation: "
@@ -1637,10 +1636,10 @@ TaggedStatementArray tagged_statements = { {
//PgSqlHostDataSourceImpl::INSERT_V6_RESRV
// Inserts a single IPv6 reservation into 'reservations' table.
{6,
- { OID_VARCHAR, OID_INT2, OID_INT4, OID_INT4, OID_INT4 },
+ { OID_VARCHAR, OID_INT2, OID_INT4, OID_INT4, OID_VARCHAR, OID_INT4},
"insert_v6_resrv",
"INSERT INTO ipv6_reservations(address, prefix_len, type, "
- " dhcp6_iaid, host_id, auth_key) "
+ " dhcp6_iaid, auth_key, host_id) "
"VALUES ($1, $2, $3, $4, $5, $6)"
},
diff --git a/src/lib/dhcpsrv/tests/host_unittest.cc b/src/lib/dhcpsrv/tests/host_unittest.cc
index 983e94a9e7..1f0442ca8a 100644
--- a/src/lib/dhcpsrv/tests/host_unittest.cc
+++ b/src/lib/dhcpsrv/tests/host_unittest.cc
@@ -35,14 +35,15 @@ TEST(IPv6ResrvTest, constructorAddress) {
EXPECT_EQ("2001:db8:1::cafe", resrv.getPrefix().toText());
EXPECT_EQ(128, resrv.getPrefixLen());
EXPECT_EQ(IPv6Resrv::TYPE_NA, resrv.getType());
- EXPECT_EQ("", resrv.getKeys());
+ EXPECT_EQ("", resrv.getKey().getAuthKey());
//create reservation with keys
- IPv6Resrv resrv_keys(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::cafe"), "#ssd@@dce3");
+ std::string key = "#ssd@@dce3";
+ IPv6Resrv resrv_keys(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::cafe"), AuthKey(key));
EXPECT_EQ("2001:db8:1::cafe", resrv_keys.getPrefix().toText());
EXPECT_EQ(128, resrv_keys.getPrefixLen());
EXPECT_EQ(IPv6Resrv::TYPE_NA, resrv_keys.getType());
- EXPECT_EQ("#ssd@@dce3", resrv_keys.getKeys());
+ EXPECT_EQ(key, resrv_keys.getKey().getAuthKey());
}
// This test verifies that it is possible to create IPv6 prefix
@@ -52,14 +53,15 @@ TEST(IPv6ResrvTest, constructorPrefix) {
EXPECT_EQ("2001:db8:1::", resrv.getPrefix().toText());
EXPECT_EQ(64, resrv.getPrefixLen());
EXPECT_EQ(IPv6Resrv::TYPE_PD, resrv.getType());
- EXPECT_EQ("", resrv.getKeys());
+ EXPECT_EQ("", resrv.getKey().getAuthKey());
//create reservation with keys
- IPv6Resrv resrv_keys(IPv6Resrv::TYPE_PD, IOAddress("2001:db8:1::"), "#ssd@@dce3", 64);
+ std::string key = "#ssd@@dce3";
+ IPv6Resrv resrv_keys(IPv6Resrv::TYPE_PD, IOAddress("2001:db8:1::"), AuthKey(key), 64);
EXPECT_EQ("2001:db8:1::", resrv_keys.getPrefix().toText());
EXPECT_EQ(64, resrv_keys.getPrefixLen());
EXPECT_EQ(IPv6Resrv::TYPE_PD, resrv_keys.getType());
- EXPECT_EQ("#ssd@@dce3", resrv_keys.getKeys());
+ EXPECT_EQ(key, resrv_keys.getKey().getAuthKey());
}
// This test verifies that the toText() function prints correctly.
@@ -128,21 +130,16 @@ TEST(IPv6ResrvTest, setKeys) {
ASSERT_EQ("2001:db8:1::1", resrv.getPrefix().toText());
ASSERT_EQ(128, resrv.getPrefixLen());
ASSERT_EQ(IPv6Resrv::TYPE_NA, resrv.getType());
- ASSERT_EQ("", resrv.getKeys());
-
- // Replace default keys with new value.
- resrv.set(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::1"), 128, "first_set_keys_#");
- ASSERT_EQ("2001:db8:1::1", resrv.getPrefix().toText());
- ASSERT_EQ(128, resrv.getPrefixLen());
- ASSERT_EQ(IPv6Resrv::TYPE_NA, resrv.getType());
- ASSERT_EQ("first_set_keys_#", resrv.getKeys());
+ ASSERT_EQ("", resrv.getKey().getAuthKey());
// Modify an existing key for the reservation
- resrv.set(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::1"), 128, "second_set_keys_#");
+ std::string key2 = "key2";
+ resrv.set(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::1"),
+ 128, AuthKey(key2));
ASSERT_EQ("2001:db8:1::1", resrv.getPrefix().toText());
ASSERT_EQ(128, resrv.getPrefixLen());
ASSERT_EQ(IPv6Resrv::TYPE_NA, resrv.getType());
- ASSERT_EQ("second_set_keys_#", resrv.getKeys());
+ ASSERT_EQ(key2, resrv.getKey().getAuthKey());
// Enusre not including the key parameter won't affect
// the current configured keys
@@ -150,7 +147,7 @@ TEST(IPv6ResrvTest, setKeys) {
ASSERT_EQ("2001:db8:1::1", resrv.getPrefix().toText());
ASSERT_EQ(128, resrv.getPrefixLen());
ASSERT_EQ(IPv6Resrv::TYPE_NA, resrv.getType());
- ASSERT_EQ("second_set_keys_#", resrv.getKeys());
+ ASSERT_EQ(key2, resrv.getKey().getAuthKey());
}
// This test checks that the equality operators work fine.
@@ -182,22 +179,22 @@ TEST(IPv6ResrvTest, equal) {
IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"), 128));
EXPECT_TRUE(IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::1"),
- "key##1", 128) ==
+ AuthKey("key##1"), 128) ==
IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::1"),
- "key##1", 128));
+ AuthKey("key##1"), 128));
EXPECT_FALSE(IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"),
- "key##1", 128) !=
+ AuthKey("key##1"), 128) !=
IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"),
- "key##1", 128));
+ AuthKey("key##1"), 128));
EXPECT_FALSE(IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::1"),
- "key##1", 128) ==
+ AuthKey("key##1"), 128) ==
IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::1"),
- "key##2", 128));
+ AuthKey("key##2"), 128));
EXPECT_TRUE(IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"),
- "key##1", 128) !=
+ AuthKey("key##1"), 128) !=
IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"),
- "key##2", 128));
+ AuthKey("key##2"), 128));
}
/// @brief Test fixture class for @c Host.
@@ -678,9 +675,9 @@ TEST_F(HostTest, addReservations) {
// Add 4 reservations: 2 for NAs, 2 for PDs
ASSERT_NO_THROW(
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
- IOAddress("2001:db8:1::cafe"), "key##1"));
+ IOAddress("2001:db8:1::cafe"), AuthKey("key##1")));
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
- IOAddress("2001:db8:1:1::"), "key##2", 64));
+ IOAddress("2001:db8:1:1::"), AuthKey("key##2"), 64));
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
IOAddress("2001:db8:1:2::"), 64));
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
@@ -691,9 +688,9 @@ TEST_F(HostTest, addReservations) {
// Check that reservations exist.
EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
- IOAddress("2001:db8:1::cafe"), "key##1")));
+ IOAddress("2001:db8:1::cafe"), AuthKey("key##1"))));
EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
- IOAddress("2001:db8:1:1::"), "key##2",
+ IOAddress("2001:db8:1:1::"), AuthKey("key##2"),
64)));
EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
IOAddress("2001:db8:1:2::"),
@@ -705,7 +702,7 @@ TEST_F(HostTest, addReservations) {
IPv6ResrvRange addresses = host->getIPv6Reservations(IPv6Resrv::TYPE_NA);
ASSERT_EQ(2, std::distance(addresses.first, addresses.second));
EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_NA,
- IOAddress("2001:db8:1::cafe"), "key##1"),
+ IOAddress("2001:db8:1::cafe"), AuthKey("key##1")),
addresses));
EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_NA,
IOAddress("2001:db8:1::1")),
@@ -716,7 +713,7 @@ TEST_F(HostTest, addReservations) {
IPv6ResrvRange prefixes = host->getIPv6Reservations(IPv6Resrv::TYPE_PD);
ASSERT_EQ(2, std::distance(prefixes.first, prefixes.second));
EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_PD,
- IOAddress("2001:db8:1:1::"),"key##2", 64),
+ IOAddress("2001:db8:1:1::"), AuthKey("key##2"), 64),
prefixes));
EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_PD,
IOAddress("2001:db8:1:2::"), 64),
@@ -1291,7 +1288,7 @@ TEST_F(HostTest, randomKeys) {
key_map.reserve(max_hash_size);
for (iter_num = 0; iter_num < max_iter; iter_num++) {
- std::string key = IPv6Resrv::getRandomKeyString();
+ std::string key = AuthKey::getRandomKeyString();
if (key_map[key]) {
dup_element++;
break;
@@ -1303,6 +1300,31 @@ TEST_F(HostTest, randomKeys) {
EXPECT_EQ(0, dup_element);
}
+//Test performs basic functionality test of the AuthKey class
+TEST(AuthKeyTest, basicTest) {
+ //call the constructor with default argument
+ // Default constructor should generate random string of 16 bytes
+ AuthKey defaultKey;
+ ASSERT_EQ(16, defaultKey.getAuthKey().size());
+
+ AuthKey longKey("someRandomStringGreaterThan16Bytes");
+ ASSERT_EQ(16, longKey.getAuthKey().size());
+
+ //check the setters for valid and invalid string
+ std::string key16ByteStr = "0123456789abcdef";
+ std::string key18ByteStr = "0123456789abcdefgh";
+
+ AuthKey defaultTestKey;
+
+ defaultTestKey.setAuthKey(key16ByteStr);
+ ASSERT_EQ(16, defaultTestKey.getAuthKey().size());
+ ASSERT_EQ(key16ByteStr, defaultTestKey.getAuthKey());
+
+ defaultTestKey.setAuthKey(key18ByteStr);
+ ASSERT_EQ(16, defaultTestKey.getAuthKey().size());
+ ASSERT_EQ(key16ByteStr, defaultTestKey.getAuthKey());
+
+}
} // end of anonymous namespace
diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
index 3d7324db82..29c2b9a279 100644
--- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
+++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
@@ -897,7 +897,7 @@ GenericHostDataSourceTest::testAddr6AndPrefix() {
true, "key##1", true);
// Create IPv6 reservation (for an address) and add it to the host
- IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::2"), "key##2", 128);
+ IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::2"), AuthKey("key##2"), 128);
host->addReservation(resv);
// Add this reservation
@@ -925,10 +925,10 @@ GenericHostDataSourceTest::testMultipleReservations() {
HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
// Add some reservations
- IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), "key##1", len);
- IPv6Resrv resv2(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::7"), "key##2", len);
- IPv6Resrv resv3(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::8"), "key##3", len);
- IPv6Resrv resv4(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::9"), "key##4", len);
+ IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), AuthKey("key##1"), len);
+ IPv6Resrv resv2(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::7"), AuthKey("key##2"), len);
+ IPv6Resrv resv3(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::8"), AuthKey("key##3"), len);
+ IPv6Resrv resv4(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::9"), AuthKey("key##4"), len);
host->addReservation(resv1);
host->addReservation(resv2);
@@ -956,10 +956,10 @@ GenericHostDataSourceTest::testMultipleReservationsDifferentOrder() {
HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
// Add some reservations
- IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), "key##1", len);
- IPv6Resrv resv2(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::7"), "key##2", len);
- IPv6Resrv resv3(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::8"), "key##3", len);
- IPv6Resrv resv4(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::9"), "key##4", len);
+ IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), AuthKey("key##1"), len);
+ IPv6Resrv resv2(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::7"), AuthKey("key##2"), len);
+ IPv6Resrv resv3(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::8"), AuthKey("key##3"), len);
+ IPv6Resrv resv4(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::9"), AuthKey("key##4"), len);
host1->addReservation(resv1);
host1->addReservation(resv2);
diff --git a/src/lib/dhcpsrv/testutils/host_data_source_utils.cc b/src/lib/dhcpsrv/testutils/host_data_source_utils.cc
index 364f26ecb9..093f1b99a3 100644
--- a/src/lib/dhcpsrv/testutils/host_data_source_utils.cc
+++ b/src/lib/dhcpsrv/testutils/host_data_source_utils.cc
@@ -112,11 +112,11 @@ HostDataSourceUtils::initializeHost6(const std::string address,
if (!prefix) {
// Create IPv6 reservation (for an address)
- IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress(address), key, 128);
+ IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress(address), AuthKey(key), 128);
host->addReservation(resv);
} else {
// Create IPv6 reservation for a /64 prefix
- IPv6Resrv resv(IPv6Resrv::TYPE_PD, IOAddress(address), key, 64);
+ IPv6Resrv resv(IPv6Resrv::TYPE_PD, IOAddress(address), AuthKey(key), 64);
host->addReservation(resv);
}
return (host);