887953
From f0e9776dd915c70bd9acb4e9624e8e2fd91ae7b7 Mon Sep 17 00:00:00 2001
887953
From: Kotresh HR <khiremat@redhat.com>
887953
Date: Tue, 19 Dec 2017 07:21:07 -0500
887953
Subject: [PATCH 376/385] rchecksum/fips: Replace MD5 usage to enable fips
887953
 support
887953
887953
rchecksum uses MD5 which is not fips compliant. Hence
887953
using sha256 for the same.
887953
887953
Backport of:
887953
 > Patch: https://review.gluster.org/19052
887953
 > Updates: #230
887953
 > Change-Id: I7fad016fcc2a9900395d0da919cf5ba996ec5278
887953
 > Signed-off-by: Kotresh HR <khiremat@redhat.com>
887953
887953
BUG: 1459709
887953
Change-Id: I7fad016fcc2a9900395d0da919cf5ba996ec5278
887953
Signed-off-by: Kotresh HR <khiremat@redhat.com>
887953
Reviewed-on: https://code.engineering.redhat.com/gerrit/149771
887953
Tested-by: RHGS Build Bot <nigelb@redhat.com>
887953
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
887953
---
887953
 libglusterfs/src/checksum.c                    | 8 +++++---
887953
 libglusterfs/src/default-args.c                | 2 +-
887953
 xlators/cluster/afr/src/afr-self-heal-common.c | 2 +-
887953
 xlators/cluster/afr/src/afr-self-heal-data.c   | 4 ++--
887953
 xlators/cluster/afr/src/afr.h                  | 2 +-
887953
 xlators/mgmt/glusterd/src/glusterd-utils.c     | 2 +-
887953
 xlators/protocol/server/src/server-common.c    | 2 +-
887953
 xlators/storage/bd/src/bd.c                    | 4 +---
887953
 xlators/storage/posix/src/posix.c              | 3 +--
887953
 9 files changed, 14 insertions(+), 15 deletions(-)
887953
887953
diff --git a/libglusterfs/src/checksum.c b/libglusterfs/src/checksum.c
887953
index 5fac133..a7f9877 100644
887953
--- a/libglusterfs/src/checksum.c
887953
+++ b/libglusterfs/src/checksum.c
887953
@@ -8,9 +8,10 @@
887953
   cases as published by the Free Software Foundation.
887953
 */
887953
 
887953
-#include <openssl/md5.h>
887953
+#include <openssl/sha.h>
887953
 #include <zlib.h>
887953
 #include <stdint.h>
887953
+#include <string.h>
887953
 
887953
 /*
887953
  * The "weak" checksum required for the rsync algorithm.
887953
@@ -30,7 +31,8 @@ gf_rsync_weak_checksum (unsigned char *buf, size_t len)
887953
  * The "strong" checksum required for the rsync algorithm.
887953
  */
887953
 void
887953
-gf_rsync_strong_checksum (unsigned char *data, size_t len, unsigned char *md5)
887953
+gf_rsync_strong_checksum (unsigned char *data, size_t len,
887953
+                          unsigned char *sha256_md)
887953
 {
887953
-        MD5 (data, len, md5);
887953
+        SHA256((const unsigned char *)data, len, sha256_md);
887953
 }
887953
diff --git a/libglusterfs/src/default-args.c b/libglusterfs/src/default-args.c
887953
index f40de2d..3ccf52a 100644
887953
--- a/libglusterfs/src/default-args.c
887953
+++ b/libglusterfs/src/default-args.c
887953
@@ -1140,7 +1140,7 @@ args_rchecksum_cbk_store (default_args_cbk_t *args,
887953
                 args->weak_checksum =
887953
                         weak_checksum;
887953
                 args->strong_checksum =
887953
-                        memdup (strong_checksum, MD5_DIGEST_LENGTH);
887953
+                        memdup (strong_checksum, SHA256_DIGEST_LENGTH);
887953
         }
887953
         if (xdata)
887953
                 args->xdata = dict_ref (xdata);
887953
diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c
887953
index 50989d6..2989b9e 100644
887953
--- a/xlators/cluster/afr/src/afr-self-heal-common.c
887953
+++ b/xlators/cluster/afr/src/afr-self-heal-common.c
887953
@@ -665,7 +665,7 @@ afr_reply_copy (struct afr_reply *dst, struct afr_reply *src)
887953
 	if (dst->xdata)
887953
 		dict_unref (dst->xdata);
887953
 	dst->xdata = xdata;
887953
-	memcpy (dst->checksum, src->checksum, MD5_DIGEST_LENGTH);
887953
+	memcpy (dst->checksum, src->checksum, SHA256_DIGEST_LENGTH);
887953
 }
887953
 
887953
 void
887953
diff --git a/xlators/cluster/afr/src/afr-self-heal-data.c b/xlators/cluster/afr/src/afr-self-heal-data.c
887953
index 3ef7376..dd44deb 100644
887953
--- a/xlators/cluster/afr/src/afr-self-heal-data.c
887953
+++ b/xlators/cluster/afr/src/afr-self-heal-data.c
887953
@@ -42,7 +42,7 @@ __checksum_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
887953
                 replies[i].buf_has_zeroes = dict_get_str_boolean (xdata,
887953
                                                    "buf-has-zeroes", _gf_false);
887953
 	if (strong)
887953
-		memcpy (local->replies[i].checksum, strong, MD5_DIGEST_LENGTH);
887953
+            memcpy (local->replies[i].checksum, strong, SHA256_DIGEST_LENGTH);
887953
 
887953
 	syncbarrier_wake (&local->barrier);
887953
 	return 0;
887953
@@ -92,7 +92,7 @@ __afr_can_skip_data_block_heal (call_frame_t *frame, xlator_t *this, fd_t *fd,
887953
                 if (local->replies[i].valid) {
887953
                         if (memcmp (local->replies[source].checksum,
887953
                                     local->replies[i].checksum,
887953
-                                    MD5_DIGEST_LENGTH)) {
887953
+                                    SHA256_DIGEST_LENGTH)) {
887953
                                 checksum_match = _gf_false;
887953
                                 break;
887953
                         }
887953
diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h
887953
index 35928a9..7cb6f00 100644
887953
--- a/xlators/cluster/afr/src/afr.h
887953
+++ b/xlators/cluster/afr/src/afr.h
887953
@@ -271,7 +271,7 @@ struct afr_reply {
887953
 	struct iatt preparent2;
887953
 	struct iatt postparent2;
887953
         /* For rchecksum */
887953
-	uint8_t checksum[MD5_DIGEST_LENGTH];
887953
+	uint8_t checksum[SHA256_DIGEST_LENGTH];
887953
         gf_boolean_t buf_has_zeroes;
887953
         /* For lookup */
887953
         int8_t need_heal;
887953
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
887953
index 3db3a15..2a176be 100644
887953
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
887953
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
887953
@@ -1873,7 +1873,7 @@ glusterd_set_brick_socket_filepath (glusterd_volinfo_t *volinfo,
887953
         char                    sock_filepath[PATH_MAX] = {0,};
887953
 
887953
         expected_file_len = strlen (GLUSTERD_SOCK_DIR) + strlen ("/") +
887953
-                            MD5_DIGEST_LENGTH*2 + strlen (".socket") + 1;
887953
+                            SHA256_DIGEST_LENGTH*2 + strlen (".socket") + 1;
887953
         GF_ASSERT (len >= expected_file_len);
887953
         this = THIS;
887953
         GF_ASSERT (this);
887953
diff --git a/xlators/protocol/server/src/server-common.c b/xlators/protocol/server/src/server-common.c
887953
index ce33089..9c38706 100644
887953
--- a/xlators/protocol/server/src/server-common.c
887953
+++ b/xlators/protocol/server/src/server-common.c
887953
@@ -298,7 +298,7 @@ server_post_rchecksum (gfs3_rchecksum_rsp *rsp, uint32_t weak_checksum,
887953
         rsp->weak_checksum = weak_checksum;
887953
 
887953
         rsp->strong_checksum.strong_checksum_val = (char *)strong_checksum;
887953
-        rsp->strong_checksum.strong_checksum_len = MD5_DIGEST_LENGTH;
887953
+        rsp->strong_checksum.strong_checksum_len = SHA256_DIGEST_LENGTH;
887953
 
887953
 }
887953
 
887953
diff --git a/xlators/storage/bd/src/bd.c b/xlators/storage/bd/src/bd.c
887953
index af3ac84..64b34d9 100644
887953
--- a/xlators/storage/bd/src/bd.c
887953
+++ b/xlators/storage/bd/src/bd.c
887953
@@ -2148,7 +2148,7 @@ bd_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
887953
         char           *buf             = NULL;
887953
         int32_t         weak_checksum   = 0;
887953
         bd_fd_t        *bd_fd           = NULL;
887953
-        unsigned char   strong_checksum[MD5_DIGEST_LENGTH] = {0};
887953
+        unsigned char   strong_checksum[SHA256_DIGEST_LENGTH] = {0};
887953
 
887953
         VALIDATE_OR_GOTO (frame, out);
887953
         VALIDATE_OR_GOTO (this, out);
887953
@@ -2162,8 +2162,6 @@ bd_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
887953
                 return 0;
887953
         }
887953
 
887953
-        memset (strong_checksum, 0, MD5_DIGEST_LENGTH);
887953
-
887953
         alloc_buf = page_aligned_alloc (len, &buf;;
887953
         if (!alloc_buf) {
887953
                 op_errno = ENOMEM;
887953
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
887953
index efbf804..4e13465 100644
887953
--- a/xlators/storage/posix/src/posix.c
887953
+++ b/xlators/storage/posix/src/posix.c
887953
@@ -7000,7 +7000,7 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this,
887953
         ssize_t                 bytes_read      = 0;
887953
         int32_t                 weak_checksum   = 0;
887953
         int32_t                 zerofillcheck   = 0;
887953
-        unsigned char           strong_checksum[MD5_DIGEST_LENGTH] = {0};
887953
+        unsigned char           strong_checksum[SHA256_DIGEST_LENGTH] = {0};
887953
         struct posix_private    *priv           = NULL;
887953
         dict_t                  *rsp_xdata      = NULL;
887953
         gf_boolean_t            buf_has_zeroes  = _gf_false;
887953
@@ -7010,7 +7010,6 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this,
887953
         VALIDATE_OR_GOTO (fd, out);
887953
 
887953
         priv = this->private;
887953
-        memset (strong_checksum, 0, MD5_DIGEST_LENGTH);
887953
 
887953
         alloc_buf = _page_aligned_alloc (len, &buf;;
887953
         if (!alloc_buf) {
887953
-- 
887953
1.8.3.1
887953