Skip to content

Commit

Permalink
Fix finding repo fingerprints when using rootdir support
Browse files Browse the repository at this point in the history
Reviewed by:	kp
Sponsored by:   Rubicon Communications, LLC ("Netgate")
  • Loading branch information
brd authored and bapt committed Oct 19, 2021
1 parent af02823 commit d04e611
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
15 changes: 13 additions & 2 deletions libpkg/pkg_repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,13 @@ pkg_repo_load_fingerprints(struct pkg_repo *repo)
char path[MAXPATHLEN];
struct stat st;

snprintf(path, sizeof(path), "%s/trusted", pkg_repo_fingerprints(repo));
if (ctx.pkg_rootdir) {
snprintf(path, sizeof(path), "%s/%s/trusted", ctx.pkg_rootdir, pkg_repo_fingerprints(repo));
}
else {
snprintf(path, sizeof(path), "%s/trusted", pkg_repo_fingerprints(repo));
}

if ((pkg_repo_load_fingerprints_from_path(path, &repo->trusted_fp)) != EPKG_OK) {
pkg_emit_error("Error loading trusted certificates");
return (EPKG_FATAL);
Expand All @@ -1057,7 +1063,12 @@ pkg_repo_load_fingerprints(struct pkg_repo *repo)
return (EPKG_FATAL);
}

snprintf(path, sizeof(path), "%s/revoked", pkg_repo_fingerprints(repo));
if (ctx.pkg_rootdir) {
snprintf(path, sizeof(path), "%s/%s/revoked", ctx.pkg_rootdir, pkg_repo_fingerprints(repo));
}
else {
snprintf(path, sizeof(path), "%s/revoked", pkg_repo_fingerprints(repo));
}
/* Absence of revoked certificates is not a fatal error */
if (stat(path, &st) != -1) {
if ((pkg_repo_load_fingerprints_from_path(path, &repo->revoked_fp)) != EPKG_OK) {
Expand Down
35 changes: 26 additions & 9 deletions tests/frontend/fingerprint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
. $(atf_get_srcdir)/test_environment.sh

tests_init \
fingerprint
fingerprint \
fingerprint_rootdir

fingerprint_body() {
setup() {
local _root=$1
atf_skip_on Darwin Test fails on Darwin
atf_skip_on Linux Test fails on Linux

atf_check -o ignore -e ignore \
openssl genrsa -out repo.key 2048
rm -rf ${TMPDIR}/keys || :
mkdir -p keys/trusted
mkdir -p keys/revoked
mkdir -p ${_root}/keys/trusted
mkdir -p ${_root}/keys/revoked
chmod 0400 repo.key
atf_check -o ignore -e ignore \
openssl rsa -in repo.key -out repo.pub -pubout
echo "function: sha256" > keys/trusted/key
echo -n "fingerprint: " >> keys/trusted/key
openssl dgst -sha256 -hex repo.pub | sed 's/^.* //' >> keys/trusted/key
echo "" >> keys/trusted/key
echo "function: sha256" > ${_root}/keys/trusted/key
echo -n "fingerprint: " >> ${_root}/keys/trusted/key
openssl dgst -sha256 -hex repo.pub | sed 's/^.* //' >> ${_root}/keys/trusted/key
echo "" >> ${_root}/keys/trusted/key
mkdir fakerepo

cat >> sign.sh << EOF
Expand All @@ -47,12 +49,27 @@ local: {
url: file:///${TMPDIR}/fakerepo
enabled: true
signature_type: FINGERPRINTS
fingerprints: ${TMPDIR}/keys
fingerprints: keys
}
EOF
}

fingerprint_body() {
setup "${TMPDIR}/."

atf_check \
-o ignore \
-e match:".*extracting signature of repo.*" \
pkg -dd -o REPOS_DIR="${TMPDIR}" \
-o PKG_CACHEDIR="${TMPDIR}" update
}

fingerprint_rootdir_body() {
setup "${TMPDIR}/rootdir"

atf_check \
-o ignore \
-e match:".*extracting signature of repo.*" \
pkg -dd -o REPOS_DIR="${TMPDIR}" \
-o PKG_CACHEDIR="${TMPDIR}" -r "${TMPDIR}/rootdir" update
}

0 comments on commit d04e611

Please sign in to comment.