yifengyou / rpms / yum

Forked from rpms/yum 3 years ago
Clone

Blame SOURCES/BZ-1287610-fips-dont-pollute-stderr.patch

5e9bef
diff -up yum-3.4.3/yum/Errors.py.orig yum-3.4.3/yum/Errors.py
5e9bef
--- yum-3.4.3/yum/Errors.py.orig	2017-09-14 18:42:26.740558383 +0200
5e9bef
+++ yum-3.4.3/yum/Errors.py	2017-09-14 18:42:30.371541754 +0200
5e9bef
@@ -99,6 +99,11 @@ class ConfigError(YumBaseError):
5e9bef
 class MiscError(YumBaseError):
5e9bef
     pass
5e9bef
 
5e9bef
+class FIPSNonCompliantError(MiscError):
5e9bef
+    def __init__(self, sumtype):
5e9bef
+        MiscError.__init__(
5e9bef
+            self, '%s algorithm is not FIPS compliant' % sumtype)
5e9bef
+
5e9bef
 class GroupsError(YumBaseError):
5e9bef
     pass
5e9bef
 
5e9bef
diff -up yum-3.4.3/yum/misc.py.orig yum-3.4.3/yum/misc.py
5e9bef
--- yum-3.4.3/yum/misc.py.orig	2017-09-14 18:42:26.794558135 +0200
5e9bef
+++ yum-3.4.3/yum/misc.py	2017-09-14 18:42:30.372541749 +0200
5e9bef
@@ -58,11 +58,20 @@ except ImportError:
5e9bef
             raise ValueError, "Bad checksum type"
5e9bef
 
5e9bef
 # some checksum types might be disabled
5e9bef
+_fips_noncompliant = set()
5e9bef
 for ctype in list(_available_checksums):
5e9bef
     try:
5e9bef
         hashlib.new(ctype)
5e9bef
-    except:
5e9bef
-        print >> sys.stderr, 'Checksum type %s disabled' % repr(ctype)
5e9bef
+    except Exception as e:
5e9bef
+        # Print an error unless this is due to FIPS mode (in which case it's
5e9bef
+        # not really an error and we don't want to pollute the output
5e9bef
+        # needlessly; if someone actually tries to instantiate a Checksum with
5e9bef
+        # a FIPS non-compliant ctype, we'll raise an explanatory exception
5e9bef
+        # anyway).
5e9bef
+        if isinstance(e, ValueError) and str(e).endswith('disabled for fips'):
5e9bef
+            _fips_noncompliant.add(ctype)
5e9bef
+        else:
5e9bef
+            print >> sys.stderr, 'Checksum type %s disabled' % repr(ctype)
5e9bef
         _available_checksums.remove(ctype)
5e9bef
 for ctype in 'sha256', 'sha1':
5e9bef
     if ctype in _available_checksums:
5e9bef
@@ -71,7 +80,7 @@ for ctype in 'sha256', 'sha1':
5e9bef
 else:
5e9bef
     raise ImportError, 'broken hashlib'
5e9bef
 
5e9bef
-from Errors import MiscError
5e9bef
+from Errors import MiscError, FIPSNonCompliantError
5e9bef
 # These are API things, so we can't remove them even if they aren't used here.
5e9bef
 # pylint: disable-msg=W0611
5e9bef
 from i18n import to_utf8, to_unicode
5e9bef
@@ -271,6 +280,8 @@ class Checksums:
5e9bef
                 sumalgo = hashlib.new(sumtype)
5e9bef
             elif ignore_missing:
5e9bef
                 continue
5e9bef
+            elif sumtype in _fips_noncompliant:
5e9bef
+                raise FIPSNonCompliantError(sumtype)
5e9bef
             else:
5e9bef
                 raise MiscError, 'Error Checksumming, bad checksum type %s' % sumtype
5e9bef
             done.add(sumtype)
5e9bef
diff -up yum-3.4.3/yum/yumRepo.py.orig yum-3.4.3/yum/yumRepo.py
5e9bef
--- yum-3.4.3/yum/yumRepo.py.orig	2017-09-14 18:42:26.879557746 +0200
5e9bef
+++ yum-3.4.3/yum/yumRepo.py	2017-09-14 18:43:23.422298802 +0200
5e9bef
@@ -497,7 +497,10 @@ class YumRepository(Repository, config.R
5e9bef
         except (Errors.MiscError, EnvironmentError), e:
5e9bef
             if checksum_can_fail:
5e9bef
                 return None
5e9bef
-            raise Errors.RepoError, 'Error opening file for checksum: %s' % e
5e9bef
+            msg = 'Error opening file for checksum: %s' % e
5e9bef
+            if isinstance(e, Errors.FIPSNonCompliantError):
5e9bef
+                msg = str(e)
5e9bef
+            raise Errors.RepoError(msg)
5e9bef
 
5e9bef
     def dump(self):
5e9bef
         output = '[%s]\n' % self.id
5e9bef
@@ -1799,7 +1802,7 @@ Insufficient space in download directory
5e9bef
         except Errors.RepoError, e:
5e9bef
             if check_can_fail:
5e9bef
                 return None
5e9bef
-            raise URLGrabError(-3, 'Error performing checksum')
5e9bef
+            raise URLGrabError(-3, 'Error performing checksum: %s' % e)
5e9bef
 
5e9bef
         if l_csum == r_csum:
5e9bef
             _xattr_set_chksum(file, r_ctype, l_csum)