michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 5 months ago
Clone
1090e7
diff -up rpm-4.11.3/lib/rpmchecksig.c.orig rpm-4.11.3/lib/rpmchecksig.c
1090e7
--- rpm-4.11.3/lib/rpmchecksig.c.orig	2013-11-22 11:31:31.000000000 +0100
1090e7
+++ rpm-4.11.3/lib/rpmchecksig.c	2017-03-15 18:18:20.688251955 +0100
1090e7
@@ -242,8 +242,8 @@ static void formatResult(rpmTagVal sigta
1090e7
     free(msg);
1090e7
 }
1090e7
 
1090e7
-static int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags,
1090e7
-			   FD_t fd, const char *fn)
1090e7
+int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags, FD_t fd,
1090e7
+                     const char *fn)
1090e7
 {
1090e7
 
1090e7
     char *buf = NULL;
1090e7
diff -up rpm-4.11.3/lib/rpmcli.h.orig rpm-4.11.3/lib/rpmcli.h
1090e7
--- rpm-4.11.3/lib/rpmcli.h.orig	2014-02-05 14:04:02.000000000 +0100
1090e7
+++ rpm-4.11.3/lib/rpmcli.h	2017-03-15 18:18:20.689251950 +0100
1090e7
@@ -254,6 +254,17 @@ int showVerifyPackage(QVA_t qva, rpmts t
1090e7
  */
1090e7
 int rpmVerifySignatures(QVA_t qva, rpmts ts, FD_t fd, const char * fn);
1090e7
 
1090e7
+/**
1090e7
+ * Check package and header signatures.
1090e7
+ * @param keyring	keyring handle
1090e7
+ * @param flags		flags to control what to verify
1090e7
+ * @param fd		package file handle
1090e7
+ * @param fn		package file name
1090e7
+ * @return		0 on success, 1 on failure
1090e7
+ */
1090e7
+int rpmpkgVerifySigs(rpmKeyring keyring, rpmQueryFlags flags, FD_t fd,
1090e7
+                     const char *fn);
1090e7
+
1090e7
 /** \ingroup rpmcli
1090e7
  * Verify package install.
1090e7
  * @todo hack: RPMQV_ALL can pass char ** arglist = NULL, not char * arg. Union?
1090e7
diff -up rpm-4.11.3/python/rpmts-py.c.orig rpm-4.11.3/python/rpmts-py.c
1090e7
--- rpm-4.11.3/python/rpmts-py.c.orig	2014-02-05 14:04:02.000000000 +0100
1090e7
+++ rpm-4.11.3/python/rpmts-py.c	2017-03-15 18:18:20.689251950 +0100
1090e7
@@ -7,6 +7,8 @@
1090e7
 #include <rpm/rpmpgp.h>
1090e7
 #include <rpm/rpmdb.h>
1090e7
 #include <rpm/rpmbuild.h>
1090e7
+#include <rpm/rpmcli.h>
1090e7
+#include <rpm/rpmkeyring.h>
1090e7
 
1090e7
 #include "header-py.h"
1090e7
 #include "rpmds-py.h"	/* XXX for rpmdsNew */
1090e7
@@ -671,6 +672,24 @@ exit:
1090e7
     return mio;
1090e7
 }
1090e7
 
1090e7
+static PyObject *
1090e7
+rpmts_VerifySigs(rpmtsObject * s, PyObject * args)
1090e7
+{
1090e7
+    rpmfdObject *fdo = NULL;
1090e7
+    char *fn = NULL;
1090e7
+    rpmQueryFlags flags = (VERIFY_DIGEST|VERIFY_SIGNATURE);
1090e7
+    int rc = 1;
1090e7
+
1090e7
+    if (!PyArg_ParseTuple(args, "O&s|i:VerifySigs", rpmfdFromPyObject, &fdo,
1090e7
+                          &fn, &flags))
1090e7
+        return NULL;
1090e7
+
1090e7
+    rpmKeyring keyring = rpmtsGetKeyring(s->ts, 1);
1090e7
+    rc = rpmpkgVerifySigs(keyring, flags, rpmfdGetFd(fdo), fn);
1090e7
+    rpmKeyringFree(keyring);
1090e7
+    return PyBool_FromLong(rc == 0);
1090e7
+}
1090e7
+
1090e7
 static struct PyMethodDef rpmts_methods[] = {
1090e7
  {"addInstall",	(PyCFunction) rpmts_AddInstall,	METH_VARARGS,
1090e7
 	NULL },
1090e7
@@ -729,6 +748,14 @@ Remove all elements from the transaction
1090e7
  {"dbIndex",     (PyCFunction) rpmts_index,	METH_VARARGS|METH_KEYWORDS,
1090e7
 "ts.dbIndex(TagN) -> ii\n\
1090e7
 - Create a key iterator for the default transaction rpmdb.\n" },
1090e7
+ {"_verifySigs",         (PyCFunction) rpmts_VerifySigs, METH_VARARGS,
1090e7
+  "ts._verifySigs(fdno, fn, [flags]) -- Verify package signature\n\n"
1090e7
+  "Returns True if it verifies, False otherwise.\n\n"
1090e7
+  "Args:\n"
1090e7
+  "  fdno  : file descriptor of the package to verify\n"
1090e7
+  "  fn    : package file name (just for logging purposes)\n"
1090e7
+  "  flags : bitfield to control what to verify\n"
1090e7
+  "          (default is rpm.VERIFY_SIGNATURE | rpm.VERIFY_DIGEST)"},
1090e7
     {NULL,		NULL}		/* sentinel */
1090e7
 };
1090e7