]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[550-authentication-key-to-text-method-miss-spelled] Addressed comments
authorFrancis Dupont <fdupont@isc.org>
Tue, 2 Jul 2019 10:40:50 +0000 (12:40 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 2 Jul 2019 15:33:39 +0000 (17:33 +0200)
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/host.cc
src/lib/dhcpsrv/host.h
src/lib/dhcpsrv/mysql_host_data_source.cc

index 79d123e09e5f04293933d0472f545ea7f29a987f..34f6d3e2725c655bc82ce32215e62ccbb08acea6 100644 (file)
@@ -85,24 +85,6 @@ struct OptionWrapper {
     std::string option_space_;
 };
 
-/// @brief Maximum length of classes stored in a host_ipv4/6_client_classes
-///     column.
-static constexpr size_t CLIENT_CLASSES_MAX_LENGTH = 255u;
-
-/// @brief Maximum length of the hostname stored in DNS. This length is
-///     restricted by the length of the domain-name carried in the Client FQDN
-///     Option (see RFC4702 and RFC4704).
-static constexpr size_t HOSTNAME_MAX_LENGTH = 255u;
-
-/// @brief Maximum length of option value
-static constexpr size_t OPTION_VALUE_MAX_LENGTH = 4096u;
-
-/// @brief Maximum length of option value specified in textual format
-static constexpr size_t OPTION_FORMATTED_VALUE_MAX_LENGTH = 8192u;
-
-/// @brief Maximum length of option space name
-static constexpr size_t OPTION_SPACE_MAX_LENGTH = 128u;
-
 /// @brief Numeric value representing the last supported identifier. This value
 ///     is used to validate whether the identifier type stored in a database is
 ///     within bounds of supported identifiers.
@@ -1377,10 +1359,10 @@ CqlHostExchange::prepareExchange(const HostPtr& host,
 
         // hostname: text
         hostname_ = host->getHostname();
-        if (hostname_.size() > HOSTNAME_MAX_LENGTH) {
+        if (hostname_.size() > HOSTNAME_MAX_LEN) {
             isc_throw(BadValue, "CqlHostExchange::prepareExchange(): hostname "
                       << hostname_ << " of length " << hostname_.size()
-                      << " is greater than allowed of " << HOSTNAME_MAX_LENGTH);
+                      << " is greater than allowed of " << HOSTNAME_MAX_LEN);
         }
 
         // user_context: text
@@ -1393,20 +1375,20 @@ CqlHostExchange::prepareExchange(const HostPtr& host,
 
         // host_ipv4_client_classes: text
         host_ipv4_client_classes_ = host->getClientClasses4().toText(",");
-        if (host_ipv4_client_classes_.size() > CLIENT_CLASSES_MAX_LENGTH) {
+        if (host_ipv4_client_classes_.size() > CLIENT_CLASSES_MAX_LEN) {
             isc_throw(BadValue, "CqlHostExchange::prepareExchange(): "
                       "IPv4 client classes " << host_ipv4_client_classes_ << " of length "
                       << host_ipv4_client_classes_.size() << " is greater than allowed of "
-                      << CLIENT_CLASSES_MAX_LENGTH);
+                      << CLIENT_CLASSES_MAX_LEN);
         }
 
         // host_ipv6_client_classes: text
         host_ipv6_client_classes_ = host->getClientClasses6().toText(",");
-        if (host_ipv6_client_classes_.size() > CLIENT_CLASSES_MAX_LENGTH) {
+        if (host_ipv6_client_classes_.size() > CLIENT_CLASSES_MAX_LEN) {
             isc_throw(BadValue, "CqlHostExchange::prepareExchange(): "
                       "IPv6 client classes " << host_ipv6_client_classes_ << " of length "
                       << host_ipv6_client_classes_.size() << " is greater than allowed of "
-                      << CLIENT_CLASSES_MAX_LENGTH);
+                      << CLIENT_CLASSES_MAX_LEN);
         }
 
         if (reservation == NULL) {
@@ -1613,7 +1595,7 @@ CqlHostExchange::hashIntoId() const {
     key_stream << std::setw(4) << std::setfill('-')
                << reserved_ipv6_prefix_length_;
     key_stream << std::setw(4) << std::setfill('-') << option_code_;
-    key_stream << std::setw(OPTION_SPACE_MAX_LENGTH) << std::setfill('-')
+    key_stream << std::setw(OPTION_SPACE_MAX_LEN) << std::setfill('-')
                << option_space_;
     const std::string key = key_stream.str();
 
index 5ffb873cce3399775ef4246fde71f12821c11583..cb5659b94fbf7e0d68aee89a97bf7931719e9237 100644 (file)
@@ -36,7 +36,7 @@ AuthKey::AuthKey() {
 
 std::vector<uint8_t>
 AuthKey::getRandomKeyString() {
-    return (isc::cryptolink::random(AuthKey::KEY_LEN));
+    return (isc::cryptolink::random(AUTH_KEY_LEN));
 }
 
 std::string
@@ -50,8 +50,8 @@ AuthKey::toText() const {
 void
 AuthKey::setAuthKey(const std::vector<uint8_t>& key) {
     authKey_ = key;
-    if (authKey_.size() > AuthKey::KEY_LEN) {
-        authKey_.resize(AuthKey::KEY_LEN);
+    if (authKey_.size() > AUTH_KEY_LEN) {
+        authKey_.resize(AUTH_KEY_LEN);
     }
 }
 
@@ -59,6 +59,7 @@ void
 AuthKey::setAuthKey(const std::string& key) {
     if (key.empty()) {
         authKey_.clear();
+        return;
     }
     try {
         std::vector<uint8_t> bin;
index 7b6bf976b63186958633db4f04b2fedae7f4637a..8c81ca8a5c1abe7e3b6b68a48fb5a162592dc00f 100644 (file)
 namespace isc {
 namespace dhcp {
 
+/// @brief Maximum size of an IPv6 address represented as a text string.
+///
+/// This is 32 hexadecimal characters written in 8 groups of four, plus seven
+/// colon separators.
+const size_t ADDRESS6_TEXT_MAX_LEN = 39;
+
+/// @brief Maximum length of classes stored in a dhcp4/6_client_classes
+/// columns.
+const size_t CLIENT_CLASSES_MAX_LEN = 255;
+
+/// @brief Maximum length of the hostname stored in DNS.
+///
+/// This length is restricted by the length of the domain-name carried
+/// in the Client FQDN %Option (see RFC4702 and RFC4704).
+const size_t HOSTNAME_MAX_LEN = 255;
+
+/// @brief Maximum length of option value.
+const size_t OPTION_VALUE_MAX_LEN = 4096;
+
+/// @brief Maximum length of option value specified in textual format.
+const size_t OPTION_FORMATTED_VALUE_MAX_LEN = 8192;
+
+/// @brief Maximum length of option space name.
+const size_t OPTION_SPACE_MAX_LEN = 128;
+
+/// @brief Maximum length of user context.
+const size_t USER_CONTEXT_MAX_LEN = 8192;
+
+/// @brief Maximum length of the server hostname.
+const size_t SERVER_HOSTNAME_MAX_LEN = 64;
+
+/// @brief Maximum length of the boot file name.
+const size_t BOOT_FILE_NAME_MAX_LEN = 128;
+
+/// @brief Maximum length of authentication keys - 128 bits.
+const uint8_t AUTH_KEY_LEN = 16;
+
+/// @brief Maximum length of authentication keys (coded in hexadecimal).
+const size_t TEXT_AUTH_KEY_LEN = AUTH_KEY_LEN * 2;
+
 /// @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.
+/// calculating HMAC in the authentication field of the reconfigure 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.
@@ -46,7 +83,10 @@ public:
     /// @brief Constructor.
     ///
     /// Constructor for assigning auth keys in host reservation.
-    /// Ensures the key length is not greater than 16 bytes.
+    /// Ensures the key length is not greater than AUTH_KEY_LEN (16) bytes
+    /// so TEXT_AUTH_KEY_LEN (32) hexadecimal digits.
+    /// See @c setKey for constraints on its input format.
+    ///
     /// @param key auth key in hexadecimal to be stored.
     AuthKey(const std::string& key);
 
@@ -76,7 +116,8 @@ public:
     /// Set the key value.
     /// If the size is greater than 16 bytes, we resize to 16 bytes.
     /// @param key auth key in hexadecimal to be stored.
-    /// @throw BadValue if the string is not a valid hexadecimal encoding.
+    /// @throw BadValue if the string is not a valid hexadecimal encoding,
+    /// for instance has a not hexadecimal or odd number of digits.
     void setAuthKey(const std::string& key);
 
     /// @brief Return auth key.
@@ -88,7 +129,7 @@ public:
 
     /// @brief Return text format for keys.
     ///
-    /// @return auth key in hexadecimal.
+    /// @return auth key as a string of hexadecimal digits.
     std::string toText() const;
 
     ///
index b11baaef23b0db112985ff1525331ad150f5225f..6e4b79f99402c6479021e65b5a3dfd86212ca484 100644 (file)
@@ -39,43 +39,6 @@ using namespace std;
 
 namespace {
 
-/// @brief Maximum size of an IPv6 address represented as a text string.
-///
-/// This is 32 hexadecimal characters written in 8 groups of four, plus seven
-/// colon separators.
-const size_t ADDRESS6_TEXT_MAX_LEN = 39;
-
-/// @brief Maximum length of classes stored in a dhcp4/6_client_classes
-/// columns.
-const size_t CLIENT_CLASSES_MAX_LEN = 255;
-
-/// @brief Maximum length of the hostname stored in DNS.
-///
-/// This length is restricted by the length of the domain-name carried
-/// in the Client FQDN %Option (see RFC4702 and RFC4704).
-const size_t HOSTNAME_MAX_LEN = 255;
-
-/// @brief Maximum length of option value.
-const size_t OPTION_VALUE_MAX_LEN = 4096;
-
-/// @brief Maximum length of option value specified in textual format.
-const size_t OPTION_FORMATTED_VALUE_MAX_LEN = 8192;
-
-/// @brief Maximum length of option space name.
-const size_t OPTION_SPACE_MAX_LEN = 128;
-
-/// @brief Maximum length of user context.
-const size_t USER_CONTEXT_MAX_LEN = 8192;
-
-/// @brief Maximum length of the server hostname.
-const size_t SERVER_HOSTNAME_MAX_LEN = 64;
-
-/// @brief Maximum length of the boot file name.
-const size_t BOOT_FILE_NAME_MAX_LEN = 128;
-
-/// @brief Maximum length of keys (coded in hexadecimal).
-const size_t KEY_LEN = 16 * 2;
-
 /// @brief Numeric value representing last supported identifier.
 ///
 /// This value is used to validate whether the identifier type stored in
@@ -407,7 +370,7 @@ public:
             // auth key
             bind_[13].buffer_type = MYSQL_TYPE_STRING;
             std::string auth_key = host->getKey().toText();
-            std::strncpy(auth_key_, auth_key.c_str(), KEY_LEN);
+            std::strncpy(auth_key_, auth_key.c_str(), TEXT_AUTH_KEY_LEN);
             auth_key_null_ =  auth_key.empty() ? MLM_TRUE : MLM_FALSE;
             bind_[13].buffer = auth_key_;
             bind_[13].buffer_length = auth_key.length();
@@ -800,7 +763,7 @@ private:
     unsigned long dhcp4_boot_file_name_length_;
 
     /// Authentication keys
-    char  auth_key_[KEY_LEN];
+    char  auth_key_[TEXT_AUTH_KEY_LEN];
 
     /// The length of the string for holding keys
     unsigned long auth_key_length_;