libxbps: verify repodata signatures even if rootdir is unset.
xbps-rindex(1) has a -r option that sets the remove mode, due to the changes added to sign repodata we need to access to the correct directory where repository public keys are stored. This makes the code use `$PWD/keys` before falling back to `metadir`. Fixes the test suite to run with unprivileged users (non root).
This commit is contained in:
parent
36a7ddd4ae
commit
be05118aa8
@ -77,8 +77,7 @@ xbps_verify_digest_signature(struct xbps_repo *repo, xbps_dictionary_t idxmeta,
|
|||||||
{
|
{
|
||||||
xbps_dictionary_t repokeyd = NULL;
|
xbps_dictionary_t repokeyd = NULL;
|
||||||
xbps_data_t pubkey;
|
xbps_data_t pubkey;
|
||||||
char *hexfp = NULL;
|
char *hexfp = NULL, *rkeyfile = NULL;
|
||||||
char *rkeyfile = NULL;
|
|
||||||
bool val = false;
|
bool val = false;
|
||||||
|
|
||||||
if (!xbps_dictionary_count(idxmeta)) {
|
if (!xbps_dictionary_count(idxmeta)) {
|
||||||
@ -94,7 +93,12 @@ xbps_verify_digest_signature(struct xbps_repo *repo, xbps_dictionary_t idxmeta,
|
|||||||
/*
|
/*
|
||||||
* Prepare repository RSA public key to verify fname signature.
|
* Prepare repository RSA public key to verify fname signature.
|
||||||
*/
|
*/
|
||||||
|
/* XXX: xbps-rindex does not set rootdir, use cwd and fallback to defaults otherwise */
|
||||||
|
rkeyfile = xbps_xasprintf("keys/%s.plist", hexfp);
|
||||||
|
if (access(rkeyfile, R_OK) == -1) {
|
||||||
|
free(rkeyfile);
|
||||||
rkeyfile = xbps_xasprintf("%s/keys/%s.plist", repo->xhp->metadir, hexfp);
|
rkeyfile = xbps_xasprintf("%s/keys/%s.plist", repo->xhp->metadir, hexfp);
|
||||||
|
}
|
||||||
repokeyd = xbps_plist_dictionary_from_file(repo->xhp, rkeyfile);
|
repokeyd = xbps_plist_dictionary_from_file(repo->xhp, rkeyfile);
|
||||||
if (xbps_object_type(repokeyd) != XBPS_TYPE_DICTIONARY) {
|
if (xbps_object_type(repokeyd) != XBPS_TYPE_DICTIONARY) {
|
||||||
xbps_dbg_printf(repo->xhp, "cannot read rkey data at %s: %s\n",
|
xbps_dbg_printf(repo->xhp, "cannot read rkey data at %s: %s\n",
|
||||||
|
@ -1,14 +1,6 @@
|
|||||||
#! /usr/bin/env atf-sh
|
#! /usr/bin/env atf-sh
|
||||||
# Test that xbps-rindex(1) signing repo metadata works as expected.
|
# Test that xbps-rindex(1) signing repo metadata works as expected.
|
||||||
|
|
||||||
get_resources() {
|
|
||||||
mkdir -p root/var/db/xbps/keys
|
|
||||||
mkdir -p /var/db/xbps/keys
|
|
||||||
cp $(atf_get_srcdir)/data/id_xbps .
|
|
||||||
cp $(atf_get_srcdir)/data/bd:75:21:4e:40:06:97:5e:72:31:40:6e:9e:08:a8:ae.plist root/var/db/xbps/keys
|
|
||||||
cp $(atf_get_srcdir)/data/bd:75:21:4e:40:06:97:5e:72:31:40:6e:9e:08:a8:ae.plist /var/db/xbps/keys
|
|
||||||
}
|
|
||||||
|
|
||||||
atf_test_case sign
|
atf_test_case sign
|
||||||
|
|
||||||
sign_head() {
|
sign_head() {
|
||||||
@ -16,11 +8,13 @@ sign_head() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sign_body() {
|
sign_body() {
|
||||||
get_resources
|
cp $(atf_get_srcdir)/data/id_xbps .
|
||||||
# make pkg
|
# make pkg
|
||||||
mkdir -p some_repo pkg_A
|
mkdir -p some_repo pkg_A
|
||||||
touch pkg_A/file00
|
touch pkg_A/file00
|
||||||
cd some_repo
|
cd some_repo
|
||||||
|
mkdir -p keys
|
||||||
|
cp $(atf_get_srcdir)/data/bd:75:21:4e:40:06:97:5e:72:31:40:6e:9e:08:a8:ae.plist keys
|
||||||
xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg_A
|
xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg_A
|
||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
# make repodata
|
# make repodata
|
||||||
@ -29,14 +23,14 @@ sign_body() {
|
|||||||
repodata=$(ls *-repodata)
|
repodata=$(ls *-repodata)
|
||||||
atf_check_equal $(tar tf $repodata | wc -l) 2
|
atf_check_equal $(tar tf $repodata | wc -l) 2
|
||||||
# sign repodata
|
# sign repodata
|
||||||
xbps-rindex -s $PWD --signedby test --privkey ../id_xbps
|
xbps-rindex -d -s $PWD --signedby test --privkey ../id_xbps
|
||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
atf_check_equal $(tar tf $repodata | wc -l) 3
|
atf_check_equal $(tar tf $repodata | wc -l) 3
|
||||||
# update pkg
|
# update pkg
|
||||||
xbps-create -A noarch -n foo-1.1_1 -s "foo pkg" ../pkg_A
|
xbps-create -A noarch -n foo-1.1_1 -s "foo pkg" ../pkg_A
|
||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
# update repodata
|
# update repodata
|
||||||
xbps-rindex -a $PWD/*.xbps --privkey ../id_xbps
|
xbps-rindex -d -a $PWD/*.xbps --privkey ../id_xbps
|
||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
atf_check_equal $(tar tf $repodata | wc -l) 3
|
atf_check_equal $(tar tf $repodata | wc -l) 3
|
||||||
}
|
}
|
||||||
@ -48,11 +42,13 @@ verify_head() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
verify_body() {
|
verify_body() {
|
||||||
get_resources
|
cp $(atf_get_srcdir)/data/id_xbps .
|
||||||
# make pkg
|
# make pkg
|
||||||
mkdir -p some_repo pkg_A
|
mkdir -p some_repo pkg_A
|
||||||
touch pkg_A/file00
|
touch pkg_A/file00
|
||||||
cd some_repo
|
cd some_repo
|
||||||
|
mkdir -p keys
|
||||||
|
cp $(atf_get_srcdir)/data/bd:75:21:4e:40:06:97:5e:72:31:40:6e:9e:08:a8:ae.plist keys
|
||||||
xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg_A
|
xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg_A
|
||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
# make repodata
|
# make repodata
|
||||||
@ -60,10 +56,10 @@ verify_body() {
|
|||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
repodata=$(ls *-repodata)
|
repodata=$(ls *-repodata)
|
||||||
# sign repodata
|
# sign repodata
|
||||||
xbps-rindex -s $PWD --signedby test --privkey ../id_xbps
|
xbps-rindex -d -s $PWD --signedby test --privkey ../id_xbps
|
||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
# verify signature
|
# verify signature
|
||||||
xbps-install -nid --repository=$PWD foo 2>&1 | grep -q "some_repo/$repodata' signature passed."
|
xbps-install -r root -nid --repository=$PWD foo 2>&1 | grep -q "some_repo/$repodata' signature passed."
|
||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
# modify what is signed
|
# modify what is signed
|
||||||
tar tf $repodata
|
tar tf $repodata
|
||||||
@ -75,7 +71,7 @@ verify_body() {
|
|||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
cd ..
|
cd ..
|
||||||
# verify wrong signature
|
# verify wrong signature
|
||||||
xbps-install -nid --repository=$PWD foo 2>&1 | grep -q "some_repo/$repodata' signature failed. Taking safe part."
|
xbps-install -r root -nid --repository=$PWD foo 2>&1 | grep -q "some_repo/$repodata' signature failed. Taking safe part."
|
||||||
atf_check_equal $? 0
|
atf_check_equal $? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user