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