Prechádzať zdrojové kódy

crypto: Support for knet_get_crypto_hash_list

Similar to the crypto cipher list, use
knet_get_crypto_hash_list (if available) to get the list
of allowed crypto hashes.

For older versions of knet, a hardcoded list (identical to what was
defined in coroparse.c) is used.

The list is displayed in the corosync -v output and used by
coroparse.c.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 2 týždňov pred
rodič
commit
6e2f7ae4da
5 zmenil súbory, kde vykonal 73 pridanie a 9 odobranie
  1. 2 0
      configure.ac
  2. 11 9
      exec/coroparse.c
  3. 6 0
      exec/main.c
  4. 50 0
      exec/util.c
  5. 4 0
      exec/util.h

+ 2 - 0
configure.ac

@@ -191,6 +191,8 @@ AC_CHECK_LIB([knet],[knet_handle_setprio_dscp],
 	     [AC_DEFINE_UNQUOTED([HAVE_KNET_SETPRIO_DSCP], 1, [have knet dscp traffic prioritization])])
 AC_CHECK_LIB([knet],[knet_get_crypto_cipher_list],
 	     [AC_DEFINE_UNQUOTED([HAVE_KNET_GET_CRYPTO_CIPHER_LIST], 1, [have knet get crypto cipher list])])
+AC_CHECK_LIB([knet],[knet_get_crypto_hash_list],
+	     [AC_DEFINE_UNQUOTED([HAVE_KNET_GET_CRYPTO_HASH_LIST], 1, [have knet get crypto hash list])])
 LIBS="$OLDLIBS"
 
 # Checks for library functions.

+ 11 - 9
exec/coroparse.c

@@ -625,6 +625,16 @@ static int handle_crypto_cipher(const char *val, const char **error_string)
 	}
 }
 
+static int handle_crypto_hash(const char *val, const char **error_string)
+{
+
+	if (util_is_valid_knet_crypto_hash(val, NULL, 0,
+	    "Invalid hash type. Should be ", error_string) == 1) {
+		return (0);
+	} else {
+		return (-1);
+	}
+}
 
 static int handle_compress_model(const char *val, const char **error_string)
 {
@@ -863,15 +873,7 @@ static int main_config_parser_cb(const char *path,
 				}
 			}
 			if (strcmp(path, "totem.crypto_hash") == 0) {
-				if ((strcmp(value, "none") != 0) &&
-				    (strcmp(value, "md5") != 0) &&
-				    (strcmp(value, "sha1") != 0) &&
-				    (strcmp(value, "sha256") != 0) &&
-				    (strcmp(value, "sha384") != 0) &&
-				    (strcmp(value, "sha512") != 0)) {
-					*error_string = "Invalid hash type. "
-					    "Should be none, md5, sha1, sha256, sha384 or sha512";
-
+				if (handle_crypto_hash(value, error_string) != 0) {
 					return (0);
 				}
 			}

+ 6 - 0
exec/main.c

@@ -1261,6 +1261,12 @@ static void show_version_info_crypto(void)
 	} else {
 		perror(error_string);
 	}
+
+	if (util_is_valid_knet_crypto_hash(NULL, &list_str, 1, "", &error_string) != -1) {
+		printf("Available crypto hashes: %s\n", list_str);
+	} else {
+		perror(error_string);
+	}
 }
 
 static void show_version_info_compress(void)

+ 50 - 0
exec/util.c

@@ -398,6 +398,56 @@ int util_is_valid_knet_crypto_cipher(const char *val,
 	    machine_parseable_str, error_string_prefix, error_string));
 }
 
+/*
+ * Similar to util_is_valid_knet_crypto_model
+ */
+int util_is_valid_knet_crypto_hash(const char *val,
+	const char **list_str, int machine_parseable_str,
+	const char *error_string_prefix, const char **error_string)
+{
+	const char *items[UTILS_IS_VALID_KNET_LIST_MAX_ITEMS];
+	size_t items_out_idx = 0;
+#ifdef HAVE_KNET_GET_CRYPTO_HASH_LIST
+	size_t entries;
+	size_t zi;
+	struct knet_crypto_hash_info crypto_hash_list[UTILS_IS_VALID_KNET_LIST_MAX_ITEMS];
+#endif
+
+#ifdef ENABLE_UNENCRYPTED
+	items[items_out_idx++] = "none";
+#endif
+
+#ifdef HAVE_KNET_GET_CRYPTO_HASH_LIST
+	if (knet_get_crypto_hash_list(NULL, &entries) != 0) {
+		*error_string = "internal error - cannot get crypto hash list";
+		return (-1);
+	}
+
+	if (entries > (sizeof(crypto_hash_list) / sizeof(crypto_hash_list[0])) - items_out_idx) {
+		*error_string = "internal error - too many knet crypto hash list entries";
+		return (-1);
+	}
+
+	if (knet_get_crypto_hash_list(crypto_hash_list, &entries) != 0) {
+		*error_string = "internal error - cannot get knet crypto hash list";
+		return (-1);
+	}
+
+	for (zi = 0; zi < entries; zi++) {
+		items[items_out_idx++] = crypto_hash_list[zi].name;
+	}
+#else
+	items[items_out_idx++] = "md5";
+	items[items_out_idx++] = "sha1";
+	items[items_out_idx++] = "sha256";
+	items[items_out_idx++] = "sha384";
+	items[items_out_idx++] = "sha512";
+#endif
+
+	return (util_is_valid_knet_list_helper(val, items, items_out_idx, list_str,
+	    machine_parseable_str, error_string_prefix, error_string));
+}
+
 int
 set_socket_dscp(int socket, unsigned char dscp)
 {

+ 4 - 0
exec/util.h

@@ -99,6 +99,10 @@ extern int util_is_valid_knet_crypto_cipher(const char *val,
 	const char **list_str, int machine_parseable_str,
 	const char *error_string_prefix, const char **error_string);
 
+extern int util_is_valid_knet_crypto_hash(const char *val,
+	const char **list_str, int machine_parseable_str,
+	const char *error_string_prefix, const char **error_string);
+
 int set_socket_dscp(int socket, unsigned char dscp);
 
 #endif /* UTIL_H_DEFINED */