12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #!/bin/sh -ex
- # vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
- #
- # Copyright (c) 2016 Red Hat, Inc.
- # Author: Nathaniel McCallum <npmccallum@redhat.com>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- fetch() {
- curl -sfg "http://127.0.0.1:${PORT}${1}"
- }
- ver() {
- jose jws ver -i- -k "${1}"
- }
- random_port() {
- if [ -n "${TANG_BSD}" ]; then
- jot -r 1 1024 65536
- else
- shuf -i 1024-65536 -n 1
- fi
- }
- start_server() {
- "${SOCAT}" TCP-LISTEN:"${1}",bind=127.0.0.1,fork SYSTEM:"${VALGRIND} tangd ${TMP}/db" &
- }
- on_exit() {
- if [ "$PID" ]; then kill "${PID}"; wait "${PID}" || true; fi
- [ -d "${TMP}" ] && rm -rf "${TMP}"
- }
- validate() {
- if ! _jwks="$(jose fmt --json="${1}" -Og payload -SyOg keys \
- -AUo- 2>/dev/null)"; then
- echo "Advertisement is malformed" >&2
- exit 1
- fi
- _ver="$(printf '%s' "${_jwks}" | jose jwk use -i- -r -u verify -o-)"
- if ! printf '%s' "${_ver}" | jose jws ver -i "${1}" -k- -a; then
- echo "Advertisement is missing signatures" >&2
- exit 1
- fi
- }
- validate_sig() {
- jose fmt --json "${1}" --output=- | jose jwk use --input=- --required \
- --use verify 2>/dev/null
- }
- validate_exc() {
- jose fmt --json "${1}" --output=- | jose jwk use --input=- --required \
- --use deriveKey 2>/dev/null
- }
- sanity_check() {
- # Skip test if socat is not available.
- [ -n "${SOCAT}" ] || exit 77
- }
- die() {
- echo "${1}" >&2
- exit 1
- }
- valid_key_perm() {
- if [ -n "${TANG_BSD}" ]; then
- _perm="$(stat -f %Lp "${1}")"
- else
- _perm="$(stat -c %a "${1}")"
- fi
- [ "${_perm}" = "440" ]
- }
- expected_fail () {
- echo "Test was expected to fail" >&2
- exit 1
- }
|