Added support to check the SHA256 hash for any binpkg before installation happens.

--HG--
extra : convert_revision : 4f812eb0cfb614461527e360db1692bd5f9c34aa
This commit is contained in:
Juan RP 2009-03-02 23:38:24 +01:00
parent 05f918ea93
commit 37e4be86f9
6 changed files with 74 additions and 14 deletions

View File

@ -16,10 +16,6 @@ xbps-bin:
* Add support to handle conf_files and keep_dirs from package metadata. * Add support to handle conf_files and keep_dirs from package metadata.
[PARTIALLY IMPLEMENTED] [PARTIALLY IMPLEMENTED]
* Add support to install binary packages without any repository. * Add support to install binary packages without any repository.
* Check SHA256 hash of pkg and dependencies before installing.
Currently the hash is checked before a pkg is unpacked, this is
suboptimal because if some pkg fails, previous packages will be
installed and therefore unusable. [IN PROGRESS]
* Show binpkg size and installed size for all packages that are going * Show binpkg size and installed size for all packages that are going
to be installed before installation happens. to be installed before installation happens.
* Add support to update packages. * Add support to update packages.

View File

@ -29,6 +29,7 @@
/* From lib/util.c */ /* From lib/util.c */
char * xbps_append_full_path(bool, const char *, const char *); char * xbps_append_full_path(bool, const char *, const char *);
int xbps_check_file_hash(const char *, const char *); int xbps_check_file_hash(const char *, const char *);
int xbps_check_pkg_file_hash(prop_dictionary_t, const char *);
int xbps_check_is_installed_pkg(const char *); int xbps_check_is_installed_pkg(const char *);
bool xbps_check_is_installed_pkgname(const char *); bool xbps_check_is_installed_pkgname(const char *);
char * xbps_get_pkg_index_plist(const char *); char * xbps_get_pkg_index_plist(const char *);

View File

@ -599,6 +599,7 @@ xbps_install_pkg_deps(const char *pkgname, const char *destdir, int flags)
prop_array_t required, missing; prop_array_t required, missing;
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
const char *repoloc;
int rv = 0; int rv = 0;
/* /*
@ -623,11 +624,22 @@ xbps_install_pkg_deps(const char *pkgname, const char *destdir, int flags)
if (required == NULL) if (required == NULL)
return 0; return 0;
iter = prop_array_iterator(required); iter = prop_array_iterator(required);
if (iter == NULL) if (iter == NULL)
return ENOMEM; return ENOMEM;
/*
* Check the SHA256 hash for any binary package that's going
* to be installed.
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
rv = xbps_check_pkg_file_hash(obj, repoloc);
if (rv != 0)
goto out;
}
prop_object_iterator_reset(iter);
/* /*
* Install all required dependencies, previously sorted. * Install all required dependencies, previously sorted.
*/ */
@ -636,6 +648,8 @@ xbps_install_pkg_deps(const char *pkgname, const char *destdir, int flags)
if (rv != 0) if (rv != 0)
break; break;
} }
out:
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
return rv; return rv;

View File

@ -111,6 +111,7 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
{ {
prop_dictionary_t repod, pkgrd; prop_dictionary_t repod, pkgrd;
struct cbargs *cb = arg; struct cbargs *cb = arg;
const char *repoloc;
char *plist; char *plist;
int rv = 0; int rv = 0;
@ -139,6 +140,16 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
/* /*
* Check SHA256 hash for binary package before anything else. * Check SHA256 hash for binary package before anything else.
*/ */
if (!prop_dictionary_get_cstring_nocopy(repod, "location-local",
&repoloc)) {
prop_object_release(repod);
return EINVAL;
}
if ((rv = xbps_check_pkg_file_hash(pkgrd, repoloc)) != 0) {
prop_object_release(repod);
return rv;
}
/* /*
* Check if this package needs dependencies. * Check if this package needs dependencies.

View File

@ -45,7 +45,6 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
const char *destdir, int flags) const char *destdir, int flags)
{ {
prop_string_t filename, repoloc, arch; prop_string_t filename, repoloc, arch;
const char *sha256;
char *binfile, *path; char *binfile, *path;
int rv = 0; int rv = 0;
@ -54,7 +53,6 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
/* Append filename to the full path for binary pkg */ /* Append filename to the full path for binary pkg */
filename = prop_dictionary_get(pkg, "filename"); filename = prop_dictionary_get(pkg, "filename");
arch = prop_dictionary_get(pkg, "architecture"); arch = prop_dictionary_get(pkg, "architecture");
prop_dictionary_get_cstring_nocopy(pkg, "filename-sha256", &sha256);
if (repo) if (repo)
repoloc = prop_dictionary_get(repo, "location-local"); repoloc = prop_dictionary_get(repo, "location-local");
else else
@ -74,13 +72,6 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
} }
free(path); free(path);
if ((rv = xbps_check_file_hash(binfile, sha256)) == ERANGE) {
printf("ERROR: SHA256 doesn't match for %s!\n",
prop_string_cstring_nocopy(filename));
free(binfile);
return rv;
}
rv = unpack_archive_init(pkg, destdir, binfile, flags); rv = unpack_archive_init(pkg, destdir, binfile, flags);
free(binfile); free(binfile);
return rv; return rv;

View File

@ -61,6 +61,53 @@ xbps_check_file_hash(const char *path, const char *sha256)
return rv; return rv;
} }
int
xbps_check_pkg_file_hash(prop_dictionary_t pkgd, const char *repoloc)
{
const char *sha256, *arch, *filename;
char *binfile, *path;
int rv = 0;
assert(repoloc != NULL);
if (!prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filename))
return EINVAL;
if (!prop_dictionary_get_cstring_nocopy(pkgd, "filename-sha256",
&sha256))
return EINVAL;
if (!prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch))
return EINVAL;
path = xbps_append_full_path(false, repoloc, arch);
if (path == NULL)
return EINVAL;
binfile = xbps_append_full_path(false, path, filename);
if (binfile == NULL) {
free(path);
return EINVAL;
}
free(path);
printf("Checking SHA256 for %s ... ", filename);
(void)fflush(stdout);
rv = xbps_check_file_hash(binfile, sha256);
if (rv != 0 && rv != ERANGE)
printf("failed (%s)\n", strerror(rv));
else if (rv == ERANGE)
printf("failed! aborting installation.\n");
else if (rv == 0)
printf("ok.\n");
(void)fflush(stdout);
free(binfile);
return rv;
}
int int
xbps_check_is_installed_pkg(const char *pkg) xbps_check_is_installed_pkg(const char *pkg)
{ {