Blame SOURCES/BZ-1343690-add-payload-gpgcheck-opt.patch

5e9bef
diff -up yum-3.4.3/docs/yum.conf.5.orig yum-3.4.3/docs/yum.conf.5
5e9bef
--- yum-3.4.3/docs/yum.conf.5.orig	2017-03-23 13:48:19.700471026 +0100
5e9bef
+++ yum-3.4.3/docs/yum.conf.5	2017-03-23 13:48:21.455461060 +0100
5e9bef
@@ -105,6 +105,31 @@ signature check on the repodata. When th
5e9bef
 default for all repositories. The default is `0'.
5e9bef
 
5e9bef
 .IP
5e9bef
+\fBpayload_gpgcheck\fR
5e9bef
+Either `1' or `0'. This tells yum whether or not it should also perform a GPG
5e9bef
+signature check on the payload (part of a package holding the actual files that
5e9bef
+comprise the package).
5e9bef
+
5e9bef
+By default, yum only performs GPG signature checks on package headers.
5e9bef
+Thus, if the payload data has been tampered with or corrupted, yum will fail in
5e9bef
+the middle of the transaction due to an RPM unpacking error, after some
5e9bef
+unverified scriptlets might have already run, and possibly leave the package in
5e9bef
+question partly installed.
5e9bef
+
5e9bef
+To prevent all of that, you can enable this option to extend the signature
5e9bef
+check to also include the payload, so that yum can avoid running the
5e9bef
+transaction in case of payload corruption.
5e9bef
+This slightly improves security, however at the expense of significantly
5e9bef
+increased transaction time, so you may want to only use this option when
5e9bef
+package corruption is a concern.
5e9bef
+
5e9bef
+For this option to have effect, make sure to also enable gpgcheck (or
5e9bef
+localpkg_gpgcheck for local packages).
5e9bef
+
5e9bef
+When this option is set in the [main] section it sets the default for all
5e9bef
+repositories. The default is `0'.
5e9bef
+
5e9bef
+.IP
5e9bef
 \fBskip_broken\fR
5e9bef
 Either `1' or `0'. Resolve depsolve problems by removing packages that
5e9bef
 are causing problems from the transaction.
5e9bef
diff -up yum-3.4.3/rpmUtils/miscutils.py.orig yum-3.4.3/rpmUtils/miscutils.py
5e9bef
--- yum-3.4.3/rpmUtils/miscutils.py.orig	2011-06-28 22:27:22.000000000 +0200
5e9bef
+++ yum-3.4.3/rpmUtils/miscutils.py	2017-03-23 13:48:21.455461060 +0100
5e9bef
@@ -58,11 +58,16 @@ def compareVerOnly(v1, v2):
5e9bef
     """compare version strings only using rpm vercmp"""
5e9bef
     return compareEVR(('', v1, ''), ('', v2, ''))
5e9bef
     
5e9bef
-def checkSig(ts, package):
5e9bef
-    """Takes a transaction set and a package, check it's sigs, 
5e9bef
+def checkSig(ts, package, payload=False):
5e9bef
+    """Takes a transaction set and a package, check it's sigs.
5e9bef
+
5e9bef
+    By default, only RPMv4 sigs (header-only) will be verified (faster).  By
5e9bef
+    setting payload to True, RPMv3 sigs (header+payload) will also be verified
5e9bef
+    (slower).
5e9bef
+
5e9bef
     return 0 if they are all fine
5e9bef
     return 1 if the gpg key can't be found
5e9bef
-    return 2 if the header is in someway damaged
5e9bef
+    return 2 if the header or payload is in someway damaged
5e9bef
     return 3 if the key is not trusted 
5e9bef
     return 4 if the pkg is not gpg or pgp signed"""
5e9bef
     
5e9bef
@@ -89,6 +94,24 @@ def checkSig(ts, package):
5e9bef
         else:
5e9bef
             del hdr
5e9bef
 
5e9bef
+    # Don't perform the payload check if the header check failed, otherwise we
5e9bef
+    # could mask the reason stored in "value" (we only return one integer from
5e9bef
+    # this function and shouldn't change that).
5e9bef
+    if payload and value == 0:
5e9bef
+        os.lseek(fdno, 0, 0)
5e9bef
+        # We don't want the OK message to pollute the output but we do want the
5e9bef
+        # BAD message (verbose version) in case of a failure, which is only
5e9bef
+        # possible by running _verifySigs() twice (temporary hack until we have
5e9bef
+        # the proper API for payload verification in RPM).
5e9bef
+        rpm.setVerbosity(rpm.RPMLOG_WARNING)
5e9bef
+        valid = ts._verifySigs(fdno, package)
5e9bef
+        if not valid:
5e9bef
+            value = 2
5e9bef
+            os.lseek(fdno, 0, 0)
5e9bef
+            rpm.setVerbosity(rpm.RPMLOG_INFO)
5e9bef
+            ts._verifySigs(fdno, package)
5e9bef
+        rpm.setVerbosity(rpm.RPMLOG_NOTICE)
5e9bef
+
5e9bef
     try:
5e9bef
         os.close(fdno)
5e9bef
     except OSError, e: # if we're not opened, don't scream about it
5e9bef
diff -up yum-3.4.3/rpmUtils/transaction.py.orig yum-3.4.3/rpmUtils/transaction.py
5e9bef
--- yum-3.4.3/rpmUtils/transaction.py.orig	2017-03-23 13:48:19.441472497 +0100
5e9bef
+++ yum-3.4.3/rpmUtils/transaction.py	2017-03-23 13:48:21.455461060 +0100
5e9bef
@@ -35,7 +35,8 @@ class TransactionWrapper:
5e9bef
                          'setProbFilter',
5e9bef
                          'hdrFromFdno',
5e9bef
                          'next',
5e9bef
-                         'clean']
5e9bef
+                         'clean',
5e9bef
+                         '_verifySigs']
5e9bef
         self.tsflags = []
5e9bef
         self.open = True
5e9bef
 
5e9bef
diff -up yum-3.4.3/yum/config.py.orig yum-3.4.3/yum/config.py
5e9bef
--- yum-3.4.3/yum/config.py.orig	2017-03-23 13:48:19.701471020 +0100
5e9bef
+++ yum-3.4.3/yum/config.py	2017-03-23 13:48:21.456461055 +0100
5e9bef
@@ -46,6 +46,7 @@ from misc import get_uuid, read_in_items
5e9bef
 # Alter/patch these to change the default checking...
5e9bef
 __pkgs_gpgcheck_default__ = False
5e9bef
 __repo_gpgcheck_default__ = False
5e9bef
+__payload_gpgcheck_default__ = False
5e9bef
 __main_multilib_policy_default__ = 'all'
5e9bef
 __main_failovermethod_default__ = 'roundrobin'
5e9bef
 __main_installonly_limit_default__ = 0
5e9bef
@@ -786,6 +787,7 @@ class YumConf(StartupConf):
5e9bef
     gpgcheck = BoolOption(__pkgs_gpgcheck_default__)
5e9bef
     repo_gpgcheck = BoolOption(__repo_gpgcheck_default__)
5e9bef
     localpkg_gpgcheck = BoolOption(__pkgs_gpgcheck_default__)
5e9bef
+    payload_gpgcheck = BoolOption(__payload_gpgcheck_default__)
5e9bef
     obsoletes = BoolOption(True)
5e9bef
     showdupesfromrepos = BoolOption(False)
5e9bef
     enabled = BoolOption(True)
5e9bef
diff -up yum-3.4.3/yum/__init__.py.orig yum-3.4.3/yum/__init__.py
5e9bef
--- yum-3.4.3/yum/__init__.py.orig	2017-03-23 13:48:19.731470850 +0100
5e9bef
+++ yum-3.4.3/yum/__init__.py	2017-03-23 13:48:21.456461055 +0100
5e9bef
@@ -2755,7 +2755,9 @@ much more problems).
5e9bef
         
5e9bef
         if check:
5e9bef
             ts = self.rpmdb.readOnlyTS()
5e9bef
-            sigresult = rpmUtils.miscutils.checkSig(ts, po.localPkg())
5e9bef
+            sigresult = rpmUtils.miscutils.checkSig(
5e9bef
+                ts, po.localPkg(), payload=self.conf.payload_gpgcheck,
5e9bef
+            )
5e9bef
             localfn = os.path.basename(po.localPkg())
5e9bef
             
5e9bef
             if sigresult == 0: