RFC: sample/rough implementation to verify detached sigs for pkg.tar.gz
This code will attempt to fire every time we call pkg_load in libalpm, which
happens every time we open a package file (during sync, upgrades, and -Qp).
It checks for the existence of either a .sig or .asc file, and if present,
attempts to verify them using gpgv. Right now a keyring file is hardcoded
to /tmp/pacman.keyring; add any keys here that are to be seen as 'valid'.
This is rough, there isn't enough error checking or any way of automatically
prompting to ask if a key should be considered valid, etc. We also use the
lighter weight gpgv rather than the full blown gpg.
I'm not the biggest fan of all this process spawning code we have using
popen and friends, but I don't know of a lot of other ways around it besides
implementing something like git has to spawn child processes.
- newpkg = _alpm_pkg_new();
- if(newpkg == NULL) {
- archive_read_finish(archive);
- RET_ERR(PM_ERR_MEMORY, NULL);
- }
-
- if(stat(pkgfile, &st) == 0) {
- newpkg->size = st.st_size;
- }
-
/* If full is false, only read through the archive until we find our needed
* metadata. If it is true, read through the entire archive, which serves
* as a verfication of integrity and allows us to create the filelist. */
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 05caf8e..884b0b6 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -111,6 +111,8 @@ const char SYMEXPORT *alpm_strerror(int err)
return _("could not find or read package");
case PM_ERR_PKG_INVALID:
return _("invalid or corrupted package");
+ case PM_ERR_PKG_BAD_SIG:
+ return _("invalid PGP signature");
case PM_ERR_PKG_OPEN:
return _("cannot open package file");
case PM_ERR_PKG_LOAD:
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 685a411..0af43c3 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -895,7 +895,7 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
return(info);
}
}
- return(NULL);
+ RET_ERR(PM_ERR_PKG_NOT_FOUND, NULL);
}
/** Test if a package should be ignored.
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 74d3ff2..52e66d9 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -416,7 +416,9 @@ int pacman_query(alpm_list_t *targets)
}