Blame tests/test-remote-gpg-import.sh

rpm-build 0fba15
#!/bin/bash
rpm-build 0fba15
#
rpm-build 0fba15
# Copyright (C) 2015 Red Hat, Inc.
rpm-build 0fba15
#
rpm-build 0fba15
# SPDX-License-Identifier: LGPL-2.0+
rpm-build 0fba15
#
rpm-build 0fba15
# This library is free software; you can redistribute it and/or
rpm-build 0fba15
# modify it under the terms of the GNU Lesser General Public
rpm-build 0fba15
# License as published by the Free Software Foundation; either
rpm-build 0fba15
# version 2 of the License, or (at your option) any later version.
rpm-build 0fba15
#
rpm-build 0fba15
# This library is distributed in the hope that it will be useful,
rpm-build 0fba15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0fba15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0fba15
# Lesser General Public License for more details.
rpm-build 0fba15
#
rpm-build 0fba15
# You should have received a copy of the GNU Lesser General Public
rpm-build 0fba15
# License along with this library; if not, write to the
rpm-build 0fba15
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
rpm-build 0fba15
# Boston, MA 02111-1307, USA.
rpm-build 0fba15
rpm-build 0fba15
set -euo pipefail
rpm-build 0fba15
rpm-build 0fba15
. $(dirname $0)/libtest.sh
rpm-build 0fba15
rpm-build 0fba15
# We don't want OSTREE_GPG_HOME used for these tests.
rpm-build 0fba15
unset OSTREE_GPG_HOME
rpm-build 0fba15
rpm-build 0fba15
setup_fake_remote_repo1 "archive"
rpm-build 0fba15
rpm-build 0fba15
# Some tests require an appropriate gpg
rpm-build 0fba15
num_non_gpg_tests=4
rpm-build 0fba15
num_gpg_tests=2
rpm-build 0fba15
num_tests=$((num_non_gpg_tests + num_gpg_tests))
rpm-build 0fba15
rpm-build 0fba15
echo "1..${num_tests}"
rpm-build 0fba15
rpm-build 0fba15
cd ${test_tmpdir}
rpm-build 0fba15
mkdir repo
rpm-build 0fba15
ostree_repo_init repo
rpm-build 0fba15
rpm-build 0fba15
#----------------------------------------------
rpm-build 0fba15
# Test synchronicity of keyring file and remote
rpm-build 0fba15
#----------------------------------------------
rpm-build 0fba15
rpm-build 0fba15
assert_not_has_file repo/R1.trustedkeys.gpg
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote add R1 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
rpm-build 0fba15
assert_not_has_file repo/R1.trustedkeys.gpg
rpm-build 0fba15
rpm-build 0fba15
# Import one valid key ID
rpm-build 0fba15
${OSTREE} remote gpg-import --keyring ${test_tmpdir}/gpghome/trusted/pubring.gpg R1 ${TEST_GPG_KEYID_1} | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
assert_file_has_content result 'Imported 1 GPG key'
rpm-build 0fba15
rpm-build 0fba15
assert_has_file repo/R1.trustedkeys.gpg
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote delete R1
rpm-build 0fba15
rpm-build 0fba15
assert_not_has_file repo/R1.trustedkeys.gpg
rpm-build 0fba15
rpm-build 0fba15
#---------------------------------------
rpm-build 0fba15
# Test gpg-import with --keyring option
rpm-build 0fba15
#---------------------------------------
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote add R1 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
rpm-build 0fba15
# Import one valid key ID
rpm-build 0fba15
${OSTREE} remote gpg-import --keyring ${test_tmpdir}/gpghome/trusted/pubring.gpg R1 ${TEST_GPG_KEYID_1} | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
assert_file_has_content result 'Imported 1 GPG key'
rpm-build 0fba15
rpm-build 0fba15
# Import multiple valid key IDs
rpm-build 0fba15
${OSTREE} remote gpg-import --keyring ${test_tmpdir}/gpghome/trusted/pubring.gpg R1 ${TEST_GPG_KEYID_2} ${TEST_GPG_KEYID_3} | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
assert_file_has_content result 'Imported 2 GPG key'
rpm-build 0fba15
rpm-build 0fba15
# Import key IDs we already have, make sure they're caught
rpm-build 0fba15
${OSTREE} remote gpg-import --keyring ${test_tmpdir}/gpghome/trusted/pubring.gpg R1 ${TEST_GPG_KEYID_1} ${TEST_GPG_KEYID_3} | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
assert_file_has_content result 'Imported 0 GPG key'
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote delete R1
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote add R1 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
rpm-build 0fba15
# Import all keys from keyring
rpm-build 0fba15
${OSTREE} remote gpg-import --keyring ${test_tmpdir}/gpghome/trusted/pubring.gpg R1 | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
assert_file_has_content result 'Imported 3 GPG key'
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote delete R1
rpm-build 0fba15
rpm-build 0fba15
#-------------------------------------
rpm-build 0fba15
# Test gpg-import with --stdin option
rpm-build 0fba15
#-------------------------------------
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote add R1 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
rpm-build 0fba15
# Import ASCII-armored keys thru stdin
rpm-build 0fba15
cat ${test_tmpdir}/gpghome/key{1,2,3}.asc | ${OSTREE} remote gpg-import --stdin R1 | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
assert_file_has_content result 'Imported 3 GPG key'
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote delete R1
rpm-build 0fba15
rpm-build 0fba15
#------------------------------------------------------------
rpm-build 0fba15
# Divide keys across multiple remotes, test GPG verification
rpm-build 0fba15
# For testing purposes the remotes all point to the same URL
rpm-build 0fba15
# This also tests "remote add" with --gpg-import.
rpm-build 0fba15
#------------------------------------------------------------
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote add --gpg-import ${test_tmpdir}/gpghome/key1.asc R1 $(cat httpd-address)/ostree/gnomerepo | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
assert_file_has_content result 'Imported 1 GPG key'
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote add --gpg-import ${test_tmpdir}/gpghome/key2.asc R2 $(cat httpd-address)/ostree/gnomerepo | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
assert_file_has_content result 'Imported 1 GPG key'
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote add --gpg-import ${test_tmpdir}/gpghome/key3.asc R3 $(cat httpd-address)/ostree/gnomerepo | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
assert_file_has_content result 'Imported 1 GPG key'
rpm-build 0fba15
rpm-build 0fba15
# Checkout the "remote" repo so we can add more commits
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo checkout main workdir
rpm-build 0fba15
rpm-build 0fba15
# Sign a new commit with key1 and try pulling from each remote
rpm-build 0fba15
echo shadow > workdir/blinky
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo commit -b main -s "Add blinky" --gpg-sign ${TEST_GPG_KEYID_1} --gpg-homedir ${test_tmpdir}/gpghome workdir
rpm-build 0fba15
if ${OSTREE} pull R2:main >/dev/null 2>&1; then
rpm-build 0fba15
    assert_not_reached "(key1/R2) GPG verification unexpectedly succeeded"
rpm-build 0fba15
fi
rpm-build 0fba15
if ${OSTREE} pull R3:main >/dev/null 2>&1; then
rpm-build 0fba15
    assert_not_reached "(key1/R3) GPG verification unexpectedly succeeded"
rpm-build 0fba15
fi
rpm-build 0fba15
${OSTREE} pull R1:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
# Sign a new commit with key2 and try pulling from each remote
rpm-build 0fba15
echo speedy > workdir/pinky
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo commit -b main -s "Add pinky" --gpg-sign ${TEST_GPG_KEYID_2} --gpg-homedir ${test_tmpdir}/gpghome workdir
rpm-build 0fba15
if ${OSTREE} pull R1:main >/dev/null 2>&1; then
rpm-build 0fba15
    assert_not_reached "(key2/R1) GPG verification unexpectedly succeeded"
rpm-build 0fba15
fi
rpm-build 0fba15
if ${OSTREE} pull R3:main >/dev/null 2>&1; then
rpm-build 0fba15
    assert_not_reached "(key2/R3) GPG verification unexpectedly succeeded"
rpm-build 0fba15
fi
rpm-build 0fba15
${OSTREE} pull R2:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
# Sign a new commit with key3 and try pulling from each remote
rpm-build 0fba15
echo bashful > workdir/inky
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo commit -b main -s "Add inky" --gpg-sign ${TEST_GPG_KEYID_3} --gpg-homedir ${test_tmpdir}/gpghome workdir
rpm-build 0fba15
if ${OSTREE} pull R1:main >/dev/null 2>&1; then
rpm-build 0fba15
    assert_not_reached "(key3/R1) GPG verification unexpectedly succeeded"
rpm-build 0fba15
fi
rpm-build 0fba15
if ${OSTREE} pull R2:main >/dev/null 2>&1; then
rpm-build 0fba15
    assert_not_reached "(key3/R2) GPG verification unexpectedly succeeded"
rpm-build 0fba15
fi
rpm-build 0fba15
${OSTREE} pull R3:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
echo "ok"
rpm-build 0fba15
rpm-build 0fba15
rm repo/refs/remotes/* -rf
rpm-build 0fba15
${OSTREE} prune --refs-only
rpm-build 0fba15
rpm-build 0fba15
# Test the successful gpgkeypath option
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/key3.asc R4 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
${OSTREE} pull R4:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath success with multiple keys to try
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/key1.asc,${test_tmpdir}/gpghome/key2.asc,${test_tmpdir}/gpghome/key3.asc R7 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
${OSTREE} pull R7:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath failure with multiple keys but none in keyring
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/key1.asc,${test_tmpdir}/gpghome/key2.asc R8 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
if ${OSTREE} pull R8:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling with different key"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt "public key not found"
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath success with directory containing a valid key
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/ R9 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
${OSTREE} pull R9:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath failure with nonexistent directory
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/INVALIDKEYDIRPATH/ R10 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
if ${OSTREE} pull R10:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling with nonexistent key directory"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt "INVALIDKEYDIRPATH.*No such file or directory"
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath failure with a directory containing a valid key, and a nonexistent key
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/,${test_tmpdir}/gpghome/INVALIDKEYPATH.asc R11 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
if ${OSTREE} pull R11:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling with nonexistent key"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt "INVALIDKEYPATH.*No such file or directory"
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath success with a directory containing a valid key, and a key not in keyring
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/,${test_tmpdir}/gpghome/key1.asc R12 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
${OSTREE} pull R12:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath failure with a nonexistent directory, and a valid key
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/INVALIDKEYDIRPATH/,${test_tmpdir}/gpghome/key3.asc R13 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
if ${OSTREE} pull R13:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling with nonexistent key directory"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt "INVALIDKEYDIRPATH.*No such file or directory"
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath failure with a nonexistent directory and a nonexistent key
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/INVALIDKEYDIRPATH/,${test_tmpdir}/gpghome/INVALIDKEYPATH.asc R14 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
if ${OSTREE} pull R14:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling with nonexistent key"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt "INVALIDKEYDIRPATH.*No such file or directory"
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath success for no trailing slash in directory path
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome R15 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
${OSTREE} pull R15:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath failure with prefixed separator giving an empty path, and a nonexistent key
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=,${test_tmpdir}/gpghome/INVALIDKEYPATH.asc R16 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
if ${OSTREE} pull R16:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling with nonexistent key"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt "().*No such file or directory"
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath success with suffixed separator
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/key3.asc, R17 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
${OSTREE} pull R17:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath success with multiple keys specified, with semicolons
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath="${test_tmpdir}/gpghome/key1.asc;${test_tmpdir}/gpghome/key2.asc;${test_tmpdir}/gpghome/key3.asc" R18 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
${OSTREE} pull R18:main >/dev/null
rpm-build 0fba15
rpm-build 0fba15
# Test gpgkeypath failure multiple keys specified, with mix of commas and semicolons
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath="${test_tmpdir}/gpghome/key1.asc,${test_tmpdir}/gpghome/key2.asc;${test_tmpdir}/gpghome/key3.asc" R19 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
if ${OSTREE} pull R19:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling with invalid gpgkeypath value"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt ".*key value list contains more than one separator"
rpm-build 0fba15
rpm-build 0fba15
rm repo/refs/remotes/* -rf
rpm-build 0fba15
${OSTREE} prune --refs-only
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/INVALIDKEYPATH.asc R5 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
if ${OSTREE} pull R5:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling with nonexistent key"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt "INVALIDKEYPATH.*No such file or directory"
rpm-build 0fba15
rpm-build 0fba15
rm repo/refs/remotes/* -rf
rpm-build 0fba15
${OSTREE} prune --refs-only
rpm-build 0fba15
rpm-build 0fba15
${OSTREE} remote add --set=gpgkeypath=${test_tmpdir}/gpghome/key2.asc R6 $(cat httpd-address)/ostree/gnomerepo
rpm-build 0fba15
if ${OSTREE} pull R6:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling with different key"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt "public key not found"
rpm-build 0fba15
rpm-build 0fba15
echo "ok"
rpm-build 0fba15
rpm-build 0fba15
# Test deltas with signed commits; this test is a bit
rpm-build 0fba15
# weird here but this file has separate per-remote keys.
rpm-build 0fba15
cd ${test_tmpdir}
rpm-build 0fba15
rm repo/refs/remotes/* -rf
rpm-build 0fba15
${OSTREE} prune --refs-only
rpm-build 0fba15
echo $(date) > workdir/testfile-for-deltas-1
rpm-build 0fba15
# Sign with keyid 1 for first commit
rpm-build 0fba15
${CMD_PREFIX} ostree  --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main --gpg-sign ${TEST_GPG_KEYID_1} --gpg-homedir ${test_tmpdir}/gpghome workdir
rpm-build 0fba15
prevrev=$(${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo rev-parse main)
rpm-build 0fba15
# Pull the previous revision
rpm-build 0fba15
${OSTREE} pull R1:main
rpm-build 0fba15
assert_streq $(${OSTREE} rev-parse R1:main) ${prevrev}
rpm-build 0fba15
# Sign with keyid 2, but use remote r1
rpm-build 0fba15
echo $(date) > workdir/testfile-for-deltas-2
rpm-build 0fba15
${CMD_PREFIX} ostree  --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main --gpg-sign ${TEST_GPG_KEYID_2} --gpg-homedir ${test_tmpdir}/gpghome workdir
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo static-delta generate main
rpm-build 0fba15
# Summary is signed with key1
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo summary -u --gpg-sign ${TEST_GPG_KEYID_1} --gpg-homedir ${test_tmpdir}/gpghome
rpm-build 0fba15
newrev=$(${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo rev-parse main)
rpm-build 0fba15
if ${OSTREE} pull --require-static-deltas R1:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling commit signed with untrusted key"
rpm-build 0fba15
fi
rpm-build 0fba15
assert_file_has_content err.txt "public key not found"
rpm-build 0fba15
rpm-build 0fba15
echo "ok gpg untrusted signed commit for delta upgrades"
rpm-build 0fba15
rpm-build 0fba15
${CMD_PREFIX} ostree  --repo=${test_tmpdir}/ostree-srv/gnomerepo reset main{,^}
rpm-build 0fba15
${CMD_PREFIX} ostree  --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main --gpg-sign ${TEST_GPG_KEYID_1} --gpg-homedir ${test_tmpdir}/gpghome workdir
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo static-delta generate main
rpm-build 0fba15
${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo summary -u --gpg-sign ${TEST_GPG_KEYID_1} --gpg-homedir ${test_tmpdir}/gpghome
rpm-build 0fba15
${OSTREE} pull --require-static-deltas R1:main
rpm-build 0fba15
rpm-build 0fba15
echo "ok gpg trusted signed commit for delta upgrades"
rpm-build 0fba15
rpm-build 0fba15
# Run some more tests if an appropriate gpg is available
rpm-build 0fba15
GPG=$(which_gpg)
rpm-build 0fba15
if [ -z "${GPG}" ]; then
rpm-build 0fba15
  # Print a skip message per skipped test
rpm-build 0fba15
  for (( i = 0; i < num_gpg_tests; i++ )); do
rpm-build 0fba15
    echo "ok # SKIP this test requires gpg"
rpm-build 0fba15
  done
rpm-build 0fba15
else
rpm-build 0fba15
  # Create a commit signed with keyid 1
rpm-build 0fba15
  echo $(date) > workdir/testfile-for-key-mangling
rpm-build 0fba15
  ${CMD_PREFIX} ostree  --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main --gpg-sign ${TEST_GPG_KEYID_1} --gpg-homedir ${test_tmpdir}/gpghome workdir
rpm-build 0fba15
rpm-build 0fba15
  # Re-add the remote
rpm-build 0fba15
  ${OSTREE} remote delete R1
rpm-build 0fba15
  ${OSTREE} remote add --gpg-import ${test_tmpdir}/gpghome/key1.asc R1 $(cat httpd-address)/ostree/gnomerepo | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
  assert_file_has_content result 'Imported 1 GPG key'
rpm-build 0fba15
rpm-build 0fba15
  # Expire key 1, wait for it to be expired and import the expired key. Only
rpm-build 0fba15
  # new keys are reported.
rpm-build 0fba15
  ${GPG} --homedir=${test_tmpdir}/gpghome --quick-set-expire ${TEST_GPG_KEYFPR_1} seconds=1
rpm-build 0fba15
  sleep 2
rpm-build 0fba15
  ${GPG} --homedir=${test_tmpdir}/gpghome --armor --export ${TEST_GPG_KEYID_1} > ${test_tmpdir}/key1expired.asc
rpm-build 0fba15
  ${OSTREE} remote gpg-import --keyring ${test_tmpdir}/key1expired.asc R1 | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
  assert_file_has_content result 'Imported 0 GPG key'
rpm-build 0fba15
rpm-build 0fba15
  # Pulling should fail since the key is expired
rpm-build 0fba15
  rm repo/refs/remotes/* -rf
rpm-build 0fba15
  ${OSTREE} prune --refs-only
rpm-build 0fba15
  if ${OSTREE} pull R1:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling commit signed with expired key"
rpm-build 0fba15
  fi
rpm-build 0fba15
  assert_file_has_content err.txt "Key expired"
rpm-build 0fba15
rpm-build 0fba15
  echo "ok imported expired key"
rpm-build 0fba15
rpm-build 0fba15
  # Unexpire keyid 1 and revoke it. Revoking is done by importing the
rpm-build 0fba15
  # pre-generated revocation certificate.
rpm-build 0fba15
  ${GPG} --homedir=${test_tmpdir}/gpghome --quick-set-expire ${TEST_GPG_KEYFPR_1} seconds=0
rpm-build 0fba15
  ${GPG} --homedir=${TEST_GPG_KEYHOME} --import ${TEST_GPG_KEYHOME}/revocations/key1.rev
rpm-build 0fba15
  ${GPG} --homedir=${test_tmpdir}/gpghome --armor --export ${TEST_GPG_KEYID_1} > ${test_tmpdir}/key1revoked.asc
rpm-build 0fba15
  ${OSTREE} remote gpg-import --keyring ${test_tmpdir}/key1revoked.asc R1 | grep -o 'Imported [[:digit:]] GPG key' > result
rpm-build 0fba15
  assert_file_has_content result 'Imported 0 GPG key'
rpm-build 0fba15
rpm-build 0fba15
  # Pulling should fail since the key is revoked
rpm-build 0fba15
  rm repo/refs/remotes/* -rf
rpm-build 0fba15
  ${OSTREE} prune --refs-only
rpm-build 0fba15
  if ${OSTREE} pull R1:main 2>err.txt; then
rpm-build 0fba15
    assert_not_reached "Unexpectedly succeeded at pulling commit signed with revoked key"
rpm-build 0fba15
  fi
rpm-build 0fba15
  assert_file_has_content err.txt "Key revoked"
rpm-build 0fba15
rpm-build 0fba15
  echo "ok imported revoked key"
rpm-build 0fba15
fi